@mastra/lance 0.0.0-vector-extension-schema-20250922130418 → 0.0.0-vnext-20251119160359
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 +527 -3
- package/README.md +61 -4
- package/dist/index.cjs +328 -616
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +329 -617
- 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/scores/index.d.ts +12 -4
- 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 +34 -86
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts +3 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +15 -10
- 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,130 +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 evals = require('@mastra/core/evals');
|
|
8
9
|
var vector = require('@mastra/core/vector');
|
|
9
10
|
var filter = require('@mastra/core/vector/filter');
|
|
10
11
|
|
|
11
12
|
// src/storage/index.ts
|
|
12
|
-
var StoreLegacyEvalsLance = class extends storage.LegacyEvalsStorage {
|
|
13
|
-
client;
|
|
14
|
-
constructor({ client }) {
|
|
15
|
-
super();
|
|
16
|
-
this.client = client;
|
|
17
|
-
}
|
|
18
|
-
async getEvalsByAgentName(agentName, type) {
|
|
19
|
-
try {
|
|
20
|
-
const table = await this.client.openTable(storage.TABLE_EVALS);
|
|
21
|
-
const query = table.query().where(`agent_name = '${agentName}'`);
|
|
22
|
-
const records = await query.toArray();
|
|
23
|
-
let filteredRecords = records;
|
|
24
|
-
if (type === "live") {
|
|
25
|
-
filteredRecords = records.filter((record) => record.test_info === null);
|
|
26
|
-
} else if (type === "test") {
|
|
27
|
-
filteredRecords = records.filter((record) => record.test_info !== null);
|
|
28
|
-
}
|
|
29
|
-
return filteredRecords.map((record) => {
|
|
30
|
-
return {
|
|
31
|
-
id: record.id,
|
|
32
|
-
input: record.input,
|
|
33
|
-
output: record.output,
|
|
34
|
-
agentName: record.agent_name,
|
|
35
|
-
metricName: record.metric_name,
|
|
36
|
-
result: JSON.parse(record.result),
|
|
37
|
-
instructions: record.instructions,
|
|
38
|
-
testInfo: record.test_info ? JSON.parse(record.test_info) : null,
|
|
39
|
-
globalRunId: record.global_run_id,
|
|
40
|
-
runId: record.run_id,
|
|
41
|
-
createdAt: new Date(record.created_at).toString()
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
} catch (error$1) {
|
|
45
|
-
throw new error.MastraError(
|
|
46
|
-
{
|
|
47
|
-
id: "LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
48
|
-
domain: error.ErrorDomain.STORAGE,
|
|
49
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
50
|
-
details: { agentName }
|
|
51
|
-
},
|
|
52
|
-
error$1
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async getEvals(options) {
|
|
57
|
-
try {
|
|
58
|
-
const table = await this.client.openTable(storage.TABLE_EVALS);
|
|
59
|
-
const conditions = [];
|
|
60
|
-
if (options.agentName) {
|
|
61
|
-
conditions.push(`agent_name = '${options.agentName}'`);
|
|
62
|
-
}
|
|
63
|
-
if (options.type === "live") {
|
|
64
|
-
conditions.push("length(test_info) = 0");
|
|
65
|
-
} else if (options.type === "test") {
|
|
66
|
-
conditions.push("length(test_info) > 0");
|
|
67
|
-
}
|
|
68
|
-
const startDate = options.dateRange?.start || options.fromDate;
|
|
69
|
-
const endDate = options.dateRange?.end || options.toDate;
|
|
70
|
-
if (startDate) {
|
|
71
|
-
conditions.push(`\`created_at\` >= ${startDate.getTime()}`);
|
|
72
|
-
}
|
|
73
|
-
if (endDate) {
|
|
74
|
-
conditions.push(`\`created_at\` <= ${endDate.getTime()}`);
|
|
75
|
-
}
|
|
76
|
-
let total = 0;
|
|
77
|
-
if (conditions.length > 0) {
|
|
78
|
-
total = await table.countRows(conditions.join(" AND "));
|
|
79
|
-
} else {
|
|
80
|
-
total = await table.countRows();
|
|
81
|
-
}
|
|
82
|
-
const query = table.query();
|
|
83
|
-
if (conditions.length > 0) {
|
|
84
|
-
const whereClause = conditions.join(" AND ");
|
|
85
|
-
query.where(whereClause);
|
|
86
|
-
}
|
|
87
|
-
const records = await query.toArray();
|
|
88
|
-
const evals = records.sort((a, b) => b.created_at - a.created_at).map((record) => {
|
|
89
|
-
return {
|
|
90
|
-
id: record.id,
|
|
91
|
-
input: record.input,
|
|
92
|
-
output: record.output,
|
|
93
|
-
agentName: record.agent_name,
|
|
94
|
-
metricName: record.metric_name,
|
|
95
|
-
result: JSON.parse(record.result),
|
|
96
|
-
instructions: record.instructions,
|
|
97
|
-
testInfo: record.test_info ? JSON.parse(record.test_info) : null,
|
|
98
|
-
globalRunId: record.global_run_id,
|
|
99
|
-
runId: record.run_id,
|
|
100
|
-
createdAt: new Date(record.created_at).toISOString()
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
const page = options.page || 0;
|
|
104
|
-
const perPage = options.perPage || 10;
|
|
105
|
-
const pagedEvals = evals.slice(page * perPage, (page + 1) * perPage);
|
|
106
|
-
return {
|
|
107
|
-
evals: pagedEvals,
|
|
108
|
-
total,
|
|
109
|
-
page,
|
|
110
|
-
perPage,
|
|
111
|
-
hasMore: total > (page + 1) * perPage
|
|
112
|
-
};
|
|
113
|
-
} catch (error$1) {
|
|
114
|
-
throw new error.MastraError(
|
|
115
|
-
{
|
|
116
|
-
id: "LANCE_STORE_GET_EVALS_FAILED",
|
|
117
|
-
domain: error.ErrorDomain.STORAGE,
|
|
118
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
119
|
-
details: { agentName: options.agentName ?? "" }
|
|
120
|
-
},
|
|
121
|
-
error$1
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
13
|
function getPrimaryKeys(tableName) {
|
|
127
14
|
let primaryId = ["id"];
|
|
128
15
|
if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
|
|
129
16
|
primaryId = ["workflow_name", "run_id"];
|
|
130
|
-
} else if (tableName === storage.TABLE_EVALS) {
|
|
131
|
-
primaryId = ["agent_name", "metric_name", "run_id"];
|
|
132
17
|
}
|
|
133
18
|
return primaryId;
|
|
134
19
|
}
|
|
@@ -248,6 +133,10 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
248
133
|
this.client = client;
|
|
249
134
|
this.operations = operations;
|
|
250
135
|
}
|
|
136
|
+
// Utility to escape single quotes in SQL strings
|
|
137
|
+
escapeSql(str) {
|
|
138
|
+
return str.replace(/'/g, "''");
|
|
139
|
+
}
|
|
251
140
|
async getThreadById({ threadId }) {
|
|
252
141
|
try {
|
|
253
142
|
const thread = await this.operations.load({ tableName: storage.TABLE_THREADS, keys: { id: threadId } });
|
|
@@ -270,26 +159,6 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
270
159
|
);
|
|
271
160
|
}
|
|
272
161
|
}
|
|
273
|
-
async getThreadsByResourceId({ resourceId }) {
|
|
274
|
-
try {
|
|
275
|
-
const table = await this.client.openTable(storage.TABLE_THREADS);
|
|
276
|
-
const query = table.query().where(`\`resourceId\` = '${resourceId}'`);
|
|
277
|
-
const records = await query.toArray();
|
|
278
|
-
return processResultWithTypeConversion(
|
|
279
|
-
records,
|
|
280
|
-
await getTableSchema({ tableName: storage.TABLE_THREADS, client: this.client })
|
|
281
|
-
);
|
|
282
|
-
} catch (error$1) {
|
|
283
|
-
throw new error.MastraError(
|
|
284
|
-
{
|
|
285
|
-
id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
|
|
286
|
-
domain: error.ErrorDomain.STORAGE,
|
|
287
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
288
|
-
},
|
|
289
|
-
error$1
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
162
|
/**
|
|
294
163
|
* Saves a thread to the database. This function doesn't overwrite existing threads.
|
|
295
164
|
* @param thread - The thread to save
|
|
@@ -394,100 +263,174 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
394
263
|
})() : message.content
|
|
395
264
|
};
|
|
396
265
|
}
|
|
397
|
-
async
|
|
398
|
-
|
|
399
|
-
resourceId,
|
|
400
|
-
selectBy,
|
|
401
|
-
format,
|
|
402
|
-
threadConfig
|
|
403
|
-
}) {
|
|
266
|
+
async listMessagesById({ messageIds }) {
|
|
267
|
+
if (messageIds.length === 0) return { messages: [] };
|
|
404
268
|
try {
|
|
405
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
406
|
-
if (threadConfig) {
|
|
407
|
-
throw new Error("ThreadConfig is not supported by LanceDB storage");
|
|
408
|
-
}
|
|
409
|
-
const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
410
269
|
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const threadIds = [...new Set(selectBy.include.map((item) => item.threadId))];
|
|
414
|
-
for (const threadId2 of threadIds) {
|
|
415
|
-
const threadQuery = table.query().where(`thread_id = '${threadId2}'`);
|
|
416
|
-
let threadRecords = await threadQuery.toArray();
|
|
417
|
-
allRecords.push(...threadRecords);
|
|
418
|
-
}
|
|
419
|
-
} else {
|
|
420
|
-
let query = table.query().where(`\`thread_id\` = '${threadId}'`);
|
|
421
|
-
allRecords = await query.toArray();
|
|
422
|
-
}
|
|
423
|
-
allRecords.sort((a, b) => {
|
|
424
|
-
const dateA = new Date(a.createdAt).getTime();
|
|
425
|
-
const dateB = new Date(b.createdAt).getTime();
|
|
426
|
-
return dateA - dateB;
|
|
427
|
-
});
|
|
428
|
-
if (selectBy?.include && selectBy.include.length > 0) {
|
|
429
|
-
allRecords = this.processMessagesWithContext(allRecords, selectBy.include);
|
|
430
|
-
}
|
|
431
|
-
if (limit !== Number.MAX_SAFE_INTEGER) {
|
|
432
|
-
allRecords = allRecords.slice(-limit);
|
|
433
|
-
}
|
|
270
|
+
const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
|
|
271
|
+
const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
|
|
434
272
|
const messages = processResultWithTypeConversion(
|
|
435
273
|
allRecords,
|
|
436
274
|
await getTableSchema({ tableName: storage.TABLE_MESSAGES, client: this.client })
|
|
437
275
|
);
|
|
438
|
-
const list = new agent.MessageList(
|
|
439
|
-
|
|
440
|
-
|
|
276
|
+
const list = new agent.MessageList().add(
|
|
277
|
+
messages.map(this.normalizeMessage),
|
|
278
|
+
"memory"
|
|
279
|
+
);
|
|
280
|
+
return { messages: list.get.all.db() };
|
|
441
281
|
} catch (error$1) {
|
|
442
282
|
throw new error.MastraError(
|
|
443
283
|
{
|
|
444
|
-
id: "
|
|
284
|
+
id: "LANCE_STORE_LIST_MESSAGES_BY_ID_FAILED",
|
|
445
285
|
domain: error.ErrorDomain.STORAGE,
|
|
446
286
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
447
287
|
details: {
|
|
448
|
-
|
|
449
|
-
resourceId: resourceId ?? ""
|
|
288
|
+
messageIds: JSON.stringify(messageIds)
|
|
450
289
|
}
|
|
451
290
|
},
|
|
452
291
|
error$1
|
|
453
292
|
);
|
|
454
293
|
}
|
|
455
294
|
}
|
|
456
|
-
async
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
295
|
+
async listMessages(args) {
|
|
296
|
+
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
297
|
+
if (!threadId.trim()) {
|
|
298
|
+
throw new error.MastraError(
|
|
299
|
+
{
|
|
300
|
+
id: "STORAGE_LANCE_LIST_MESSAGES_INVALID_THREAD_ID",
|
|
301
|
+
domain: error.ErrorDomain.STORAGE,
|
|
302
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
303
|
+
details: { threadId }
|
|
304
|
+
},
|
|
305
|
+
new Error("threadId must be a non-empty string")
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
const perPage = storage.normalizePerPage(perPageInput, 40);
|
|
309
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
461
310
|
try {
|
|
311
|
+
if (page < 0) {
|
|
312
|
+
throw new error.MastraError(
|
|
313
|
+
{
|
|
314
|
+
id: "STORAGE_LANCE_LIST_MESSAGES_INVALID_PAGE",
|
|
315
|
+
domain: error.ErrorDomain.STORAGE,
|
|
316
|
+
category: error.ErrorCategory.USER,
|
|
317
|
+
details: { page }
|
|
318
|
+
},
|
|
319
|
+
new Error("page must be >= 0")
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
462
323
|
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
324
|
+
const conditions = [`thread_id = '${this.escapeSql(threadId)}'`];
|
|
325
|
+
if (resourceId) {
|
|
326
|
+
conditions.push(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
|
|
327
|
+
}
|
|
328
|
+
if (filter?.dateRange?.start) {
|
|
329
|
+
const startTime = filter.dateRange.start instanceof Date ? filter.dateRange.start.getTime() : new Date(filter.dateRange.start).getTime();
|
|
330
|
+
conditions.push(`\`createdAt\` >= ${startTime}`);
|
|
331
|
+
}
|
|
332
|
+
if (filter?.dateRange?.end) {
|
|
333
|
+
const endTime = filter.dateRange.end instanceof Date ? filter.dateRange.end.getTime() : new Date(filter.dateRange.end).getTime();
|
|
334
|
+
conditions.push(`\`createdAt\` <= ${endTime}`);
|
|
335
|
+
}
|
|
336
|
+
const whereClause = conditions.join(" AND ");
|
|
337
|
+
const total = await table.countRows(whereClause);
|
|
338
|
+
const query = table.query().where(whereClause);
|
|
339
|
+
let allRecords = await query.toArray();
|
|
340
|
+
allRecords.sort((a, b) => {
|
|
341
|
+
const aValue = field === "createdAt" ? a.createdAt : a[field];
|
|
342
|
+
const bValue = field === "createdAt" ? b.createdAt : b[field];
|
|
343
|
+
if (aValue == null && bValue == null) return 0;
|
|
344
|
+
if (aValue == null) return direction === "ASC" ? -1 : 1;
|
|
345
|
+
if (bValue == null) return direction === "ASC" ? 1 : -1;
|
|
346
|
+
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
347
|
+
return direction === "ASC" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
|
|
348
|
+
}
|
|
349
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
350
|
+
});
|
|
351
|
+
const paginatedRecords = allRecords.slice(offset, offset + perPage);
|
|
352
|
+
const messages = paginatedRecords.map((row) => this.normalizeMessage(row));
|
|
353
|
+
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
354
|
+
return {
|
|
355
|
+
messages: [],
|
|
356
|
+
total: 0,
|
|
357
|
+
page,
|
|
358
|
+
perPage: perPageForResponse,
|
|
359
|
+
hasMore: false
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
const messageIds = new Set(messages.map((m) => m.id));
|
|
363
|
+
if (include && include.length > 0) {
|
|
364
|
+
const threadIds = [...new Set(include.map((item) => item.threadId || threadId))];
|
|
365
|
+
const allThreadMessages = [];
|
|
366
|
+
for (const tid of threadIds) {
|
|
367
|
+
const threadQuery = table.query().where(`thread_id = '${tid}'`);
|
|
368
|
+
let threadRecords = await threadQuery.toArray();
|
|
369
|
+
allThreadMessages.push(...threadRecords);
|
|
370
|
+
}
|
|
371
|
+
allThreadMessages.sort((a, b) => a.createdAt - b.createdAt);
|
|
372
|
+
const contextMessages = this.processMessagesWithContext(allThreadMessages, include);
|
|
373
|
+
const includedMessages = contextMessages.map((row) => this.normalizeMessage(row));
|
|
374
|
+
for (const includeMsg of includedMessages) {
|
|
375
|
+
if (!messageIds.has(includeMsg.id)) {
|
|
376
|
+
messages.push(includeMsg);
|
|
377
|
+
messageIds.add(includeMsg.id);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const list = new agent.MessageList().add(messages, "memory");
|
|
382
|
+
let finalMessages = list.get.all.db();
|
|
383
|
+
finalMessages = finalMessages.sort((a, b) => {
|
|
384
|
+
const aValue = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
|
|
385
|
+
const bValue = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
|
|
386
|
+
if (aValue == null && bValue == null) return 0;
|
|
387
|
+
if (aValue == null) return direction === "ASC" ? -1 : 1;
|
|
388
|
+
if (bValue == null) return direction === "ASC" ? 1 : -1;
|
|
389
|
+
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
390
|
+
return direction === "ASC" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
|
|
391
|
+
}
|
|
392
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
393
|
+
});
|
|
394
|
+
const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
|
|
395
|
+
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
396
|
+
const fetchedAll = perPageInput === false || allThreadMessagesReturned;
|
|
397
|
+
const hasMore = !fetchedAll && offset + perPage < total;
|
|
398
|
+
return {
|
|
399
|
+
messages: finalMessages,
|
|
400
|
+
total,
|
|
401
|
+
page,
|
|
402
|
+
perPage: perPageForResponse,
|
|
403
|
+
hasMore
|
|
404
|
+
};
|
|
472
405
|
} catch (error$1) {
|
|
473
|
-
|
|
406
|
+
const mastraError = new error.MastraError(
|
|
474
407
|
{
|
|
475
|
-
id: "
|
|
408
|
+
id: "LANCE_STORE_LIST_MESSAGES_FAILED",
|
|
476
409
|
domain: error.ErrorDomain.STORAGE,
|
|
477
410
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
478
411
|
details: {
|
|
479
|
-
|
|
412
|
+
threadId,
|
|
413
|
+
resourceId: resourceId ?? ""
|
|
480
414
|
}
|
|
481
415
|
},
|
|
482
416
|
error$1
|
|
483
417
|
);
|
|
418
|
+
this.logger?.error?.(mastraError.toString());
|
|
419
|
+
this.logger?.trackException?.(mastraError);
|
|
420
|
+
return {
|
|
421
|
+
messages: [],
|
|
422
|
+
total: 0,
|
|
423
|
+
page,
|
|
424
|
+
perPage: perPageForResponse,
|
|
425
|
+
hasMore: false
|
|
426
|
+
};
|
|
484
427
|
}
|
|
485
428
|
}
|
|
486
429
|
async saveMessages(args) {
|
|
487
430
|
try {
|
|
488
|
-
const { messages
|
|
431
|
+
const { messages } = args;
|
|
489
432
|
if (messages.length === 0) {
|
|
490
|
-
return [];
|
|
433
|
+
return { messages: [] };
|
|
491
434
|
}
|
|
492
435
|
const threadId = messages[0]?.threadId;
|
|
493
436
|
if (!threadId) {
|
|
@@ -523,8 +466,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
523
466
|
const updateRecord = { id: threadId, updatedAt: currentTime };
|
|
524
467
|
await threadsTable.mergeInsert("id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([updateRecord]);
|
|
525
468
|
const list = new agent.MessageList().add(messages, "memory");
|
|
526
|
-
|
|
527
|
-
return list.get.all.v1();
|
|
469
|
+
return { messages: list.get.all.db() };
|
|
528
470
|
} catch (error$1) {
|
|
529
471
|
throw new error.MastraError(
|
|
530
472
|
{
|
|
@@ -536,32 +478,54 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
536
478
|
);
|
|
537
479
|
}
|
|
538
480
|
}
|
|
539
|
-
async
|
|
481
|
+
async listThreadsByResourceId(args) {
|
|
540
482
|
try {
|
|
541
|
-
const { resourceId, page = 0, perPage
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
483
|
+
const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
|
|
484
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
485
|
+
if (page < 0) {
|
|
486
|
+
throw new error.MastraError(
|
|
487
|
+
{
|
|
488
|
+
id: "STORAGE_LANCE_LIST_THREADS_BY_RESOURCE_ID_INVALID_PAGE",
|
|
489
|
+
domain: error.ErrorDomain.STORAGE,
|
|
490
|
+
category: error.ErrorCategory.USER,
|
|
491
|
+
details: { page }
|
|
492
|
+
},
|
|
493
|
+
new Error("page must be >= 0")
|
|
494
|
+
);
|
|
549
495
|
}
|
|
496
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
497
|
+
const { field, direction } = this.parseOrderBy(orderBy);
|
|
498
|
+
const table = await this.client.openTable(storage.TABLE_THREADS);
|
|
499
|
+
const total = await table.countRows(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
|
|
500
|
+
const query = table.query().where(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
|
|
550
501
|
const records = await query.toArray();
|
|
551
|
-
records.sort((a, b) =>
|
|
502
|
+
records.sort((a, b) => {
|
|
503
|
+
const aValue = ["createdAt", "updatedAt"].includes(field) ? new Date(a[field]).getTime() : a[field];
|
|
504
|
+
const bValue = ["createdAt", "updatedAt"].includes(field) ? new Date(b[field]).getTime() : b[field];
|
|
505
|
+
if (aValue == null && bValue == null) return 0;
|
|
506
|
+
if (aValue == null) return direction === "ASC" ? -1 : 1;
|
|
507
|
+
if (bValue == null) return direction === "ASC" ? 1 : -1;
|
|
508
|
+
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
509
|
+
return direction === "ASC" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
|
|
510
|
+
}
|
|
511
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
512
|
+
});
|
|
513
|
+
const paginatedRecords = records.slice(offset, offset + perPage);
|
|
552
514
|
const schema = await getTableSchema({ tableName: storage.TABLE_THREADS, client: this.client });
|
|
553
|
-
const threads =
|
|
515
|
+
const threads = paginatedRecords.map(
|
|
516
|
+
(record) => processResultWithTypeConversion(record, schema)
|
|
517
|
+
);
|
|
554
518
|
return {
|
|
555
519
|
threads,
|
|
556
520
|
total,
|
|
557
521
|
page,
|
|
558
|
-
perPage,
|
|
559
|
-
hasMore:
|
|
522
|
+
perPage: perPageForResponse,
|
|
523
|
+
hasMore: offset + perPage < total
|
|
560
524
|
};
|
|
561
525
|
} catch (error$1) {
|
|
562
526
|
throw new error.MastraError(
|
|
563
527
|
{
|
|
564
|
-
id: "
|
|
528
|
+
id: "LANCE_STORE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
|
|
565
529
|
domain: error.ErrorDomain.STORAGE,
|
|
566
530
|
category: error.ErrorCategory.THIRD_PARTY
|
|
567
531
|
},
|
|
@@ -617,132 +581,8 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
617
581
|
});
|
|
618
582
|
return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
|
|
619
583
|
}
|
|
620
|
-
async getMessagesPaginated(args) {
|
|
621
|
-
const { threadId, resourceId, selectBy, format = "v1" } = args;
|
|
622
|
-
const page = selectBy?.pagination?.page ?? 0;
|
|
623
|
-
const perPage = selectBy?.pagination?.perPage ?? 10;
|
|
624
|
-
try {
|
|
625
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
626
|
-
const dateRange = selectBy?.pagination?.dateRange;
|
|
627
|
-
const fromDate = dateRange?.start;
|
|
628
|
-
const toDate = dateRange?.end;
|
|
629
|
-
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
630
|
-
const messages = [];
|
|
631
|
-
if (selectBy?.include && Array.isArray(selectBy.include)) {
|
|
632
|
-
const threadIds = [...new Set(selectBy.include.map((item) => item.threadId))];
|
|
633
|
-
const allThreadMessages = [];
|
|
634
|
-
for (const threadId2 of threadIds) {
|
|
635
|
-
const threadQuery = table.query().where(`thread_id = '${threadId2}'`);
|
|
636
|
-
let threadRecords = await threadQuery.toArray();
|
|
637
|
-
if (fromDate) threadRecords = threadRecords.filter((m) => m.createdAt >= fromDate.getTime());
|
|
638
|
-
if (toDate) threadRecords = threadRecords.filter((m) => m.createdAt <= toDate.getTime());
|
|
639
|
-
allThreadMessages.push(...threadRecords);
|
|
640
|
-
}
|
|
641
|
-
allThreadMessages.sort((a, b) => a.createdAt - b.createdAt);
|
|
642
|
-
const contextMessages = this.processMessagesWithContext(allThreadMessages, selectBy.include);
|
|
643
|
-
messages.push(...contextMessages);
|
|
644
|
-
}
|
|
645
|
-
const conditions = [`thread_id = '${threadId}'`];
|
|
646
|
-
if (resourceId) {
|
|
647
|
-
conditions.push(`\`resourceId\` = '${resourceId}'`);
|
|
648
|
-
}
|
|
649
|
-
if (fromDate) {
|
|
650
|
-
conditions.push(`\`createdAt\` >= ${fromDate.getTime()}`);
|
|
651
|
-
}
|
|
652
|
-
if (toDate) {
|
|
653
|
-
conditions.push(`\`createdAt\` <= ${toDate.getTime()}`);
|
|
654
|
-
}
|
|
655
|
-
let total = 0;
|
|
656
|
-
if (conditions.length > 0) {
|
|
657
|
-
total = await table.countRows(conditions.join(" AND "));
|
|
658
|
-
} else {
|
|
659
|
-
total = await table.countRows();
|
|
660
|
-
}
|
|
661
|
-
if (total === 0 && messages.length === 0) {
|
|
662
|
-
return {
|
|
663
|
-
messages: [],
|
|
664
|
-
total: 0,
|
|
665
|
-
page,
|
|
666
|
-
perPage,
|
|
667
|
-
hasMore: false
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
const excludeIds = messages.map((m) => m.id);
|
|
671
|
-
let selectedMessages = [];
|
|
672
|
-
if (selectBy?.last && selectBy.last > 0) {
|
|
673
|
-
const query = table.query();
|
|
674
|
-
if (conditions.length > 0) {
|
|
675
|
-
query.where(conditions.join(" AND "));
|
|
676
|
-
}
|
|
677
|
-
let records = await query.toArray();
|
|
678
|
-
records = records.sort((a, b) => a.createdAt - b.createdAt);
|
|
679
|
-
if (excludeIds.length > 0) {
|
|
680
|
-
records = records.filter((m) => !excludeIds.includes(m.id));
|
|
681
|
-
}
|
|
682
|
-
selectedMessages = records.slice(-selectBy.last);
|
|
683
|
-
} else {
|
|
684
|
-
const query = table.query();
|
|
685
|
-
if (conditions.length > 0) {
|
|
686
|
-
query.where(conditions.join(" AND "));
|
|
687
|
-
}
|
|
688
|
-
let records = await query.toArray();
|
|
689
|
-
records = records.sort((a, b) => a.createdAt - b.createdAt);
|
|
690
|
-
if (excludeIds.length > 0) {
|
|
691
|
-
records = records.filter((m) => !excludeIds.includes(m.id));
|
|
692
|
-
}
|
|
693
|
-
selectedMessages = records.slice(page * perPage, (page + 1) * perPage);
|
|
694
|
-
}
|
|
695
|
-
const allMessages = [...messages, ...selectedMessages];
|
|
696
|
-
const seen = /* @__PURE__ */ new Set();
|
|
697
|
-
const dedupedMessages = allMessages.filter((m) => {
|
|
698
|
-
const key = `${m.id}:${m.thread_id}`;
|
|
699
|
-
if (seen.has(key)) return false;
|
|
700
|
-
seen.add(key);
|
|
701
|
-
return true;
|
|
702
|
-
});
|
|
703
|
-
const formattedMessages = dedupedMessages.map((msg) => {
|
|
704
|
-
const { thread_id, ...rest } = msg;
|
|
705
|
-
return {
|
|
706
|
-
...rest,
|
|
707
|
-
threadId: thread_id,
|
|
708
|
-
content: typeof msg.content === "string" ? (() => {
|
|
709
|
-
try {
|
|
710
|
-
return JSON.parse(msg.content);
|
|
711
|
-
} catch {
|
|
712
|
-
return msg.content;
|
|
713
|
-
}
|
|
714
|
-
})() : msg.content
|
|
715
|
-
};
|
|
716
|
-
});
|
|
717
|
-
const list = new agent.MessageList().add(formattedMessages, "memory");
|
|
718
|
-
return {
|
|
719
|
-
messages: format === "v2" ? list.get.all.v2() : list.get.all.v1(),
|
|
720
|
-
total,
|
|
721
|
-
// Total should be the count of messages matching the filters
|
|
722
|
-
page,
|
|
723
|
-
perPage,
|
|
724
|
-
hasMore: total > (page + 1) * perPage
|
|
725
|
-
};
|
|
726
|
-
} catch (error$1) {
|
|
727
|
-
const mastraError = new error.MastraError(
|
|
728
|
-
{
|
|
729
|
-
id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
730
|
-
domain: error.ErrorDomain.STORAGE,
|
|
731
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
732
|
-
details: {
|
|
733
|
-
threadId,
|
|
734
|
-
resourceId: resourceId ?? ""
|
|
735
|
-
}
|
|
736
|
-
},
|
|
737
|
-
error$1
|
|
738
|
-
);
|
|
739
|
-
this.logger?.trackException?.(mastraError);
|
|
740
|
-
this.logger?.error?.(mastraError.toString());
|
|
741
|
-
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
584
|
/**
|
|
745
|
-
* Parse message data from LanceDB record format to
|
|
585
|
+
* Parse message data from LanceDB record format to MastraDBMessage format
|
|
746
586
|
*/
|
|
747
587
|
parseMessageData(data) {
|
|
748
588
|
const { thread_id, ...rest } = data;
|
|
@@ -1398,13 +1238,27 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1398
1238
|
this.client = client;
|
|
1399
1239
|
}
|
|
1400
1240
|
async saveScore(score) {
|
|
1241
|
+
let validatedScore;
|
|
1242
|
+
try {
|
|
1243
|
+
validatedScore = evals.saveScorePayloadSchema.parse(score);
|
|
1244
|
+
} catch (error$1) {
|
|
1245
|
+
throw new error.MastraError(
|
|
1246
|
+
{
|
|
1247
|
+
id: "LANCE_STORAGE_SAVE_SCORE_FAILED",
|
|
1248
|
+
text: "Failed to save score in LanceStorage",
|
|
1249
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1250
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1251
|
+
},
|
|
1252
|
+
error$1
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1401
1255
|
try {
|
|
1402
1256
|
const id = crypto.randomUUID();
|
|
1403
1257
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1404
1258
|
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1405
1259
|
const allowedFields = new Set(schema.fields.map((f) => f.name));
|
|
1406
1260
|
const filteredScore = {};
|
|
1407
|
-
Object.keys(
|
|
1261
|
+
Object.keys(validatedScore).forEach((key) => {
|
|
1408
1262
|
if (allowedFields.has(key)) {
|
|
1409
1263
|
filteredScore[key] = score[key];
|
|
1410
1264
|
}
|
|
@@ -1451,7 +1305,7 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1451
1305
|
);
|
|
1452
1306
|
}
|
|
1453
1307
|
}
|
|
1454
|
-
async
|
|
1308
|
+
async listScoresByScorerId({
|
|
1455
1309
|
scorerId,
|
|
1456
1310
|
pagination,
|
|
1457
1311
|
entityId,
|
|
@@ -1459,9 +1313,10 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1459
1313
|
source
|
|
1460
1314
|
}) {
|
|
1461
1315
|
try {
|
|
1316
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1317
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1318
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1462
1319
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1463
|
-
const { page = 0, perPage = 10 } = pagination || {};
|
|
1464
|
-
const offset = page * perPage;
|
|
1465
1320
|
let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1466
1321
|
if (source) {
|
|
1467
1322
|
query = query.where(`\`source\` = '${source}'`);
|
|
@@ -1472,23 +1327,32 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1472
1327
|
if (entityType) {
|
|
1473
1328
|
query = query.where(`\`entityType\` = '${entityType}'`);
|
|
1474
1329
|
}
|
|
1475
|
-
query = query.limit(perPage);
|
|
1476
|
-
if (offset > 0) query.offset(offset);
|
|
1477
|
-
const records = await query.toArray();
|
|
1478
|
-
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1479
|
-
const scores = processResultWithTypeConversion(records, schema);
|
|
1480
1330
|
let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1481
1331
|
if (source) {
|
|
1482
1332
|
totalQuery = totalQuery.where(`\`source\` = '${source}'`);
|
|
1483
1333
|
}
|
|
1334
|
+
if (entityId) {
|
|
1335
|
+
totalQuery = totalQuery.where(`\`entityId\` = '${entityId}'`);
|
|
1336
|
+
}
|
|
1337
|
+
if (entityType) {
|
|
1338
|
+
totalQuery = totalQuery.where(`\`entityType\` = '${entityType}'`);
|
|
1339
|
+
}
|
|
1484
1340
|
const allRecords = await totalQuery.toArray();
|
|
1485
1341
|
const total = allRecords.length;
|
|
1342
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
1343
|
+
if (perPageInput !== false) {
|
|
1344
|
+
query = query.limit(perPage);
|
|
1345
|
+
if (start > 0) query = query.offset(start);
|
|
1346
|
+
}
|
|
1347
|
+
const records = await query.toArray();
|
|
1348
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1349
|
+
const scores = processResultWithTypeConversion(records, schema);
|
|
1486
1350
|
return {
|
|
1487
1351
|
pagination: {
|
|
1488
1352
|
page,
|
|
1489
|
-
perPage,
|
|
1353
|
+
perPage: perPageForResponse,
|
|
1490
1354
|
total,
|
|
1491
|
-
hasMore:
|
|
1355
|
+
hasMore: end < total
|
|
1492
1356
|
},
|
|
1493
1357
|
scores
|
|
1494
1358
|
};
|
|
@@ -1505,27 +1369,32 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1505
1369
|
);
|
|
1506
1370
|
}
|
|
1507
1371
|
}
|
|
1508
|
-
async
|
|
1372
|
+
async listScoresByRunId({
|
|
1509
1373
|
runId,
|
|
1510
1374
|
pagination
|
|
1511
1375
|
}) {
|
|
1512
1376
|
try {
|
|
1377
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1378
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1379
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1513
1380
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1514
|
-
const
|
|
1515
|
-
const
|
|
1516
|
-
const
|
|
1517
|
-
|
|
1381
|
+
const allRecords = await table.query().where(`\`runId\` = '${runId}'`).toArray();
|
|
1382
|
+
const total = allRecords.length;
|
|
1383
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
1384
|
+
let query = table.query().where(`\`runId\` = '${runId}'`);
|
|
1385
|
+
if (perPageInput !== false) {
|
|
1386
|
+
query = query.limit(perPage);
|
|
1387
|
+
if (start > 0) query = query.offset(start);
|
|
1388
|
+
}
|
|
1518
1389
|
const records = await query.toArray();
|
|
1519
1390
|
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1520
1391
|
const scores = processResultWithTypeConversion(records, schema);
|
|
1521
|
-
const allRecords = await table.query().where(`\`runId\` = '${runId}'`).toArray();
|
|
1522
|
-
const total = allRecords.length;
|
|
1523
1392
|
return {
|
|
1524
1393
|
pagination: {
|
|
1525
1394
|
page,
|
|
1526
|
-
perPage,
|
|
1395
|
+
perPage: perPageForResponse,
|
|
1527
1396
|
total,
|
|
1528
|
-
hasMore:
|
|
1397
|
+
hasMore: end < total
|
|
1529
1398
|
},
|
|
1530
1399
|
scores
|
|
1531
1400
|
};
|
|
@@ -1542,28 +1411,33 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1542
1411
|
);
|
|
1543
1412
|
}
|
|
1544
1413
|
}
|
|
1545
|
-
async
|
|
1414
|
+
async listScoresByEntityId({
|
|
1546
1415
|
entityId,
|
|
1547
1416
|
entityType,
|
|
1548
1417
|
pagination
|
|
1549
1418
|
}) {
|
|
1550
1419
|
try {
|
|
1420
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1421
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1422
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1551
1423
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1552
|
-
const
|
|
1553
|
-
const
|
|
1554
|
-
const
|
|
1555
|
-
|
|
1424
|
+
const allRecords = await table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).toArray();
|
|
1425
|
+
const total = allRecords.length;
|
|
1426
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
1427
|
+
let query = table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`);
|
|
1428
|
+
if (perPageInput !== false) {
|
|
1429
|
+
query = query.limit(perPage);
|
|
1430
|
+
if (start > 0) query = query.offset(start);
|
|
1431
|
+
}
|
|
1556
1432
|
const records = await query.toArray();
|
|
1557
1433
|
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1558
1434
|
const scores = processResultWithTypeConversion(records, schema);
|
|
1559
|
-
const allRecords = await table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).toArray();
|
|
1560
|
-
const total = allRecords.length;
|
|
1561
1435
|
return {
|
|
1562
1436
|
pagination: {
|
|
1563
1437
|
page,
|
|
1564
|
-
perPage,
|
|
1438
|
+
perPage: perPageForResponse,
|
|
1565
1439
|
total,
|
|
1566
|
-
hasMore:
|
|
1440
|
+
hasMore: end < total
|
|
1567
1441
|
},
|
|
1568
1442
|
scores
|
|
1569
1443
|
};
|
|
@@ -1580,198 +1454,49 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1580
1454
|
);
|
|
1581
1455
|
}
|
|
1582
1456
|
}
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
constructor({ client, operations }) {
|
|
1588
|
-
super();
|
|
1589
|
-
this.client = client;
|
|
1590
|
-
this.operations = operations;
|
|
1591
|
-
}
|
|
1592
|
-
async saveTrace({ trace }) {
|
|
1593
|
-
try {
|
|
1594
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1595
|
-
const record = {
|
|
1596
|
-
...trace,
|
|
1597
|
-
attributes: JSON.stringify(trace.attributes),
|
|
1598
|
-
status: JSON.stringify(trace.status),
|
|
1599
|
-
events: JSON.stringify(trace.events),
|
|
1600
|
-
links: JSON.stringify(trace.links),
|
|
1601
|
-
other: JSON.stringify(trace.other)
|
|
1602
|
-
};
|
|
1603
|
-
await table.add([record], { mode: "append" });
|
|
1604
|
-
return trace;
|
|
1605
|
-
} catch (error$1) {
|
|
1606
|
-
throw new error.MastraError(
|
|
1607
|
-
{
|
|
1608
|
-
id: "LANCE_STORE_SAVE_TRACE_FAILED",
|
|
1609
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1610
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
1611
|
-
},
|
|
1612
|
-
error$1
|
|
1613
|
-
);
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
async getTraceById({ traceId }) {
|
|
1617
|
-
try {
|
|
1618
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1619
|
-
const query = table.query().where(`id = '${traceId}'`);
|
|
1620
|
-
const records = await query.toArray();
|
|
1621
|
-
return records[0];
|
|
1622
|
-
} catch (error$1) {
|
|
1623
|
-
throw new error.MastraError(
|
|
1624
|
-
{
|
|
1625
|
-
id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
|
|
1626
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1627
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
1628
|
-
},
|
|
1629
|
-
error$1
|
|
1630
|
-
);
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
async getTraces({
|
|
1634
|
-
name,
|
|
1635
|
-
scope,
|
|
1636
|
-
page = 1,
|
|
1637
|
-
perPage = 10,
|
|
1638
|
-
attributes
|
|
1457
|
+
async listScoresBySpan({
|
|
1458
|
+
traceId,
|
|
1459
|
+
spanId,
|
|
1460
|
+
pagination
|
|
1639
1461
|
}) {
|
|
1640
1462
|
try {
|
|
1641
|
-
const
|
|
1642
|
-
const
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
}
|
|
1649
|
-
if (
|
|
1650
|
-
query
|
|
1651
|
-
|
|
1652
|
-
const offset = (page - 1) * perPage;
|
|
1653
|
-
query.limit(perPage);
|
|
1654
|
-
if (offset > 0) {
|
|
1655
|
-
query.offset(offset);
|
|
1656
|
-
}
|
|
1657
|
-
const records = await query.toArray();
|
|
1658
|
-
return records.map((record) => {
|
|
1659
|
-
const processed = {
|
|
1660
|
-
...record,
|
|
1661
|
-
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1662
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1663
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1664
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1665
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1666
|
-
startTime: new Date(record.startTime),
|
|
1667
|
-
endTime: new Date(record.endTime),
|
|
1668
|
-
createdAt: new Date(record.createdAt)
|
|
1669
|
-
};
|
|
1670
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1671
|
-
processed.parentSpanId = "";
|
|
1672
|
-
} else {
|
|
1673
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1674
|
-
}
|
|
1675
|
-
return processed;
|
|
1676
|
-
});
|
|
1677
|
-
} catch (error$1) {
|
|
1678
|
-
throw new error.MastraError(
|
|
1679
|
-
{
|
|
1680
|
-
id: "LANCE_STORE_GET_TRACES_FAILED",
|
|
1681
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1682
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1683
|
-
details: { name: name ?? "", scope: scope ?? "" }
|
|
1684
|
-
},
|
|
1685
|
-
error$1
|
|
1686
|
-
);
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
async getTracesPaginated(args) {
|
|
1690
|
-
try {
|
|
1691
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1692
|
-
const query = table.query();
|
|
1693
|
-
const conditions = [];
|
|
1694
|
-
if (args.name) {
|
|
1695
|
-
conditions.push(`name = '${args.name}'`);
|
|
1696
|
-
}
|
|
1697
|
-
if (args.scope) {
|
|
1698
|
-
conditions.push(`scope = '${args.scope}'`);
|
|
1699
|
-
}
|
|
1700
|
-
if (args.attributes) {
|
|
1701
|
-
const attributesStr = JSON.stringify(args.attributes);
|
|
1702
|
-
conditions.push(`attributes LIKE '%${attributesStr.replace(/"/g, '\\"')}%'`);
|
|
1703
|
-
}
|
|
1704
|
-
if (args.dateRange?.start) {
|
|
1705
|
-
conditions.push(`\`createdAt\` >= ${args.dateRange.start.getTime()}`);
|
|
1706
|
-
}
|
|
1707
|
-
if (args.dateRange?.end) {
|
|
1708
|
-
conditions.push(`\`createdAt\` <= ${args.dateRange.end.getTime()}`);
|
|
1709
|
-
}
|
|
1710
|
-
if (conditions.length > 0) {
|
|
1711
|
-
const whereClause = conditions.join(" AND ");
|
|
1712
|
-
query.where(whereClause);
|
|
1713
|
-
}
|
|
1714
|
-
let total = 0;
|
|
1715
|
-
if (conditions.length > 0) {
|
|
1716
|
-
const countQuery = table.query().where(conditions.join(" AND "));
|
|
1717
|
-
const allRecords = await countQuery.toArray();
|
|
1718
|
-
total = allRecords.length;
|
|
1719
|
-
} else {
|
|
1720
|
-
total = await table.countRows();
|
|
1721
|
-
}
|
|
1722
|
-
const page = args.page || 0;
|
|
1723
|
-
const perPage = args.perPage || 10;
|
|
1724
|
-
const offset = page * perPage;
|
|
1725
|
-
query.limit(perPage);
|
|
1726
|
-
if (offset > 0) {
|
|
1727
|
-
query.offset(offset);
|
|
1463
|
+
const { page, perPage: perPageInput } = pagination;
|
|
1464
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1465
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1466
|
+
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1467
|
+
const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
|
|
1468
|
+
const total = allRecords.length;
|
|
1469
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
1470
|
+
let query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`);
|
|
1471
|
+
if (perPageInput !== false) {
|
|
1472
|
+
query = query.limit(perPage);
|
|
1473
|
+
if (start > 0) query = query.offset(start);
|
|
1728
1474
|
}
|
|
1729
1475
|
const records = await query.toArray();
|
|
1730
|
-
const
|
|
1731
|
-
|
|
1732
|
-
...record,
|
|
1733
|
-
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1734
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1735
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1736
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1737
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1738
|
-
startTime: new Date(record.startTime),
|
|
1739
|
-
endTime: new Date(record.endTime),
|
|
1740
|
-
createdAt: new Date(record.createdAt)
|
|
1741
|
-
};
|
|
1742
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1743
|
-
processed.parentSpanId = "";
|
|
1744
|
-
} else {
|
|
1745
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1746
|
-
}
|
|
1747
|
-
return processed;
|
|
1748
|
-
});
|
|
1476
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1477
|
+
const scores = processResultWithTypeConversion(records, schema);
|
|
1749
1478
|
return {
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1479
|
+
pagination: {
|
|
1480
|
+
page,
|
|
1481
|
+
perPage: perPageForResponse,
|
|
1482
|
+
total,
|
|
1483
|
+
hasMore: end < total
|
|
1484
|
+
},
|
|
1485
|
+
scores
|
|
1755
1486
|
};
|
|
1756
1487
|
} catch (error$1) {
|
|
1757
1488
|
throw new error.MastraError(
|
|
1758
1489
|
{
|
|
1759
|
-
id: "
|
|
1490
|
+
id: "LANCE_STORAGE_GET_SCORES_BY_SPAN_FAILED",
|
|
1491
|
+
text: "Failed to get scores by traceId and spanId in LanceStorage",
|
|
1760
1492
|
domain: error.ErrorDomain.STORAGE,
|
|
1761
1493
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1762
|
-
details: {
|
|
1494
|
+
details: { error: error$1?.message }
|
|
1763
1495
|
},
|
|
1764
1496
|
error$1
|
|
1765
1497
|
);
|
|
1766
1498
|
}
|
|
1767
1499
|
}
|
|
1768
|
-
async batchTraceInsert({ records }) {
|
|
1769
|
-
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
1770
|
-
await this.operations.batchInsert({
|
|
1771
|
-
tableName: storage.TABLE_TRACES,
|
|
1772
|
-
records
|
|
1773
|
-
});
|
|
1774
|
-
}
|
|
1775
1500
|
};
|
|
1776
1501
|
function parseWorkflowRun(row) {
|
|
1777
1502
|
let parsedSnapshot = row.snapshot;
|
|
@@ -1802,7 +1527,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1802
1527
|
// runId,
|
|
1803
1528
|
// stepId,
|
|
1804
1529
|
// result,
|
|
1805
|
-
//
|
|
1530
|
+
// requestContext,
|
|
1806
1531
|
}) {
|
|
1807
1532
|
throw new Error("Method not implemented.");
|
|
1808
1533
|
}
|
|
@@ -1830,11 +1555,13 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1830
1555
|
} else {
|
|
1831
1556
|
createdAt = now;
|
|
1832
1557
|
}
|
|
1558
|
+
const { status, value, ...rest } = snapshot;
|
|
1833
1559
|
const record = {
|
|
1834
1560
|
workflow_name: workflowName,
|
|
1835
1561
|
run_id: runId,
|
|
1836
1562
|
resourceId,
|
|
1837
|
-
snapshot: JSON.stringify(
|
|
1563
|
+
snapshot: JSON.stringify({ status, value, ...rest }),
|
|
1564
|
+
// this is to ensure status is always just before value, for when querying the db by status
|
|
1838
1565
|
createdAt,
|
|
1839
1566
|
updatedAt: now
|
|
1840
1567
|
};
|
|
@@ -1896,7 +1623,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1896
1623
|
);
|
|
1897
1624
|
}
|
|
1898
1625
|
}
|
|
1899
|
-
async
|
|
1626
|
+
async listWorkflowRuns(args) {
|
|
1900
1627
|
try {
|
|
1901
1628
|
const table = await this.client.openTable(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
1902
1629
|
let query = table.query();
|
|
@@ -1904,6 +1631,10 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1904
1631
|
if (args?.workflowName) {
|
|
1905
1632
|
conditions.push(`workflow_name = '${args.workflowName.replace(/'/g, "''")}'`);
|
|
1906
1633
|
}
|
|
1634
|
+
if (args?.status) {
|
|
1635
|
+
const escapedStatus = args.status.replace(/\\/g, "\\\\").replace(/'/g, "''").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
1636
|
+
conditions.push(`\`snapshot\` LIKE '%"status":"${escapedStatus}","value"%'`);
|
|
1637
|
+
}
|
|
1907
1638
|
if (args?.resourceId) {
|
|
1908
1639
|
conditions.push(`\`resourceId\` = '${args.resourceId}'`);
|
|
1909
1640
|
}
|
|
@@ -1920,11 +1651,22 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1920
1651
|
} else {
|
|
1921
1652
|
total = await table.countRows();
|
|
1922
1653
|
}
|
|
1923
|
-
if (args?.
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1654
|
+
if (args?.perPage !== void 0 && args?.page !== void 0) {
|
|
1655
|
+
const normalizedPerPage = storage.normalizePerPage(args.perPage, Number.MAX_SAFE_INTEGER);
|
|
1656
|
+
if (args.page < 0 || !Number.isInteger(args.page)) {
|
|
1657
|
+
throw new error.MastraError(
|
|
1658
|
+
{
|
|
1659
|
+
id: "LANCE_STORE_INVALID_PAGINATION_PARAMS",
|
|
1660
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1661
|
+
category: error.ErrorCategory.USER,
|
|
1662
|
+
details: { page: args.page, perPage: args.perPage }
|
|
1663
|
+
},
|
|
1664
|
+
new Error(`Invalid pagination parameters: page=${args.page}, perPage=${args.perPage}`)
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
const offset = args.page * normalizedPerPage;
|
|
1668
|
+
query.limit(normalizedPerPage);
|
|
1669
|
+
query.offset(offset);
|
|
1928
1670
|
}
|
|
1929
1671
|
const records = await query.toArray();
|
|
1930
1672
|
return {
|
|
@@ -1934,10 +1676,10 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1934
1676
|
} catch (error$1) {
|
|
1935
1677
|
throw new error.MastraError(
|
|
1936
1678
|
{
|
|
1937
|
-
id: "
|
|
1679
|
+
id: "LANCE_STORE_LIST_WORKFLOW_RUNS_FAILED",
|
|
1938
1680
|
domain: error.ErrorDomain.STORAGE,
|
|
1939
1681
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1940
|
-
details: {
|
|
1682
|
+
details: { resourceId: args?.resourceId ?? "", workflowName: args?.workflowName ?? "" }
|
|
1941
1683
|
},
|
|
1942
1684
|
error$1
|
|
1943
1685
|
);
|
|
@@ -1951,6 +1693,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1951
1693
|
lanceClient;
|
|
1952
1694
|
/**
|
|
1953
1695
|
* Creates a new instance of LanceStorage
|
|
1696
|
+
* @param id The unique identifier for this storage instance
|
|
1697
|
+
* @param name The name for this storage instance
|
|
1954
1698
|
* @param uri The URI to connect to LanceDB
|
|
1955
1699
|
* @param options connection options
|
|
1956
1700
|
*
|
|
@@ -1958,31 +1702,29 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1958
1702
|
*
|
|
1959
1703
|
* Connect to a local database
|
|
1960
1704
|
* ```ts
|
|
1961
|
-
* const store = await LanceStorage.create('/path/to/db');
|
|
1705
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', '/path/to/db');
|
|
1962
1706
|
* ```
|
|
1963
1707
|
*
|
|
1964
1708
|
* Connect to a LanceDB cloud database
|
|
1965
1709
|
* ```ts
|
|
1966
|
-
* const store = await LanceStorage.create('db://host:port');
|
|
1710
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', 'db://host:port');
|
|
1967
1711
|
* ```
|
|
1968
1712
|
*
|
|
1969
1713
|
* Connect to a cloud database
|
|
1970
1714
|
* ```ts
|
|
1971
|
-
* const store = await LanceStorage.create('s3://bucket/db', { storageOptions: { timeout: '60s' } });
|
|
1715
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', 's3://bucket/db', { storageOptions: { timeout: '60s' } });
|
|
1972
1716
|
* ```
|
|
1973
1717
|
*/
|
|
1974
|
-
static async create(name, uri, options) {
|
|
1975
|
-
const instance = new _LanceStorage(name);
|
|
1718
|
+
static async create(id, name, uri, options) {
|
|
1719
|
+
const instance = new _LanceStorage(id, name);
|
|
1976
1720
|
try {
|
|
1977
1721
|
instance.lanceClient = await lancedb.connect(uri, options);
|
|
1978
1722
|
const operations = new StoreOperationsLance({ client: instance.lanceClient });
|
|
1979
1723
|
instance.stores = {
|
|
1980
1724
|
operations: new StoreOperationsLance({ client: instance.lanceClient }),
|
|
1981
1725
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
1982
|
-
traces: new StoreTracesLance({ client: instance.lanceClient, operations }),
|
|
1983
1726
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
1984
|
-
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
1985
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
|
|
1727
|
+
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
1986
1728
|
};
|
|
1987
1729
|
return instance;
|
|
1988
1730
|
} catch (e) {
|
|
@@ -2002,15 +1744,13 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2002
1744
|
* @internal
|
|
2003
1745
|
* Private constructor to enforce using the create factory method
|
|
2004
1746
|
*/
|
|
2005
|
-
constructor(name) {
|
|
2006
|
-
super({ name });
|
|
1747
|
+
constructor(id, name) {
|
|
1748
|
+
super({ id, name });
|
|
2007
1749
|
const operations = new StoreOperationsLance({ client: this.lanceClient });
|
|
2008
1750
|
this.stores = {
|
|
2009
1751
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
2010
1752
|
workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
|
|
2011
|
-
traces: new StoreTracesLance({ client: this.lanceClient, operations }),
|
|
2012
1753
|
scores: new StoreScoresLance({ client: this.lanceClient }),
|
|
2013
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
|
|
2014
1754
|
memory: new StoreMemoryLance({ client: this.lanceClient, operations })
|
|
2015
1755
|
};
|
|
2016
1756
|
}
|
|
@@ -2045,9 +1785,6 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2045
1785
|
async getThreadById({ threadId }) {
|
|
2046
1786
|
return this.stores.memory.getThreadById({ threadId });
|
|
2047
1787
|
}
|
|
2048
|
-
async getThreadsByResourceId({ resourceId }) {
|
|
2049
|
-
return this.stores.memory.getThreadsByResourceId({ resourceId });
|
|
2050
|
-
}
|
|
2051
1788
|
/**
|
|
2052
1789
|
* Saves a thread to the database. This function doesn't overwrite existing threads.
|
|
2053
1790
|
* @param thread - The thread to save
|
|
@@ -2072,7 +1809,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2072
1809
|
resourceWorkingMemory: true,
|
|
2073
1810
|
hasColumn: true,
|
|
2074
1811
|
createTable: true,
|
|
2075
|
-
deleteMessages: false
|
|
1812
|
+
deleteMessages: false,
|
|
1813
|
+
listScoresBySpan: true
|
|
2076
1814
|
};
|
|
2077
1815
|
}
|
|
2078
1816
|
async getResourceById({ resourceId }) {
|
|
@@ -2136,50 +1874,17 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2136
1874
|
});
|
|
2137
1875
|
return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
|
|
2138
1876
|
}
|
|
2139
|
-
async
|
|
2140
|
-
|
|
2141
|
-
resourceId,
|
|
2142
|
-
selectBy,
|
|
2143
|
-
format,
|
|
2144
|
-
threadConfig
|
|
2145
|
-
}) {
|
|
2146
|
-
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2147
|
-
}
|
|
2148
|
-
async getMessagesById({
|
|
2149
|
-
messageIds,
|
|
2150
|
-
format
|
|
2151
|
-
}) {
|
|
2152
|
-
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
1877
|
+
async listMessagesById({ messageIds }) {
|
|
1878
|
+
return this.stores.memory.listMessagesById({ messageIds });
|
|
2153
1879
|
}
|
|
2154
1880
|
async saveMessages(args) {
|
|
2155
1881
|
return this.stores.memory.saveMessages(args);
|
|
2156
1882
|
}
|
|
2157
|
-
async getThreadsByResourceIdPaginated(args) {
|
|
2158
|
-
return this.stores.memory.getThreadsByResourceIdPaginated(args);
|
|
2159
|
-
}
|
|
2160
|
-
async getMessagesPaginated(args) {
|
|
2161
|
-
return this.stores.memory.getMessagesPaginated(args);
|
|
2162
|
-
}
|
|
2163
1883
|
async updateMessages(_args) {
|
|
2164
1884
|
return this.stores.memory.updateMessages(_args);
|
|
2165
1885
|
}
|
|
2166
|
-
async
|
|
2167
|
-
return this.stores.
|
|
2168
|
-
}
|
|
2169
|
-
async getTraces(args) {
|
|
2170
|
-
return this.stores.traces.getTraces(args);
|
|
2171
|
-
}
|
|
2172
|
-
async getTracesPaginated(args) {
|
|
2173
|
-
return this.stores.traces.getTracesPaginated(args);
|
|
2174
|
-
}
|
|
2175
|
-
async getEvalsByAgentName(agentName, type) {
|
|
2176
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
2177
|
-
}
|
|
2178
|
-
async getEvals(options) {
|
|
2179
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
2180
|
-
}
|
|
2181
|
-
async getWorkflowRuns(args) {
|
|
2182
|
-
return this.stores.workflows.getWorkflowRuns(args);
|
|
1886
|
+
async listWorkflowRuns(args) {
|
|
1887
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
2183
1888
|
}
|
|
2184
1889
|
async getWorkflowRunById(args) {
|
|
2185
1890
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
@@ -2189,9 +1894,9 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2189
1894
|
runId,
|
|
2190
1895
|
stepId,
|
|
2191
1896
|
result,
|
|
2192
|
-
|
|
1897
|
+
requestContext
|
|
2193
1898
|
}) {
|
|
2194
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
1899
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
2195
1900
|
}
|
|
2196
1901
|
async updateWorkflowState({
|
|
2197
1902
|
workflowName,
|
|
@@ -2217,30 +1922,37 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2217
1922
|
async getScoreById({ id: _id }) {
|
|
2218
1923
|
return this.stores.scores.getScoreById({ id: _id });
|
|
2219
1924
|
}
|
|
2220
|
-
async
|
|
1925
|
+
async listScoresByScorerId({
|
|
2221
1926
|
scorerId,
|
|
2222
1927
|
source,
|
|
2223
1928
|
entityId,
|
|
2224
1929
|
entityType,
|
|
2225
1930
|
pagination
|
|
2226
1931
|
}) {
|
|
2227
|
-
return this.stores.scores.
|
|
1932
|
+
return this.stores.scores.listScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
|
|
2228
1933
|
}
|
|
2229
1934
|
async saveScore(_score) {
|
|
2230
1935
|
return this.stores.scores.saveScore(_score);
|
|
2231
1936
|
}
|
|
2232
|
-
async
|
|
1937
|
+
async listScoresByRunId({
|
|
2233
1938
|
runId,
|
|
2234
1939
|
pagination
|
|
2235
1940
|
}) {
|
|
2236
|
-
return this.stores.scores.
|
|
1941
|
+
return this.stores.scores.listScoresByRunId({ runId, pagination });
|
|
2237
1942
|
}
|
|
2238
|
-
async
|
|
1943
|
+
async listScoresByEntityId({
|
|
2239
1944
|
entityId,
|
|
2240
1945
|
entityType,
|
|
2241
1946
|
pagination
|
|
2242
1947
|
}) {
|
|
2243
|
-
return this.stores.scores.
|
|
1948
|
+
return this.stores.scores.listScoresByEntityId({ entityId, entityType, pagination });
|
|
1949
|
+
}
|
|
1950
|
+
async listScoresBySpan({
|
|
1951
|
+
traceId,
|
|
1952
|
+
spanId,
|
|
1953
|
+
pagination
|
|
1954
|
+
}) {
|
|
1955
|
+
return this.stores.scores.listScoresBySpan({ traceId, spanId, pagination });
|
|
2244
1956
|
}
|
|
2245
1957
|
};
|
|
2246
1958
|
var LanceFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
@@ -2589,7 +2301,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2589
2301
|
* ```
|
|
2590
2302
|
*/
|
|
2591
2303
|
static async create(uri, options) {
|
|
2592
|
-
const instance = new _LanceVectorStore();
|
|
2304
|
+
const instance = new _LanceVectorStore(options?.id || crypto.randomUUID());
|
|
2593
2305
|
try {
|
|
2594
2306
|
instance.lanceClient = await lancedb.connect(uri, options);
|
|
2595
2307
|
return instance;
|
|
@@ -2609,8 +2321,8 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2609
2321
|
* @internal
|
|
2610
2322
|
* Private constructor to enforce using the create factory method
|
|
2611
2323
|
*/
|
|
2612
|
-
constructor() {
|
|
2613
|
-
super();
|
|
2324
|
+
constructor(id) {
|
|
2325
|
+
super({ id });
|
|
2614
2326
|
}
|
|
2615
2327
|
close() {
|
|
2616
2328
|
if (this.lanceClient) {
|