@mastra/lance 0.0.0-fix-backport-setserver-20251201151948 → 0.0.0-fix-request-context-as-query-key-20251209130646
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 +524 -44
- package/README.md +61 -4
- package/dist/index.cjs +412 -735
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +412 -735
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +15 -39
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +14 -6
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +4 -11
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +57 -90
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/filter.d.ts +5 -5
- package/dist/vector/index.d.ts +3 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +13 -15
- package/dist/storage/domains/legacy-evals/index.d.ts +0 -25
- package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
- package/dist/storage/domains/traces/index.d.ts +0 -34
- package/dist/storage/domains/traces/index.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -5,131 +5,15 @@ var error = require('@mastra/core/error');
|
|
|
5
5
|
var storage = require('@mastra/core/storage');
|
|
6
6
|
var agent = require('@mastra/core/agent');
|
|
7
7
|
var apacheArrow = require('apache-arrow');
|
|
8
|
-
var
|
|
8
|
+
var evals = require('@mastra/core/evals');
|
|
9
9
|
var vector = require('@mastra/core/vector');
|
|
10
10
|
var filter = require('@mastra/core/vector/filter');
|
|
11
11
|
|
|
12
12
|
// src/storage/index.ts
|
|
13
|
-
var StoreLegacyEvalsLance = class extends storage.LegacyEvalsStorage {
|
|
14
|
-
client;
|
|
15
|
-
constructor({ client }) {
|
|
16
|
-
super();
|
|
17
|
-
this.client = client;
|
|
18
|
-
}
|
|
19
|
-
async getEvalsByAgentName(agentName, type) {
|
|
20
|
-
try {
|
|
21
|
-
const table = await this.client.openTable(storage.TABLE_EVALS);
|
|
22
|
-
const query = table.query().where(`agent_name = '${agentName}'`);
|
|
23
|
-
const records = await query.toArray();
|
|
24
|
-
let filteredRecords = records;
|
|
25
|
-
if (type === "live") {
|
|
26
|
-
filteredRecords = records.filter((record) => record.test_info === null);
|
|
27
|
-
} else if (type === "test") {
|
|
28
|
-
filteredRecords = records.filter((record) => record.test_info !== null);
|
|
29
|
-
}
|
|
30
|
-
return filteredRecords.map((record) => {
|
|
31
|
-
return {
|
|
32
|
-
id: record.id,
|
|
33
|
-
input: record.input,
|
|
34
|
-
output: record.output,
|
|
35
|
-
agentName: record.agent_name,
|
|
36
|
-
metricName: record.metric_name,
|
|
37
|
-
result: JSON.parse(record.result),
|
|
38
|
-
instructions: record.instructions,
|
|
39
|
-
testInfo: record.test_info ? JSON.parse(record.test_info) : null,
|
|
40
|
-
globalRunId: record.global_run_id,
|
|
41
|
-
runId: record.run_id,
|
|
42
|
-
createdAt: new Date(record.created_at).toString()
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
} catch (error$1) {
|
|
46
|
-
throw new error.MastraError(
|
|
47
|
-
{
|
|
48
|
-
id: "LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
49
|
-
domain: error.ErrorDomain.STORAGE,
|
|
50
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
51
|
-
details: { agentName }
|
|
52
|
-
},
|
|
53
|
-
error$1
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async getEvals(options) {
|
|
58
|
-
try {
|
|
59
|
-
const table = await this.client.openTable(storage.TABLE_EVALS);
|
|
60
|
-
const conditions = [];
|
|
61
|
-
if (options.agentName) {
|
|
62
|
-
conditions.push(`agent_name = '${options.agentName}'`);
|
|
63
|
-
}
|
|
64
|
-
if (options.type === "live") {
|
|
65
|
-
conditions.push("test_info IS NULL");
|
|
66
|
-
} else if (options.type === "test") {
|
|
67
|
-
conditions.push("test_info IS NOT NULL");
|
|
68
|
-
}
|
|
69
|
-
const startDate = options.dateRange?.start || options.fromDate;
|
|
70
|
-
const endDate = options.dateRange?.end || options.toDate;
|
|
71
|
-
if (startDate) {
|
|
72
|
-
conditions.push(`\`created_at\` >= ${startDate.getTime()}`);
|
|
73
|
-
}
|
|
74
|
-
if (endDate) {
|
|
75
|
-
conditions.push(`\`created_at\` <= ${endDate.getTime()}`);
|
|
76
|
-
}
|
|
77
|
-
let total = 0;
|
|
78
|
-
if (conditions.length > 0) {
|
|
79
|
-
total = await table.countRows(conditions.join(" AND "));
|
|
80
|
-
} else {
|
|
81
|
-
total = await table.countRows();
|
|
82
|
-
}
|
|
83
|
-
const query = table.query();
|
|
84
|
-
if (conditions.length > 0) {
|
|
85
|
-
const whereClause = conditions.join(" AND ");
|
|
86
|
-
query.where(whereClause);
|
|
87
|
-
}
|
|
88
|
-
const records = await query.toArray();
|
|
89
|
-
const evals = records.sort((a, b) => b.created_at - a.created_at).map((record) => {
|
|
90
|
-
return {
|
|
91
|
-
id: record.id,
|
|
92
|
-
input: record.input,
|
|
93
|
-
output: record.output,
|
|
94
|
-
agentName: record.agent_name,
|
|
95
|
-
metricName: record.metric_name,
|
|
96
|
-
result: JSON.parse(record.result),
|
|
97
|
-
instructions: record.instructions,
|
|
98
|
-
testInfo: record.test_info ? JSON.parse(record.test_info) : null,
|
|
99
|
-
globalRunId: record.global_run_id,
|
|
100
|
-
runId: record.run_id,
|
|
101
|
-
createdAt: new Date(record.created_at).toISOString()
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
const page = options.page || 0;
|
|
105
|
-
const perPage = options.perPage || 10;
|
|
106
|
-
const pagedEvals = evals.slice(page * perPage, (page + 1) * perPage);
|
|
107
|
-
return {
|
|
108
|
-
evals: pagedEvals,
|
|
109
|
-
total,
|
|
110
|
-
page,
|
|
111
|
-
perPage,
|
|
112
|
-
hasMore: total > (page + 1) * perPage
|
|
113
|
-
};
|
|
114
|
-
} catch (error$1) {
|
|
115
|
-
throw new error.MastraError(
|
|
116
|
-
{
|
|
117
|
-
id: "LANCE_STORE_GET_EVALS_FAILED",
|
|
118
|
-
domain: error.ErrorDomain.STORAGE,
|
|
119
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
120
|
-
details: { agentName: options.agentName ?? "" }
|
|
121
|
-
},
|
|
122
|
-
error$1
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
13
|
function getPrimaryKeys(tableName) {
|
|
128
14
|
let primaryId = ["id"];
|
|
129
15
|
if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
|
|
130
16
|
primaryId = ["workflow_name", "run_id"];
|
|
131
|
-
} else if (tableName === storage.TABLE_EVALS) {
|
|
132
|
-
primaryId = ["agent_name", "metric_name", "run_id"];
|
|
133
17
|
}
|
|
134
18
|
return primaryId;
|
|
135
19
|
}
|
|
@@ -207,7 +91,7 @@ async function getTableSchema({
|
|
|
207
91
|
} catch (validationError) {
|
|
208
92
|
throw new error.MastraError(
|
|
209
93
|
{
|
|
210
|
-
id: "
|
|
94
|
+
id: storage.createStorageErrorId("LANCE", "GET_TABLE_SCHEMA", "INVALID_ARGS"),
|
|
211
95
|
domain: error.ErrorDomain.STORAGE,
|
|
212
96
|
category: error.ErrorCategory.USER,
|
|
213
97
|
text: validationError.message,
|
|
@@ -230,7 +114,7 @@ async function getTableSchema({
|
|
|
230
114
|
} catch (error$1) {
|
|
231
115
|
throw new error.MastraError(
|
|
232
116
|
{
|
|
233
|
-
id: "
|
|
117
|
+
id: storage.createStorageErrorId("LANCE", "GET_TABLE_SCHEMA", "FAILED"),
|
|
234
118
|
domain: error.ErrorDomain.STORAGE,
|
|
235
119
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
236
120
|
details: { tableName }
|
|
@@ -249,6 +133,10 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
249
133
|
this.client = client;
|
|
250
134
|
this.operations = operations;
|
|
251
135
|
}
|
|
136
|
+
// Utility to escape single quotes in SQL strings
|
|
137
|
+
escapeSql(str) {
|
|
138
|
+
return str.replace(/'/g, "''");
|
|
139
|
+
}
|
|
252
140
|
async getThreadById({ threadId }) {
|
|
253
141
|
try {
|
|
254
142
|
const thread = await this.operations.load({ tableName: storage.TABLE_THREADS, keys: { id: threadId } });
|
|
@@ -263,27 +151,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
263
151
|
} catch (error$1) {
|
|
264
152
|
throw new error.MastraError(
|
|
265
153
|
{
|
|
266
|
-
id: "
|
|
267
|
-
domain: error.ErrorDomain.STORAGE,
|
|
268
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
269
|
-
},
|
|
270
|
-
error$1
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
async getThreadsByResourceId({ resourceId }) {
|
|
275
|
-
try {
|
|
276
|
-
const table = await this.client.openTable(storage.TABLE_THREADS);
|
|
277
|
-
const query = table.query().where(`\`resourceId\` = '${resourceId}'`);
|
|
278
|
-
const records = await query.toArray();
|
|
279
|
-
return processResultWithTypeConversion(
|
|
280
|
-
records,
|
|
281
|
-
await getTableSchema({ tableName: storage.TABLE_THREADS, client: this.client })
|
|
282
|
-
);
|
|
283
|
-
} catch (error$1) {
|
|
284
|
-
throw new error.MastraError(
|
|
285
|
-
{
|
|
286
|
-
id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
|
|
154
|
+
id: storage.createStorageErrorId("LANCE", "GET_THREAD_BY_ID", "FAILED"),
|
|
287
155
|
domain: error.ErrorDomain.STORAGE,
|
|
288
156
|
category: error.ErrorCategory.THIRD_PARTY
|
|
289
157
|
},
|
|
@@ -305,7 +173,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
305
173
|
} catch (error$1) {
|
|
306
174
|
throw new error.MastraError(
|
|
307
175
|
{
|
|
308
|
-
id: "
|
|
176
|
+
id: storage.createStorageErrorId("LANCE", "SAVE_THREAD", "FAILED"),
|
|
309
177
|
domain: error.ErrorDomain.STORAGE,
|
|
310
178
|
category: error.ErrorCategory.THIRD_PARTY
|
|
311
179
|
},
|
|
@@ -347,7 +215,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
347
215
|
}
|
|
348
216
|
throw new error.MastraError(
|
|
349
217
|
{
|
|
350
|
-
id: "
|
|
218
|
+
id: storage.createStorageErrorId("LANCE", "UPDATE_THREAD", "FAILED"),
|
|
351
219
|
domain: error.ErrorDomain.STORAGE,
|
|
352
220
|
category: error.ErrorCategory.THIRD_PARTY
|
|
353
221
|
},
|
|
@@ -357,7 +225,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
357
225
|
}
|
|
358
226
|
throw new error.MastraError(
|
|
359
227
|
{
|
|
360
|
-
id: "
|
|
228
|
+
id: storage.createStorageErrorId("LANCE", "UPDATE_THREAD", "FAILED"),
|
|
361
229
|
domain: error.ErrorDomain.STORAGE,
|
|
362
230
|
category: error.ErrorCategory.THIRD_PARTY
|
|
363
231
|
},
|
|
@@ -373,7 +241,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
373
241
|
} catch (error$1) {
|
|
374
242
|
throw new error.MastraError(
|
|
375
243
|
{
|
|
376
|
-
id: "
|
|
244
|
+
id: storage.createStorageErrorId("LANCE", "DELETE_THREAD", "FAILED"),
|
|
377
245
|
domain: error.ErrorDomain.STORAGE,
|
|
378
246
|
category: error.ErrorCategory.THIRD_PARTY
|
|
379
247
|
},
|
|
@@ -395,100 +263,176 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
395
263
|
})() : message.content
|
|
396
264
|
};
|
|
397
265
|
}
|
|
398
|
-
async
|
|
399
|
-
|
|
400
|
-
resourceId,
|
|
401
|
-
selectBy,
|
|
402
|
-
format,
|
|
403
|
-
threadConfig
|
|
404
|
-
}) {
|
|
266
|
+
async listMessagesById({ messageIds }) {
|
|
267
|
+
if (messageIds.length === 0) return { messages: [] };
|
|
405
268
|
try {
|
|
406
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
407
|
-
if (threadConfig) {
|
|
408
|
-
throw new Error("ThreadConfig is not supported by LanceDB storage");
|
|
409
|
-
}
|
|
410
|
-
const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
411
269
|
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const threadIds = [...new Set(selectBy.include.map((item) => item.threadId))];
|
|
415
|
-
for (const threadId2 of threadIds) {
|
|
416
|
-
const threadQuery = table.query().where(`thread_id = '${threadId2}'`);
|
|
417
|
-
let threadRecords = await threadQuery.toArray();
|
|
418
|
-
allRecords.push(...threadRecords);
|
|
419
|
-
}
|
|
420
|
-
} else {
|
|
421
|
-
let query = table.query().where(`\`thread_id\` = '${threadId}'`);
|
|
422
|
-
allRecords = await query.toArray();
|
|
423
|
-
}
|
|
424
|
-
allRecords.sort((a, b) => {
|
|
425
|
-
const dateA = new Date(a.createdAt).getTime();
|
|
426
|
-
const dateB = new Date(b.createdAt).getTime();
|
|
427
|
-
return dateA - dateB;
|
|
428
|
-
});
|
|
429
|
-
if (selectBy?.include && selectBy.include.length > 0) {
|
|
430
|
-
allRecords = this.processMessagesWithContext(allRecords, selectBy.include);
|
|
431
|
-
}
|
|
432
|
-
if (limit !== Number.MAX_SAFE_INTEGER) {
|
|
433
|
-
allRecords = allRecords.slice(-limit);
|
|
434
|
-
}
|
|
270
|
+
const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
|
|
271
|
+
const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
|
|
435
272
|
const messages = processResultWithTypeConversion(
|
|
436
273
|
allRecords,
|
|
437
274
|
await getTableSchema({ tableName: storage.TABLE_MESSAGES, client: this.client })
|
|
438
275
|
);
|
|
439
|
-
const list = new agent.MessageList(
|
|
440
|
-
|
|
441
|
-
|
|
276
|
+
const list = new agent.MessageList().add(
|
|
277
|
+
messages.map(this.normalizeMessage),
|
|
278
|
+
"memory"
|
|
279
|
+
);
|
|
280
|
+
return { messages: list.get.all.db() };
|
|
442
281
|
} catch (error$1) {
|
|
443
282
|
throw new error.MastraError(
|
|
444
283
|
{
|
|
445
|
-
id: "
|
|
284
|
+
id: storage.createStorageErrorId("LANCE", "LIST_MESSAGES_BY_ID", "FAILED"),
|
|
446
285
|
domain: error.ErrorDomain.STORAGE,
|
|
447
286
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
448
287
|
details: {
|
|
449
|
-
|
|
450
|
-
resourceId: resourceId ?? ""
|
|
288
|
+
messageIds: JSON.stringify(messageIds)
|
|
451
289
|
}
|
|
452
290
|
},
|
|
453
291
|
error$1
|
|
454
292
|
);
|
|
455
293
|
}
|
|
456
294
|
}
|
|
457
|
-
async
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
295
|
+
async listMessages(args) {
|
|
296
|
+
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
297
|
+
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
298
|
+
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
299
|
+
throw new error.MastraError(
|
|
300
|
+
{
|
|
301
|
+
id: storage.createStorageErrorId("LANCE", "LIST_MESSAGES", "INVALID_THREAD_ID"),
|
|
302
|
+
domain: error.ErrorDomain.STORAGE,
|
|
303
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
304
|
+
details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
|
|
305
|
+
},
|
|
306
|
+
new Error("threadId must be a non-empty string or array of non-empty strings")
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
const perPage = storage.normalizePerPage(perPageInput, 40);
|
|
310
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
462
311
|
try {
|
|
312
|
+
if (page < 0) {
|
|
313
|
+
throw new error.MastraError(
|
|
314
|
+
{
|
|
315
|
+
id: storage.createStorageErrorId("LANCE", "LIST_MESSAGES", "INVALID_PAGE"),
|
|
316
|
+
domain: error.ErrorDomain.STORAGE,
|
|
317
|
+
category: error.ErrorCategory.USER,
|
|
318
|
+
details: { page }
|
|
319
|
+
},
|
|
320
|
+
new Error("page must be >= 0")
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
463
324
|
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
)
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
325
|
+
const threadCondition = threadIds.length === 1 ? `thread_id = '${this.escapeSql(threadIds[0])}'` : `thread_id IN (${threadIds.map((t) => `'${this.escapeSql(t)}'`).join(", ")})`;
|
|
326
|
+
const conditions = [threadCondition];
|
|
327
|
+
if (resourceId) {
|
|
328
|
+
conditions.push(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
|
|
329
|
+
}
|
|
330
|
+
if (filter?.dateRange?.start) {
|
|
331
|
+
const startTime = filter.dateRange.start instanceof Date ? filter.dateRange.start.getTime() : new Date(filter.dateRange.start).getTime();
|
|
332
|
+
conditions.push(`\`createdAt\` >= ${startTime}`);
|
|
333
|
+
}
|
|
334
|
+
if (filter?.dateRange?.end) {
|
|
335
|
+
const endTime = filter.dateRange.end instanceof Date ? filter.dateRange.end.getTime() : new Date(filter.dateRange.end).getTime();
|
|
336
|
+
conditions.push(`\`createdAt\` <= ${endTime}`);
|
|
337
|
+
}
|
|
338
|
+
const whereClause = conditions.join(" AND ");
|
|
339
|
+
const total = await table.countRows(whereClause);
|
|
340
|
+
const query = table.query().where(whereClause);
|
|
341
|
+
let allRecords = await query.toArray();
|
|
342
|
+
allRecords.sort((a, b) => {
|
|
343
|
+
const aValue = field === "createdAt" ? a.createdAt : a[field];
|
|
344
|
+
const bValue = field === "createdAt" ? b.createdAt : b[field];
|
|
345
|
+
if (aValue == null && bValue == null) return 0;
|
|
346
|
+
if (aValue == null) return direction === "ASC" ? -1 : 1;
|
|
347
|
+
if (bValue == null) return direction === "ASC" ? 1 : -1;
|
|
348
|
+
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
349
|
+
return direction === "ASC" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
|
|
350
|
+
}
|
|
351
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
352
|
+
});
|
|
353
|
+
const paginatedRecords = allRecords.slice(offset, offset + perPage);
|
|
354
|
+
const messages = paginatedRecords.map((row) => this.normalizeMessage(row));
|
|
355
|
+
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
356
|
+
return {
|
|
357
|
+
messages: [],
|
|
358
|
+
total: 0,
|
|
359
|
+
page,
|
|
360
|
+
perPage: perPageForResponse,
|
|
361
|
+
hasMore: false
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
const messageIds = new Set(messages.map((m) => m.id));
|
|
365
|
+
if (include && include.length > 0) {
|
|
366
|
+
const threadIds2 = [...new Set(include.map((item) => item.threadId || threadId))];
|
|
367
|
+
const allThreadMessages = [];
|
|
368
|
+
for (const tid of threadIds2) {
|
|
369
|
+
const threadQuery = table.query().where(`thread_id = '${tid}'`);
|
|
370
|
+
let threadRecords = await threadQuery.toArray();
|
|
371
|
+
allThreadMessages.push(...threadRecords);
|
|
372
|
+
}
|
|
373
|
+
allThreadMessages.sort((a, b) => a.createdAt - b.createdAt);
|
|
374
|
+
const contextMessages = this.processMessagesWithContext(allThreadMessages, include);
|
|
375
|
+
const includedMessages = contextMessages.map((row) => this.normalizeMessage(row));
|
|
376
|
+
for (const includeMsg of includedMessages) {
|
|
377
|
+
if (!messageIds.has(includeMsg.id)) {
|
|
378
|
+
messages.push(includeMsg);
|
|
379
|
+
messageIds.add(includeMsg.id);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const list = new agent.MessageList().add(messages, "memory");
|
|
384
|
+
let finalMessages = list.get.all.db();
|
|
385
|
+
finalMessages = finalMessages.sort((a, b) => {
|
|
386
|
+
const aValue = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
|
|
387
|
+
const bValue = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
|
|
388
|
+
if (aValue == null && bValue == null) return 0;
|
|
389
|
+
if (aValue == null) return direction === "ASC" ? -1 : 1;
|
|
390
|
+
if (bValue == null) return direction === "ASC" ? 1 : -1;
|
|
391
|
+
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
392
|
+
return direction === "ASC" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
|
|
393
|
+
}
|
|
394
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
395
|
+
});
|
|
396
|
+
const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
|
|
397
|
+
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
398
|
+
const fetchedAll = perPageInput === false || allThreadMessagesReturned;
|
|
399
|
+
const hasMore = !fetchedAll && offset + perPage < total;
|
|
400
|
+
return {
|
|
401
|
+
messages: finalMessages,
|
|
402
|
+
total,
|
|
403
|
+
page,
|
|
404
|
+
perPage: perPageForResponse,
|
|
405
|
+
hasMore
|
|
406
|
+
};
|
|
473
407
|
} catch (error$1) {
|
|
474
|
-
|
|
408
|
+
const mastraError = new error.MastraError(
|
|
475
409
|
{
|
|
476
|
-
id: "
|
|
410
|
+
id: storage.createStorageErrorId("LANCE", "LIST_MESSAGES", "FAILED"),
|
|
477
411
|
domain: error.ErrorDomain.STORAGE,
|
|
478
412
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
479
413
|
details: {
|
|
480
|
-
|
|
414
|
+
threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
|
|
415
|
+
resourceId: resourceId ?? ""
|
|
481
416
|
}
|
|
482
417
|
},
|
|
483
418
|
error$1
|
|
484
419
|
);
|
|
420
|
+
this.logger?.error?.(mastraError.toString());
|
|
421
|
+
this.logger?.trackException?.(mastraError);
|
|
422
|
+
return {
|
|
423
|
+
messages: [],
|
|
424
|
+
total: 0,
|
|
425
|
+
page,
|
|
426
|
+
perPage: perPageForResponse,
|
|
427
|
+
hasMore: false
|
|
428
|
+
};
|
|
485
429
|
}
|
|
486
430
|
}
|
|
487
431
|
async saveMessages(args) {
|
|
488
432
|
try {
|
|
489
|
-
const { messages
|
|
433
|
+
const { messages } = args;
|
|
490
434
|
if (messages.length === 0) {
|
|
491
|
-
return [];
|
|
435
|
+
return { messages: [] };
|
|
492
436
|
}
|
|
493
437
|
const threadId = messages[0]?.threadId;
|
|
494
438
|
if (!threadId) {
|
|
@@ -524,12 +468,11 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
524
468
|
const updateRecord = { id: threadId, updatedAt: currentTime };
|
|
525
469
|
await threadsTable.mergeInsert("id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([updateRecord]);
|
|
526
470
|
const list = new agent.MessageList().add(messages, "memory");
|
|
527
|
-
|
|
528
|
-
return list.get.all.v1();
|
|
471
|
+
return { messages: list.get.all.db() };
|
|
529
472
|
} catch (error$1) {
|
|
530
473
|
throw new error.MastraError(
|
|
531
474
|
{
|
|
532
|
-
id: "
|
|
475
|
+
id: storage.createStorageErrorId("LANCE", "SAVE_MESSAGES", "FAILED"),
|
|
533
476
|
domain: error.ErrorDomain.STORAGE,
|
|
534
477
|
category: error.ErrorCategory.THIRD_PARTY
|
|
535
478
|
},
|
|
@@ -537,32 +480,54 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
537
480
|
);
|
|
538
481
|
}
|
|
539
482
|
}
|
|
540
|
-
async
|
|
483
|
+
async listThreadsByResourceId(args) {
|
|
541
484
|
try {
|
|
542
|
-
const { resourceId, page = 0, perPage
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
485
|
+
const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
|
|
486
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
487
|
+
if (page < 0) {
|
|
488
|
+
throw new error.MastraError(
|
|
489
|
+
{
|
|
490
|
+
id: storage.createStorageErrorId("LANCE", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
491
|
+
domain: error.ErrorDomain.STORAGE,
|
|
492
|
+
category: error.ErrorCategory.USER,
|
|
493
|
+
details: { page }
|
|
494
|
+
},
|
|
495
|
+
new Error("page must be >= 0")
|
|
496
|
+
);
|
|
550
497
|
}
|
|
498
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
499
|
+
const { field, direction } = this.parseOrderBy(orderBy);
|
|
500
|
+
const table = await this.client.openTable(storage.TABLE_THREADS);
|
|
501
|
+
const total = await table.countRows(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
|
|
502
|
+
const query = table.query().where(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
|
|
551
503
|
const records = await query.toArray();
|
|
552
|
-
records.sort((a, b) =>
|
|
504
|
+
records.sort((a, b) => {
|
|
505
|
+
const aValue = ["createdAt", "updatedAt"].includes(field) ? new Date(a[field]).getTime() : a[field];
|
|
506
|
+
const bValue = ["createdAt", "updatedAt"].includes(field) ? new Date(b[field]).getTime() : b[field];
|
|
507
|
+
if (aValue == null && bValue == null) return 0;
|
|
508
|
+
if (aValue == null) return direction === "ASC" ? -1 : 1;
|
|
509
|
+
if (bValue == null) return direction === "ASC" ? 1 : -1;
|
|
510
|
+
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
511
|
+
return direction === "ASC" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
|
|
512
|
+
}
|
|
513
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
514
|
+
});
|
|
515
|
+
const paginatedRecords = records.slice(offset, offset + perPage);
|
|
553
516
|
const schema = await getTableSchema({ tableName: storage.TABLE_THREADS, client: this.client });
|
|
554
|
-
const threads =
|
|
517
|
+
const threads = paginatedRecords.map(
|
|
518
|
+
(record) => processResultWithTypeConversion(record, schema)
|
|
519
|
+
);
|
|
555
520
|
return {
|
|
556
521
|
threads,
|
|
557
522
|
total,
|
|
558
523
|
page,
|
|
559
|
-
perPage,
|
|
560
|
-
hasMore:
|
|
524
|
+
perPage: perPageForResponse,
|
|
525
|
+
hasMore: offset + perPage < total
|
|
561
526
|
};
|
|
562
527
|
} catch (error$1) {
|
|
563
528
|
throw new error.MastraError(
|
|
564
529
|
{
|
|
565
|
-
id: "
|
|
530
|
+
id: storage.createStorageErrorId("LANCE", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
|
|
566
531
|
domain: error.ErrorDomain.STORAGE,
|
|
567
532
|
category: error.ErrorCategory.THIRD_PARTY
|
|
568
533
|
},
|
|
@@ -618,132 +583,8 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
618
583
|
});
|
|
619
584
|
return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
|
|
620
585
|
}
|
|
621
|
-
async getMessagesPaginated(args) {
|
|
622
|
-
const { threadId, resourceId, selectBy, format = "v1" } = args;
|
|
623
|
-
const page = selectBy?.pagination?.page ?? 0;
|
|
624
|
-
const perPage = selectBy?.pagination?.perPage ?? 10;
|
|
625
|
-
try {
|
|
626
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
627
|
-
const dateRange = selectBy?.pagination?.dateRange;
|
|
628
|
-
const fromDate = dateRange?.start;
|
|
629
|
-
const toDate = dateRange?.end;
|
|
630
|
-
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
631
|
-
const messages = [];
|
|
632
|
-
if (selectBy?.include && Array.isArray(selectBy.include)) {
|
|
633
|
-
const threadIds = [...new Set(selectBy.include.map((item) => item.threadId))];
|
|
634
|
-
const allThreadMessages = [];
|
|
635
|
-
for (const threadId2 of threadIds) {
|
|
636
|
-
const threadQuery = table.query().where(`thread_id = '${threadId2}'`);
|
|
637
|
-
let threadRecords = await threadQuery.toArray();
|
|
638
|
-
if (fromDate) threadRecords = threadRecords.filter((m) => m.createdAt >= fromDate.getTime());
|
|
639
|
-
if (toDate) threadRecords = threadRecords.filter((m) => m.createdAt <= toDate.getTime());
|
|
640
|
-
allThreadMessages.push(...threadRecords);
|
|
641
|
-
}
|
|
642
|
-
allThreadMessages.sort((a, b) => a.createdAt - b.createdAt);
|
|
643
|
-
const contextMessages = this.processMessagesWithContext(allThreadMessages, selectBy.include);
|
|
644
|
-
messages.push(...contextMessages);
|
|
645
|
-
}
|
|
646
|
-
const conditions = [`thread_id = '${threadId}'`];
|
|
647
|
-
if (resourceId) {
|
|
648
|
-
conditions.push(`\`resourceId\` = '${resourceId}'`);
|
|
649
|
-
}
|
|
650
|
-
if (fromDate) {
|
|
651
|
-
conditions.push(`\`createdAt\` >= ${fromDate.getTime()}`);
|
|
652
|
-
}
|
|
653
|
-
if (toDate) {
|
|
654
|
-
conditions.push(`\`createdAt\` <= ${toDate.getTime()}`);
|
|
655
|
-
}
|
|
656
|
-
let total = 0;
|
|
657
|
-
if (conditions.length > 0) {
|
|
658
|
-
total = await table.countRows(conditions.join(" AND "));
|
|
659
|
-
} else {
|
|
660
|
-
total = await table.countRows();
|
|
661
|
-
}
|
|
662
|
-
if (total === 0 && messages.length === 0) {
|
|
663
|
-
return {
|
|
664
|
-
messages: [],
|
|
665
|
-
total: 0,
|
|
666
|
-
page,
|
|
667
|
-
perPage,
|
|
668
|
-
hasMore: false
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
const excludeIds = messages.map((m) => m.id);
|
|
672
|
-
let selectedMessages = [];
|
|
673
|
-
if (selectBy?.last && selectBy.last > 0) {
|
|
674
|
-
const query = table.query();
|
|
675
|
-
if (conditions.length > 0) {
|
|
676
|
-
query.where(conditions.join(" AND "));
|
|
677
|
-
}
|
|
678
|
-
let records = await query.toArray();
|
|
679
|
-
records = records.sort((a, b) => a.createdAt - b.createdAt);
|
|
680
|
-
if (excludeIds.length > 0) {
|
|
681
|
-
records = records.filter((m) => !excludeIds.includes(m.id));
|
|
682
|
-
}
|
|
683
|
-
selectedMessages = records.slice(-selectBy.last);
|
|
684
|
-
} else {
|
|
685
|
-
const query = table.query();
|
|
686
|
-
if (conditions.length > 0) {
|
|
687
|
-
query.where(conditions.join(" AND "));
|
|
688
|
-
}
|
|
689
|
-
let records = await query.toArray();
|
|
690
|
-
records = records.sort((a, b) => a.createdAt - b.createdAt);
|
|
691
|
-
if (excludeIds.length > 0) {
|
|
692
|
-
records = records.filter((m) => !excludeIds.includes(m.id));
|
|
693
|
-
}
|
|
694
|
-
selectedMessages = records.slice(page * perPage, (page + 1) * perPage);
|
|
695
|
-
}
|
|
696
|
-
const allMessages = [...messages, ...selectedMessages];
|
|
697
|
-
const seen = /* @__PURE__ */ new Set();
|
|
698
|
-
const dedupedMessages = allMessages.filter((m) => {
|
|
699
|
-
const key = `${m.id}:${m.thread_id}`;
|
|
700
|
-
if (seen.has(key)) return false;
|
|
701
|
-
seen.add(key);
|
|
702
|
-
return true;
|
|
703
|
-
});
|
|
704
|
-
const formattedMessages = dedupedMessages.map((msg) => {
|
|
705
|
-
const { thread_id, ...rest } = msg;
|
|
706
|
-
return {
|
|
707
|
-
...rest,
|
|
708
|
-
threadId: thread_id,
|
|
709
|
-
content: typeof msg.content === "string" ? (() => {
|
|
710
|
-
try {
|
|
711
|
-
return JSON.parse(msg.content);
|
|
712
|
-
} catch {
|
|
713
|
-
return msg.content;
|
|
714
|
-
}
|
|
715
|
-
})() : msg.content
|
|
716
|
-
};
|
|
717
|
-
});
|
|
718
|
-
const list = new agent.MessageList().add(formattedMessages, "memory");
|
|
719
|
-
return {
|
|
720
|
-
messages: format === "v2" ? list.get.all.v2() : list.get.all.v1(),
|
|
721
|
-
total,
|
|
722
|
-
// Total should be the count of messages matching the filters
|
|
723
|
-
page,
|
|
724
|
-
perPage,
|
|
725
|
-
hasMore: total > (page + 1) * perPage
|
|
726
|
-
};
|
|
727
|
-
} catch (error$1) {
|
|
728
|
-
const mastraError = new error.MastraError(
|
|
729
|
-
{
|
|
730
|
-
id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
731
|
-
domain: error.ErrorDomain.STORAGE,
|
|
732
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
733
|
-
details: {
|
|
734
|
-
threadId,
|
|
735
|
-
resourceId: resourceId ?? ""
|
|
736
|
-
}
|
|
737
|
-
},
|
|
738
|
-
error$1
|
|
739
|
-
);
|
|
740
|
-
this.logger?.trackException?.(mastraError);
|
|
741
|
-
this.logger?.error?.(mastraError.toString());
|
|
742
|
-
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
586
|
/**
|
|
746
|
-
* Parse message data from LanceDB record format to
|
|
587
|
+
* Parse message data from LanceDB record format to MastraDBMessage format
|
|
747
588
|
*/
|
|
748
589
|
parseMessageData(data) {
|
|
749
590
|
const { thread_id, ...rest } = data;
|
|
@@ -821,7 +662,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
821
662
|
} catch (error$1) {
|
|
822
663
|
throw new error.MastraError(
|
|
823
664
|
{
|
|
824
|
-
id: "
|
|
665
|
+
id: storage.createStorageErrorId("LANCE", "UPDATE_MESSAGES", "FAILED"),
|
|
825
666
|
domain: error.ErrorDomain.STORAGE,
|
|
826
667
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
827
668
|
details: { count: messages.length }
|
|
@@ -898,7 +739,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
898
739
|
} catch (error$1) {
|
|
899
740
|
throw new error.MastraError(
|
|
900
741
|
{
|
|
901
|
-
id: "
|
|
742
|
+
id: storage.createStorageErrorId("LANCE", "GET_RESOURCE_BY_ID", "FAILED"),
|
|
902
743
|
domain: error.ErrorDomain.STORAGE,
|
|
903
744
|
category: error.ErrorCategory.THIRD_PARTY
|
|
904
745
|
},
|
|
@@ -922,7 +763,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
922
763
|
} catch (error$1) {
|
|
923
764
|
throw new error.MastraError(
|
|
924
765
|
{
|
|
925
|
-
id: "
|
|
766
|
+
id: storage.createStorageErrorId("LANCE", "SAVE_RESOURCE", "FAILED"),
|
|
926
767
|
domain: error.ErrorDomain.STORAGE,
|
|
927
768
|
category: error.ErrorCategory.THIRD_PARTY
|
|
928
769
|
},
|
|
@@ -976,7 +817,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
976
817
|
}
|
|
977
818
|
throw new error.MastraError(
|
|
978
819
|
{
|
|
979
|
-
id: "
|
|
820
|
+
id: storage.createStorageErrorId("LANCE", "UPDATE_RESOURCE", "FAILED"),
|
|
980
821
|
domain: error.ErrorDomain.STORAGE,
|
|
981
822
|
category: error.ErrorCategory.THIRD_PARTY
|
|
982
823
|
},
|
|
@@ -1067,7 +908,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1067
908
|
} catch (error$1) {
|
|
1068
909
|
throw new error.MastraError(
|
|
1069
910
|
{
|
|
1070
|
-
id: "
|
|
911
|
+
id: storage.createStorageErrorId("LANCE", "CREATE_TABLE", "INVALID_ARGS"),
|
|
1071
912
|
domain: error.ErrorDomain.STORAGE,
|
|
1072
913
|
category: error.ErrorCategory.USER,
|
|
1073
914
|
details: { tableName }
|
|
@@ -1085,7 +926,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1085
926
|
}
|
|
1086
927
|
throw new error.MastraError(
|
|
1087
928
|
{
|
|
1088
|
-
id: "
|
|
929
|
+
id: storage.createStorageErrorId("LANCE", "CREATE_TABLE", "FAILED"),
|
|
1089
930
|
domain: error.ErrorDomain.STORAGE,
|
|
1090
931
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1091
932
|
details: { tableName }
|
|
@@ -1105,7 +946,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1105
946
|
} catch (validationError) {
|
|
1106
947
|
throw new error.MastraError(
|
|
1107
948
|
{
|
|
1108
|
-
id: "
|
|
949
|
+
id: storage.createStorageErrorId("LANCE", "DROP_TABLE", "INVALID_ARGS"),
|
|
1109
950
|
domain: error.ErrorDomain.STORAGE,
|
|
1110
951
|
category: error.ErrorCategory.USER,
|
|
1111
952
|
text: validationError.message,
|
|
@@ -1123,7 +964,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1123
964
|
}
|
|
1124
965
|
throw new error.MastraError(
|
|
1125
966
|
{
|
|
1126
|
-
id: "
|
|
967
|
+
id: storage.createStorageErrorId("LANCE", "DROP_TABLE", "FAILED"),
|
|
1127
968
|
domain: error.ErrorDomain.STORAGE,
|
|
1128
969
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1129
970
|
details: { tableName }
|
|
@@ -1154,7 +995,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1154
995
|
} catch (validationError) {
|
|
1155
996
|
throw new error.MastraError(
|
|
1156
997
|
{
|
|
1157
|
-
id: "
|
|
998
|
+
id: storage.createStorageErrorId("LANCE", "ALTER_TABLE", "INVALID_ARGS"),
|
|
1158
999
|
domain: error.ErrorDomain.STORAGE,
|
|
1159
1000
|
category: error.ErrorCategory.USER,
|
|
1160
1001
|
text: validationError.message,
|
|
@@ -1189,7 +1030,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1189
1030
|
} catch (error$1) {
|
|
1190
1031
|
throw new error.MastraError(
|
|
1191
1032
|
{
|
|
1192
|
-
id: "
|
|
1033
|
+
id: storage.createStorageErrorId("LANCE", "ALTER_TABLE", "FAILED"),
|
|
1193
1034
|
domain: error.ErrorDomain.STORAGE,
|
|
1194
1035
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1195
1036
|
details: { tableName }
|
|
@@ -1209,7 +1050,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1209
1050
|
} catch (validationError) {
|
|
1210
1051
|
throw new error.MastraError(
|
|
1211
1052
|
{
|
|
1212
|
-
id: "
|
|
1053
|
+
id: storage.createStorageErrorId("LANCE", "CLEAR_TABLE", "INVALID_ARGS"),
|
|
1213
1054
|
domain: error.ErrorDomain.STORAGE,
|
|
1214
1055
|
category: error.ErrorCategory.USER,
|
|
1215
1056
|
text: validationError.message,
|
|
@@ -1224,7 +1065,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1224
1065
|
} catch (error$1) {
|
|
1225
1066
|
throw new error.MastraError(
|
|
1226
1067
|
{
|
|
1227
|
-
id: "
|
|
1068
|
+
id: storage.createStorageErrorId("LANCE", "CLEAR_TABLE", "FAILED"),
|
|
1228
1069
|
domain: error.ErrorDomain.STORAGE,
|
|
1229
1070
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1230
1071
|
details: { tableName }
|
|
@@ -1247,7 +1088,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1247
1088
|
} catch (validationError) {
|
|
1248
1089
|
throw new error.MastraError(
|
|
1249
1090
|
{
|
|
1250
|
-
id: "
|
|
1091
|
+
id: storage.createStorageErrorId("LANCE", "INSERT", "INVALID_ARGS"),
|
|
1251
1092
|
domain: error.ErrorDomain.STORAGE,
|
|
1252
1093
|
category: error.ErrorCategory.USER,
|
|
1253
1094
|
text: validationError.message,
|
|
@@ -1266,12 +1107,11 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1266
1107
|
processedRecord[key] = JSON.stringify(processedRecord[key]);
|
|
1267
1108
|
}
|
|
1268
1109
|
}
|
|
1269
|
-
console.info(await table.schema());
|
|
1270
1110
|
await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([processedRecord]);
|
|
1271
1111
|
} catch (error$1) {
|
|
1272
1112
|
throw new error.MastraError(
|
|
1273
1113
|
{
|
|
1274
|
-
id: "
|
|
1114
|
+
id: storage.createStorageErrorId("LANCE", "INSERT", "FAILED"),
|
|
1275
1115
|
domain: error.ErrorDomain.STORAGE,
|
|
1276
1116
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1277
1117
|
details: { tableName }
|
|
@@ -1294,7 +1134,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1294
1134
|
} catch (validationError) {
|
|
1295
1135
|
throw new error.MastraError(
|
|
1296
1136
|
{
|
|
1297
|
-
id: "
|
|
1137
|
+
id: storage.createStorageErrorId("LANCE", "BATCH_INSERT", "INVALID_ARGS"),
|
|
1298
1138
|
domain: error.ErrorDomain.STORAGE,
|
|
1299
1139
|
category: error.ErrorCategory.USER,
|
|
1300
1140
|
text: validationError.message,
|
|
@@ -1320,7 +1160,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1320
1160
|
} catch (error$1) {
|
|
1321
1161
|
throw new error.MastraError(
|
|
1322
1162
|
{
|
|
1323
|
-
id: "
|
|
1163
|
+
id: storage.createStorageErrorId("LANCE", "BATCH_INSERT", "FAILED"),
|
|
1324
1164
|
domain: error.ErrorDomain.STORAGE,
|
|
1325
1165
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1326
1166
|
details: { tableName }
|
|
@@ -1343,7 +1183,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1343
1183
|
} catch (validationError) {
|
|
1344
1184
|
throw new error.MastraError(
|
|
1345
1185
|
{
|
|
1346
|
-
id: "
|
|
1186
|
+
id: storage.createStorageErrorId("LANCE", "LOAD", "INVALID_ARGS"),
|
|
1347
1187
|
domain: error.ErrorDomain.STORAGE,
|
|
1348
1188
|
category: error.ErrorCategory.USER,
|
|
1349
1189
|
text: validationError.message,
|
|
@@ -1382,7 +1222,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1382
1222
|
if (error$1 instanceof error.MastraError) throw error$1;
|
|
1383
1223
|
throw new error.MastraError(
|
|
1384
1224
|
{
|
|
1385
|
-
id: "
|
|
1225
|
+
id: storage.createStorageErrorId("LANCE", "LOAD", "FAILED"),
|
|
1386
1226
|
domain: error.ErrorDomain.STORAGE,
|
|
1387
1227
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1388
1228
|
details: { tableName, keyCount: Object.keys(keys).length, firstKey: Object.keys(keys)[0] ?? "" }
|
|
@@ -1401,43 +1241,51 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1401
1241
|
async saveScore(score) {
|
|
1402
1242
|
let validatedScore;
|
|
1403
1243
|
try {
|
|
1404
|
-
validatedScore =
|
|
1244
|
+
validatedScore = evals.saveScorePayloadSchema.parse(score);
|
|
1405
1245
|
} catch (error$1) {
|
|
1406
1246
|
throw new error.MastraError(
|
|
1407
1247
|
{
|
|
1408
|
-
id: "
|
|
1248
|
+
id: storage.createStorageErrorId("LANCE", "SAVE_SCORE", "VALIDATION_FAILED"),
|
|
1409
1249
|
text: "Failed to save score in LanceStorage",
|
|
1410
1250
|
domain: error.ErrorDomain.STORAGE,
|
|
1411
|
-
category: error.ErrorCategory.
|
|
1251
|
+
category: error.ErrorCategory.USER,
|
|
1252
|
+
details: {
|
|
1253
|
+
scorer: score.scorer?.id ?? "unknown",
|
|
1254
|
+
entityId: score.entityId ?? "unknown",
|
|
1255
|
+
entityType: score.entityType ?? "unknown",
|
|
1256
|
+
traceId: score.traceId ?? "",
|
|
1257
|
+
spanId: score.spanId ?? ""
|
|
1258
|
+
}
|
|
1412
1259
|
},
|
|
1413
1260
|
error$1
|
|
1414
1261
|
);
|
|
1415
1262
|
}
|
|
1263
|
+
const id = crypto.randomUUID();
|
|
1264
|
+
const now = /* @__PURE__ */ new Date();
|
|
1416
1265
|
try {
|
|
1417
|
-
const id = crypto.randomUUID();
|
|
1418
1266
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1419
1267
|
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1420
1268
|
const allowedFields = new Set(schema.fields.map((f) => f.name));
|
|
1421
1269
|
const filteredScore = {};
|
|
1422
|
-
Object.keys(validatedScore)
|
|
1270
|
+
for (const key of Object.keys(validatedScore)) {
|
|
1423
1271
|
if (allowedFields.has(key)) {
|
|
1424
|
-
filteredScore[key] =
|
|
1272
|
+
filteredScore[key] = validatedScore[key];
|
|
1425
1273
|
}
|
|
1426
|
-
}
|
|
1274
|
+
}
|
|
1427
1275
|
for (const key in filteredScore) {
|
|
1428
1276
|
if (filteredScore[key] !== null && typeof filteredScore[key] === "object" && !(filteredScore[key] instanceof Date)) {
|
|
1429
1277
|
filteredScore[key] = JSON.stringify(filteredScore[key]);
|
|
1430
1278
|
}
|
|
1431
1279
|
}
|
|
1432
|
-
filteredScore.createdAt = /* @__PURE__ */ new Date();
|
|
1433
|
-
filteredScore.updatedAt = /* @__PURE__ */ new Date();
|
|
1434
1280
|
filteredScore.id = id;
|
|
1281
|
+
filteredScore.createdAt = now;
|
|
1282
|
+
filteredScore.updatedAt = now;
|
|
1435
1283
|
await table.add([filteredScore], { mode: "append" });
|
|
1436
|
-
return { score };
|
|
1284
|
+
return { score: { ...validatedScore, id, createdAt: now, updatedAt: now } };
|
|
1437
1285
|
} catch (error$1) {
|
|
1438
1286
|
throw new error.MastraError(
|
|
1439
1287
|
{
|
|
1440
|
-
id: "
|
|
1288
|
+
id: storage.createStorageErrorId("LANCE", "SAVE_SCORE", "FAILED"),
|
|
1441
1289
|
text: "Failed to save score in LanceStorage",
|
|
1442
1290
|
domain: error.ErrorDomain.STORAGE,
|
|
1443
1291
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
@@ -1453,12 +1301,11 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1453
1301
|
const query = table.query().where(`id = '${id}'`).limit(1);
|
|
1454
1302
|
const records = await query.toArray();
|
|
1455
1303
|
if (records.length === 0) return null;
|
|
1456
|
-
|
|
1457
|
-
return processResultWithTypeConversion(records[0], schema);
|
|
1304
|
+
return await this.transformScoreRow(records[0]);
|
|
1458
1305
|
} catch (error$1) {
|
|
1459
1306
|
throw new error.MastraError(
|
|
1460
1307
|
{
|
|
1461
|
-
id: "
|
|
1308
|
+
id: storage.createStorageErrorId("LANCE", "GET_SCORE_BY_ID", "FAILED"),
|
|
1462
1309
|
text: "Failed to get score by id in LanceStorage",
|
|
1463
1310
|
domain: error.ErrorDomain.STORAGE,
|
|
1464
1311
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
@@ -1468,7 +1315,23 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1468
1315
|
);
|
|
1469
1316
|
}
|
|
1470
1317
|
}
|
|
1471
|
-
|
|
1318
|
+
/**
|
|
1319
|
+
* LanceDB-specific score row transformation.
|
|
1320
|
+
*
|
|
1321
|
+
* Note: This implementation does NOT use coreTransformScoreRow because:
|
|
1322
|
+
* 1. LanceDB stores schema information in the table itself (requires async fetch)
|
|
1323
|
+
* 2. Uses processResultWithTypeConversion utility for LanceDB-specific type handling
|
|
1324
|
+
*/
|
|
1325
|
+
async transformScoreRow(row) {
|
|
1326
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1327
|
+
const transformed = processResultWithTypeConversion(row, schema);
|
|
1328
|
+
return {
|
|
1329
|
+
...transformed,
|
|
1330
|
+
createdAt: row.createdAt,
|
|
1331
|
+
updatedAt: row.updatedAt
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
async listScoresByScorerId({
|
|
1472
1335
|
scorerId,
|
|
1473
1336
|
pagination,
|
|
1474
1337
|
entityId,
|
|
@@ -1476,9 +1339,10 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1476
1339
|
source
|
|
1477
1340
|
}) {
|
|
1478
1341
|
try {
|
|
1342
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1343
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1344
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1479
1345
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1480
|
-
const { page = 0, perPage = 10 } = pagination || {};
|
|
1481
|
-
const offset = page * perPage;
|
|
1482
1346
|
let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1483
1347
|
if (source) {
|
|
1484
1348
|
query = query.where(`\`source\` = '${source}'`);
|
|
@@ -1489,30 +1353,38 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1489
1353
|
if (entityType) {
|
|
1490
1354
|
query = query.where(`\`entityType\` = '${entityType}'`);
|
|
1491
1355
|
}
|
|
1492
|
-
query = query.limit(perPage);
|
|
1493
|
-
if (offset > 0) query.offset(offset);
|
|
1494
|
-
const records = await query.toArray();
|
|
1495
|
-
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1496
|
-
const scores = processResultWithTypeConversion(records, schema);
|
|
1497
1356
|
let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1498
1357
|
if (source) {
|
|
1499
1358
|
totalQuery = totalQuery.where(`\`source\` = '${source}'`);
|
|
1500
1359
|
}
|
|
1360
|
+
if (entityId) {
|
|
1361
|
+
totalQuery = totalQuery.where(`\`entityId\` = '${entityId}'`);
|
|
1362
|
+
}
|
|
1363
|
+
if (entityType) {
|
|
1364
|
+
totalQuery = totalQuery.where(`\`entityType\` = '${entityType}'`);
|
|
1365
|
+
}
|
|
1501
1366
|
const allRecords = await totalQuery.toArray();
|
|
1502
1367
|
const total = allRecords.length;
|
|
1368
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
1369
|
+
if (perPageInput !== false) {
|
|
1370
|
+
query = query.limit(perPage);
|
|
1371
|
+
if (start > 0) query = query.offset(start);
|
|
1372
|
+
}
|
|
1373
|
+
const records = await query.toArray();
|
|
1374
|
+
const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
|
|
1503
1375
|
return {
|
|
1504
1376
|
pagination: {
|
|
1505
1377
|
page,
|
|
1506
|
-
perPage,
|
|
1378
|
+
perPage: perPageForResponse,
|
|
1507
1379
|
total,
|
|
1508
|
-
hasMore:
|
|
1380
|
+
hasMore: end < total
|
|
1509
1381
|
},
|
|
1510
1382
|
scores
|
|
1511
1383
|
};
|
|
1512
1384
|
} catch (error$1) {
|
|
1513
1385
|
throw new error.MastraError(
|
|
1514
1386
|
{
|
|
1515
|
-
id: "
|
|
1387
|
+
id: storage.createStorageErrorId("LANCE", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
|
|
1516
1388
|
text: "Failed to get scores by scorerId in LanceStorage",
|
|
1517
1389
|
domain: error.ErrorDomain.STORAGE,
|
|
1518
1390
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
@@ -1522,34 +1394,38 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1522
1394
|
);
|
|
1523
1395
|
}
|
|
1524
1396
|
}
|
|
1525
|
-
async
|
|
1397
|
+
async listScoresByRunId({
|
|
1526
1398
|
runId,
|
|
1527
1399
|
pagination
|
|
1528
1400
|
}) {
|
|
1529
1401
|
try {
|
|
1402
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1403
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1404
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1530
1405
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1531
|
-
const { page = 0, perPage = 10 } = pagination || {};
|
|
1532
|
-
const offset = page * perPage;
|
|
1533
|
-
const query = table.query().where(`\`runId\` = '${runId}'`).limit(perPage);
|
|
1534
|
-
if (offset > 0) query.offset(offset);
|
|
1535
|
-
const records = await query.toArray();
|
|
1536
|
-
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1537
|
-
const scores = processResultWithTypeConversion(records, schema);
|
|
1538
1406
|
const allRecords = await table.query().where(`\`runId\` = '${runId}'`).toArray();
|
|
1539
1407
|
const total = allRecords.length;
|
|
1408
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
1409
|
+
let query = table.query().where(`\`runId\` = '${runId}'`);
|
|
1410
|
+
if (perPageInput !== false) {
|
|
1411
|
+
query = query.limit(perPage);
|
|
1412
|
+
if (start > 0) query = query.offset(start);
|
|
1413
|
+
}
|
|
1414
|
+
const records = await query.toArray();
|
|
1415
|
+
const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
|
|
1540
1416
|
return {
|
|
1541
1417
|
pagination: {
|
|
1542
1418
|
page,
|
|
1543
|
-
perPage,
|
|
1419
|
+
perPage: perPageForResponse,
|
|
1544
1420
|
total,
|
|
1545
|
-
hasMore:
|
|
1421
|
+
hasMore: end < total
|
|
1546
1422
|
},
|
|
1547
1423
|
scores
|
|
1548
1424
|
};
|
|
1549
1425
|
} catch (error$1) {
|
|
1550
1426
|
throw new error.MastraError(
|
|
1551
1427
|
{
|
|
1552
|
-
id: "
|
|
1428
|
+
id: storage.createStorageErrorId("LANCE", "LIST_SCORES_BY_RUN_ID", "FAILED"),
|
|
1553
1429
|
text: "Failed to get scores by runId in LanceStorage",
|
|
1554
1430
|
domain: error.ErrorDomain.STORAGE,
|
|
1555
1431
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
@@ -1559,35 +1435,39 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1559
1435
|
);
|
|
1560
1436
|
}
|
|
1561
1437
|
}
|
|
1562
|
-
async
|
|
1438
|
+
async listScoresByEntityId({
|
|
1563
1439
|
entityId,
|
|
1564
1440
|
entityType,
|
|
1565
1441
|
pagination
|
|
1566
1442
|
}) {
|
|
1567
1443
|
try {
|
|
1444
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1445
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1446
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1568
1447
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1569
|
-
const { page = 0, perPage = 10 } = pagination || {};
|
|
1570
|
-
const offset = page * perPage;
|
|
1571
|
-
const query = table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).limit(perPage);
|
|
1572
|
-
if (offset > 0) query.offset(offset);
|
|
1573
|
-
const records = await query.toArray();
|
|
1574
|
-
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1575
|
-
const scores = processResultWithTypeConversion(records, schema);
|
|
1576
1448
|
const allRecords = await table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).toArray();
|
|
1577
1449
|
const total = allRecords.length;
|
|
1450
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
1451
|
+
let query = table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`);
|
|
1452
|
+
if (perPageInput !== false) {
|
|
1453
|
+
query = query.limit(perPage);
|
|
1454
|
+
if (start > 0) query = query.offset(start);
|
|
1455
|
+
}
|
|
1456
|
+
const records = await query.toArray();
|
|
1457
|
+
const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
|
|
1578
1458
|
return {
|
|
1579
1459
|
pagination: {
|
|
1580
1460
|
page,
|
|
1581
|
-
perPage,
|
|
1461
|
+
perPage: perPageForResponse,
|
|
1582
1462
|
total,
|
|
1583
|
-
hasMore:
|
|
1463
|
+
hasMore: end < total
|
|
1584
1464
|
},
|
|
1585
1465
|
scores
|
|
1586
1466
|
};
|
|
1587
1467
|
} catch (error$1) {
|
|
1588
1468
|
throw new error.MastraError(
|
|
1589
1469
|
{
|
|
1590
|
-
id: "
|
|
1470
|
+
id: storage.createStorageErrorId("LANCE", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
|
|
1591
1471
|
text: "Failed to get scores by entityId and entityType in LanceStorage",
|
|
1592
1472
|
domain: error.ErrorDomain.STORAGE,
|
|
1593
1473
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
@@ -1597,35 +1477,39 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1597
1477
|
);
|
|
1598
1478
|
}
|
|
1599
1479
|
}
|
|
1600
|
-
async
|
|
1480
|
+
async listScoresBySpan({
|
|
1601
1481
|
traceId,
|
|
1602
1482
|
spanId,
|
|
1603
1483
|
pagination
|
|
1604
1484
|
}) {
|
|
1605
1485
|
try {
|
|
1486
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1487
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1488
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1606
1489
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1607
|
-
const { page = 0, perPage = 10 } = pagination || {};
|
|
1608
|
-
const offset = page * perPage;
|
|
1609
|
-
const query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).limit(perPage);
|
|
1610
|
-
if (offset > 0) query.offset(offset);
|
|
1611
|
-
const records = await query.toArray();
|
|
1612
|
-
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1613
|
-
const scores = processResultWithTypeConversion(records, schema);
|
|
1614
1490
|
const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
|
|
1615
1491
|
const total = allRecords.length;
|
|
1492
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
1493
|
+
let query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`);
|
|
1494
|
+
if (perPageInput !== false) {
|
|
1495
|
+
query = query.limit(perPage);
|
|
1496
|
+
if (start > 0) query = query.offset(start);
|
|
1497
|
+
}
|
|
1498
|
+
const records = await query.toArray();
|
|
1499
|
+
const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
|
|
1616
1500
|
return {
|
|
1617
1501
|
pagination: {
|
|
1618
1502
|
page,
|
|
1619
|
-
perPage,
|
|
1503
|
+
perPage: perPageForResponse,
|
|
1620
1504
|
total,
|
|
1621
|
-
hasMore:
|
|
1505
|
+
hasMore: end < total
|
|
1622
1506
|
},
|
|
1623
1507
|
scores
|
|
1624
1508
|
};
|
|
1625
1509
|
} catch (error$1) {
|
|
1626
1510
|
throw new error.MastraError(
|
|
1627
1511
|
{
|
|
1628
|
-
id: "
|
|
1512
|
+
id: storage.createStorageErrorId("LANCE", "LIST_SCORES_BY_SPAN", "FAILED"),
|
|
1629
1513
|
text: "Failed to get scores by traceId and spanId in LanceStorage",
|
|
1630
1514
|
domain: error.ErrorDomain.STORAGE,
|
|
1631
1515
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
@@ -1636,198 +1520,6 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1636
1520
|
}
|
|
1637
1521
|
}
|
|
1638
1522
|
};
|
|
1639
|
-
var StoreTracesLance = class extends storage.TracesStorage {
|
|
1640
|
-
client;
|
|
1641
|
-
operations;
|
|
1642
|
-
constructor({ client, operations }) {
|
|
1643
|
-
super();
|
|
1644
|
-
this.client = client;
|
|
1645
|
-
this.operations = operations;
|
|
1646
|
-
}
|
|
1647
|
-
async saveTrace({ trace }) {
|
|
1648
|
-
try {
|
|
1649
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1650
|
-
const record = {
|
|
1651
|
-
...trace,
|
|
1652
|
-
attributes: JSON.stringify(trace.attributes),
|
|
1653
|
-
status: JSON.stringify(trace.status),
|
|
1654
|
-
events: JSON.stringify(trace.events),
|
|
1655
|
-
links: JSON.stringify(trace.links),
|
|
1656
|
-
other: JSON.stringify(trace.other)
|
|
1657
|
-
};
|
|
1658
|
-
await table.add([record], { mode: "append" });
|
|
1659
|
-
return trace;
|
|
1660
|
-
} catch (error$1) {
|
|
1661
|
-
throw new error.MastraError(
|
|
1662
|
-
{
|
|
1663
|
-
id: "LANCE_STORE_SAVE_TRACE_FAILED",
|
|
1664
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1665
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
1666
|
-
},
|
|
1667
|
-
error$1
|
|
1668
|
-
);
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
async getTraceById({ traceId }) {
|
|
1672
|
-
try {
|
|
1673
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1674
|
-
const query = table.query().where(`id = '${traceId}'`);
|
|
1675
|
-
const records = await query.toArray();
|
|
1676
|
-
return records[0];
|
|
1677
|
-
} catch (error$1) {
|
|
1678
|
-
throw new error.MastraError(
|
|
1679
|
-
{
|
|
1680
|
-
id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
|
|
1681
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1682
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
1683
|
-
},
|
|
1684
|
-
error$1
|
|
1685
|
-
);
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
async getTraces({
|
|
1689
|
-
name,
|
|
1690
|
-
scope,
|
|
1691
|
-
page = 1,
|
|
1692
|
-
perPage = 10,
|
|
1693
|
-
attributes
|
|
1694
|
-
}) {
|
|
1695
|
-
try {
|
|
1696
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1697
|
-
const query = table.query();
|
|
1698
|
-
if (name) {
|
|
1699
|
-
query.where(`name = '${name}'`);
|
|
1700
|
-
}
|
|
1701
|
-
if (scope) {
|
|
1702
|
-
query.where(`scope = '${scope}'`);
|
|
1703
|
-
}
|
|
1704
|
-
if (attributes) {
|
|
1705
|
-
query.where(`attributes = '${JSON.stringify(attributes)}'`);
|
|
1706
|
-
}
|
|
1707
|
-
const offset = (page - 1) * perPage;
|
|
1708
|
-
query.limit(perPage);
|
|
1709
|
-
if (offset > 0) {
|
|
1710
|
-
query.offset(offset);
|
|
1711
|
-
}
|
|
1712
|
-
const records = await query.toArray();
|
|
1713
|
-
return records.map((record) => {
|
|
1714
|
-
const processed = {
|
|
1715
|
-
...record,
|
|
1716
|
-
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1717
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1718
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1719
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1720
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1721
|
-
startTime: new Date(record.startTime),
|
|
1722
|
-
endTime: new Date(record.endTime),
|
|
1723
|
-
createdAt: new Date(record.createdAt)
|
|
1724
|
-
};
|
|
1725
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1726
|
-
processed.parentSpanId = "";
|
|
1727
|
-
} else {
|
|
1728
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1729
|
-
}
|
|
1730
|
-
return processed;
|
|
1731
|
-
});
|
|
1732
|
-
} catch (error$1) {
|
|
1733
|
-
throw new error.MastraError(
|
|
1734
|
-
{
|
|
1735
|
-
id: "LANCE_STORE_GET_TRACES_FAILED",
|
|
1736
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1737
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1738
|
-
details: { name: name ?? "", scope: scope ?? "" }
|
|
1739
|
-
},
|
|
1740
|
-
error$1
|
|
1741
|
-
);
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
async getTracesPaginated(args) {
|
|
1745
|
-
try {
|
|
1746
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1747
|
-
const query = table.query();
|
|
1748
|
-
const conditions = [];
|
|
1749
|
-
if (args.name) {
|
|
1750
|
-
conditions.push(`name = '${args.name}'`);
|
|
1751
|
-
}
|
|
1752
|
-
if (args.scope) {
|
|
1753
|
-
conditions.push(`scope = '${args.scope}'`);
|
|
1754
|
-
}
|
|
1755
|
-
if (args.attributes) {
|
|
1756
|
-
const attributesStr = JSON.stringify(args.attributes);
|
|
1757
|
-
conditions.push(`attributes LIKE '%${attributesStr.replace(/"/g, '\\"')}%'`);
|
|
1758
|
-
}
|
|
1759
|
-
if (args.dateRange?.start) {
|
|
1760
|
-
conditions.push(`\`createdAt\` >= ${args.dateRange.start.getTime()}`);
|
|
1761
|
-
}
|
|
1762
|
-
if (args.dateRange?.end) {
|
|
1763
|
-
conditions.push(`\`createdAt\` <= ${args.dateRange.end.getTime()}`);
|
|
1764
|
-
}
|
|
1765
|
-
if (conditions.length > 0) {
|
|
1766
|
-
const whereClause = conditions.join(" AND ");
|
|
1767
|
-
query.where(whereClause);
|
|
1768
|
-
}
|
|
1769
|
-
let total = 0;
|
|
1770
|
-
if (conditions.length > 0) {
|
|
1771
|
-
const countQuery = table.query().where(conditions.join(" AND "));
|
|
1772
|
-
const allRecords = await countQuery.toArray();
|
|
1773
|
-
total = allRecords.length;
|
|
1774
|
-
} else {
|
|
1775
|
-
total = await table.countRows();
|
|
1776
|
-
}
|
|
1777
|
-
const page = args.page || 0;
|
|
1778
|
-
const perPage = args.perPage || 10;
|
|
1779
|
-
const offset = page * perPage;
|
|
1780
|
-
query.limit(perPage);
|
|
1781
|
-
if (offset > 0) {
|
|
1782
|
-
query.offset(offset);
|
|
1783
|
-
}
|
|
1784
|
-
const records = await query.toArray();
|
|
1785
|
-
const traces = records.map((record) => {
|
|
1786
|
-
const processed = {
|
|
1787
|
-
...record,
|
|
1788
|
-
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1789
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1790
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1791
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1792
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1793
|
-
startTime: new Date(record.startTime),
|
|
1794
|
-
endTime: new Date(record.endTime),
|
|
1795
|
-
createdAt: new Date(record.createdAt)
|
|
1796
|
-
};
|
|
1797
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1798
|
-
processed.parentSpanId = "";
|
|
1799
|
-
} else {
|
|
1800
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1801
|
-
}
|
|
1802
|
-
return processed;
|
|
1803
|
-
});
|
|
1804
|
-
return {
|
|
1805
|
-
traces,
|
|
1806
|
-
total,
|
|
1807
|
-
page,
|
|
1808
|
-
perPage,
|
|
1809
|
-
hasMore: total > (page + 1) * perPage
|
|
1810
|
-
};
|
|
1811
|
-
} catch (error$1) {
|
|
1812
|
-
throw new error.MastraError(
|
|
1813
|
-
{
|
|
1814
|
-
id: "LANCE_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
1815
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1816
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1817
|
-
details: { name: args.name ?? "", scope: args.scope ?? "" }
|
|
1818
|
-
},
|
|
1819
|
-
error$1
|
|
1820
|
-
);
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
async batchTraceInsert({ records }) {
|
|
1824
|
-
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
1825
|
-
await this.operations.batchInsert({
|
|
1826
|
-
tableName: storage.TABLE_TRACES,
|
|
1827
|
-
records
|
|
1828
|
-
});
|
|
1829
|
-
}
|
|
1830
|
-
};
|
|
1831
1523
|
function parseWorkflowRun(row) {
|
|
1832
1524
|
let parsedSnapshot = row.snapshot;
|
|
1833
1525
|
if (typeof parsedSnapshot === "string") {
|
|
@@ -1857,7 +1549,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1857
1549
|
// runId,
|
|
1858
1550
|
// stepId,
|
|
1859
1551
|
// result,
|
|
1860
|
-
//
|
|
1552
|
+
// requestContext,
|
|
1861
1553
|
}) {
|
|
1862
1554
|
throw new Error("Method not implemented.");
|
|
1863
1555
|
}
|
|
@@ -1885,11 +1577,13 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1885
1577
|
} else {
|
|
1886
1578
|
createdAt = now;
|
|
1887
1579
|
}
|
|
1580
|
+
const { status, value, ...rest } = snapshot;
|
|
1888
1581
|
const record = {
|
|
1889
1582
|
workflow_name: workflowName,
|
|
1890
1583
|
run_id: runId,
|
|
1891
1584
|
resourceId,
|
|
1892
|
-
snapshot: JSON.stringify(
|
|
1585
|
+
snapshot: JSON.stringify({ status, value, ...rest }),
|
|
1586
|
+
// this is to ensure status is always just before value, for when querying the db by status
|
|
1893
1587
|
createdAt,
|
|
1894
1588
|
updatedAt: now
|
|
1895
1589
|
};
|
|
@@ -1897,7 +1591,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1897
1591
|
} catch (error$1) {
|
|
1898
1592
|
throw new error.MastraError(
|
|
1899
1593
|
{
|
|
1900
|
-
id: "
|
|
1594
|
+
id: storage.createStorageErrorId("LANCE", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1901
1595
|
domain: error.ErrorDomain.STORAGE,
|
|
1902
1596
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1903
1597
|
details: { workflowName, runId }
|
|
@@ -1918,7 +1612,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1918
1612
|
} catch (error$1) {
|
|
1919
1613
|
throw new error.MastraError(
|
|
1920
1614
|
{
|
|
1921
|
-
id: "
|
|
1615
|
+
id: storage.createStorageErrorId("LANCE", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1922
1616
|
domain: error.ErrorDomain.STORAGE,
|
|
1923
1617
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1924
1618
|
details: { workflowName, runId }
|
|
@@ -1942,7 +1636,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1942
1636
|
} catch (error$1) {
|
|
1943
1637
|
throw new error.MastraError(
|
|
1944
1638
|
{
|
|
1945
|
-
id: "
|
|
1639
|
+
id: storage.createStorageErrorId("LANCE", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
1946
1640
|
domain: error.ErrorDomain.STORAGE,
|
|
1947
1641
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1948
1642
|
details: { runId: args.runId, workflowName: args.workflowName ?? "" }
|
|
@@ -1951,7 +1645,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1951
1645
|
);
|
|
1952
1646
|
}
|
|
1953
1647
|
}
|
|
1954
|
-
async
|
|
1648
|
+
async listWorkflowRuns(args) {
|
|
1955
1649
|
try {
|
|
1956
1650
|
const table = await this.client.openTable(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
1957
1651
|
let query = table.query();
|
|
@@ -1959,6 +1653,10 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1959
1653
|
if (args?.workflowName) {
|
|
1960
1654
|
conditions.push(`workflow_name = '${args.workflowName.replace(/'/g, "''")}'`);
|
|
1961
1655
|
}
|
|
1656
|
+
if (args?.status) {
|
|
1657
|
+
const escapedStatus = args.status.replace(/\\/g, "\\\\").replace(/'/g, "''").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
1658
|
+
conditions.push(`\`snapshot\` LIKE '%"status":"${escapedStatus}","value"%'`);
|
|
1659
|
+
}
|
|
1962
1660
|
if (args?.resourceId) {
|
|
1963
1661
|
conditions.push(`\`resourceId\` = '${args.resourceId}'`);
|
|
1964
1662
|
}
|
|
@@ -1975,11 +1673,22 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1975
1673
|
} else {
|
|
1976
1674
|
total = await table.countRows();
|
|
1977
1675
|
}
|
|
1978
|
-
if (args?.
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1676
|
+
if (args?.perPage !== void 0 && args?.page !== void 0) {
|
|
1677
|
+
const normalizedPerPage = storage.normalizePerPage(args.perPage, Number.MAX_SAFE_INTEGER);
|
|
1678
|
+
if (args.page < 0 || !Number.isInteger(args.page)) {
|
|
1679
|
+
throw new error.MastraError(
|
|
1680
|
+
{
|
|
1681
|
+
id: storage.createStorageErrorId("LANCE", "LIST_WORKFLOW_RUNS", "INVALID_PAGINATION"),
|
|
1682
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1683
|
+
category: error.ErrorCategory.USER,
|
|
1684
|
+
details: { page: args.page, perPage: args.perPage }
|
|
1685
|
+
},
|
|
1686
|
+
new Error(`Invalid pagination parameters: page=${args.page}, perPage=${args.perPage}`)
|
|
1687
|
+
);
|
|
1688
|
+
}
|
|
1689
|
+
const offset = args.page * normalizedPerPage;
|
|
1690
|
+
query.limit(normalizedPerPage);
|
|
1691
|
+
query.offset(offset);
|
|
1983
1692
|
}
|
|
1984
1693
|
const records = await query.toArray();
|
|
1985
1694
|
return {
|
|
@@ -1989,10 +1698,10 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1989
1698
|
} catch (error$1) {
|
|
1990
1699
|
throw new error.MastraError(
|
|
1991
1700
|
{
|
|
1992
|
-
id: "
|
|
1701
|
+
id: storage.createStorageErrorId("LANCE", "LIST_WORKFLOW_RUNS", "FAILED"),
|
|
1993
1702
|
domain: error.ErrorDomain.STORAGE,
|
|
1994
1703
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1995
|
-
details: {
|
|
1704
|
+
details: { resourceId: args?.resourceId ?? "", workflowName: args?.workflowName ?? "" }
|
|
1996
1705
|
},
|
|
1997
1706
|
error$1
|
|
1998
1707
|
);
|
|
@@ -2006,48 +1715,54 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2006
1715
|
lanceClient;
|
|
2007
1716
|
/**
|
|
2008
1717
|
* Creates a new instance of LanceStorage
|
|
1718
|
+
* @param id The unique identifier for this storage instance
|
|
1719
|
+
* @param name The name for this storage instance
|
|
2009
1720
|
* @param uri The URI to connect to LanceDB
|
|
2010
|
-
* @param
|
|
1721
|
+
* @param connectionOptions connection options for LanceDB
|
|
1722
|
+
* @param storageOptions storage options including disableInit
|
|
2011
1723
|
*
|
|
2012
1724
|
* Usage:
|
|
2013
1725
|
*
|
|
2014
1726
|
* Connect to a local database
|
|
2015
1727
|
* ```ts
|
|
2016
|
-
* const store = await LanceStorage.create('/path/to/db');
|
|
1728
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', '/path/to/db');
|
|
2017
1729
|
* ```
|
|
2018
1730
|
*
|
|
2019
1731
|
* Connect to a LanceDB cloud database
|
|
2020
1732
|
* ```ts
|
|
2021
|
-
* const store = await LanceStorage.create('db://host:port');
|
|
1733
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', 'db://host:port');
|
|
2022
1734
|
* ```
|
|
2023
1735
|
*
|
|
2024
1736
|
* Connect to a cloud database
|
|
2025
1737
|
* ```ts
|
|
2026
|
-
* const store = await LanceStorage.create('s3://bucket/db', { storageOptions: { timeout: '60s' } });
|
|
1738
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', 's3://bucket/db', { storageOptions: { timeout: '60s' } });
|
|
1739
|
+
* ```
|
|
1740
|
+
*
|
|
1741
|
+
* Disable auto-init for runtime (after CI/CD has run migrations)
|
|
1742
|
+
* ```ts
|
|
1743
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', '/path/to/db', undefined, { disableInit: true });
|
|
2027
1744
|
* ```
|
|
2028
1745
|
*/
|
|
2029
|
-
static async create(name, uri,
|
|
2030
|
-
const instance = new _LanceStorage(name);
|
|
1746
|
+
static async create(id, name, uri, connectionOptions, storageOptions) {
|
|
1747
|
+
const instance = new _LanceStorage(id, name, storageOptions?.disableInit);
|
|
2031
1748
|
try {
|
|
2032
|
-
instance.lanceClient = await lancedb.connect(uri,
|
|
1749
|
+
instance.lanceClient = await lancedb.connect(uri, connectionOptions);
|
|
2033
1750
|
const operations = new StoreOperationsLance({ client: instance.lanceClient });
|
|
2034
1751
|
instance.stores = {
|
|
2035
1752
|
operations: new StoreOperationsLance({ client: instance.lanceClient }),
|
|
2036
1753
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
2037
|
-
traces: new StoreTracesLance({ client: instance.lanceClient, operations }),
|
|
2038
1754
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
2039
|
-
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
2040
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
|
|
1755
|
+
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
2041
1756
|
};
|
|
2042
1757
|
return instance;
|
|
2043
1758
|
} catch (e) {
|
|
2044
1759
|
throw new error.MastraError(
|
|
2045
1760
|
{
|
|
2046
|
-
id: "
|
|
1761
|
+
id: storage.createStorageErrorId("LANCE", "CONNECT", "FAILED"),
|
|
2047
1762
|
domain: error.ErrorDomain.STORAGE,
|
|
2048
1763
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2049
1764
|
text: `Failed to connect to LanceDB: ${e.message || e}`,
|
|
2050
|
-
details: { uri, optionsProvided: !!
|
|
1765
|
+
details: { uri, optionsProvided: !!connectionOptions }
|
|
2051
1766
|
},
|
|
2052
1767
|
e
|
|
2053
1768
|
);
|
|
@@ -2057,15 +1772,13 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2057
1772
|
* @internal
|
|
2058
1773
|
* Private constructor to enforce using the create factory method
|
|
2059
1774
|
*/
|
|
2060
|
-
constructor(name) {
|
|
2061
|
-
super({ name });
|
|
1775
|
+
constructor(id, name, disableInit) {
|
|
1776
|
+
super({ id, name, disableInit });
|
|
2062
1777
|
const operations = new StoreOperationsLance({ client: this.lanceClient });
|
|
2063
1778
|
this.stores = {
|
|
2064
1779
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
2065
1780
|
workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
|
|
2066
|
-
traces: new StoreTracesLance({ client: this.lanceClient, operations }),
|
|
2067
1781
|
scores: new StoreScoresLance({ client: this.lanceClient }),
|
|
2068
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
|
|
2069
1782
|
memory: new StoreMemoryLance({ client: this.lanceClient, operations })
|
|
2070
1783
|
};
|
|
2071
1784
|
}
|
|
@@ -2100,9 +1813,6 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2100
1813
|
async getThreadById({ threadId }) {
|
|
2101
1814
|
return this.stores.memory.getThreadById({ threadId });
|
|
2102
1815
|
}
|
|
2103
|
-
async getThreadsByResourceId({ resourceId }) {
|
|
2104
|
-
return this.stores.memory.getThreadsByResourceId({ resourceId });
|
|
2105
|
-
}
|
|
2106
1816
|
/**
|
|
2107
1817
|
* Saves a thread to the database. This function doesn't overwrite existing threads.
|
|
2108
1818
|
* @param thread - The thread to save
|
|
@@ -2128,7 +1838,7 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2128
1838
|
hasColumn: true,
|
|
2129
1839
|
createTable: true,
|
|
2130
1840
|
deleteMessages: false,
|
|
2131
|
-
|
|
1841
|
+
listScoresBySpan: true
|
|
2132
1842
|
};
|
|
2133
1843
|
}
|
|
2134
1844
|
async getResourceById({ resourceId }) {
|
|
@@ -2192,50 +1902,17 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2192
1902
|
});
|
|
2193
1903
|
return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
|
|
2194
1904
|
}
|
|
2195
|
-
async
|
|
2196
|
-
|
|
2197
|
-
resourceId,
|
|
2198
|
-
selectBy,
|
|
2199
|
-
format,
|
|
2200
|
-
threadConfig
|
|
2201
|
-
}) {
|
|
2202
|
-
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2203
|
-
}
|
|
2204
|
-
async getMessagesById({
|
|
2205
|
-
messageIds,
|
|
2206
|
-
format
|
|
2207
|
-
}) {
|
|
2208
|
-
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
1905
|
+
async listMessagesById({ messageIds }) {
|
|
1906
|
+
return this.stores.memory.listMessagesById({ messageIds });
|
|
2209
1907
|
}
|
|
2210
1908
|
async saveMessages(args) {
|
|
2211
1909
|
return this.stores.memory.saveMessages(args);
|
|
2212
1910
|
}
|
|
2213
|
-
async getThreadsByResourceIdPaginated(args) {
|
|
2214
|
-
return this.stores.memory.getThreadsByResourceIdPaginated(args);
|
|
2215
|
-
}
|
|
2216
|
-
async getMessagesPaginated(args) {
|
|
2217
|
-
return this.stores.memory.getMessagesPaginated(args);
|
|
2218
|
-
}
|
|
2219
1911
|
async updateMessages(_args) {
|
|
2220
1912
|
return this.stores.memory.updateMessages(_args);
|
|
2221
1913
|
}
|
|
2222
|
-
async
|
|
2223
|
-
return this.stores.
|
|
2224
|
-
}
|
|
2225
|
-
async getTraces(args) {
|
|
2226
|
-
return this.stores.traces.getTraces(args);
|
|
2227
|
-
}
|
|
2228
|
-
async getTracesPaginated(args) {
|
|
2229
|
-
return this.stores.traces.getTracesPaginated(args);
|
|
2230
|
-
}
|
|
2231
|
-
async getEvalsByAgentName(agentName, type) {
|
|
2232
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
2233
|
-
}
|
|
2234
|
-
async getEvals(options) {
|
|
2235
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
2236
|
-
}
|
|
2237
|
-
async getWorkflowRuns(args) {
|
|
2238
|
-
return this.stores.workflows.getWorkflowRuns(args);
|
|
1914
|
+
async listWorkflowRuns(args) {
|
|
1915
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
2239
1916
|
}
|
|
2240
1917
|
async getWorkflowRunById(args) {
|
|
2241
1918
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
@@ -2245,9 +1922,9 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2245
1922
|
runId,
|
|
2246
1923
|
stepId,
|
|
2247
1924
|
result,
|
|
2248
|
-
|
|
1925
|
+
requestContext
|
|
2249
1926
|
}) {
|
|
2250
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
1927
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
2251
1928
|
}
|
|
2252
1929
|
async updateWorkflowState({
|
|
2253
1930
|
workflowName,
|
|
@@ -2273,37 +1950,37 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2273
1950
|
async getScoreById({ id: _id }) {
|
|
2274
1951
|
return this.stores.scores.getScoreById({ id: _id });
|
|
2275
1952
|
}
|
|
2276
|
-
async
|
|
1953
|
+
async listScoresByScorerId({
|
|
2277
1954
|
scorerId,
|
|
2278
1955
|
source,
|
|
2279
1956
|
entityId,
|
|
2280
1957
|
entityType,
|
|
2281
1958
|
pagination
|
|
2282
1959
|
}) {
|
|
2283
|
-
return this.stores.scores.
|
|
1960
|
+
return this.stores.scores.listScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
|
|
2284
1961
|
}
|
|
2285
|
-
async saveScore(
|
|
2286
|
-
return this.stores.scores.saveScore(
|
|
1962
|
+
async saveScore(score) {
|
|
1963
|
+
return this.stores.scores.saveScore(score);
|
|
2287
1964
|
}
|
|
2288
|
-
async
|
|
1965
|
+
async listScoresByRunId({
|
|
2289
1966
|
runId,
|
|
2290
1967
|
pagination
|
|
2291
1968
|
}) {
|
|
2292
|
-
return this.stores.scores.
|
|
1969
|
+
return this.stores.scores.listScoresByRunId({ runId, pagination });
|
|
2293
1970
|
}
|
|
2294
|
-
async
|
|
1971
|
+
async listScoresByEntityId({
|
|
2295
1972
|
entityId,
|
|
2296
1973
|
entityType,
|
|
2297
1974
|
pagination
|
|
2298
1975
|
}) {
|
|
2299
|
-
return this.stores.scores.
|
|
1976
|
+
return this.stores.scores.listScoresByEntityId({ entityId, entityType, pagination });
|
|
2300
1977
|
}
|
|
2301
|
-
async
|
|
1978
|
+
async listScoresBySpan({
|
|
2302
1979
|
traceId,
|
|
2303
1980
|
spanId,
|
|
2304
1981
|
pagination
|
|
2305
1982
|
}) {
|
|
2306
|
-
return this.stores.scores.
|
|
1983
|
+
return this.stores.scores.listScoresBySpan({ traceId, spanId, pagination });
|
|
2307
1984
|
}
|
|
2308
1985
|
};
|
|
2309
1986
|
var LanceFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
@@ -2652,14 +2329,14 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2652
2329
|
* ```
|
|
2653
2330
|
*/
|
|
2654
2331
|
static async create(uri, options) {
|
|
2655
|
-
const instance = new _LanceVectorStore();
|
|
2332
|
+
const instance = new _LanceVectorStore(options?.id || crypto.randomUUID());
|
|
2656
2333
|
try {
|
|
2657
2334
|
instance.lanceClient = await lancedb.connect(uri, options);
|
|
2658
2335
|
return instance;
|
|
2659
2336
|
} catch (e) {
|
|
2660
2337
|
throw new error.MastraError(
|
|
2661
2338
|
{
|
|
2662
|
-
id: "
|
|
2339
|
+
id: storage.createVectorErrorId("LANCE", "CONNECT", "FAILED"),
|
|
2663
2340
|
domain: error.ErrorDomain.STORAGE,
|
|
2664
2341
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2665
2342
|
details: { uri }
|
|
@@ -2672,8 +2349,8 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2672
2349
|
* @internal
|
|
2673
2350
|
* Private constructor to enforce using the create factory method
|
|
2674
2351
|
*/
|
|
2675
|
-
constructor() {
|
|
2676
|
-
super();
|
|
2352
|
+
constructor(id) {
|
|
2353
|
+
super({ id });
|
|
2677
2354
|
}
|
|
2678
2355
|
close() {
|
|
2679
2356
|
if (this.lanceClient) {
|
|
@@ -2702,7 +2379,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2702
2379
|
} catch (error$1) {
|
|
2703
2380
|
throw new error.MastraError(
|
|
2704
2381
|
{
|
|
2705
|
-
id: "
|
|
2382
|
+
id: storage.createVectorErrorId("LANCE", "QUERY", "INVALID_ARGS"),
|
|
2706
2383
|
domain: error.ErrorDomain.STORAGE,
|
|
2707
2384
|
category: error.ErrorCategory.USER,
|
|
2708
2385
|
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
@@ -2750,7 +2427,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2750
2427
|
} catch (error$1) {
|
|
2751
2428
|
throw new error.MastraError(
|
|
2752
2429
|
{
|
|
2753
|
-
id: "
|
|
2430
|
+
id: storage.createVectorErrorId("LANCE", "QUERY", "FAILED"),
|
|
2754
2431
|
domain: error.ErrorDomain.STORAGE,
|
|
2755
2432
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2756
2433
|
details: { tableName, includeVector, columnsCount: columns?.length, includeAllColumns }
|
|
@@ -2802,7 +2479,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2802
2479
|
} catch (error$1) {
|
|
2803
2480
|
throw new error.MastraError(
|
|
2804
2481
|
{
|
|
2805
|
-
id: "
|
|
2482
|
+
id: storage.createVectorErrorId("LANCE", "UPSERT", "INVALID_ARGS"),
|
|
2806
2483
|
domain: error.ErrorDomain.STORAGE,
|
|
2807
2484
|
category: error.ErrorCategory.USER,
|
|
2808
2485
|
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
@@ -2838,7 +2515,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2838
2515
|
} catch (error$1) {
|
|
2839
2516
|
throw new error.MastraError(
|
|
2840
2517
|
{
|
|
2841
|
-
id: "
|
|
2518
|
+
id: storage.createVectorErrorId("LANCE", "UPSERT", "FAILED"),
|
|
2842
2519
|
domain: error.ErrorDomain.STORAGE,
|
|
2843
2520
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2844
2521
|
details: { tableName, vectorCount: vectors.length, metadataCount: metadata.length, idsCount: ids.length }
|
|
@@ -2865,7 +2542,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2865
2542
|
async createTable(tableName, data, options) {
|
|
2866
2543
|
if (!this.lanceClient) {
|
|
2867
2544
|
throw new error.MastraError({
|
|
2868
|
-
id: "
|
|
2545
|
+
id: storage.createVectorErrorId("LANCE", "CREATE_TABLE", "INVALID_ARGS"),
|
|
2869
2546
|
domain: error.ErrorDomain.STORAGE,
|
|
2870
2547
|
category: error.ErrorCategory.USER,
|
|
2871
2548
|
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
@@ -2880,7 +2557,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2880
2557
|
} catch (error$1) {
|
|
2881
2558
|
throw new error.MastraError(
|
|
2882
2559
|
{
|
|
2883
|
-
id: "
|
|
2560
|
+
id: storage.createVectorErrorId("LANCE", "CREATE_TABLE", "FAILED"),
|
|
2884
2561
|
domain: error.ErrorDomain.STORAGE,
|
|
2885
2562
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2886
2563
|
details: { tableName }
|
|
@@ -2892,7 +2569,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2892
2569
|
async listTables() {
|
|
2893
2570
|
if (!this.lanceClient) {
|
|
2894
2571
|
throw new error.MastraError({
|
|
2895
|
-
id: "
|
|
2572
|
+
id: storage.createVectorErrorId("LANCE", "LIST_TABLES", "INVALID_ARGS"),
|
|
2896
2573
|
domain: error.ErrorDomain.STORAGE,
|
|
2897
2574
|
category: error.ErrorCategory.USER,
|
|
2898
2575
|
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
@@ -2904,7 +2581,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2904
2581
|
} catch (error$1) {
|
|
2905
2582
|
throw new error.MastraError(
|
|
2906
2583
|
{
|
|
2907
|
-
id: "
|
|
2584
|
+
id: storage.createVectorErrorId("LANCE", "LIST_TABLES", "FAILED"),
|
|
2908
2585
|
domain: error.ErrorDomain.STORAGE,
|
|
2909
2586
|
category: error.ErrorCategory.THIRD_PARTY
|
|
2910
2587
|
},
|
|
@@ -2915,7 +2592,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2915
2592
|
async getTableSchema(tableName) {
|
|
2916
2593
|
if (!this.lanceClient) {
|
|
2917
2594
|
throw new error.MastraError({
|
|
2918
|
-
id: "
|
|
2595
|
+
id: storage.createVectorErrorId("LANCE", "GET_TABLE_SCHEMA", "INVALID_ARGS"),
|
|
2919
2596
|
domain: error.ErrorDomain.STORAGE,
|
|
2920
2597
|
category: error.ErrorCategory.USER,
|
|
2921
2598
|
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
@@ -2928,7 +2605,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2928
2605
|
} catch (error$1) {
|
|
2929
2606
|
throw new error.MastraError(
|
|
2930
2607
|
{
|
|
2931
|
-
id: "
|
|
2608
|
+
id: storage.createVectorErrorId("LANCE", "GET_TABLE_SCHEMA", "FAILED"),
|
|
2932
2609
|
domain: error.ErrorDomain.STORAGE,
|
|
2933
2610
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2934
2611
|
details: { tableName }
|
|
@@ -2963,7 +2640,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2963
2640
|
} catch (err) {
|
|
2964
2641
|
throw new error.MastraError(
|
|
2965
2642
|
{
|
|
2966
|
-
id: "
|
|
2643
|
+
id: storage.createVectorErrorId("LANCE", "CREATE_INDEX", "INVALID_ARGS"),
|
|
2967
2644
|
domain: error.ErrorDomain.STORAGE,
|
|
2968
2645
|
category: error.ErrorCategory.USER,
|
|
2969
2646
|
details: { tableName: tableName || "", indexName, dimension, metric }
|
|
@@ -3008,7 +2685,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3008
2685
|
} catch (error$1) {
|
|
3009
2686
|
throw new error.MastraError(
|
|
3010
2687
|
{
|
|
3011
|
-
id: "
|
|
2688
|
+
id: storage.createVectorErrorId("LANCE", "CREATE_INDEX", "FAILED"),
|
|
3012
2689
|
domain: error.ErrorDomain.STORAGE,
|
|
3013
2690
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3014
2691
|
details: { tableName: tableName || "", indexName, dimension }
|
|
@@ -3020,7 +2697,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3020
2697
|
async listIndexes() {
|
|
3021
2698
|
if (!this.lanceClient) {
|
|
3022
2699
|
throw new error.MastraError({
|
|
3023
|
-
id: "
|
|
2700
|
+
id: storage.createVectorErrorId("LANCE", "LIST_INDEXES", "INVALID_ARGS"),
|
|
3024
2701
|
domain: error.ErrorDomain.STORAGE,
|
|
3025
2702
|
category: error.ErrorCategory.USER,
|
|
3026
2703
|
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
@@ -3039,7 +2716,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3039
2716
|
} catch (error$1) {
|
|
3040
2717
|
throw new error.MastraError(
|
|
3041
2718
|
{
|
|
3042
|
-
id: "
|
|
2719
|
+
id: storage.createVectorErrorId("LANCE", "LIST_INDEXES", "FAILED"),
|
|
3043
2720
|
domain: error.ErrorDomain.STORAGE,
|
|
3044
2721
|
category: error.ErrorCategory.THIRD_PARTY
|
|
3045
2722
|
},
|
|
@@ -3058,7 +2735,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3058
2735
|
} catch (err) {
|
|
3059
2736
|
throw new error.MastraError(
|
|
3060
2737
|
{
|
|
3061
|
-
id: "
|
|
2738
|
+
id: storage.createVectorErrorId("LANCE", "DESCRIBE_INDEX", "INVALID_ARGS"),
|
|
3062
2739
|
domain: error.ErrorDomain.STORAGE,
|
|
3063
2740
|
category: error.ErrorCategory.USER,
|
|
3064
2741
|
details: { indexName }
|
|
@@ -3093,7 +2770,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3093
2770
|
} catch (error$1) {
|
|
3094
2771
|
throw new error.MastraError(
|
|
3095
2772
|
{
|
|
3096
|
-
id: "
|
|
2773
|
+
id: storage.createVectorErrorId("LANCE", "DESCRIBE_INDEX", "FAILED"),
|
|
3097
2774
|
domain: error.ErrorDomain.STORAGE,
|
|
3098
2775
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3099
2776
|
details: { indexName }
|
|
@@ -3113,7 +2790,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3113
2790
|
} catch (err) {
|
|
3114
2791
|
throw new error.MastraError(
|
|
3115
2792
|
{
|
|
3116
|
-
id: "
|
|
2793
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_INDEX", "INVALID_ARGS"),
|
|
3117
2794
|
domain: error.ErrorDomain.STORAGE,
|
|
3118
2795
|
category: error.ErrorCategory.USER,
|
|
3119
2796
|
details: { indexName }
|
|
@@ -3136,7 +2813,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3136
2813
|
} catch (error$1) {
|
|
3137
2814
|
throw new error.MastraError(
|
|
3138
2815
|
{
|
|
3139
|
-
id: "
|
|
2816
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_INDEX", "FAILED"),
|
|
3140
2817
|
domain: error.ErrorDomain.STORAGE,
|
|
3141
2818
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3142
2819
|
details: { indexName }
|
|
@@ -3151,7 +2828,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3151
2828
|
async deleteAllTables() {
|
|
3152
2829
|
if (!this.lanceClient) {
|
|
3153
2830
|
throw new error.MastraError({
|
|
3154
|
-
id: "
|
|
2831
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_ALL_TABLES", "INVALID_ARGS"),
|
|
3155
2832
|
domain: error.ErrorDomain.STORAGE,
|
|
3156
2833
|
category: error.ErrorCategory.USER,
|
|
3157
2834
|
details: { methodName: "deleteAllTables" },
|
|
@@ -3163,7 +2840,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3163
2840
|
} catch (error$1) {
|
|
3164
2841
|
throw new error.MastraError(
|
|
3165
2842
|
{
|
|
3166
|
-
id: "
|
|
2843
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_ALL_TABLES", "FAILED"),
|
|
3167
2844
|
domain: error.ErrorDomain.STORAGE,
|
|
3168
2845
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3169
2846
|
details: { methodName: "deleteAllTables" }
|
|
@@ -3175,7 +2852,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3175
2852
|
async deleteTable(tableName) {
|
|
3176
2853
|
if (!this.lanceClient) {
|
|
3177
2854
|
throw new error.MastraError({
|
|
3178
|
-
id: "
|
|
2855
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_TABLE", "INVALID_ARGS"),
|
|
3179
2856
|
domain: error.ErrorDomain.STORAGE,
|
|
3180
2857
|
category: error.ErrorCategory.USER,
|
|
3181
2858
|
details: { tableName },
|
|
@@ -3187,7 +2864,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3187
2864
|
} catch (error$1) {
|
|
3188
2865
|
throw new error.MastraError(
|
|
3189
2866
|
{
|
|
3190
|
-
id: "
|
|
2867
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_TABLE", "FAILED"),
|
|
3191
2868
|
domain: error.ErrorDomain.STORAGE,
|
|
3192
2869
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3193
2870
|
details: { tableName }
|
|
@@ -3200,7 +2877,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3200
2877
|
const { indexName, update } = params;
|
|
3201
2878
|
if ("id" in params && "filter" in params && params.id && params.filter) {
|
|
3202
2879
|
throw new error.MastraError({
|
|
3203
|
-
id: "
|
|
2880
|
+
id: storage.createVectorErrorId("LANCE", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
|
|
3204
2881
|
domain: error.ErrorDomain.STORAGE,
|
|
3205
2882
|
category: error.ErrorCategory.USER,
|
|
3206
2883
|
text: "id and filter are mutually exclusive",
|
|
@@ -3209,7 +2886,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3209
2886
|
}
|
|
3210
2887
|
if (!("id" in params || "filter" in params) || !params.id && !params.filter) {
|
|
3211
2888
|
throw new error.MastraError({
|
|
3212
|
-
id: "
|
|
2889
|
+
id: storage.createVectorErrorId("LANCE", "UPDATE_VECTOR", "NO_TARGET"),
|
|
3213
2890
|
domain: error.ErrorDomain.STORAGE,
|
|
3214
2891
|
category: error.ErrorCategory.USER,
|
|
3215
2892
|
text: "Either id or filter must be provided",
|
|
@@ -3218,7 +2895,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3218
2895
|
}
|
|
3219
2896
|
if ("filter" in params && params.filter && Object.keys(params.filter).length === 0) {
|
|
3220
2897
|
throw new error.MastraError({
|
|
3221
|
-
id: "
|
|
2898
|
+
id: storage.createVectorErrorId("LANCE", "UPDATE_VECTOR", "EMPTY_FILTER"),
|
|
3222
2899
|
domain: error.ErrorDomain.STORAGE,
|
|
3223
2900
|
category: error.ErrorCategory.USER,
|
|
3224
2901
|
text: "Cannot update with empty filter",
|
|
@@ -3227,7 +2904,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3227
2904
|
}
|
|
3228
2905
|
if (!update.vector && !update.metadata) {
|
|
3229
2906
|
throw new error.MastraError({
|
|
3230
|
-
id: "
|
|
2907
|
+
id: storage.createVectorErrorId("LANCE", "UPDATE_VECTOR", "NO_PAYLOAD"),
|
|
3231
2908
|
domain: error.ErrorDomain.STORAGE,
|
|
3232
2909
|
category: error.ErrorCategory.USER,
|
|
3233
2910
|
text: "No updates provided",
|
|
@@ -3322,7 +2999,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3322
2999
|
if (error$1 instanceof error.MastraError) throw error$1;
|
|
3323
3000
|
throw new error.MastraError(
|
|
3324
3001
|
{
|
|
3325
|
-
id: "
|
|
3002
|
+
id: storage.createVectorErrorId("LANCE", "UPDATE_VECTOR", "FAILED"),
|
|
3326
3003
|
domain: error.ErrorDomain.STORAGE,
|
|
3327
3004
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3328
3005
|
details: {
|
|
@@ -3351,7 +3028,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3351
3028
|
} catch (err) {
|
|
3352
3029
|
throw new error.MastraError(
|
|
3353
3030
|
{
|
|
3354
|
-
id: "
|
|
3031
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_VECTOR", "INVALID_ARGS"),
|
|
3355
3032
|
domain: error.ErrorDomain.STORAGE,
|
|
3356
3033
|
category: error.ErrorCategory.USER,
|
|
3357
3034
|
details: {
|
|
@@ -3384,7 +3061,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3384
3061
|
} catch (error$1) {
|
|
3385
3062
|
throw new error.MastraError(
|
|
3386
3063
|
{
|
|
3387
|
-
id: "
|
|
3064
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_VECTOR", "FAILED"),
|
|
3388
3065
|
domain: error.ErrorDomain.STORAGE,
|
|
3389
3066
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3390
3067
|
details: {
|
|
@@ -3424,7 +3101,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3424
3101
|
async deleteVectors({ indexName, filter, ids }) {
|
|
3425
3102
|
if (ids && filter) {
|
|
3426
3103
|
throw new error.MastraError({
|
|
3427
|
-
id: "
|
|
3104
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
|
|
3428
3105
|
domain: error.ErrorDomain.STORAGE,
|
|
3429
3106
|
category: error.ErrorCategory.USER,
|
|
3430
3107
|
text: "ids and filter are mutually exclusive",
|
|
@@ -3433,7 +3110,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3433
3110
|
}
|
|
3434
3111
|
if (!ids && !filter) {
|
|
3435
3112
|
throw new error.MastraError({
|
|
3436
|
-
id: "
|
|
3113
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_VECTORS", "NO_TARGET"),
|
|
3437
3114
|
domain: error.ErrorDomain.STORAGE,
|
|
3438
3115
|
category: error.ErrorCategory.USER,
|
|
3439
3116
|
text: "Either filter or ids must be provided",
|
|
@@ -3442,7 +3119,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3442
3119
|
}
|
|
3443
3120
|
if (ids && ids.length === 0) {
|
|
3444
3121
|
throw new error.MastraError({
|
|
3445
|
-
id: "
|
|
3122
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_VECTORS", "EMPTY_IDS"),
|
|
3446
3123
|
domain: error.ErrorDomain.STORAGE,
|
|
3447
3124
|
category: error.ErrorCategory.USER,
|
|
3448
3125
|
text: "Cannot delete with empty ids array",
|
|
@@ -3451,7 +3128,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3451
3128
|
}
|
|
3452
3129
|
if (filter && Object.keys(filter).length === 0) {
|
|
3453
3130
|
throw new error.MastraError({
|
|
3454
|
-
id: "
|
|
3131
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_VECTORS", "EMPTY_FILTER"),
|
|
3455
3132
|
domain: error.ErrorDomain.STORAGE,
|
|
3456
3133
|
category: error.ErrorCategory.USER,
|
|
3457
3134
|
text: "Cannot delete with empty filter",
|
|
@@ -3511,7 +3188,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3511
3188
|
if (error$1 instanceof error.MastraError) throw error$1;
|
|
3512
3189
|
throw new error.MastraError(
|
|
3513
3190
|
{
|
|
3514
|
-
id: "
|
|
3191
|
+
id: storage.createVectorErrorId("LANCE", "DELETE_VECTORS", "FAILED"),
|
|
3515
3192
|
domain: error.ErrorDomain.STORAGE,
|
|
3516
3193
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3517
3194
|
details: {
|