@mastra/lance 0.0.0-remove-unused-import-20250909212718 → 0.0.0-remove-unused-model-providers-api-20251030210744
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 +174 -3
- package/dist/index.cjs +193 -336
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +194 -337
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +8 -7
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +8 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +5 -11
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +16 -50
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/storage/domains/legacy-evals/index.d.ts +0 -25
- package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
- package/dist/storage/domains/traces/index.d.ts +0 -34
- package/dist/storage/domains/traces/index.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -5,130 +5,15 @@ var error = require('@mastra/core/error');
|
|
|
5
5
|
var storage = require('@mastra/core/storage');
|
|
6
6
|
var agent = require('@mastra/core/agent');
|
|
7
7
|
var apacheArrow = require('apache-arrow');
|
|
8
|
+
var scores = require('@mastra/core/scores');
|
|
8
9
|
var vector = require('@mastra/core/vector');
|
|
9
10
|
var filter = require('@mastra/core/vector/filter');
|
|
10
11
|
|
|
11
12
|
// src/storage/index.ts
|
|
12
|
-
var StoreLegacyEvalsLance = class extends storage.LegacyEvalsStorage {
|
|
13
|
-
client;
|
|
14
|
-
constructor({ client }) {
|
|
15
|
-
super();
|
|
16
|
-
this.client = client;
|
|
17
|
-
}
|
|
18
|
-
async getEvalsByAgentName(agentName, type) {
|
|
19
|
-
try {
|
|
20
|
-
const table = await this.client.openTable(storage.TABLE_EVALS);
|
|
21
|
-
const query = table.query().where(`agent_name = '${agentName}'`);
|
|
22
|
-
const records = await query.toArray();
|
|
23
|
-
let filteredRecords = records;
|
|
24
|
-
if (type === "live") {
|
|
25
|
-
filteredRecords = records.filter((record) => record.test_info === null);
|
|
26
|
-
} else if (type === "test") {
|
|
27
|
-
filteredRecords = records.filter((record) => record.test_info !== null);
|
|
28
|
-
}
|
|
29
|
-
return filteredRecords.map((record) => {
|
|
30
|
-
return {
|
|
31
|
-
id: record.id,
|
|
32
|
-
input: record.input,
|
|
33
|
-
output: record.output,
|
|
34
|
-
agentName: record.agent_name,
|
|
35
|
-
metricName: record.metric_name,
|
|
36
|
-
result: JSON.parse(record.result),
|
|
37
|
-
instructions: record.instructions,
|
|
38
|
-
testInfo: record.test_info ? JSON.parse(record.test_info) : null,
|
|
39
|
-
globalRunId: record.global_run_id,
|
|
40
|
-
runId: record.run_id,
|
|
41
|
-
createdAt: new Date(record.created_at).toString()
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
} catch (error$1) {
|
|
45
|
-
throw new error.MastraError(
|
|
46
|
-
{
|
|
47
|
-
id: "LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
48
|
-
domain: error.ErrorDomain.STORAGE,
|
|
49
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
50
|
-
details: { agentName }
|
|
51
|
-
},
|
|
52
|
-
error$1
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async getEvals(options) {
|
|
57
|
-
try {
|
|
58
|
-
const table = await this.client.openTable(storage.TABLE_EVALS);
|
|
59
|
-
const conditions = [];
|
|
60
|
-
if (options.agentName) {
|
|
61
|
-
conditions.push(`agent_name = '${options.agentName}'`);
|
|
62
|
-
}
|
|
63
|
-
if (options.type === "live") {
|
|
64
|
-
conditions.push("length(test_info) = 0");
|
|
65
|
-
} else if (options.type === "test") {
|
|
66
|
-
conditions.push("length(test_info) > 0");
|
|
67
|
-
}
|
|
68
|
-
const startDate = options.dateRange?.start || options.fromDate;
|
|
69
|
-
const endDate = options.dateRange?.end || options.toDate;
|
|
70
|
-
if (startDate) {
|
|
71
|
-
conditions.push(`\`created_at\` >= ${startDate.getTime()}`);
|
|
72
|
-
}
|
|
73
|
-
if (endDate) {
|
|
74
|
-
conditions.push(`\`created_at\` <= ${endDate.getTime()}`);
|
|
75
|
-
}
|
|
76
|
-
let total = 0;
|
|
77
|
-
if (conditions.length > 0) {
|
|
78
|
-
total = await table.countRows(conditions.join(" AND "));
|
|
79
|
-
} else {
|
|
80
|
-
total = await table.countRows();
|
|
81
|
-
}
|
|
82
|
-
const query = table.query();
|
|
83
|
-
if (conditions.length > 0) {
|
|
84
|
-
const whereClause = conditions.join(" AND ");
|
|
85
|
-
query.where(whereClause);
|
|
86
|
-
}
|
|
87
|
-
const records = await query.toArray();
|
|
88
|
-
const evals = records.sort((a, b) => b.created_at - a.created_at).map((record) => {
|
|
89
|
-
return {
|
|
90
|
-
id: record.id,
|
|
91
|
-
input: record.input,
|
|
92
|
-
output: record.output,
|
|
93
|
-
agentName: record.agent_name,
|
|
94
|
-
metricName: record.metric_name,
|
|
95
|
-
result: JSON.parse(record.result),
|
|
96
|
-
instructions: record.instructions,
|
|
97
|
-
testInfo: record.test_info ? JSON.parse(record.test_info) : null,
|
|
98
|
-
globalRunId: record.global_run_id,
|
|
99
|
-
runId: record.run_id,
|
|
100
|
-
createdAt: new Date(record.created_at).toISOString()
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
const page = options.page || 0;
|
|
104
|
-
const perPage = options.perPage || 10;
|
|
105
|
-
const pagedEvals = evals.slice(page * perPage, (page + 1) * perPage);
|
|
106
|
-
return {
|
|
107
|
-
evals: pagedEvals,
|
|
108
|
-
total,
|
|
109
|
-
page,
|
|
110
|
-
perPage,
|
|
111
|
-
hasMore: total > (page + 1) * perPage
|
|
112
|
-
};
|
|
113
|
-
} catch (error$1) {
|
|
114
|
-
throw new error.MastraError(
|
|
115
|
-
{
|
|
116
|
-
id: "LANCE_STORE_GET_EVALS_FAILED",
|
|
117
|
-
domain: error.ErrorDomain.STORAGE,
|
|
118
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
119
|
-
details: { agentName: options.agentName ?? "" }
|
|
120
|
-
},
|
|
121
|
-
error$1
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
13
|
function getPrimaryKeys(tableName) {
|
|
127
14
|
let primaryId = ["id"];
|
|
128
15
|
if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
|
|
129
16
|
primaryId = ["workflow_name", "run_id"];
|
|
130
|
-
} else if (tableName === storage.TABLE_EVALS) {
|
|
131
|
-
primaryId = ["agent_name", "metric_name", "run_id"];
|
|
132
17
|
}
|
|
133
18
|
return primaryId;
|
|
134
19
|
}
|
|
@@ -189,7 +74,6 @@ function processResultWithTypeConversion(rawResult, tableSchema) {
|
|
|
189
74
|
} else if (fieldTypeStr.includes("float64") && ["createdAt", "updatedAt"].includes(key)) {
|
|
190
75
|
processedResult[key] = new Date(processedResult[key]);
|
|
191
76
|
}
|
|
192
|
-
console.log(key, "processedResult", processedResult);
|
|
193
77
|
}
|
|
194
78
|
return processedResult;
|
|
195
79
|
}
|
|
@@ -454,10 +338,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
454
338
|
);
|
|
455
339
|
}
|
|
456
340
|
}
|
|
457
|
-
async
|
|
458
|
-
messageIds,
|
|
459
|
-
format
|
|
460
|
-
}) {
|
|
341
|
+
async listMessagesById({ messageIds }) {
|
|
461
342
|
if (messageIds.length === 0) return [];
|
|
462
343
|
try {
|
|
463
344
|
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
@@ -468,7 +349,6 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
468
349
|
await getTableSchema({ tableName: storage.TABLE_MESSAGES, client: this.client })
|
|
469
350
|
);
|
|
470
351
|
const list = new agent.MessageList().add(messages.map(this.normalizeMessage), "memory");
|
|
471
|
-
if (format === `v1`) return list.get.all.v1();
|
|
472
352
|
return list.get.all.v2();
|
|
473
353
|
} catch (error$1) {
|
|
474
354
|
throw new error.MastraError(
|
|
@@ -484,6 +364,138 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
|
|
|
484
364
|
);
|
|
485
365
|
}
|
|
486
366
|
}
|
|
367
|
+
async listMessages(args) {
|
|
368
|
+
const { threadId, resourceId, include, filter, limit, offset = 0, orderBy } = args;
|
|
369
|
+
if (!threadId.trim()) {
|
|
370
|
+
throw new error.MastraError(
|
|
371
|
+
{
|
|
372
|
+
id: "STORAGE_LANCE_LIST_MESSAGES_INVALID_THREAD_ID",
|
|
373
|
+
domain: error.ErrorDomain.STORAGE,
|
|
374
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
375
|
+
details: { threadId }
|
|
376
|
+
},
|
|
377
|
+
new Error("threadId must be a non-empty string")
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
try {
|
|
381
|
+
let perPage = 40;
|
|
382
|
+
if (limit !== void 0) {
|
|
383
|
+
if (limit === false) {
|
|
384
|
+
perPage = Number.MAX_SAFE_INTEGER;
|
|
385
|
+
} else if (limit === 0) {
|
|
386
|
+
perPage = 0;
|
|
387
|
+
} else if (typeof limit === "number" && limit > 0) {
|
|
388
|
+
perPage = limit;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const page = perPage === 0 ? 0 : Math.floor(offset / perPage);
|
|
392
|
+
const sortField = orderBy?.field || "createdAt";
|
|
393
|
+
const sortDirection = orderBy?.direction || "DESC";
|
|
394
|
+
const table = await this.client.openTable(storage.TABLE_MESSAGES);
|
|
395
|
+
const escapeSql = (str) => str.replace(/'/g, "''");
|
|
396
|
+
const conditions = [`thread_id = '${escapeSql(threadId)}'`];
|
|
397
|
+
if (resourceId) {
|
|
398
|
+
conditions.push(`\`resourceId\` = '${escapeSql(resourceId)}'`);
|
|
399
|
+
}
|
|
400
|
+
if (filter?.dateRange?.start) {
|
|
401
|
+
const startTime = filter.dateRange.start instanceof Date ? filter.dateRange.start.getTime() : new Date(filter.dateRange.start).getTime();
|
|
402
|
+
conditions.push(`\`createdAt\` >= ${startTime}`);
|
|
403
|
+
}
|
|
404
|
+
if (filter?.dateRange?.end) {
|
|
405
|
+
const endTime = filter.dateRange.end instanceof Date ? filter.dateRange.end.getTime() : new Date(filter.dateRange.end).getTime();
|
|
406
|
+
conditions.push(`\`createdAt\` <= ${endTime}`);
|
|
407
|
+
}
|
|
408
|
+
const whereClause = conditions.join(" AND ");
|
|
409
|
+
const total = await table.countRows(whereClause);
|
|
410
|
+
const query = table.query().where(whereClause);
|
|
411
|
+
let allRecords = await query.toArray();
|
|
412
|
+
allRecords.sort((a, b) => {
|
|
413
|
+
const aValue = sortField === "createdAt" ? a.createdAt : a[sortField];
|
|
414
|
+
const bValue = sortField === "createdAt" ? b.createdAt : b[sortField];
|
|
415
|
+
return sortDirection === "ASC" ? aValue - bValue : bValue - aValue;
|
|
416
|
+
});
|
|
417
|
+
const paginatedRecords = allRecords.slice(offset, offset + perPage);
|
|
418
|
+
const messages = paginatedRecords.map((row) => this.normalizeMessage(row));
|
|
419
|
+
if (total === 0 && messages.length === 0) {
|
|
420
|
+
return {
|
|
421
|
+
messages: [],
|
|
422
|
+
total: 0,
|
|
423
|
+
page,
|
|
424
|
+
perPage,
|
|
425
|
+
hasMore: false
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
const messageIds = new Set(messages.map((m) => m.id));
|
|
429
|
+
if (include && include.length > 0) {
|
|
430
|
+
const threadIds = [...new Set(include.map((item) => item.threadId || threadId))];
|
|
431
|
+
const allThreadMessages = [];
|
|
432
|
+
for (const tid of threadIds) {
|
|
433
|
+
const threadQuery = table.query().where(`thread_id = '${tid}'`);
|
|
434
|
+
let threadRecords = await threadQuery.toArray();
|
|
435
|
+
allThreadMessages.push(...threadRecords);
|
|
436
|
+
}
|
|
437
|
+
allThreadMessages.sort((a, b) => a.createdAt - b.createdAt);
|
|
438
|
+
const contextMessages = this.processMessagesWithContext(allThreadMessages, include);
|
|
439
|
+
const includedMessages = contextMessages.map((row) => this.normalizeMessage(row));
|
|
440
|
+
for (const includeMsg of includedMessages) {
|
|
441
|
+
if (!messageIds.has(includeMsg.id)) {
|
|
442
|
+
messages.push(includeMsg);
|
|
443
|
+
messageIds.add(includeMsg.id);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
const list = new agent.MessageList().add(messages, "memory");
|
|
448
|
+
let finalMessages = list.get.all.v2();
|
|
449
|
+
finalMessages = finalMessages.sort((a, b) => {
|
|
450
|
+
const aValue = sortField === "createdAt" ? new Date(a.createdAt).getTime() : a[sortField];
|
|
451
|
+
const bValue = sortField === "createdAt" ? new Date(b.createdAt).getTime() : b[sortField];
|
|
452
|
+
return sortDirection === "ASC" ? aValue - bValue : bValue - aValue;
|
|
453
|
+
});
|
|
454
|
+
const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
|
|
455
|
+
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
456
|
+
const hasMore = limit === false ? false : allThreadMessagesReturned ? false : offset + paginatedRecords.length < total;
|
|
457
|
+
return {
|
|
458
|
+
messages: finalMessages,
|
|
459
|
+
total,
|
|
460
|
+
page,
|
|
461
|
+
perPage,
|
|
462
|
+
hasMore
|
|
463
|
+
};
|
|
464
|
+
} catch (error$1) {
|
|
465
|
+
const errorPerPage = limit === false ? Number.MAX_SAFE_INTEGER : limit === 0 ? 0 : limit || 40;
|
|
466
|
+
const mastraError = new error.MastraError(
|
|
467
|
+
{
|
|
468
|
+
id: "LANCE_STORE_LIST_MESSAGES_FAILED",
|
|
469
|
+
domain: error.ErrorDomain.STORAGE,
|
|
470
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
471
|
+
details: {
|
|
472
|
+
threadId,
|
|
473
|
+
resourceId: resourceId ?? ""
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
error$1
|
|
477
|
+
);
|
|
478
|
+
this.logger?.error?.(mastraError.toString());
|
|
479
|
+
this.logger?.trackException?.(mastraError);
|
|
480
|
+
return {
|
|
481
|
+
messages: [],
|
|
482
|
+
total: 0,
|
|
483
|
+
page: errorPerPage === 0 ? 0 : Math.floor(offset / errorPerPage),
|
|
484
|
+
perPage: errorPerPage,
|
|
485
|
+
hasMore: false
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* @todo When migrating from getThreadsByResourceIdPaginated to this method,
|
|
491
|
+
* implement orderBy and sortDirection support for full sorting capabilities
|
|
492
|
+
*/
|
|
493
|
+
async listThreadsByResourceId(args) {
|
|
494
|
+
const { resourceId, limit, offset } = args;
|
|
495
|
+
const page = Math.floor(offset / limit);
|
|
496
|
+
const perPage = limit;
|
|
497
|
+
return this.getThreadsByResourceIdPaginated({ resourceId, page, perPage });
|
|
498
|
+
}
|
|
487
499
|
async saveMessages(args) {
|
|
488
500
|
try {
|
|
489
501
|
const { messages, format = "v1" } = args;
|
|
@@ -1266,7 +1278,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1266
1278
|
processedRecord[key] = JSON.stringify(processedRecord[key]);
|
|
1267
1279
|
}
|
|
1268
1280
|
}
|
|
1269
|
-
console.
|
|
1281
|
+
console.info(await table.schema());
|
|
1270
1282
|
await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([processedRecord]);
|
|
1271
1283
|
} catch (error$1) {
|
|
1272
1284
|
throw new error.MastraError(
|
|
@@ -1316,7 +1328,6 @@ var StoreOperationsLance = class extends storage.StoreOperations {
|
|
|
1316
1328
|
}
|
|
1317
1329
|
return processedRecord;
|
|
1318
1330
|
});
|
|
1319
|
-
console.log(processedRecords);
|
|
1320
1331
|
await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(processedRecords);
|
|
1321
1332
|
} catch (error$1) {
|
|
1322
1333
|
throw new error.MastraError(
|
|
@@ -1400,13 +1411,27 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1400
1411
|
this.client = client;
|
|
1401
1412
|
}
|
|
1402
1413
|
async saveScore(score) {
|
|
1414
|
+
let validatedScore;
|
|
1415
|
+
try {
|
|
1416
|
+
validatedScore = scores.saveScorePayloadSchema.parse(score);
|
|
1417
|
+
} catch (error$1) {
|
|
1418
|
+
throw new error.MastraError(
|
|
1419
|
+
{
|
|
1420
|
+
id: "LANCE_STORAGE_SAVE_SCORE_FAILED",
|
|
1421
|
+
text: "Failed to save score in LanceStorage",
|
|
1422
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1423
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1424
|
+
},
|
|
1425
|
+
error$1
|
|
1426
|
+
);
|
|
1427
|
+
}
|
|
1403
1428
|
try {
|
|
1404
1429
|
const id = crypto.randomUUID();
|
|
1405
1430
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1406
1431
|
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1407
1432
|
const allowedFields = new Set(schema.fields.map((f) => f.name));
|
|
1408
1433
|
const filteredScore = {};
|
|
1409
|
-
Object.keys(
|
|
1434
|
+
Object.keys(validatedScore).forEach((key) => {
|
|
1410
1435
|
if (allowedFields.has(key)) {
|
|
1411
1436
|
filteredScore[key] = score[key];
|
|
1412
1437
|
}
|
|
@@ -1582,198 +1607,44 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1582
1607
|
);
|
|
1583
1608
|
}
|
|
1584
1609
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
constructor({ client, operations }) {
|
|
1590
|
-
super();
|
|
1591
|
-
this.client = client;
|
|
1592
|
-
this.operations = operations;
|
|
1593
|
-
}
|
|
1594
|
-
async saveTrace({ trace }) {
|
|
1595
|
-
try {
|
|
1596
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1597
|
-
const record = {
|
|
1598
|
-
...trace,
|
|
1599
|
-
attributes: JSON.stringify(trace.attributes),
|
|
1600
|
-
status: JSON.stringify(trace.status),
|
|
1601
|
-
events: JSON.stringify(trace.events),
|
|
1602
|
-
links: JSON.stringify(trace.links),
|
|
1603
|
-
other: JSON.stringify(trace.other)
|
|
1604
|
-
};
|
|
1605
|
-
await table.add([record], { mode: "append" });
|
|
1606
|
-
return trace;
|
|
1607
|
-
} catch (error$1) {
|
|
1608
|
-
throw new error.MastraError(
|
|
1609
|
-
{
|
|
1610
|
-
id: "LANCE_STORE_SAVE_TRACE_FAILED",
|
|
1611
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1612
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
1613
|
-
},
|
|
1614
|
-
error$1
|
|
1615
|
-
);
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
async getTraceById({ traceId }) {
|
|
1619
|
-
try {
|
|
1620
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1621
|
-
const query = table.query().where(`id = '${traceId}'`);
|
|
1622
|
-
const records = await query.toArray();
|
|
1623
|
-
return records[0];
|
|
1624
|
-
} catch (error$1) {
|
|
1625
|
-
throw new error.MastraError(
|
|
1626
|
-
{
|
|
1627
|
-
id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
|
|
1628
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1629
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
1630
|
-
},
|
|
1631
|
-
error$1
|
|
1632
|
-
);
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
async getTraces({
|
|
1636
|
-
name,
|
|
1637
|
-
scope,
|
|
1638
|
-
page = 1,
|
|
1639
|
-
perPage = 10,
|
|
1640
|
-
attributes
|
|
1610
|
+
async getScoresBySpan({
|
|
1611
|
+
traceId,
|
|
1612
|
+
spanId,
|
|
1613
|
+
pagination
|
|
1641
1614
|
}) {
|
|
1642
1615
|
try {
|
|
1643
|
-
const table = await this.client.openTable(storage.
|
|
1644
|
-
const
|
|
1645
|
-
if (name) {
|
|
1646
|
-
query.where(`name = '${name}'`);
|
|
1647
|
-
}
|
|
1648
|
-
if (scope) {
|
|
1649
|
-
query.where(`scope = '${scope}'`);
|
|
1650
|
-
}
|
|
1651
|
-
if (attributes) {
|
|
1652
|
-
query.where(`attributes = '${JSON.stringify(attributes)}'`);
|
|
1653
|
-
}
|
|
1654
|
-
const offset = (page - 1) * perPage;
|
|
1655
|
-
query.limit(perPage);
|
|
1656
|
-
if (offset > 0) {
|
|
1657
|
-
query.offset(offset);
|
|
1658
|
-
}
|
|
1659
|
-
const records = await query.toArray();
|
|
1660
|
-
return records.map((record) => {
|
|
1661
|
-
const processed = {
|
|
1662
|
-
...record,
|
|
1663
|
-
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1664
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1665
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1666
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1667
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1668
|
-
startTime: new Date(record.startTime),
|
|
1669
|
-
endTime: new Date(record.endTime),
|
|
1670
|
-
createdAt: new Date(record.createdAt)
|
|
1671
|
-
};
|
|
1672
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1673
|
-
processed.parentSpanId = "";
|
|
1674
|
-
} else {
|
|
1675
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1676
|
-
}
|
|
1677
|
-
return processed;
|
|
1678
|
-
});
|
|
1679
|
-
} catch (error$1) {
|
|
1680
|
-
throw new error.MastraError(
|
|
1681
|
-
{
|
|
1682
|
-
id: "LANCE_STORE_GET_TRACES_FAILED",
|
|
1683
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1684
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1685
|
-
details: { name: name ?? "", scope: scope ?? "" }
|
|
1686
|
-
},
|
|
1687
|
-
error$1
|
|
1688
|
-
);
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
async getTracesPaginated(args) {
|
|
1692
|
-
try {
|
|
1693
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1694
|
-
const query = table.query();
|
|
1695
|
-
const conditions = [];
|
|
1696
|
-
if (args.name) {
|
|
1697
|
-
conditions.push(`name = '${args.name}'`);
|
|
1698
|
-
}
|
|
1699
|
-
if (args.scope) {
|
|
1700
|
-
conditions.push(`scope = '${args.scope}'`);
|
|
1701
|
-
}
|
|
1702
|
-
if (args.attributes) {
|
|
1703
|
-
const attributesStr = JSON.stringify(args.attributes);
|
|
1704
|
-
conditions.push(`attributes LIKE '%${attributesStr.replace(/"/g, '\\"')}%'`);
|
|
1705
|
-
}
|
|
1706
|
-
if (args.dateRange?.start) {
|
|
1707
|
-
conditions.push(`\`createdAt\` >= ${args.dateRange.start.getTime()}`);
|
|
1708
|
-
}
|
|
1709
|
-
if (args.dateRange?.end) {
|
|
1710
|
-
conditions.push(`\`createdAt\` <= ${args.dateRange.end.getTime()}`);
|
|
1711
|
-
}
|
|
1712
|
-
if (conditions.length > 0) {
|
|
1713
|
-
const whereClause = conditions.join(" AND ");
|
|
1714
|
-
query.where(whereClause);
|
|
1715
|
-
}
|
|
1716
|
-
let total = 0;
|
|
1717
|
-
if (conditions.length > 0) {
|
|
1718
|
-
const countQuery = table.query().where(conditions.join(" AND "));
|
|
1719
|
-
const allRecords = await countQuery.toArray();
|
|
1720
|
-
total = allRecords.length;
|
|
1721
|
-
} else {
|
|
1722
|
-
total = await table.countRows();
|
|
1723
|
-
}
|
|
1724
|
-
const page = args.page || 0;
|
|
1725
|
-
const perPage = args.perPage || 10;
|
|
1616
|
+
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1617
|
+
const { page = 0, perPage = 10 } = pagination || {};
|
|
1726
1618
|
const offset = page * perPage;
|
|
1727
|
-
query.limit(perPage);
|
|
1728
|
-
if (offset > 0)
|
|
1729
|
-
query.offset(offset);
|
|
1730
|
-
}
|
|
1619
|
+
const query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).limit(perPage);
|
|
1620
|
+
if (offset > 0) query.offset(offset);
|
|
1731
1621
|
const records = await query.toArray();
|
|
1732
|
-
const
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1737
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1738
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1739
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1740
|
-
startTime: new Date(record.startTime),
|
|
1741
|
-
endTime: new Date(record.endTime),
|
|
1742
|
-
createdAt: new Date(record.createdAt)
|
|
1743
|
-
};
|
|
1744
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1745
|
-
processed.parentSpanId = "";
|
|
1746
|
-
} else {
|
|
1747
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1748
|
-
}
|
|
1749
|
-
return processed;
|
|
1750
|
-
});
|
|
1622
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1623
|
+
const scores = processResultWithTypeConversion(records, schema);
|
|
1624
|
+
const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
|
|
1625
|
+
const total = allRecords.length;
|
|
1751
1626
|
return {
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1627
|
+
pagination: {
|
|
1628
|
+
page,
|
|
1629
|
+
perPage,
|
|
1630
|
+
total,
|
|
1631
|
+
hasMore: offset + scores.length < total
|
|
1632
|
+
},
|
|
1633
|
+
scores
|
|
1757
1634
|
};
|
|
1758
1635
|
} catch (error$1) {
|
|
1759
1636
|
throw new error.MastraError(
|
|
1760
1637
|
{
|
|
1761
|
-
id: "
|
|
1638
|
+
id: "LANCE_STORAGE_GET_SCORES_BY_SPAN_FAILED",
|
|
1639
|
+
text: "Failed to get scores by traceId and spanId in LanceStorage",
|
|
1762
1640
|
domain: error.ErrorDomain.STORAGE,
|
|
1763
1641
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1764
|
-
details: {
|
|
1642
|
+
details: { error: error$1?.message }
|
|
1765
1643
|
},
|
|
1766
1644
|
error$1
|
|
1767
1645
|
);
|
|
1768
1646
|
}
|
|
1769
1647
|
}
|
|
1770
|
-
async batchTraceInsert({ records }) {
|
|
1771
|
-
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
1772
|
-
await this.operations.batchInsert({
|
|
1773
|
-
tableName: storage.TABLE_TRACES,
|
|
1774
|
-
records
|
|
1775
|
-
});
|
|
1776
|
-
}
|
|
1777
1648
|
};
|
|
1778
1649
|
function parseWorkflowRun(row) {
|
|
1779
1650
|
let parsedSnapshot = row.snapshot;
|
|
@@ -1804,7 +1675,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1804
1675
|
// runId,
|
|
1805
1676
|
// stepId,
|
|
1806
1677
|
// result,
|
|
1807
|
-
//
|
|
1678
|
+
// requestContext,
|
|
1808
1679
|
}) {
|
|
1809
1680
|
throw new Error("Method not implemented.");
|
|
1810
1681
|
}
|
|
@@ -1818,6 +1689,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1818
1689
|
async persistWorkflowSnapshot({
|
|
1819
1690
|
workflowName,
|
|
1820
1691
|
runId,
|
|
1692
|
+
resourceId,
|
|
1821
1693
|
snapshot
|
|
1822
1694
|
}) {
|
|
1823
1695
|
try {
|
|
@@ -1834,6 +1706,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1834
1706
|
const record = {
|
|
1835
1707
|
workflow_name: workflowName,
|
|
1836
1708
|
run_id: runId,
|
|
1709
|
+
resourceId,
|
|
1837
1710
|
snapshot: JSON.stringify(snapshot),
|
|
1838
1711
|
createdAt,
|
|
1839
1712
|
updatedAt: now
|
|
@@ -1896,7 +1769,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1896
1769
|
);
|
|
1897
1770
|
}
|
|
1898
1771
|
}
|
|
1899
|
-
async
|
|
1772
|
+
async listWorkflowRuns(args) {
|
|
1900
1773
|
try {
|
|
1901
1774
|
const table = await this.client.openTable(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
1902
1775
|
let query = table.query();
|
|
@@ -1937,7 +1810,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1937
1810
|
id: "LANCE_STORE_GET_WORKFLOW_RUNS_FAILED",
|
|
1938
1811
|
domain: error.ErrorDomain.STORAGE,
|
|
1939
1812
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1940
|
-
details: {
|
|
1813
|
+
details: { resourceId: args?.resourceId ?? "", workflowName: args?.workflowName ?? "" }
|
|
1941
1814
|
},
|
|
1942
1815
|
error$1
|
|
1943
1816
|
);
|
|
@@ -1979,10 +1852,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
1979
1852
|
instance.stores = {
|
|
1980
1853
|
operations: new StoreOperationsLance({ client: instance.lanceClient }),
|
|
1981
1854
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
1982
|
-
traces: new StoreTracesLance({ client: instance.lanceClient, operations }),
|
|
1983
1855
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
1984
|
-
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
1985
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
|
|
1856
|
+
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
1986
1857
|
};
|
|
1987
1858
|
return instance;
|
|
1988
1859
|
} catch (e) {
|
|
@@ -2008,9 +1879,7 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2008
1879
|
this.stores = {
|
|
2009
1880
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
2010
1881
|
workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
|
|
2011
|
-
traces: new StoreTracesLance({ client: this.lanceClient, operations }),
|
|
2012
1882
|
scores: new StoreScoresLance({ client: this.lanceClient }),
|
|
2013
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
|
|
2014
1883
|
memory: new StoreMemoryLance({ client: this.lanceClient, operations })
|
|
2015
1884
|
};
|
|
2016
1885
|
}
|
|
@@ -2072,7 +1941,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2072
1941
|
resourceWorkingMemory: true,
|
|
2073
1942
|
hasColumn: true,
|
|
2074
1943
|
createTable: true,
|
|
2075
|
-
deleteMessages: false
|
|
1944
|
+
deleteMessages: false,
|
|
1945
|
+
getScoresBySpan: true
|
|
2076
1946
|
};
|
|
2077
1947
|
}
|
|
2078
1948
|
async getResourceById({ resourceId }) {
|
|
@@ -2145,12 +2015,6 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2145
2015
|
}) {
|
|
2146
2016
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2147
2017
|
}
|
|
2148
|
-
async getMessagesById({
|
|
2149
|
-
messageIds,
|
|
2150
|
-
format
|
|
2151
|
-
}) {
|
|
2152
|
-
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2153
|
-
}
|
|
2154
2018
|
async saveMessages(args) {
|
|
2155
2019
|
return this.stores.memory.saveMessages(args);
|
|
2156
2020
|
}
|
|
@@ -2163,23 +2027,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2163
2027
|
async updateMessages(_args) {
|
|
2164
2028
|
return this.stores.memory.updateMessages(_args);
|
|
2165
2029
|
}
|
|
2166
|
-
async
|
|
2167
|
-
return this.stores.
|
|
2168
|
-
}
|
|
2169
|
-
async getTraces(args) {
|
|
2170
|
-
return this.stores.traces.getTraces(args);
|
|
2171
|
-
}
|
|
2172
|
-
async getTracesPaginated(args) {
|
|
2173
|
-
return this.stores.traces.getTracesPaginated(args);
|
|
2174
|
-
}
|
|
2175
|
-
async getEvalsByAgentName(agentName, type) {
|
|
2176
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
2177
|
-
}
|
|
2178
|
-
async getEvals(options) {
|
|
2179
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
2180
|
-
}
|
|
2181
|
-
async getWorkflowRuns(args) {
|
|
2182
|
-
return this.stores.workflows.getWorkflowRuns(args);
|
|
2030
|
+
async listWorkflowRuns(args) {
|
|
2031
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
2183
2032
|
}
|
|
2184
2033
|
async getWorkflowRunById(args) {
|
|
2185
2034
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
@@ -2189,9 +2038,9 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2189
2038
|
runId,
|
|
2190
2039
|
stepId,
|
|
2191
2040
|
result,
|
|
2192
|
-
|
|
2041
|
+
requestContext
|
|
2193
2042
|
}) {
|
|
2194
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
2043
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
2195
2044
|
}
|
|
2196
2045
|
async updateWorkflowState({
|
|
2197
2046
|
workflowName,
|
|
@@ -2203,9 +2052,10 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2203
2052
|
async persistWorkflowSnapshot({
|
|
2204
2053
|
workflowName,
|
|
2205
2054
|
runId,
|
|
2055
|
+
resourceId,
|
|
2206
2056
|
snapshot
|
|
2207
2057
|
}) {
|
|
2208
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
2058
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2209
2059
|
}
|
|
2210
2060
|
async loadWorkflowSnapshot({
|
|
2211
2061
|
workflowName,
|
|
@@ -2241,6 +2091,13 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2241
2091
|
}) {
|
|
2242
2092
|
return this.stores.scores.getScoresByEntityId({ entityId, entityType, pagination });
|
|
2243
2093
|
}
|
|
2094
|
+
async getScoresBySpan({
|
|
2095
|
+
traceId,
|
|
2096
|
+
spanId,
|
|
2097
|
+
pagination
|
|
2098
|
+
}) {
|
|
2099
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2100
|
+
}
|
|
2244
2101
|
};
|
|
2245
2102
|
var LanceFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
2246
2103
|
translate(filter) {
|