@mastra/lance 0.0.0-netlify-no-bundle-20251127120354 → 0.0.0-partial-response-backport-20251204204441
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 +50 -408
- package/README.md +4 -61
- package/dist/index.cjs +647 -297
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +647 -297
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/legacy-evals/index.d.ts +25 -0
- package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +39 -15
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +5 -6
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/traces/index.d.ts +34 -0
- package/dist/storage/domains/traces/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +4 -4
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +81 -27
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/filter.d.ts +5 -5
- package/dist/vector/index.d.ts +1 -3
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +15 -13
package/dist/index.cjs
CHANGED
|
@@ -5,15 +5,131 @@ var error = require('@mastra/core/error');
|
|
|
5
5
|
var storage = require('@mastra/core/storage');
|
|
6
6
|
var agent = require('@mastra/core/agent');
|
|
7
7
|
var apacheArrow = require('apache-arrow');
|
|
8
|
-
var
|
|
8
|
+
var scores = require('@mastra/core/scores');
|
|
9
9
|
var vector = require('@mastra/core/vector');
|
|
10
10
|
var filter = require('@mastra/core/vector/filter');
|
|
11
11
|
|
|
12
12
|
// src/storage/index.ts
|
|
13
|
+
var StoreLegacyEvalsLance = class extends storage.LegacyEvalsStorage {
|
|
14
|
+
client;
|
|
15
|
+
constructor({ client }) {
|
|
16
|
+
super();
|
|
17
|
+
this.client = client;
|
|
18
|
+
}
|
|
19
|
+
async getEvalsByAgentName(agentName, type) {
|
|
20
|
+
try {
|
|
21
|
+
const table = await this.client.openTable(storage.TABLE_EVALS);
|
|
22
|
+
const query = table.query().where(`agent_name = '${agentName}'`);
|
|
23
|
+
const records = await query.toArray();
|
|
24
|
+
let filteredRecords = records;
|
|
25
|
+
if (type === "live") {
|
|
26
|
+
filteredRecords = records.filter((record) => record.test_info === null);
|
|
27
|
+
} else if (type === "test") {
|
|
28
|
+
filteredRecords = records.filter((record) => record.test_info !== null);
|
|
29
|
+
}
|
|
30
|
+
return filteredRecords.map((record) => {
|
|
31
|
+
return {
|
|
32
|
+
id: record.id,
|
|
33
|
+
input: record.input,
|
|
34
|
+
output: record.output,
|
|
35
|
+
agentName: record.agent_name,
|
|
36
|
+
metricName: record.metric_name,
|
|
37
|
+
result: JSON.parse(record.result),
|
|
38
|
+
instructions: record.instructions,
|
|
39
|
+
testInfo: record.test_info ? JSON.parse(record.test_info) : null,
|
|
40
|
+
globalRunId: record.global_run_id,
|
|
41
|
+
runId: record.run_id,
|
|
42
|
+
createdAt: new Date(record.created_at).toString()
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
} catch (error$1) {
|
|
46
|
+
throw new error.MastraError(
|
|
47
|
+
{
|
|
48
|
+
id: "LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
49
|
+
domain: error.ErrorDomain.STORAGE,
|
|
50
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
51
|
+
details: { agentName }
|
|
52
|
+
},
|
|
53
|
+
error$1
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async getEvals(options) {
|
|
58
|
+
try {
|
|
59
|
+
const table = await this.client.openTable(storage.TABLE_EVALS);
|
|
60
|
+
const conditions = [];
|
|
61
|
+
if (options.agentName) {
|
|
62
|
+
conditions.push(`agent_name = '${options.agentName}'`);
|
|
63
|
+
}
|
|
64
|
+
if (options.type === "live") {
|
|
65
|
+
conditions.push("test_info IS NULL");
|
|
66
|
+
} else if (options.type === "test") {
|
|
67
|
+
conditions.push("test_info IS NOT NULL");
|
|
68
|
+
}
|
|
69
|
+
const startDate = options.dateRange?.start || options.fromDate;
|
|
70
|
+
const endDate = options.dateRange?.end || options.toDate;
|
|
71
|
+
if (startDate) {
|
|
72
|
+
conditions.push(`\`created_at\` >= ${startDate.getTime()}`);
|
|
73
|
+
}
|
|
74
|
+
if (endDate) {
|
|
75
|
+
conditions.push(`\`created_at\` <= ${endDate.getTime()}`);
|
|
76
|
+
}
|
|
77
|
+
let total = 0;
|
|
78
|
+
if (conditions.length > 0) {
|
|
79
|
+
total = await table.countRows(conditions.join(" AND "));
|
|
80
|
+
} else {
|
|
81
|
+
total = await table.countRows();
|
|
82
|
+
}
|
|
83
|
+
const query = table.query();
|
|
84
|
+
if (conditions.length > 0) {
|
|
85
|
+
const whereClause = conditions.join(" AND ");
|
|
86
|
+
query.where(whereClause);
|
|
87
|
+
}
|
|
88
|
+
const records = await query.toArray();
|
|
89
|
+
const evals = records.sort((a, b) => b.created_at - a.created_at).map((record) => {
|
|
90
|
+
return {
|
|
91
|
+
id: record.id,
|
|
92
|
+
input: record.input,
|
|
93
|
+
output: record.output,
|
|
94
|
+
agentName: record.agent_name,
|
|
95
|
+
metricName: record.metric_name,
|
|
96
|
+
result: JSON.parse(record.result),
|
|
97
|
+
instructions: record.instructions,
|
|
98
|
+
testInfo: record.test_info ? JSON.parse(record.test_info) : null,
|
|
99
|
+
globalRunId: record.global_run_id,
|
|
100
|
+
runId: record.run_id,
|
|
101
|
+
createdAt: new Date(record.created_at).toISOString()
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
const page = options.page || 0;
|
|
105
|
+
const perPage = options.perPage || 10;
|
|
106
|
+
const pagedEvals = evals.slice(page * perPage, (page + 1) * perPage);
|
|
107
|
+
return {
|
|
108
|
+
evals: pagedEvals,
|
|
109
|
+
total,
|
|
110
|
+
page,
|
|
111
|
+
perPage,
|
|
112
|
+
hasMore: total > (page + 1) * perPage
|
|
113
|
+
};
|
|
114
|
+
} catch (error$1) {
|
|
115
|
+
throw new error.MastraError(
|
|
116
|
+
{
|
|
117
|
+
id: "LANCE_STORE_GET_EVALS_FAILED",
|
|
118
|
+
domain: error.ErrorDomain.STORAGE,
|
|
119
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
120
|
+
details: { agentName: options.agentName ?? "" }
|
|
121
|
+
},
|
|
122
|
+
error$1
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
13
127
|
function getPrimaryKeys(tableName) {
|
|
14
128
|
let primaryId = ["id"];
|
|
15
129
|
if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
|
|
16
130
|
primaryId = ["workflow_name", "run_id"];
|
|
131
|
+
} else if (tableName === storage.TABLE_EVALS) {
|
|
132
|
+
primaryId = ["agent_name", "metric_name", "run_id"];
|
|
17
133
|
}
|
|
18
134
|
return primaryId;
|
|
19
135
|
}
|
|
@@ -133,10 +249,6 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
133
249
|
this.client = client;
|
|
134
250
|
this.operations = operations;
|
|
135
251
|
}
|
|
136
|
-
// Utility to escape single quotes in SQL strings
|
|
137
|
-
escapeSql(str) {
|
|
138
|
-
return str.replace(/'/g, "''");
|
|
139
|
-
}
|
|
140
252
|
async getThreadById({ threadId }) {
|
|
141
253
|
try {
|
|
142
254
|
const thread = await this.operations.load({ tableName: storage.TABLE_THREADS, keys: { id: threadId } });
|
|
@@ -159,6 +271,26 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
159
271
|
);
|
|
160
272
|
}
|
|
161
273
|
}
|
|
274
|
+
async getThreadsByResourceId({ resourceId }) {
|
|
275
|
+
try {
|
|
276
|
+
const table = await this.client.openTable(storage.TABLE_THREADS);
|
|
277
|
+
const query = table.query().where(`\`resourceId\` = '${resourceId}'`);
|
|
278
|
+
const records = await query.toArray();
|
|
279
|
+
return processResultWithTypeConversion(
|
|
280
|
+
records,
|
|
281
|
+
await getTableSchema({ tableName: storage.TABLE_THREADS, client: this.client })
|
|
282
|
+
);
|
|
283
|
+
} catch (error$1) {
|
|
284
|
+
throw new error.MastraError(
|
|
285
|
+
{
|
|
286
|
+
id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
|
|
287
|
+
domain: error.ErrorDomain.STORAGE,
|
|
288
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
289
|
+
},
|
|
290
|
+
error$1
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
162
294
|
/**
|
|
163
295
|
* Saves a thread to the database. This function doesn't overwrite existing threads.
|
|
164
296
|
* @param thread - The thread to save
|
|
@@ -263,174 +395,100 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
263
395
|
})() : message.content
|
|
264
396
|
};
|
|
265
397
|
}
|
|
266
|
-
async
|
|
267
|
-
|
|
398
|
+
async getMessages({
|
|
399
|
+
threadId,
|
|
400
|
+
resourceId,
|
|
401
|
+
selectBy,
|
|
402
|
+
format,
|
|
403
|
+
threadConfig
|
|
404
|
+
}) {
|
|
268
405
|
try {
|
|
406
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
407
|
+
if (threadConfig) {
|
|
408
|
+
throw new Error("ThreadConfig is not supported by LanceDB storage");
|
|
409
|
+
}
|
|
410
|
+
const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
269
411
|
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
270
|
-
|
|
271
|
-
|
|
412
|
+
let allRecords = [];
|
|
413
|
+
if (selectBy?.include && selectBy.include.length > 0) {
|
|
414
|
+
const threadIds = [...new Set(selectBy.include.map((item) => item.threadId))];
|
|
415
|
+
for (const threadId2 of threadIds) {
|
|
416
|
+
const threadQuery = table.query().where(`thread_id = '${threadId2}'`);
|
|
417
|
+
let threadRecords = await threadQuery.toArray();
|
|
418
|
+
allRecords.push(...threadRecords);
|
|
419
|
+
}
|
|
420
|
+
} else {
|
|
421
|
+
let query = table.query().where(`\`thread_id\` = '${threadId}'`);
|
|
422
|
+
allRecords = await query.toArray();
|
|
423
|
+
}
|
|
424
|
+
allRecords.sort((a, b) => {
|
|
425
|
+
const dateA = new Date(a.createdAt).getTime();
|
|
426
|
+
const dateB = new Date(b.createdAt).getTime();
|
|
427
|
+
return dateA - dateB;
|
|
428
|
+
});
|
|
429
|
+
if (selectBy?.include && selectBy.include.length > 0) {
|
|
430
|
+
allRecords = this.processMessagesWithContext(allRecords, selectBy.include);
|
|
431
|
+
}
|
|
432
|
+
if (limit !== Number.MAX_SAFE_INTEGER) {
|
|
433
|
+
allRecords = allRecords.slice(-limit);
|
|
434
|
+
}
|
|
272
435
|
const messages = processResultWithTypeConversion(
|
|
273
436
|
allRecords,
|
|
274
437
|
await getTableSchema({ tableName: storage.TABLE_MESSAGES, client: this.client })
|
|
275
438
|
);
|
|
276
|
-
const list = new agent.MessageList().add(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
);
|
|
280
|
-
return { messages: list.get.all.db() };
|
|
439
|
+
const list = new agent.MessageList({ threadId, resourceId }).add(messages.map(this.normalizeMessage), "memory");
|
|
440
|
+
if (format === "v2") return list.get.all.v2();
|
|
441
|
+
return list.get.all.v1();
|
|
281
442
|
} catch (error$1) {
|
|
282
443
|
throw new error.MastraError(
|
|
283
444
|
{
|
|
284
|
-
id: "
|
|
445
|
+
id: "LANCE_STORE_GET_MESSAGES_FAILED",
|
|
285
446
|
domain: error.ErrorDomain.STORAGE,
|
|
286
447
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
287
448
|
details: {
|
|
288
|
-
|
|
449
|
+
threadId,
|
|
450
|
+
resourceId: resourceId ?? ""
|
|
289
451
|
}
|
|
290
452
|
},
|
|
291
453
|
error$1
|
|
292
454
|
);
|
|
293
455
|
}
|
|
294
456
|
}
|
|
295
|
-
async
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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);
|
|
457
|
+
async getMessagesById({
|
|
458
|
+
messageIds,
|
|
459
|
+
format
|
|
460
|
+
}) {
|
|
461
|
+
if (messageIds.length === 0) return [];
|
|
310
462
|
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");
|
|
323
463
|
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
};
|
|
464
|
+
const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
|
|
465
|
+
const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
|
|
466
|
+
const messages = processResultWithTypeConversion(
|
|
467
|
+
allRecords,
|
|
468
|
+
await getTableSchema({ tableName: storage.TABLE_MESSAGES, client: this.client })
|
|
469
|
+
);
|
|
470
|
+
const list = new agent.MessageList().add(messages.map(this.normalizeMessage), "memory");
|
|
471
|
+
if (format === `v1`) return list.get.all.v1();
|
|
472
|
+
return list.get.all.v2();
|
|
405
473
|
} catch (error$1) {
|
|
406
|
-
|
|
474
|
+
throw new error.MastraError(
|
|
407
475
|
{
|
|
408
|
-
id: "
|
|
476
|
+
id: "LANCE_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
409
477
|
domain: error.ErrorDomain.STORAGE,
|
|
410
478
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
411
479
|
details: {
|
|
412
|
-
|
|
413
|
-
resourceId: resourceId ?? ""
|
|
480
|
+
messageIds: JSON.stringify(messageIds)
|
|
414
481
|
}
|
|
415
482
|
},
|
|
416
483
|
error$1
|
|
417
484
|
);
|
|
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
|
-
};
|
|
427
485
|
}
|
|
428
486
|
}
|
|
429
487
|
async saveMessages(args) {
|
|
430
488
|
try {
|
|
431
|
-
const { messages } = args;
|
|
489
|
+
const { messages, format = "v1" } = args;
|
|
432
490
|
if (messages.length === 0) {
|
|
433
|
-
return
|
|
491
|
+
return [];
|
|
434
492
|
}
|
|
435
493
|
const threadId = messages[0]?.threadId;
|
|
436
494
|
if (!threadId) {
|
|
@@ -466,7 +524,8 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
466
524
|
const updateRecord = { id: threadId, updatedAt: currentTime };
|
|
467
525
|
await threadsTable.mergeInsert("id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([updateRecord]);
|
|
468
526
|
const list = new agent.MessageList().add(messages, "memory");
|
|
469
|
-
|
|
527
|
+
if (format === `v2`) return list.get.all.v2();
|
|
528
|
+
return list.get.all.v1();
|
|
470
529
|
} catch (error$1) {
|
|
471
530
|
throw new error.MastraError(
|
|
472
531
|
{
|
|
@@ -478,54 +537,32 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
478
537
|
);
|
|
479
538
|
}
|
|
480
539
|
}
|
|
481
|
-
async
|
|
540
|
+
async getThreadsByResourceIdPaginated(args) {
|
|
482
541
|
try {
|
|
483
|
-
const { resourceId, page = 0, perPage
|
|
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
|
-
);
|
|
495
|
-
}
|
|
496
|
-
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
497
|
-
const { field, direction } = this.parseOrderBy(orderBy);
|
|
542
|
+
const { resourceId, page = 0, perPage = 10 } = args;
|
|
498
543
|
const table = await this.client.openTable(storage.TABLE_THREADS);
|
|
499
|
-
const total = await table.countRows(`\`resourceId\` = '${
|
|
500
|
-
const query = table.query().where(`\`resourceId\` = '${
|
|
544
|
+
const total = await table.countRows(`\`resourceId\` = '${resourceId}'`);
|
|
545
|
+
const query = table.query().where(`\`resourceId\` = '${resourceId}'`);
|
|
546
|
+
const offset = page * perPage;
|
|
547
|
+
query.limit(perPage);
|
|
548
|
+
if (offset > 0) {
|
|
549
|
+
query.offset(offset);
|
|
550
|
+
}
|
|
501
551
|
const records = await query.toArray();
|
|
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
|
+
records.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
|
|
514
553
|
const schema = await getTableSchema({ tableName: storage.TABLE_THREADS, client: this.client });
|
|
515
|
-
const threads =
|
|
516
|
-
(record) => processResultWithTypeConversion(record, schema)
|
|
517
|
-
);
|
|
554
|
+
const threads = records.map((record) => processResultWithTypeConversion(record, schema));
|
|
518
555
|
return {
|
|
519
556
|
threads,
|
|
520
557
|
total,
|
|
521
558
|
page,
|
|
522
|
-
perPage
|
|
523
|
-
hasMore:
|
|
559
|
+
perPage,
|
|
560
|
+
hasMore: total > (page + 1) * perPage
|
|
524
561
|
};
|
|
525
562
|
} catch (error$1) {
|
|
526
563
|
throw new error.MastraError(
|
|
527
564
|
{
|
|
528
|
-
id: "
|
|
565
|
+
id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED",
|
|
529
566
|
domain: error.ErrorDomain.STORAGE,
|
|
530
567
|
category: error.ErrorCategory.THIRD_PARTY
|
|
531
568
|
},
|
|
@@ -581,8 +618,132 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
581
618
|
});
|
|
582
619
|
return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
|
|
583
620
|
}
|
|
621
|
+
async getMessagesPaginated(args) {
|
|
622
|
+
const { threadId, resourceId, selectBy, format = "v1" } = args;
|
|
623
|
+
const page = selectBy?.pagination?.page ?? 0;
|
|
624
|
+
const perPage = selectBy?.pagination?.perPage ?? 10;
|
|
625
|
+
try {
|
|
626
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
627
|
+
const dateRange = selectBy?.pagination?.dateRange;
|
|
628
|
+
const fromDate = dateRange?.start;
|
|
629
|
+
const toDate = dateRange?.end;
|
|
630
|
+
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
631
|
+
const messages = [];
|
|
632
|
+
if (selectBy?.include && Array.isArray(selectBy.include)) {
|
|
633
|
+
const threadIds = [...new Set(selectBy.include.map((item) => item.threadId))];
|
|
634
|
+
const allThreadMessages = [];
|
|
635
|
+
for (const threadId2 of threadIds) {
|
|
636
|
+
const threadQuery = table.query().where(`thread_id = '${threadId2}'`);
|
|
637
|
+
let threadRecords = await threadQuery.toArray();
|
|
638
|
+
if (fromDate) threadRecords = threadRecords.filter((m) => m.createdAt >= fromDate.getTime());
|
|
639
|
+
if (toDate) threadRecords = threadRecords.filter((m) => m.createdAt <= toDate.getTime());
|
|
640
|
+
allThreadMessages.push(...threadRecords);
|
|
641
|
+
}
|
|
642
|
+
allThreadMessages.sort((a, b) => a.createdAt - b.createdAt);
|
|
643
|
+
const contextMessages = this.processMessagesWithContext(allThreadMessages, selectBy.include);
|
|
644
|
+
messages.push(...contextMessages);
|
|
645
|
+
}
|
|
646
|
+
const conditions = [`thread_id = '${threadId}'`];
|
|
647
|
+
if (resourceId) {
|
|
648
|
+
conditions.push(`\`resourceId\` = '${resourceId}'`);
|
|
649
|
+
}
|
|
650
|
+
if (fromDate) {
|
|
651
|
+
conditions.push(`\`createdAt\` >= ${fromDate.getTime()}`);
|
|
652
|
+
}
|
|
653
|
+
if (toDate) {
|
|
654
|
+
conditions.push(`\`createdAt\` <= ${toDate.getTime()}`);
|
|
655
|
+
}
|
|
656
|
+
let total = 0;
|
|
657
|
+
if (conditions.length > 0) {
|
|
658
|
+
total = await table.countRows(conditions.join(" AND "));
|
|
659
|
+
} else {
|
|
660
|
+
total = await table.countRows();
|
|
661
|
+
}
|
|
662
|
+
if (total === 0 && messages.length === 0) {
|
|
663
|
+
return {
|
|
664
|
+
messages: [],
|
|
665
|
+
total: 0,
|
|
666
|
+
page,
|
|
667
|
+
perPage,
|
|
668
|
+
hasMore: false
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
const excludeIds = messages.map((m) => m.id);
|
|
672
|
+
let selectedMessages = [];
|
|
673
|
+
if (selectBy?.last && selectBy.last > 0) {
|
|
674
|
+
const query = table.query();
|
|
675
|
+
if (conditions.length > 0) {
|
|
676
|
+
query.where(conditions.join(" AND "));
|
|
677
|
+
}
|
|
678
|
+
let records = await query.toArray();
|
|
679
|
+
records = records.sort((a, b) => a.createdAt - b.createdAt);
|
|
680
|
+
if (excludeIds.length > 0) {
|
|
681
|
+
records = records.filter((m) => !excludeIds.includes(m.id));
|
|
682
|
+
}
|
|
683
|
+
selectedMessages = records.slice(-selectBy.last);
|
|
684
|
+
} else {
|
|
685
|
+
const query = table.query();
|
|
686
|
+
if (conditions.length > 0) {
|
|
687
|
+
query.where(conditions.join(" AND "));
|
|
688
|
+
}
|
|
689
|
+
let records = await query.toArray();
|
|
690
|
+
records = records.sort((a, b) => a.createdAt - b.createdAt);
|
|
691
|
+
if (excludeIds.length > 0) {
|
|
692
|
+
records = records.filter((m) => !excludeIds.includes(m.id));
|
|
693
|
+
}
|
|
694
|
+
selectedMessages = records.slice(page * perPage, (page + 1) * perPage);
|
|
695
|
+
}
|
|
696
|
+
const allMessages = [...messages, ...selectedMessages];
|
|
697
|
+
const seen = /* @__PURE__ */ new Set();
|
|
698
|
+
const dedupedMessages = allMessages.filter((m) => {
|
|
699
|
+
const key = `${m.id}:${m.thread_id}`;
|
|
700
|
+
if (seen.has(key)) return false;
|
|
701
|
+
seen.add(key);
|
|
702
|
+
return true;
|
|
703
|
+
});
|
|
704
|
+
const formattedMessages = dedupedMessages.map((msg) => {
|
|
705
|
+
const { thread_id, ...rest } = msg;
|
|
706
|
+
return {
|
|
707
|
+
...rest,
|
|
708
|
+
threadId: thread_id,
|
|
709
|
+
content: typeof msg.content === "string" ? (() => {
|
|
710
|
+
try {
|
|
711
|
+
return JSON.parse(msg.content);
|
|
712
|
+
} catch {
|
|
713
|
+
return msg.content;
|
|
714
|
+
}
|
|
715
|
+
})() : msg.content
|
|
716
|
+
};
|
|
717
|
+
});
|
|
718
|
+
const list = new agent.MessageList().add(formattedMessages, "memory");
|
|
719
|
+
return {
|
|
720
|
+
messages: format === "v2" ? list.get.all.v2() : list.get.all.v1(),
|
|
721
|
+
total,
|
|
722
|
+
// Total should be the count of messages matching the filters
|
|
723
|
+
page,
|
|
724
|
+
perPage,
|
|
725
|
+
hasMore: total > (page + 1) * perPage
|
|
726
|
+
};
|
|
727
|
+
} catch (error$1) {
|
|
728
|
+
const mastraError = new error.MastraError(
|
|
729
|
+
{
|
|
730
|
+
id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
731
|
+
domain: error.ErrorDomain.STORAGE,
|
|
732
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
733
|
+
details: {
|
|
734
|
+
threadId,
|
|
735
|
+
resourceId: resourceId ?? ""
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
error$1
|
|
739
|
+
);
|
|
740
|
+
this.logger?.trackException?.(mastraError);
|
|
741
|
+
this.logger?.error?.(mastraError.toString());
|
|
742
|
+
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
743
|
+
}
|
|
744
|
+
}
|
|
584
745
|
/**
|
|
585
|
-
* Parse message data from LanceDB record format to
|
|
746
|
+
* Parse message data from LanceDB record format to MastraMessageV2 format
|
|
586
747
|
*/
|
|
587
748
|
parseMessageData(data) {
|
|
588
749
|
const { thread_id, ...rest } = data;
|
|
@@ -1240,7 +1401,7 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1240
1401
|
async saveScore(score) {
|
|
1241
1402
|
let validatedScore;
|
|
1242
1403
|
try {
|
|
1243
|
-
validatedScore =
|
|
1404
|
+
validatedScore = scores.saveScorePayloadSchema.parse(score);
|
|
1244
1405
|
} catch (error$1) {
|
|
1245
1406
|
throw new error.MastraError(
|
|
1246
1407
|
{
|
|
@@ -1292,7 +1453,8 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1292
1453
|
const query = table.query().where(`id = '${id}'`).limit(1);
|
|
1293
1454
|
const records = await query.toArray();
|
|
1294
1455
|
if (records.length === 0) return null;
|
|
1295
|
-
|
|
1456
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1457
|
+
return processResultWithTypeConversion(records[0], schema);
|
|
1296
1458
|
} catch (error$1) {
|
|
1297
1459
|
throw new error.MastraError(
|
|
1298
1460
|
{
|
|
@@ -1306,17 +1468,7 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1306
1468
|
);
|
|
1307
1469
|
}
|
|
1308
1470
|
}
|
|
1309
|
-
async
|
|
1310
|
-
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1311
|
-
const transformed = processResultWithTypeConversion(row, schema);
|
|
1312
|
-
const result = {
|
|
1313
|
-
...transformed,
|
|
1314
|
-
createdAt: row.createdAt,
|
|
1315
|
-
updatedAt: row.updatedAt
|
|
1316
|
-
};
|
|
1317
|
-
return result;
|
|
1318
|
-
}
|
|
1319
|
-
async listScoresByScorerId({
|
|
1471
|
+
async getScoresByScorerId({
|
|
1320
1472
|
scorerId,
|
|
1321
1473
|
pagination,
|
|
1322
1474
|
entityId,
|
|
@@ -1324,10 +1476,9 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1324
1476
|
source
|
|
1325
1477
|
}) {
|
|
1326
1478
|
try {
|
|
1327
|
-
const { page, perPage: perPageInput } = pagination;
|
|
1328
|
-
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1329
|
-
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1330
1479
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1480
|
+
const { page = 0, perPage = 10 } = pagination || {};
|
|
1481
|
+
const offset = page * perPage;
|
|
1331
1482
|
let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1332
1483
|
if (source) {
|
|
1333
1484
|
query = query.where(`\`source\` = '${source}'`);
|
|
@@ -1338,31 +1489,23 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1338
1489
|
if (entityType) {
|
|
1339
1490
|
query = query.where(`\`entityType\` = '${entityType}'`);
|
|
1340
1491
|
}
|
|
1492
|
+
query = query.limit(perPage);
|
|
1493
|
+
if (offset > 0) query.offset(offset);
|
|
1494
|
+
const records = await query.toArray();
|
|
1495
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1496
|
+
const scores = processResultWithTypeConversion(records, schema);
|
|
1341
1497
|
let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1342
1498
|
if (source) {
|
|
1343
1499
|
totalQuery = totalQuery.where(`\`source\` = '${source}'`);
|
|
1344
1500
|
}
|
|
1345
|
-
if (entityId) {
|
|
1346
|
-
totalQuery = totalQuery.where(`\`entityId\` = '${entityId}'`);
|
|
1347
|
-
}
|
|
1348
|
-
if (entityType) {
|
|
1349
|
-
totalQuery = totalQuery.where(`\`entityType\` = '${entityType}'`);
|
|
1350
|
-
}
|
|
1351
1501
|
const allRecords = await totalQuery.toArray();
|
|
1352
1502
|
const total = allRecords.length;
|
|
1353
|
-
const end = perPageInput === false ? total : start + perPage;
|
|
1354
|
-
if (perPageInput !== false) {
|
|
1355
|
-
query = query.limit(perPage);
|
|
1356
|
-
if (start > 0) query = query.offset(start);
|
|
1357
|
-
}
|
|
1358
|
-
const records = await query.toArray();
|
|
1359
|
-
const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
|
|
1360
1503
|
return {
|
|
1361
1504
|
pagination: {
|
|
1362
1505
|
page,
|
|
1363
|
-
perPage
|
|
1506
|
+
perPage,
|
|
1364
1507
|
total,
|
|
1365
|
-
hasMore:
|
|
1508
|
+
hasMore: offset + scores.length < total
|
|
1366
1509
|
},
|
|
1367
1510
|
scores
|
|
1368
1511
|
};
|
|
@@ -1379,31 +1522,27 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1379
1522
|
);
|
|
1380
1523
|
}
|
|
1381
1524
|
}
|
|
1382
|
-
async
|
|
1525
|
+
async getScoresByRunId({
|
|
1383
1526
|
runId,
|
|
1384
1527
|
pagination
|
|
1385
1528
|
}) {
|
|
1386
1529
|
try {
|
|
1387
|
-
const { page, perPage: perPageInput } = pagination;
|
|
1388
|
-
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1389
|
-
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1390
1530
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1531
|
+
const { page = 0, perPage = 10 } = pagination || {};
|
|
1532
|
+
const offset = page * perPage;
|
|
1533
|
+
const query = table.query().where(`\`runId\` = '${runId}'`).limit(perPage);
|
|
1534
|
+
if (offset > 0) query.offset(offset);
|
|
1535
|
+
const records = await query.toArray();
|
|
1536
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1537
|
+
const scores = processResultWithTypeConversion(records, schema);
|
|
1391
1538
|
const allRecords = await table.query().where(`\`runId\` = '${runId}'`).toArray();
|
|
1392
1539
|
const total = allRecords.length;
|
|
1393
|
-
const end = perPageInput === false ? total : start + perPage;
|
|
1394
|
-
let query = table.query().where(`\`runId\` = '${runId}'`);
|
|
1395
|
-
if (perPageInput !== false) {
|
|
1396
|
-
query = query.limit(perPage);
|
|
1397
|
-
if (start > 0) query = query.offset(start);
|
|
1398
|
-
}
|
|
1399
|
-
const records = await query.toArray();
|
|
1400
|
-
const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
|
|
1401
1540
|
return {
|
|
1402
1541
|
pagination: {
|
|
1403
1542
|
page,
|
|
1404
|
-
perPage
|
|
1543
|
+
perPage,
|
|
1405
1544
|
total,
|
|
1406
|
-
hasMore:
|
|
1545
|
+
hasMore: offset + scores.length < total
|
|
1407
1546
|
},
|
|
1408
1547
|
scores
|
|
1409
1548
|
};
|
|
@@ -1420,32 +1559,28 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1420
1559
|
);
|
|
1421
1560
|
}
|
|
1422
1561
|
}
|
|
1423
|
-
async
|
|
1562
|
+
async getScoresByEntityId({
|
|
1424
1563
|
entityId,
|
|
1425
1564
|
entityType,
|
|
1426
1565
|
pagination
|
|
1427
1566
|
}) {
|
|
1428
1567
|
try {
|
|
1429
|
-
const { page, perPage: perPageInput } = pagination;
|
|
1430
|
-
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1431
|
-
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1432
1568
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1569
|
+
const { page = 0, perPage = 10 } = pagination || {};
|
|
1570
|
+
const offset = page * perPage;
|
|
1571
|
+
const query = table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).limit(perPage);
|
|
1572
|
+
if (offset > 0) query.offset(offset);
|
|
1573
|
+
const records = await query.toArray();
|
|
1574
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1575
|
+
const scores = processResultWithTypeConversion(records, schema);
|
|
1433
1576
|
const allRecords = await table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).toArray();
|
|
1434
1577
|
const total = allRecords.length;
|
|
1435
|
-
const end = perPageInput === false ? total : start + perPage;
|
|
1436
|
-
let query = table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`);
|
|
1437
|
-
if (perPageInput !== false) {
|
|
1438
|
-
query = query.limit(perPage);
|
|
1439
|
-
if (start > 0) query = query.offset(start);
|
|
1440
|
-
}
|
|
1441
|
-
const records = await query.toArray();
|
|
1442
|
-
const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
|
|
1443
1578
|
return {
|
|
1444
1579
|
pagination: {
|
|
1445
1580
|
page,
|
|
1446
|
-
perPage
|
|
1581
|
+
perPage,
|
|
1447
1582
|
total,
|
|
1448
|
-
hasMore:
|
|
1583
|
+
hasMore: offset + scores.length < total
|
|
1449
1584
|
},
|
|
1450
1585
|
scores
|
|
1451
1586
|
};
|
|
@@ -1462,32 +1597,28 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1462
1597
|
);
|
|
1463
1598
|
}
|
|
1464
1599
|
}
|
|
1465
|
-
async
|
|
1600
|
+
async getScoresBySpan({
|
|
1466
1601
|
traceId,
|
|
1467
1602
|
spanId,
|
|
1468
1603
|
pagination
|
|
1469
1604
|
}) {
|
|
1470
1605
|
try {
|
|
1471
|
-
const { page, perPage: perPageInput } = pagination;
|
|
1472
|
-
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1473
|
-
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1474
1606
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1607
|
+
const { page = 0, perPage = 10 } = pagination || {};
|
|
1608
|
+
const offset = page * perPage;
|
|
1609
|
+
const query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).limit(perPage);
|
|
1610
|
+
if (offset > 0) query.offset(offset);
|
|
1611
|
+
const records = await query.toArray();
|
|
1612
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1613
|
+
const scores = processResultWithTypeConversion(records, schema);
|
|
1475
1614
|
const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
|
|
1476
1615
|
const total = allRecords.length;
|
|
1477
|
-
const end = perPageInput === false ? total : start + perPage;
|
|
1478
|
-
let query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`);
|
|
1479
|
-
if (perPageInput !== false) {
|
|
1480
|
-
query = query.limit(perPage);
|
|
1481
|
-
if (start > 0) query = query.offset(start);
|
|
1482
|
-
}
|
|
1483
|
-
const records = await query.toArray();
|
|
1484
|
-
const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
|
|
1485
1616
|
return {
|
|
1486
1617
|
pagination: {
|
|
1487
1618
|
page,
|
|
1488
|
-
perPage
|
|
1619
|
+
perPage,
|
|
1489
1620
|
total,
|
|
1490
|
-
hasMore:
|
|
1621
|
+
hasMore: offset + scores.length < total
|
|
1491
1622
|
},
|
|
1492
1623
|
scores
|
|
1493
1624
|
};
|
|
@@ -1505,6 +1636,198 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1505
1636
|
}
|
|
1506
1637
|
}
|
|
1507
1638
|
};
|
|
1639
|
+
var StoreTracesLance = class extends storage.TracesStorage {
|
|
1640
|
+
client;
|
|
1641
|
+
operations;
|
|
1642
|
+
constructor({ client, operations }) {
|
|
1643
|
+
super();
|
|
1644
|
+
this.client = client;
|
|
1645
|
+
this.operations = operations;
|
|
1646
|
+
}
|
|
1647
|
+
async saveTrace({ trace }) {
|
|
1648
|
+
try {
|
|
1649
|
+
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1650
|
+
const record = {
|
|
1651
|
+
...trace,
|
|
1652
|
+
attributes: JSON.stringify(trace.attributes),
|
|
1653
|
+
status: JSON.stringify(trace.status),
|
|
1654
|
+
events: JSON.stringify(trace.events),
|
|
1655
|
+
links: JSON.stringify(trace.links),
|
|
1656
|
+
other: JSON.stringify(trace.other)
|
|
1657
|
+
};
|
|
1658
|
+
await table.add([record], { mode: "append" });
|
|
1659
|
+
return trace;
|
|
1660
|
+
} catch (error$1) {
|
|
1661
|
+
throw new error.MastraError(
|
|
1662
|
+
{
|
|
1663
|
+
id: "LANCE_STORE_SAVE_TRACE_FAILED",
|
|
1664
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1665
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1666
|
+
},
|
|
1667
|
+
error$1
|
|
1668
|
+
);
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
async getTraceById({ traceId }) {
|
|
1672
|
+
try {
|
|
1673
|
+
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1674
|
+
const query = table.query().where(`id = '${traceId}'`);
|
|
1675
|
+
const records = await query.toArray();
|
|
1676
|
+
return records[0];
|
|
1677
|
+
} catch (error$1) {
|
|
1678
|
+
throw new error.MastraError(
|
|
1679
|
+
{
|
|
1680
|
+
id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
|
|
1681
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1682
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1683
|
+
},
|
|
1684
|
+
error$1
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
async getTraces({
|
|
1689
|
+
name,
|
|
1690
|
+
scope,
|
|
1691
|
+
page = 1,
|
|
1692
|
+
perPage = 10,
|
|
1693
|
+
attributes
|
|
1694
|
+
}) {
|
|
1695
|
+
try {
|
|
1696
|
+
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1697
|
+
const query = table.query();
|
|
1698
|
+
if (name) {
|
|
1699
|
+
query.where(`name = '${name}'`);
|
|
1700
|
+
}
|
|
1701
|
+
if (scope) {
|
|
1702
|
+
query.where(`scope = '${scope}'`);
|
|
1703
|
+
}
|
|
1704
|
+
if (attributes) {
|
|
1705
|
+
query.where(`attributes = '${JSON.stringify(attributes)}'`);
|
|
1706
|
+
}
|
|
1707
|
+
const offset = (page - 1) * perPage;
|
|
1708
|
+
query.limit(perPage);
|
|
1709
|
+
if (offset > 0) {
|
|
1710
|
+
query.offset(offset);
|
|
1711
|
+
}
|
|
1712
|
+
const records = await query.toArray();
|
|
1713
|
+
return records.map((record) => {
|
|
1714
|
+
const processed = {
|
|
1715
|
+
...record,
|
|
1716
|
+
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1717
|
+
status: record.status ? JSON.parse(record.status) : {},
|
|
1718
|
+
events: record.events ? JSON.parse(record.events) : [],
|
|
1719
|
+
links: record.links ? JSON.parse(record.links) : [],
|
|
1720
|
+
other: record.other ? JSON.parse(record.other) : {},
|
|
1721
|
+
startTime: new Date(record.startTime),
|
|
1722
|
+
endTime: new Date(record.endTime),
|
|
1723
|
+
createdAt: new Date(record.createdAt)
|
|
1724
|
+
};
|
|
1725
|
+
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1726
|
+
processed.parentSpanId = "";
|
|
1727
|
+
} else {
|
|
1728
|
+
processed.parentSpanId = String(processed.parentSpanId);
|
|
1729
|
+
}
|
|
1730
|
+
return processed;
|
|
1731
|
+
});
|
|
1732
|
+
} catch (error$1) {
|
|
1733
|
+
throw new error.MastraError(
|
|
1734
|
+
{
|
|
1735
|
+
id: "LANCE_STORE_GET_TRACES_FAILED",
|
|
1736
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1737
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1738
|
+
details: { name: name ?? "", scope: scope ?? "" }
|
|
1739
|
+
},
|
|
1740
|
+
error$1
|
|
1741
|
+
);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
async getTracesPaginated(args) {
|
|
1745
|
+
try {
|
|
1746
|
+
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1747
|
+
const query = table.query();
|
|
1748
|
+
const conditions = [];
|
|
1749
|
+
if (args.name) {
|
|
1750
|
+
conditions.push(`name = '${args.name}'`);
|
|
1751
|
+
}
|
|
1752
|
+
if (args.scope) {
|
|
1753
|
+
conditions.push(`scope = '${args.scope}'`);
|
|
1754
|
+
}
|
|
1755
|
+
if (args.attributes) {
|
|
1756
|
+
const attributesStr = JSON.stringify(args.attributes);
|
|
1757
|
+
conditions.push(`attributes LIKE '%${attributesStr.replace(/"/g, '\\"')}%'`);
|
|
1758
|
+
}
|
|
1759
|
+
if (args.dateRange?.start) {
|
|
1760
|
+
conditions.push(`\`createdAt\` >= ${args.dateRange.start.getTime()}`);
|
|
1761
|
+
}
|
|
1762
|
+
if (args.dateRange?.end) {
|
|
1763
|
+
conditions.push(`\`createdAt\` <= ${args.dateRange.end.getTime()}`);
|
|
1764
|
+
}
|
|
1765
|
+
if (conditions.length > 0) {
|
|
1766
|
+
const whereClause = conditions.join(" AND ");
|
|
1767
|
+
query.where(whereClause);
|
|
1768
|
+
}
|
|
1769
|
+
let total = 0;
|
|
1770
|
+
if (conditions.length > 0) {
|
|
1771
|
+
const countQuery = table.query().where(conditions.join(" AND "));
|
|
1772
|
+
const allRecords = await countQuery.toArray();
|
|
1773
|
+
total = allRecords.length;
|
|
1774
|
+
} else {
|
|
1775
|
+
total = await table.countRows();
|
|
1776
|
+
}
|
|
1777
|
+
const page = args.page || 0;
|
|
1778
|
+
const perPage = args.perPage || 10;
|
|
1779
|
+
const offset = page * perPage;
|
|
1780
|
+
query.limit(perPage);
|
|
1781
|
+
if (offset > 0) {
|
|
1782
|
+
query.offset(offset);
|
|
1783
|
+
}
|
|
1784
|
+
const records = await query.toArray();
|
|
1785
|
+
const traces = records.map((record) => {
|
|
1786
|
+
const processed = {
|
|
1787
|
+
...record,
|
|
1788
|
+
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1789
|
+
status: record.status ? JSON.parse(record.status) : {},
|
|
1790
|
+
events: record.events ? JSON.parse(record.events) : [],
|
|
1791
|
+
links: record.links ? JSON.parse(record.links) : [],
|
|
1792
|
+
other: record.other ? JSON.parse(record.other) : {},
|
|
1793
|
+
startTime: new Date(record.startTime),
|
|
1794
|
+
endTime: new Date(record.endTime),
|
|
1795
|
+
createdAt: new Date(record.createdAt)
|
|
1796
|
+
};
|
|
1797
|
+
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1798
|
+
processed.parentSpanId = "";
|
|
1799
|
+
} else {
|
|
1800
|
+
processed.parentSpanId = String(processed.parentSpanId);
|
|
1801
|
+
}
|
|
1802
|
+
return processed;
|
|
1803
|
+
});
|
|
1804
|
+
return {
|
|
1805
|
+
traces,
|
|
1806
|
+
total,
|
|
1807
|
+
page,
|
|
1808
|
+
perPage,
|
|
1809
|
+
hasMore: total > (page + 1) * perPage
|
|
1810
|
+
};
|
|
1811
|
+
} catch (error$1) {
|
|
1812
|
+
throw new error.MastraError(
|
|
1813
|
+
{
|
|
1814
|
+
id: "LANCE_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
1815
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1816
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1817
|
+
details: { name: args.name ?? "", scope: args.scope ?? "" }
|
|
1818
|
+
},
|
|
1819
|
+
error$1
|
|
1820
|
+
);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
async batchTraceInsert({ records }) {
|
|
1824
|
+
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
1825
|
+
await this.operations.batchInsert({
|
|
1826
|
+
tableName: storage.TABLE_TRACES,
|
|
1827
|
+
records
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
};
|
|
1508
1831
|
function parseWorkflowRun(row) {
|
|
1509
1832
|
let parsedSnapshot = row.snapshot;
|
|
1510
1833
|
if (typeof parsedSnapshot === "string") {
|
|
@@ -1534,7 +1857,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1534
1857
|
// runId,
|
|
1535
1858
|
// stepId,
|
|
1536
1859
|
// result,
|
|
1537
|
-
//
|
|
1860
|
+
// runtimeContext,
|
|
1538
1861
|
}) {
|
|
1539
1862
|
throw new Error("Method not implemented.");
|
|
1540
1863
|
}
|
|
@@ -1630,7 +1953,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1630
1953
|
);
|
|
1631
1954
|
}
|
|
1632
1955
|
}
|
|
1633
|
-
async
|
|
1956
|
+
async getWorkflowRuns(args) {
|
|
1634
1957
|
try {
|
|
1635
1958
|
const table = await this.client.openTable(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
1636
1959
|
let query = table.query();
|
|
@@ -1658,22 +1981,11 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1658
1981
|
} else {
|
|
1659
1982
|
total = await table.countRows();
|
|
1660
1983
|
}
|
|
1661
|
-
if (args?.
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
id: "LANCE_STORE_INVALID_PAGINATION_PARAMS",
|
|
1667
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1668
|
-
category: error.ErrorCategory.USER,
|
|
1669
|
-
details: { page: args.page, perPage: args.perPage }
|
|
1670
|
-
},
|
|
1671
|
-
new Error(`Invalid pagination parameters: page=${args.page}, perPage=${args.perPage}`)
|
|
1672
|
-
);
|
|
1673
|
-
}
|
|
1674
|
-
const offset = args.page * normalizedPerPage;
|
|
1675
|
-
query.limit(normalizedPerPage);
|
|
1676
|
-
query.offset(offset);
|
|
1984
|
+
if (args?.limit) {
|
|
1985
|
+
query.limit(args.limit);
|
|
1986
|
+
}
|
|
1987
|
+
if (args?.offset) {
|
|
1988
|
+
query.offset(args.offset);
|
|
1677
1989
|
}
|
|
1678
1990
|
const records = await query.toArray();
|
|
1679
1991
|
return {
|
|
@@ -1683,7 +1995,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1683
1995
|
} catch (error$1) {
|
|
1684
1996
|
throw new error.MastraError(
|
|
1685
1997
|
{
|
|
1686
|
-
id: "
|
|
1998
|
+
id: "LANCE_STORE_GET_WORKFLOW_RUNS_FAILED",
|
|
1687
1999
|
domain: error.ErrorDomain.STORAGE,
|
|
1688
2000
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1689
2001
|
details: { resourceId: args?.resourceId ?? "", workflowName: args?.workflowName ?? "" }
|
|
@@ -1700,8 +2012,6 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1700
2012
|
lanceClient;
|
|
1701
2013
|
/**
|
|
1702
2014
|
* Creates a new instance of LanceStorage
|
|
1703
|
-
* @param id The unique identifier for this storage instance
|
|
1704
|
-
* @param name The name for this storage instance
|
|
1705
2015
|
* @param uri The URI to connect to LanceDB
|
|
1706
2016
|
* @param options connection options
|
|
1707
2017
|
*
|
|
@@ -1709,29 +2019,31 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1709
2019
|
*
|
|
1710
2020
|
* Connect to a local database
|
|
1711
2021
|
* ```ts
|
|
1712
|
-
* const store = await LanceStorage.create('
|
|
2022
|
+
* const store = await LanceStorage.create('/path/to/db');
|
|
1713
2023
|
* ```
|
|
1714
2024
|
*
|
|
1715
2025
|
* Connect to a LanceDB cloud database
|
|
1716
2026
|
* ```ts
|
|
1717
|
-
* const store = await LanceStorage.create('
|
|
2027
|
+
* const store = await LanceStorage.create('db://host:port');
|
|
1718
2028
|
* ```
|
|
1719
2029
|
*
|
|
1720
2030
|
* Connect to a cloud database
|
|
1721
2031
|
* ```ts
|
|
1722
|
-
* const store = await LanceStorage.create('
|
|
2032
|
+
* const store = await LanceStorage.create('s3://bucket/db', { storageOptions: { timeout: '60s' } });
|
|
1723
2033
|
* ```
|
|
1724
2034
|
*/
|
|
1725
|
-
static async create(
|
|
1726
|
-
const instance = new _LanceStorage(
|
|
2035
|
+
static async create(name, uri, options) {
|
|
2036
|
+
const instance = new _LanceStorage(name);
|
|
1727
2037
|
try {
|
|
1728
2038
|
instance.lanceClient = await lancedb.connect(uri, options);
|
|
1729
2039
|
const operations = new StoreOperationsLance({ client: instance.lanceClient });
|
|
1730
2040
|
instance.stores = {
|
|
1731
2041
|
operations: new StoreOperationsLance({ client: instance.lanceClient }),
|
|
1732
2042
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
2043
|
+
traces: new StoreTracesLance({ client: instance.lanceClient, operations }),
|
|
1733
2044
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
1734
|
-
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
2045
|
+
memory: new StoreMemoryLance({ client: instance.lanceClient, operations }),
|
|
2046
|
+
legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
|
|
1735
2047
|
};
|
|
1736
2048
|
return instance;
|
|
1737
2049
|
} catch (e) {
|
|
@@ -1751,13 +2063,15 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1751
2063
|
* @internal
|
|
1752
2064
|
* Private constructor to enforce using the create factory method
|
|
1753
2065
|
*/
|
|
1754
|
-
constructor(
|
|
1755
|
-
super({
|
|
2066
|
+
constructor(name) {
|
|
2067
|
+
super({ name });
|
|
1756
2068
|
const operations = new StoreOperationsLance({ client: this.lanceClient });
|
|
1757
2069
|
this.stores = {
|
|
1758
2070
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
1759
2071
|
workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
|
|
2072
|
+
traces: new StoreTracesLance({ client: this.lanceClient, operations }),
|
|
1760
2073
|
scores: new StoreScoresLance({ client: this.lanceClient }),
|
|
2074
|
+
legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
|
|
1761
2075
|
memory: new StoreMemoryLance({ client: this.lanceClient, operations })
|
|
1762
2076
|
};
|
|
1763
2077
|
}
|
|
@@ -1792,6 +2106,9 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1792
2106
|
async getThreadById({ threadId }) {
|
|
1793
2107
|
return this.stores.memory.getThreadById({ threadId });
|
|
1794
2108
|
}
|
|
2109
|
+
async getThreadsByResourceId({ resourceId }) {
|
|
2110
|
+
return this.stores.memory.getThreadsByResourceId({ resourceId });
|
|
2111
|
+
}
|
|
1795
2112
|
/**
|
|
1796
2113
|
* Saves a thread to the database. This function doesn't overwrite existing threads.
|
|
1797
2114
|
* @param thread - The thread to save
|
|
@@ -1817,7 +2134,7 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1817
2134
|
hasColumn: true,
|
|
1818
2135
|
createTable: true,
|
|
1819
2136
|
deleteMessages: false,
|
|
1820
|
-
|
|
2137
|
+
getScoresBySpan: true
|
|
1821
2138
|
};
|
|
1822
2139
|
}
|
|
1823
2140
|
async getResourceById({ resourceId }) {
|
|
@@ -1881,17 +2198,50 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1881
2198
|
});
|
|
1882
2199
|
return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
|
|
1883
2200
|
}
|
|
1884
|
-
async
|
|
1885
|
-
|
|
2201
|
+
async getMessages({
|
|
2202
|
+
threadId,
|
|
2203
|
+
resourceId,
|
|
2204
|
+
selectBy,
|
|
2205
|
+
format,
|
|
2206
|
+
threadConfig
|
|
2207
|
+
}) {
|
|
2208
|
+
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2209
|
+
}
|
|
2210
|
+
async getMessagesById({
|
|
2211
|
+
messageIds,
|
|
2212
|
+
format
|
|
2213
|
+
}) {
|
|
2214
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
1886
2215
|
}
|
|
1887
2216
|
async saveMessages(args) {
|
|
1888
2217
|
return this.stores.memory.saveMessages(args);
|
|
1889
2218
|
}
|
|
2219
|
+
async getThreadsByResourceIdPaginated(args) {
|
|
2220
|
+
return this.stores.memory.getThreadsByResourceIdPaginated(args);
|
|
2221
|
+
}
|
|
2222
|
+
async getMessagesPaginated(args) {
|
|
2223
|
+
return this.stores.memory.getMessagesPaginated(args);
|
|
2224
|
+
}
|
|
1890
2225
|
async updateMessages(_args) {
|
|
1891
2226
|
return this.stores.memory.updateMessages(_args);
|
|
1892
2227
|
}
|
|
1893
|
-
async
|
|
1894
|
-
return this.stores.
|
|
2228
|
+
async getTraceById(args) {
|
|
2229
|
+
return this.stores.traces.getTraceById(args);
|
|
2230
|
+
}
|
|
2231
|
+
async getTraces(args) {
|
|
2232
|
+
return this.stores.traces.getTraces(args);
|
|
2233
|
+
}
|
|
2234
|
+
async getTracesPaginated(args) {
|
|
2235
|
+
return this.stores.traces.getTracesPaginated(args);
|
|
2236
|
+
}
|
|
2237
|
+
async getEvalsByAgentName(agentName, type) {
|
|
2238
|
+
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
2239
|
+
}
|
|
2240
|
+
async getEvals(options) {
|
|
2241
|
+
return this.stores.legacyEvals.getEvals(options);
|
|
2242
|
+
}
|
|
2243
|
+
async getWorkflowRuns(args) {
|
|
2244
|
+
return this.stores.workflows.getWorkflowRuns(args);
|
|
1895
2245
|
}
|
|
1896
2246
|
async getWorkflowRunById(args) {
|
|
1897
2247
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
@@ -1901,9 +2251,9 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1901
2251
|
runId,
|
|
1902
2252
|
stepId,
|
|
1903
2253
|
result,
|
|
1904
|
-
|
|
2254
|
+
runtimeContext
|
|
1905
2255
|
}) {
|
|
1906
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
2256
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
1907
2257
|
}
|
|
1908
2258
|
async updateWorkflowState({
|
|
1909
2259
|
workflowName,
|
|
@@ -1929,37 +2279,37 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1929
2279
|
async getScoreById({ id: _id }) {
|
|
1930
2280
|
return this.stores.scores.getScoreById({ id: _id });
|
|
1931
2281
|
}
|
|
1932
|
-
async
|
|
2282
|
+
async getScoresByScorerId({
|
|
1933
2283
|
scorerId,
|
|
1934
2284
|
source,
|
|
1935
2285
|
entityId,
|
|
1936
2286
|
entityType,
|
|
1937
2287
|
pagination
|
|
1938
2288
|
}) {
|
|
1939
|
-
return this.stores.scores.
|
|
2289
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
|
|
1940
2290
|
}
|
|
1941
2291
|
async saveScore(_score) {
|
|
1942
2292
|
return this.stores.scores.saveScore(_score);
|
|
1943
2293
|
}
|
|
1944
|
-
async
|
|
2294
|
+
async getScoresByRunId({
|
|
1945
2295
|
runId,
|
|
1946
2296
|
pagination
|
|
1947
2297
|
}) {
|
|
1948
|
-
return this.stores.scores.
|
|
2298
|
+
return this.stores.scores.getScoresByRunId({ runId, pagination });
|
|
1949
2299
|
}
|
|
1950
|
-
async
|
|
2300
|
+
async getScoresByEntityId({
|
|
1951
2301
|
entityId,
|
|
1952
2302
|
entityType,
|
|
1953
2303
|
pagination
|
|
1954
2304
|
}) {
|
|
1955
|
-
return this.stores.scores.
|
|
2305
|
+
return this.stores.scores.getScoresByEntityId({ entityId, entityType, pagination });
|
|
1956
2306
|
}
|
|
1957
|
-
async
|
|
2307
|
+
async getScoresBySpan({
|
|
1958
2308
|
traceId,
|
|
1959
2309
|
spanId,
|
|
1960
2310
|
pagination
|
|
1961
2311
|
}) {
|
|
1962
|
-
return this.stores.scores.
|
|
2312
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
1963
2313
|
}
|
|
1964
2314
|
};
|
|
1965
2315
|
var LanceFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
@@ -2308,7 +2658,7 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2308
2658
|
* ```
|
|
2309
2659
|
*/
|
|
2310
2660
|
static async create(uri, options) {
|
|
2311
|
-
const instance = new _LanceVectorStore(
|
|
2661
|
+
const instance = new _LanceVectorStore();
|
|
2312
2662
|
try {
|
|
2313
2663
|
instance.lanceClient = await lancedb.connect(uri, options);
|
|
2314
2664
|
return instance;
|
|
@@ -2328,8 +2678,8 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2328
2678
|
* @internal
|
|
2329
2679
|
* Private constructor to enforce using the create factory method
|
|
2330
2680
|
*/
|
|
2331
|
-
constructor(
|
|
2332
|
-
super(
|
|
2681
|
+
constructor() {
|
|
2682
|
+
super();
|
|
2333
2683
|
}
|
|
2334
2684
|
close() {
|
|
2335
2685
|
if (this.lanceClient) {
|