@mastra/lance 0.0.0-fix-memory-search-fetch-20251027160505 → 0.0.0-fix-persist-session-cache-option-mcp-server-20251030161352
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 +11 -3
- package/dist/index.cjs +25 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -129
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +10 -1
- 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 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +3 -18
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
- 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/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("test_info IS NULL");
|
|
64
|
-
} else if (options.type === "test") {
|
|
65
|
-
conditions.push("test_info IS NOT NULL");
|
|
66
|
-
}
|
|
67
|
-
const startDate = options.dateRange?.start || options.fromDate;
|
|
68
|
-
const endDate = options.dateRange?.end || options.toDate;
|
|
69
|
-
if (startDate) {
|
|
70
|
-
conditions.push(`\`created_at\` >= ${startDate.getTime()}`);
|
|
71
|
-
}
|
|
72
|
-
if (endDate) {
|
|
73
|
-
conditions.push(`\`created_at\` <= ${endDate.getTime()}`);
|
|
74
|
-
}
|
|
75
|
-
let total = 0;
|
|
76
|
-
if (conditions.length > 0) {
|
|
77
|
-
total = await table.countRows(conditions.join(" AND "));
|
|
78
|
-
} else {
|
|
79
|
-
total = await table.countRows();
|
|
80
|
-
}
|
|
81
|
-
const query = table.query();
|
|
82
|
-
if (conditions.length > 0) {
|
|
83
|
-
const whereClause = conditions.join(" AND ");
|
|
84
|
-
query.where(whereClause);
|
|
85
|
-
}
|
|
86
|
-
const records = await query.toArray();
|
|
87
|
-
const evals = records.sort((a, b) => b.created_at - a.created_at).map((record) => {
|
|
88
|
-
return {
|
|
89
|
-
id: record.id,
|
|
90
|
-
input: record.input,
|
|
91
|
-
output: record.output,
|
|
92
|
-
agentName: record.agent_name,
|
|
93
|
-
metricName: record.metric_name,
|
|
94
|
-
result: JSON.parse(record.result),
|
|
95
|
-
instructions: record.instructions,
|
|
96
|
-
testInfo: record.test_info ? JSON.parse(record.test_info) : null,
|
|
97
|
-
globalRunId: record.global_run_id,
|
|
98
|
-
runId: record.run_id,
|
|
99
|
-
createdAt: new Date(record.created_at).toISOString()
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
const page = options.page || 0;
|
|
103
|
-
const perPage = options.perPage || 10;
|
|
104
|
-
const pagedEvals = evals.slice(page * perPage, (page + 1) * perPage);
|
|
105
|
-
return {
|
|
106
|
-
evals: pagedEvals,
|
|
107
|
-
total,
|
|
108
|
-
page,
|
|
109
|
-
perPage,
|
|
110
|
-
hasMore: total > (page + 1) * perPage
|
|
111
|
-
};
|
|
112
|
-
} catch (error) {
|
|
113
|
-
throw new MastraError(
|
|
114
|
-
{
|
|
115
|
-
id: "LANCE_STORE_GET_EVALS_FAILED",
|
|
116
|
-
domain: ErrorDomain.STORAGE,
|
|
117
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
118
|
-
details: { agentName: options.agentName ?? "" }
|
|
119
|
-
},
|
|
120
|
-
error
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
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
|
}
|
|
@@ -482,6 +366,24 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
482
366
|
);
|
|
483
367
|
}
|
|
484
368
|
}
|
|
369
|
+
async listMessages(_args) {
|
|
370
|
+
throw new Error(
|
|
371
|
+
`listMessages is not yet implemented by this storage adapter (${this.constructor.name}). This method is currently being rolled out across all storage adapters. Please use getMessages or getMessagesPaginated as an alternative, or wait for the implementation.`
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
async listMessagesById({ messageIds }) {
|
|
375
|
+
return this.getMessagesById({ messageIds, format: "v2" });
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* @todo When migrating from getThreadsByResourceIdPaginated to this method,
|
|
379
|
+
* implement orderBy and sortDirection support for full sorting capabilities
|
|
380
|
+
*/
|
|
381
|
+
async listThreadsByResourceId(args) {
|
|
382
|
+
const { resourceId, limit, offset } = args;
|
|
383
|
+
const page = Math.floor(offset / limit);
|
|
384
|
+
const perPage = limit;
|
|
385
|
+
return this.getThreadsByResourceIdPaginated({ resourceId, page, perPage });
|
|
386
|
+
}
|
|
485
387
|
async saveMessages(args) {
|
|
486
388
|
try {
|
|
487
389
|
const { messages, format = "v1" } = args;
|
|
@@ -1661,7 +1563,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1661
1563
|
// runId,
|
|
1662
1564
|
// stepId,
|
|
1663
1565
|
// result,
|
|
1664
|
-
//
|
|
1566
|
+
// requestContext,
|
|
1665
1567
|
}) {
|
|
1666
1568
|
throw new Error("Method not implemented.");
|
|
1667
1569
|
}
|
|
@@ -1802,6 +1704,9 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1802
1704
|
);
|
|
1803
1705
|
}
|
|
1804
1706
|
}
|
|
1707
|
+
async listWorkflowRuns(args) {
|
|
1708
|
+
return this.getWorkflowRuns(args);
|
|
1709
|
+
}
|
|
1805
1710
|
};
|
|
1806
1711
|
|
|
1807
1712
|
// src/storage/index.ts
|
|
@@ -1839,8 +1744,7 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
1839
1744
|
operations: new StoreOperationsLance({ client: instance.lanceClient }),
|
|
1840
1745
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
1841
1746
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
1842
|
-
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
1843
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
|
|
1747
|
+
memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
|
|
1844
1748
|
};
|
|
1845
1749
|
return instance;
|
|
1846
1750
|
} catch (e) {
|
|
@@ -1867,7 +1771,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
1867
1771
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
1868
1772
|
workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
|
|
1869
1773
|
scores: new StoreScoresLance({ client: this.lanceClient }),
|
|
1870
|
-
legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
|
|
1871
1774
|
memory: new StoreMemoryLance({ client: this.lanceClient, operations })
|
|
1872
1775
|
};
|
|
1873
1776
|
}
|
|
@@ -2021,12 +1924,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2021
1924
|
async updateMessages(_args) {
|
|
2022
1925
|
return this.stores.memory.updateMessages(_args);
|
|
2023
1926
|
}
|
|
2024
|
-
async getEvalsByAgentName(agentName, type) {
|
|
2025
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
2026
|
-
}
|
|
2027
|
-
async getEvals(options) {
|
|
2028
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
2029
|
-
}
|
|
2030
1927
|
async getWorkflowRuns(args) {
|
|
2031
1928
|
return this.stores.workflows.getWorkflowRuns(args);
|
|
2032
1929
|
}
|
|
@@ -2038,9 +1935,9 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2038
1935
|
runId,
|
|
2039
1936
|
stepId,
|
|
2040
1937
|
result,
|
|
2041
|
-
|
|
1938
|
+
requestContext
|
|
2042
1939
|
}) {
|
|
2043
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
1940
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
2044
1941
|
}
|
|
2045
1942
|
async updateWorkflowState({
|
|
2046
1943
|
workflowName,
|