@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.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { connect, Index } from '@lancedb/lancedb';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import { MastraStorage, StoreOperations,
|
|
3
|
+
import { MastraStorage, StoreOperations, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, resolveMessageLimit, TABLE_RESOURCES, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, ensureDate } from '@mastra/core/storage';
|
|
4
4
|
import { MessageList } from '@mastra/core/agent';
|
|
5
5
|
import { Utf8, Float64, Binary, Float32, Int32, Field, Schema } from 'apache-arrow';
|
|
6
6
|
import { saveScorePayloadSchema } from '@mastra/core/scores';
|
|
@@ -8,126 +8,10 @@ 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("length(test_info) = 0");
|
|
64
|
-
} else if (options.type === "test") {
|
|
65
|
-
conditions.push("length(test_info) > 0");
|
|
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
|
-
};
|
|
125
11
|
function getPrimaryKeys(tableName) {
|
|
126
12
|
let primaryId = ["id"];
|
|
127
13
|
if (tableName === TABLE_WORKFLOW_SNAPSHOT) {
|
|
128
14
|
primaryId = ["workflow_name", "run_id"];
|
|
129
|
-
} else if (tableName === TABLE_EVALS) {
|
|
130
|
-
primaryId = ["agent_name", "metric_name", "run_id"];
|
|
131
15
|
}
|
|
132
16
|
return primaryId;
|
|
133
17
|
}
|
|
@@ -452,10 +336,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
452
336
|
);
|
|
453
337
|
}
|
|
454
338
|
}
|
|
455
|
-
async
|
|
456
|
-
messageIds,
|
|
457
|
-
format
|
|
458
|
-
}) {
|
|
339
|
+
async listMessagesById({ messageIds }) {
|
|
459
340
|
if (messageIds.length === 0) return [];
|
|
460
341
|
try {
|
|
461
342
|
const table = await this.client.openTable(TABLE_MESSAGES);
|
|
@@ -466,7 +347,6 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
466
347
|
await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
|
|
467
348
|
);
|
|
468
349
|
const list = new MessageList().add(messages.map(this.normalizeMessage), "memory");
|
|
469
|
-
if (format === `v1`) return list.get.all.v1();
|
|
470
350
|
return list.get.all.v2();
|
|
471
351
|
} catch (error) {
|
|
472
352
|
throw new MastraError(
|
|
@@ -482,6 +362,138 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
482
362
|
);
|
|
483
363
|
}
|
|
484
364
|
}
|
|
365
|
+
async listMessages(args) {
|
|
366
|
+
const { threadId, resourceId, include, filter, limit, offset = 0, orderBy } = args;
|
|
367
|
+
if (!threadId.trim()) {
|
|
368
|
+
throw new MastraError(
|
|
369
|
+
{
|
|
370
|
+
id: "STORAGE_LANCE_LIST_MESSAGES_INVALID_THREAD_ID",
|
|
371
|
+
domain: ErrorDomain.STORAGE,
|
|
372
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
373
|
+
details: { threadId }
|
|
374
|
+
},
|
|
375
|
+
new Error("threadId must be a non-empty string")
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
try {
|
|
379
|
+
let perPage = 40;
|
|
380
|
+
if (limit !== void 0) {
|
|
381
|
+
if (limit === false) {
|
|
382
|
+
perPage = Number.MAX_SAFE_INTEGER;
|
|
383
|
+
} else if (limit === 0) {
|
|
384
|
+
perPage = 0;
|
|
385
|
+
} else if (typeof limit === "number" && limit > 0) {
|
|
386
|
+
perPage = limit;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const page = perPage === 0 ? 0 : Math.floor(offset / perPage);
|
|
390
|
+
const sortField = orderBy?.field || "createdAt";
|
|
391
|
+
const sortDirection = orderBy?.direction || "DESC";
|
|
392
|
+
const table = await this.client.openTable(TABLE_MESSAGES);
|
|
393
|
+
const escapeSql = (str) => str.replace(/'/g, "''");
|
|
394
|
+
const conditions = [`thread_id = '${escapeSql(threadId)}'`];
|
|
395
|
+
if (resourceId) {
|
|
396
|
+
conditions.push(`\`resourceId\` = '${escapeSql(resourceId)}'`);
|
|
397
|
+
}
|
|
398
|
+
if (filter?.dateRange?.start) {
|
|
399
|
+
const startTime = filter.dateRange.start instanceof Date ? filter.dateRange.start.getTime() : new Date(filter.dateRange.start).getTime();
|
|
400
|
+
conditions.push(`\`createdAt\` >= ${startTime}`);
|
|
401
|
+
}
|
|
402
|
+
if (filter?.dateRange?.end) {
|
|
403
|
+
const endTime = filter.dateRange.end instanceof Date ? filter.dateRange.end.getTime() : new Date(filter.dateRange.end).getTime();
|
|
404
|
+
conditions.push(`\`createdAt\` <= ${endTime}`);
|
|
405
|
+
}
|
|
406
|
+
const whereClause = conditions.join(" AND ");
|
|
407
|
+
const total = await table.countRows(whereClause);
|
|
408
|
+
const query = table.query().where(whereClause);
|
|
409
|
+
let allRecords = await query.toArray();
|
|
410
|
+
allRecords.sort((a, b) => {
|
|
411
|
+
const aValue = sortField === "createdAt" ? a.createdAt : a[sortField];
|
|
412
|
+
const bValue = sortField === "createdAt" ? b.createdAt : b[sortField];
|
|
413
|
+
return sortDirection === "ASC" ? aValue - bValue : bValue - aValue;
|
|
414
|
+
});
|
|
415
|
+
const paginatedRecords = allRecords.slice(offset, offset + perPage);
|
|
416
|
+
const messages = paginatedRecords.map((row) => this.normalizeMessage(row));
|
|
417
|
+
if (total === 0 && messages.length === 0) {
|
|
418
|
+
return {
|
|
419
|
+
messages: [],
|
|
420
|
+
total: 0,
|
|
421
|
+
page,
|
|
422
|
+
perPage,
|
|
423
|
+
hasMore: false
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
const messageIds = new Set(messages.map((m) => m.id));
|
|
427
|
+
if (include && include.length > 0) {
|
|
428
|
+
const threadIds = [...new Set(include.map((item) => item.threadId || threadId))];
|
|
429
|
+
const allThreadMessages = [];
|
|
430
|
+
for (const tid of threadIds) {
|
|
431
|
+
const threadQuery = table.query().where(`thread_id = '${tid}'`);
|
|
432
|
+
let threadRecords = await threadQuery.toArray();
|
|
433
|
+
allThreadMessages.push(...threadRecords);
|
|
434
|
+
}
|
|
435
|
+
allThreadMessages.sort((a, b) => a.createdAt - b.createdAt);
|
|
436
|
+
const contextMessages = this.processMessagesWithContext(allThreadMessages, include);
|
|
437
|
+
const includedMessages = contextMessages.map((row) => this.normalizeMessage(row));
|
|
438
|
+
for (const includeMsg of includedMessages) {
|
|
439
|
+
if (!messageIds.has(includeMsg.id)) {
|
|
440
|
+
messages.push(includeMsg);
|
|
441
|
+
messageIds.add(includeMsg.id);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const list = new MessageList().add(messages, "memory");
|
|
446
|
+
let finalMessages = list.get.all.v2();
|
|
447
|
+
finalMessages = finalMessages.sort((a, b) => {
|
|
448
|
+
const aValue = sortField === "createdAt" ? new Date(a.createdAt).getTime() : a[sortField];
|
|
449
|
+
const bValue = sortField === "createdAt" ? new Date(b.createdAt).getTime() : b[sortField];
|
|
450
|
+
return sortDirection === "ASC" ? aValue - bValue : bValue - aValue;
|
|
451
|
+
});
|
|
452
|
+
const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
|
|
453
|
+
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
454
|
+
const hasMore = limit === false ? false : allThreadMessagesReturned ? false : offset + paginatedRecords.length < total;
|
|
455
|
+
return {
|
|
456
|
+
messages: finalMessages,
|
|
457
|
+
total,
|
|
458
|
+
page,
|
|
459
|
+
perPage,
|
|
460
|
+
hasMore
|
|
461
|
+
};
|
|
462
|
+
} catch (error) {
|
|
463
|
+
const errorPerPage = limit === false ? Number.MAX_SAFE_INTEGER : limit === 0 ? 0 : limit || 40;
|
|
464
|
+
const mastraError = new MastraError(
|
|
465
|
+
{
|
|
466
|
+
id: "LANCE_STORE_LIST_MESSAGES_FAILED",
|
|
467
|
+
domain: ErrorDomain.STORAGE,
|
|
468
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
469
|
+
details: {
|
|
470
|
+
threadId,
|
|
471
|
+
resourceId: resourceId ?? ""
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
error
|
|
475
|
+
);
|
|
476
|
+
this.logger?.error?.(mastraError.toString());
|
|
477
|
+
this.logger?.trackException?.(mastraError);
|
|
478
|
+
return {
|
|
479
|
+
messages: [],
|
|
480
|
+
total: 0,
|
|
481
|
+
page: errorPerPage === 0 ? 0 : Math.floor(offset / errorPerPage),
|
|
482
|
+
perPage: errorPerPage,
|
|
483
|
+
hasMore: false
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* @todo When migrating from getThreadsByResourceIdPaginated to this method,
|
|
489
|
+
* implement orderBy and sortDirection support for full sorting capabilities
|
|
490
|
+
*/
|
|
491
|
+
async listThreadsByResourceId(args) {
|
|
492
|
+
const { resourceId, limit, offset } = args;
|
|
493
|
+
const page = Math.floor(offset / limit);
|
|
494
|
+
const perPage = limit;
|
|
495
|
+
return this.getThreadsByResourceIdPaginated({ resourceId, page, perPage });
|
|
496
|
+
}
|
|
485
497
|
async saveMessages(args) {
|
|
486
498
|
try {
|
|
487
499
|
const { messages, format = "v1" } = args;
|
|
@@ -1632,198 +1644,6 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1632
1644
|
}
|
|
1633
1645
|
}
|
|
1634
1646
|
};
|
|
1635
|
-
var StoreTracesLance = class extends TracesStorage {
|
|
1636
|
-
client;
|
|
1637
|
-
operations;
|
|
1638
|
-
constructor({ client, operations }) {
|
|
1639
|
-
super();
|
|
1640
|
-
this.client = client;
|
|
1641
|
-
this.operations = operations;
|
|
1642
|
-
}
|
|
1643
|
-
async saveTrace({ trace }) {
|
|
1644
|
-
try {
|
|
1645
|
-
const table = await this.client.openTable(TABLE_TRACES);
|
|
1646
|
-
const record = {
|
|
1647
|
-
...trace,
|
|
1648
|
-
attributes: JSON.stringify(trace.attributes),
|
|
1649
|
-
status: JSON.stringify(trace.status),
|
|
1650
|
-
events: JSON.stringify(trace.events),
|
|
1651
|
-
links: JSON.stringify(trace.links),
|
|
1652
|
-
other: JSON.stringify(trace.other)
|
|
1653
|
-
};
|
|
1654
|
-
await table.add([record], { mode: "append" });
|
|
1655
|
-
return trace;
|
|
1656
|
-
} catch (error) {
|
|
1657
|
-
throw new MastraError(
|
|
1658
|
-
{
|
|
1659
|
-
id: "LANCE_STORE_SAVE_TRACE_FAILED",
|
|
1660
|
-
domain: ErrorDomain.STORAGE,
|
|
1661
|
-
category: ErrorCategory.THIRD_PARTY
|
|
1662
|
-
},
|
|
1663
|
-
error
|
|
1664
|
-
);
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
async getTraceById({ traceId }) {
|
|
1668
|
-
try {
|
|
1669
|
-
const table = await this.client.openTable(TABLE_TRACES);
|
|
1670
|
-
const query = table.query().where(`id = '${traceId}'`);
|
|
1671
|
-
const records = await query.toArray();
|
|
1672
|
-
return records[0];
|
|
1673
|
-
} catch (error) {
|
|
1674
|
-
throw new MastraError(
|
|
1675
|
-
{
|
|
1676
|
-
id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
|
|
1677
|
-
domain: ErrorDomain.STORAGE,
|
|
1678
|
-
category: ErrorCategory.THIRD_PARTY
|
|
1679
|
-
},
|
|
1680
|
-
error
|
|
1681
|
-
);
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
async getTraces({
|
|
1685
|
-
name,
|
|
1686
|
-
scope,
|
|
1687
|
-
page = 1,
|
|
1688
|
-
perPage = 10,
|
|
1689
|
-
attributes
|
|
1690
|
-
}) {
|
|
1691
|
-
try {
|
|
1692
|
-
const table = await this.client.openTable(TABLE_TRACES);
|
|
1693
|
-
const query = table.query();
|
|
1694
|
-
if (name) {
|
|
1695
|
-
query.where(`name = '${name}'`);
|
|
1696
|
-
}
|
|
1697
|
-
if (scope) {
|
|
1698
|
-
query.where(`scope = '${scope}'`);
|
|
1699
|
-
}
|
|
1700
|
-
if (attributes) {
|
|
1701
|
-
query.where(`attributes = '${JSON.stringify(attributes)}'`);
|
|
1702
|
-
}
|
|
1703
|
-
const offset = (page - 1) * perPage;
|
|
1704
|
-
query.limit(perPage);
|
|
1705
|
-
if (offset > 0) {
|
|
1706
|
-
query.offset(offset);
|
|
1707
|
-
}
|
|
1708
|
-
const records = await query.toArray();
|
|
1709
|
-
return records.map((record) => {
|
|
1710
|
-
const processed = {
|
|
1711
|
-
...record,
|
|
1712
|
-
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1713
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1714
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1715
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1716
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1717
|
-
startTime: new Date(record.startTime),
|
|
1718
|
-
endTime: new Date(record.endTime),
|
|
1719
|
-
createdAt: new Date(record.createdAt)
|
|
1720
|
-
};
|
|
1721
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1722
|
-
processed.parentSpanId = "";
|
|
1723
|
-
} else {
|
|
1724
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1725
|
-
}
|
|
1726
|
-
return processed;
|
|
1727
|
-
});
|
|
1728
|
-
} catch (error) {
|
|
1729
|
-
throw new MastraError(
|
|
1730
|
-
{
|
|
1731
|
-
id: "LANCE_STORE_GET_TRACES_FAILED",
|
|
1732
|
-
domain: ErrorDomain.STORAGE,
|
|
1733
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
1734
|
-
details: { name: name ?? "", scope: scope ?? "" }
|
|
1735
|
-
},
|
|
1736
|
-
error
|
|
1737
|
-
);
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
async getTracesPaginated(args) {
|
|
1741
|
-
try {
|
|
1742
|
-
const table = await this.client.openTable(TABLE_TRACES);
|
|
1743
|
-
const query = table.query();
|
|
1744
|
-
const conditions = [];
|
|
1745
|
-
if (args.name) {
|
|
1746
|
-
conditions.push(`name = '${args.name}'`);
|
|
1747
|
-
}
|
|
1748
|
-
if (args.scope) {
|
|
1749
|
-
conditions.push(`scope = '${args.scope}'`);
|
|
1750
|
-
}
|
|
1751
|
-
if (args.attributes) {
|
|
1752
|
-
const attributesStr = JSON.stringify(args.attributes);
|
|
1753
|
-
conditions.push(`attributes LIKE '%${attributesStr.replace(/"/g, '\\"')}%'`);
|
|
1754
|
-
}
|
|
1755
|
-
if (args.dateRange?.start) {
|
|
1756
|
-
conditions.push(`\`createdAt\` >= ${args.dateRange.start.getTime()}`);
|
|
1757
|
-
}
|
|
1758
|
-
if (args.dateRange?.end) {
|
|
1759
|
-
conditions.push(`\`createdAt\` <= ${args.dateRange.end.getTime()}`);
|
|
1760
|
-
}
|
|
1761
|
-
if (conditions.length > 0) {
|
|
1762
|
-
const whereClause = conditions.join(" AND ");
|
|
1763
|
-
query.where(whereClause);
|
|
1764
|
-
}
|
|
1765
|
-
let total = 0;
|
|
1766
|
-
if (conditions.length > 0) {
|
|
1767
|
-
const countQuery = table.query().where(conditions.join(" AND "));
|
|
1768
|
-
const allRecords = await countQuery.toArray();
|
|
1769
|
-
total = allRecords.length;
|
|
1770
|
-
} else {
|
|
1771
|
-
total = await table.countRows();
|
|
1772
|
-
}
|
|
1773
|
-
const page = args.page || 0;
|
|
1774
|
-
const perPage = args.perPage || 10;
|
|
1775
|
-
const offset = page * perPage;
|
|
1776
|
-
query.limit(perPage);
|
|
1777
|
-
if (offset > 0) {
|
|
1778
|
-
query.offset(offset);
|
|
1779
|
-
}
|
|
1780
|
-
const records = await query.toArray();
|
|
1781
|
-
const traces = records.map((record) => {
|
|
1782
|
-
const processed = {
|
|
1783
|
-
...record,
|
|
1784
|
-
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1785
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1786
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1787
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1788
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1789
|
-
startTime: new Date(record.startTime),
|
|
1790
|
-
endTime: new Date(record.endTime),
|
|
1791
|
-
createdAt: new Date(record.createdAt)
|
|
1792
|
-
};
|
|
1793
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1794
|
-
processed.parentSpanId = "";
|
|
1795
|
-
} else {
|
|
1796
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1797
|
-
}
|
|
1798
|
-
return processed;
|
|
1799
|
-
});
|
|
1800
|
-
return {
|
|
1801
|
-
traces,
|
|
1802
|
-
total,
|
|
1803
|
-
page,
|
|
1804
|
-
perPage,
|
|
1805
|
-
hasMore: total > (page + 1) * perPage
|
|
1806
|
-
};
|
|
1807
|
-
} catch (error) {
|
|
1808
|
-
throw new MastraError(
|
|
1809
|
-
{
|
|
1810
|
-
id: "LANCE_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
1811
|
-
domain: ErrorDomain.STORAGE,
|
|
1812
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
1813
|
-
details: { name: args.name ?? "", scope: args.scope ?? "" }
|
|
1814
|
-
},
|
|
1815
|
-
error
|
|
1816
|
-
);
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
async batchTraceInsert({ records }) {
|
|
1820
|
-
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
1821
|
-
await this.operations.batchInsert({
|
|
1822
|
-
tableName: TABLE_TRACES,
|
|
1823
|
-
records
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
|
-
};
|
|
1827
1647
|
function parseWorkflowRun(row) {
|
|
1828
1648
|
let parsedSnapshot = row.snapshot;
|
|
1829
1649
|
if (typeof parsedSnapshot === "string") {
|
|
@@ -1853,7 +1673,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1853
1673
|
// runId,
|
|
1854
1674
|
// stepId,
|
|
1855
1675
|
// result,
|
|
1856
|
-
//
|
|
1676
|
+
// requestContext,
|
|
1857
1677
|
}) {
|
|
1858
1678
|
throw new Error("Method not implemented.");
|
|
1859
1679
|
}
|
|
@@ -1947,7 +1767,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1947
1767
|
);
|
|
1948
1768
|
}
|
|
1949
1769
|
}
|
|
1950
|
-
async
|
|
1770
|
+
async listWorkflowRuns(args) {
|
|
1951
1771
|
try {
|
|
1952
1772
|
const table = await this.client.openTable(TABLE_WORKFLOW_SNAPSHOT);
|
|
1953
1773
|
let query = table.query();
|
|
@@ -1988,7 +1808,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1988
1808
|
id: "LANCE_STORE_GET_WORKFLOW_RUNS_FAILED",
|
|
1989
1809
|
domain: ErrorDomain.STORAGE,
|
|
1990
1810
|
category: ErrorCategory.THIRD_PARTY,
|
|
1991
|
-
details: {
|
|
1811
|
+
details: { resourceId: args?.resourceId ?? "", workflowName: args?.workflowName ?? "" }
|
|
1992
1812
|
},
|
|
1993
1813
|
error
|
|
1994
1814
|
);
|
|
@@ -2030,10 +1850,8 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2030
1850
|
instance.stores = {
|
|
2031
1851
|
operations: new StoreOperationsLance({ client: instance.lanceClient }),
|
|
2032
1852
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
2033
|
-
traces: new StoreTracesLance({ client: instance.lanceClient, operations }),
|
|
2034
1853
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
2035
|
-
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
2036
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
|
|
1854
|
+
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
2037
1855
|
};
|
|
2038
1856
|
return instance;
|
|
2039
1857
|
} catch (e) {
|
|
@@ -2059,9 +1877,7 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2059
1877
|
this.stores = {
|
|
2060
1878
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
2061
1879
|
workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
|
|
2062
|
-
traces: new StoreTracesLance({ client: this.lanceClient, operations }),
|
|
2063
1880
|
scores: new StoreScoresLance({ client: this.lanceClient }),
|
|
2064
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
|
|
2065
1881
|
memory: new StoreMemoryLance({ client: this.lanceClient, operations })
|
|
2066
1882
|
};
|
|
2067
1883
|
}
|
|
@@ -2197,12 +2013,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2197
2013
|
}) {
|
|
2198
2014
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2199
2015
|
}
|
|
2200
|
-
async getMessagesById({
|
|
2201
|
-
messageIds,
|
|
2202
|
-
format
|
|
2203
|
-
}) {
|
|
2204
|
-
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2205
|
-
}
|
|
2206
2016
|
async saveMessages(args) {
|
|
2207
2017
|
return this.stores.memory.saveMessages(args);
|
|
2208
2018
|
}
|
|
@@ -2215,23 +2025,8 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2215
2025
|
async updateMessages(_args) {
|
|
2216
2026
|
return this.stores.memory.updateMessages(_args);
|
|
2217
2027
|
}
|
|
2218
|
-
async
|
|
2219
|
-
return this.stores.
|
|
2220
|
-
}
|
|
2221
|
-
async getTraces(args) {
|
|
2222
|
-
return this.stores.traces.getTraces(args);
|
|
2223
|
-
}
|
|
2224
|
-
async getTracesPaginated(args) {
|
|
2225
|
-
return this.stores.traces.getTracesPaginated(args);
|
|
2226
|
-
}
|
|
2227
|
-
async getEvalsByAgentName(agentName, type) {
|
|
2228
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
2229
|
-
}
|
|
2230
|
-
async getEvals(options) {
|
|
2231
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
2232
|
-
}
|
|
2233
|
-
async getWorkflowRuns(args) {
|
|
2234
|
-
return this.stores.workflows.getWorkflowRuns(args);
|
|
2028
|
+
async listWorkflowRuns(args) {
|
|
2029
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
2235
2030
|
}
|
|
2236
2031
|
async getWorkflowRunById(args) {
|
|
2237
2032
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
@@ -2241,9 +2036,9 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2241
2036
|
runId,
|
|
2242
2037
|
stepId,
|
|
2243
2038
|
result,
|
|
2244
|
-
|
|
2039
|
+
requestContext
|
|
2245
2040
|
}) {
|
|
2246
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
2041
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
2247
2042
|
}
|
|
2248
2043
|
async updateWorkflowState({
|
|
2249
2044
|
workflowName,
|