@mastra/lance 0.0.0-rag-chunk-extract-llm-option-20250926183645 → 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 +112 -3
- package/dist/index.cjs +141 -346
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +142 -347
- 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/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +3 -10
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +5 -49
- 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
|
@@ -10,126 +10,10 @@ 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("length(test_info) = 0");
|
|
66
|
-
} else if (options.type === "test") {
|
|
67
|
-
conditions.push("length(test_info) > 0");
|
|
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
|
-
};
|
|
127
13
|
function getPrimaryKeys(tableName) {
|
|
128
14
|
let primaryId = ["id"];
|
|
129
15
|
if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
|
|
130
16
|
primaryId = ["workflow_name", "run_id"];
|
|
131
|
-
} else if (tableName === storage.TABLE_EVALS) {
|
|
132
|
-
primaryId = ["agent_name", "metric_name", "run_id"];
|
|
133
17
|
}
|
|
134
18
|
return primaryId;
|
|
135
19
|
}
|
|
@@ -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;
|
|
@@ -1634,198 +1646,6 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1634
1646
|
}
|
|
1635
1647
|
}
|
|
1636
1648
|
};
|
|
1637
|
-
var StoreTracesLance = class extends storage.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(storage.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$1) {
|
|
1659
|
-
throw new error.MastraError(
|
|
1660
|
-
{
|
|
1661
|
-
id: "LANCE_STORE_SAVE_TRACE_FAILED",
|
|
1662
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1663
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
1664
|
-
},
|
|
1665
|
-
error$1
|
|
1666
|
-
);
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
async getTraceById({ traceId }) {
|
|
1670
|
-
try {
|
|
1671
|
-
const table = await this.client.openTable(storage.TABLE_TRACES);
|
|
1672
|
-
const query = table.query().where(`id = '${traceId}'`);
|
|
1673
|
-
const records = await query.toArray();
|
|
1674
|
-
return records[0];
|
|
1675
|
-
} catch (error$1) {
|
|
1676
|
-
throw new error.MastraError(
|
|
1677
|
-
{
|
|
1678
|
-
id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
|
|
1679
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1680
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
1681
|
-
},
|
|
1682
|
-
error$1
|
|
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(storage.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$1) {
|
|
1731
|
-
throw new error.MastraError(
|
|
1732
|
-
{
|
|
1733
|
-
id: "LANCE_STORE_GET_TRACES_FAILED",
|
|
1734
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1735
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1736
|
-
details: { name: name ?? "", scope: scope ?? "" }
|
|
1737
|
-
},
|
|
1738
|
-
error$1
|
|
1739
|
-
);
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
async getTracesPaginated(args) {
|
|
1743
|
-
try {
|
|
1744
|
-
const table = await this.client.openTable(storage.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$1) {
|
|
1810
|
-
throw new error.MastraError(
|
|
1811
|
-
{
|
|
1812
|
-
id: "LANCE_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
1813
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1814
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1815
|
-
details: { name: args.name ?? "", scope: args.scope ?? "" }
|
|
1816
|
-
},
|
|
1817
|
-
error$1
|
|
1818
|
-
);
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
async batchTraceInsert({ records }) {
|
|
1822
|
-
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
1823
|
-
await this.operations.batchInsert({
|
|
1824
|
-
tableName: storage.TABLE_TRACES,
|
|
1825
|
-
records
|
|
1826
|
-
});
|
|
1827
|
-
}
|
|
1828
|
-
};
|
|
1829
1649
|
function parseWorkflowRun(row) {
|
|
1830
1650
|
let parsedSnapshot = row.snapshot;
|
|
1831
1651
|
if (typeof parsedSnapshot === "string") {
|
|
@@ -1855,7 +1675,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1855
1675
|
// runId,
|
|
1856
1676
|
// stepId,
|
|
1857
1677
|
// result,
|
|
1858
|
-
//
|
|
1678
|
+
// requestContext,
|
|
1859
1679
|
}) {
|
|
1860
1680
|
throw new Error("Method not implemented.");
|
|
1861
1681
|
}
|
|
@@ -1949,7 +1769,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1949
1769
|
);
|
|
1950
1770
|
}
|
|
1951
1771
|
}
|
|
1952
|
-
async
|
|
1772
|
+
async listWorkflowRuns(args) {
|
|
1953
1773
|
try {
|
|
1954
1774
|
const table = await this.client.openTable(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
1955
1775
|
let query = table.query();
|
|
@@ -1990,7 +1810,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1990
1810
|
id: "LANCE_STORE_GET_WORKFLOW_RUNS_FAILED",
|
|
1991
1811
|
domain: error.ErrorDomain.STORAGE,
|
|
1992
1812
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1993
|
-
details: {
|
|
1813
|
+
details: { resourceId: args?.resourceId ?? "", workflowName: args?.workflowName ?? "" }
|
|
1994
1814
|
},
|
|
1995
1815
|
error$1
|
|
1996
1816
|
);
|
|
@@ -2032,10 +1852,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2032
1852
|
instance.stores = {
|
|
2033
1853
|
operations: new StoreOperationsLance({ client: instance.lanceClient }),
|
|
2034
1854
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
2035
|
-
traces: new StoreTracesLance({ client: instance.lanceClient, operations }),
|
|
2036
1855
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
2037
|
-
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
2038
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
|
|
1856
|
+
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
2039
1857
|
};
|
|
2040
1858
|
return instance;
|
|
2041
1859
|
} catch (e) {
|
|
@@ -2061,9 +1879,7 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2061
1879
|
this.stores = {
|
|
2062
1880
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
2063
1881
|
workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
|
|
2064
|
-
traces: new StoreTracesLance({ client: this.lanceClient, operations }),
|
|
2065
1882
|
scores: new StoreScoresLance({ client: this.lanceClient }),
|
|
2066
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
|
|
2067
1883
|
memory: new StoreMemoryLance({ client: this.lanceClient, operations })
|
|
2068
1884
|
};
|
|
2069
1885
|
}
|
|
@@ -2199,12 +2015,6 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2199
2015
|
}) {
|
|
2200
2016
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2201
2017
|
}
|
|
2202
|
-
async getMessagesById({
|
|
2203
|
-
messageIds,
|
|
2204
|
-
format
|
|
2205
|
-
}) {
|
|
2206
|
-
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2207
|
-
}
|
|
2208
2018
|
async saveMessages(args) {
|
|
2209
2019
|
return this.stores.memory.saveMessages(args);
|
|
2210
2020
|
}
|
|
@@ -2217,23 +2027,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2217
2027
|
async updateMessages(_args) {
|
|
2218
2028
|
return this.stores.memory.updateMessages(_args);
|
|
2219
2029
|
}
|
|
2220
|
-
async
|
|
2221
|
-
return this.stores.
|
|
2222
|
-
}
|
|
2223
|
-
async getTraces(args) {
|
|
2224
|
-
return this.stores.traces.getTraces(args);
|
|
2225
|
-
}
|
|
2226
|
-
async getTracesPaginated(args) {
|
|
2227
|
-
return this.stores.traces.getTracesPaginated(args);
|
|
2228
|
-
}
|
|
2229
|
-
async getEvalsByAgentName(agentName, type) {
|
|
2230
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
2231
|
-
}
|
|
2232
|
-
async getEvals(options) {
|
|
2233
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
2234
|
-
}
|
|
2235
|
-
async getWorkflowRuns(args) {
|
|
2236
|
-
return this.stores.workflows.getWorkflowRuns(args);
|
|
2030
|
+
async listWorkflowRuns(args) {
|
|
2031
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
2237
2032
|
}
|
|
2238
2033
|
async getWorkflowRunById(args) {
|
|
2239
2034
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
@@ -2243,9 +2038,9 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2243
2038
|
runId,
|
|
2244
2039
|
stepId,
|
|
2245
2040
|
result,
|
|
2246
|
-
|
|
2041
|
+
requestContext
|
|
2247
2042
|
}) {
|
|
2248
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
2043
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
2249
2044
|
}
|
|
2250
2045
|
async updateWorkflowState({
|
|
2251
2046
|
workflowName,
|