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