@mastra/lance 0.0.0-fix-writer-workflow-resumestream-20251022161252 → 0.0.0-fix-memory-search-fetch-20251027160505
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 +16 -3
- package/dist/index.cjs +2 -205
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -206
- package/dist/index.js.map +1 -1
- package/dist/storage/index.d.ts +2 -16
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +7 -7
- 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, LegacyEvalsStorage, TABLE_EVALS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, resolveMessageLimit, TABLE_RESOURCES, ScoresStorage, TABLE_SCORERS,
|
|
3
|
+
import { MastraStorage, StoreOperations, LegacyEvalsStorage, TABLE_EVALS, 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';
|
|
@@ -60,9 +60,9 @@ var StoreLegacyEvalsLance = class extends LegacyEvalsStorage {
|
|
|
60
60
|
conditions.push(`agent_name = '${options.agentName}'`);
|
|
61
61
|
}
|
|
62
62
|
if (options.type === "live") {
|
|
63
|
-
conditions.push("
|
|
63
|
+
conditions.push("test_info IS NULL");
|
|
64
64
|
} else if (options.type === "test") {
|
|
65
|
-
conditions.push("
|
|
65
|
+
conditions.push("test_info IS NOT NULL");
|
|
66
66
|
}
|
|
67
67
|
const startDate = options.dateRange?.start || options.fromDate;
|
|
68
68
|
const endDate = options.dateRange?.end || options.toDate;
|
|
@@ -1632,198 +1632,6 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1632
1632
|
}
|
|
1633
1633
|
}
|
|
1634
1634
|
};
|
|
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
1635
|
function parseWorkflowRun(row) {
|
|
1828
1636
|
let parsedSnapshot = row.snapshot;
|
|
1829
1637
|
if (typeof parsedSnapshot === "string") {
|
|
@@ -2030,7 +1838,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2030
1838
|
instance.stores = {
|
|
2031
1839
|
operations: new StoreOperationsLance({ client: instance.lanceClient }),
|
|
2032
1840
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
2033
|
-
traces: new StoreTracesLance({ client: instance.lanceClient, operations }),
|
|
2034
1841
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
2035
1842
|
memory: new StoreMemoryLance({ client: instance.lanceClient, operations }),
|
|
2036
1843
|
legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
|
|
@@ -2059,7 +1866,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2059
1866
|
this.stores = {
|
|
2060
1867
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
2061
1868
|
workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
|
|
2062
|
-
traces: new StoreTracesLance({ client: this.lanceClient, operations }),
|
|
2063
1869
|
scores: new StoreScoresLance({ client: this.lanceClient }),
|
|
2064
1870
|
legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
|
|
2065
1871
|
memory: new StoreMemoryLance({ client: this.lanceClient, operations })
|
|
@@ -2215,15 +2021,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2215
2021
|
async updateMessages(_args) {
|
|
2216
2022
|
return this.stores.memory.updateMessages(_args);
|
|
2217
2023
|
}
|
|
2218
|
-
async getTraceById(args) {
|
|
2219
|
-
return this.stores.traces.getTraceById(args);
|
|
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
2024
|
async getEvalsByAgentName(agentName, type) {
|
|
2228
2025
|
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
2229
2026
|
}
|