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