@mastra/lance 0.2.9 → 0.2.11-alpha.0
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 +18 -0
- package/package.json +19 -6
- package/.turbo/turbo-build.log +0 -4
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -2
- package/src/storage/domains/legacy-evals/index.ts +0 -156
- package/src/storage/domains/memory/index.ts +0 -1000
- package/src/storage/domains/operations/index.ts +0 -489
- package/src/storage/domains/scores/index.ts +0 -243
- package/src/storage/domains/traces/index.ts +0 -212
- package/src/storage/domains/utils.ts +0 -158
- package/src/storage/domains/workflows/index.ts +0 -245
- package/src/storage/index.test.ts +0 -10
- package/src/storage/index.ts +0 -494
- package/src/vector/filter.test.ts +0 -295
- package/src/vector/filter.ts +0 -443
- package/src/vector/index.test.ts +0 -1493
- package/src/vector/index.ts +0 -941
- package/src/vector/types.ts +0 -16
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -17
- package/vitest.config.ts +0 -11
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import type { Connection } from '@lancedb/lancedb';
|
|
2
|
-
import type { StepResult, WorkflowRunState, WorkflowRuns } from '@mastra/core';
|
|
3
|
-
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
4
|
-
import type { WorkflowRun } from '@mastra/core/storage';
|
|
5
|
-
import { ensureDate, TABLE_WORKFLOW_SNAPSHOT, WorkflowsStorage } from '@mastra/core/storage';
|
|
6
|
-
|
|
7
|
-
function parseWorkflowRun(row: any): WorkflowRun {
|
|
8
|
-
let parsedSnapshot: WorkflowRunState | string = row.snapshot;
|
|
9
|
-
if (typeof parsedSnapshot === 'string') {
|
|
10
|
-
try {
|
|
11
|
-
parsedSnapshot = JSON.parse(row.snapshot as string) as WorkflowRunState;
|
|
12
|
-
} catch (e) {
|
|
13
|
-
// If parsing fails, return the raw snapshot string
|
|
14
|
-
console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
workflowName: row.workflow_name,
|
|
20
|
-
runId: row.run_id,
|
|
21
|
-
snapshot: parsedSnapshot,
|
|
22
|
-
createdAt: ensureDate(row.createdAt)!,
|
|
23
|
-
updatedAt: ensureDate(row.updatedAt)!,
|
|
24
|
-
resourceId: row.resourceId,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class StoreWorkflowsLance extends WorkflowsStorage {
|
|
29
|
-
client: Connection;
|
|
30
|
-
constructor({ client }: { client: Connection }) {
|
|
31
|
-
super();
|
|
32
|
-
this.client = client;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
updateWorkflowResults(
|
|
36
|
-
{
|
|
37
|
-
// workflowName,
|
|
38
|
-
// runId,
|
|
39
|
-
// stepId,
|
|
40
|
-
// result,
|
|
41
|
-
// runtimeContext,
|
|
42
|
-
}: {
|
|
43
|
-
workflowName: string;
|
|
44
|
-
runId: string;
|
|
45
|
-
stepId: string;
|
|
46
|
-
result: StepResult<any, any, any, any>;
|
|
47
|
-
runtimeContext: Record<string, any>;
|
|
48
|
-
},
|
|
49
|
-
): Promise<Record<string, StepResult<any, any, any, any>>> {
|
|
50
|
-
throw new Error('Method not implemented.');
|
|
51
|
-
}
|
|
52
|
-
updateWorkflowState(
|
|
53
|
-
{
|
|
54
|
-
// workflowName,
|
|
55
|
-
// runId,
|
|
56
|
-
// opts,
|
|
57
|
-
}: {
|
|
58
|
-
workflowName: string;
|
|
59
|
-
runId: string;
|
|
60
|
-
opts: {
|
|
61
|
-
status: string;
|
|
62
|
-
result?: StepResult<any, any, any, any>;
|
|
63
|
-
error?: string;
|
|
64
|
-
suspendedPaths?: Record<string, number[]>;
|
|
65
|
-
waitingPaths?: Record<string, number[]>;
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
): Promise<WorkflowRunState | undefined> {
|
|
69
|
-
throw new Error('Method not implemented.');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async persistWorkflowSnapshot({
|
|
73
|
-
workflowName,
|
|
74
|
-
runId,
|
|
75
|
-
snapshot,
|
|
76
|
-
}: {
|
|
77
|
-
workflowName: string;
|
|
78
|
-
runId: string;
|
|
79
|
-
snapshot: WorkflowRunState;
|
|
80
|
-
}): Promise<void> {
|
|
81
|
-
try {
|
|
82
|
-
const table = await this.client.openTable(TABLE_WORKFLOW_SNAPSHOT);
|
|
83
|
-
|
|
84
|
-
// Try to find the existing record
|
|
85
|
-
const query = table.query().where(`workflow_name = '${workflowName}' AND run_id = '${runId}'`);
|
|
86
|
-
const records = await query.toArray();
|
|
87
|
-
let createdAt: number;
|
|
88
|
-
const now = Date.now();
|
|
89
|
-
|
|
90
|
-
if (records.length > 0) {
|
|
91
|
-
createdAt = records[0].createdAt ?? now;
|
|
92
|
-
} else {
|
|
93
|
-
createdAt = now;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const record = {
|
|
97
|
-
workflow_name: workflowName,
|
|
98
|
-
run_id: runId,
|
|
99
|
-
snapshot: JSON.stringify(snapshot),
|
|
100
|
-
createdAt,
|
|
101
|
-
updatedAt: now,
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
await table
|
|
105
|
-
.mergeInsert(['workflow_name', 'run_id'])
|
|
106
|
-
.whenMatchedUpdateAll()
|
|
107
|
-
.whenNotMatchedInsertAll()
|
|
108
|
-
.execute([record]);
|
|
109
|
-
} catch (error: any) {
|
|
110
|
-
throw new MastraError(
|
|
111
|
-
{
|
|
112
|
-
id: 'LANCE_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED',
|
|
113
|
-
domain: ErrorDomain.STORAGE,
|
|
114
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
115
|
-
details: { workflowName, runId },
|
|
116
|
-
},
|
|
117
|
-
error,
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async loadWorkflowSnapshot({
|
|
122
|
-
workflowName,
|
|
123
|
-
runId,
|
|
124
|
-
}: {
|
|
125
|
-
workflowName: string;
|
|
126
|
-
runId: string;
|
|
127
|
-
}): Promise<WorkflowRunState | null> {
|
|
128
|
-
try {
|
|
129
|
-
const table = await this.client.openTable(TABLE_WORKFLOW_SNAPSHOT);
|
|
130
|
-
const query = table.query().where(`workflow_name = '${workflowName}' AND run_id = '${runId}'`);
|
|
131
|
-
const records = await query.toArray();
|
|
132
|
-
return records.length > 0 ? JSON.parse(records[0].snapshot) : null;
|
|
133
|
-
} catch (error: any) {
|
|
134
|
-
throw new MastraError(
|
|
135
|
-
{
|
|
136
|
-
id: 'LANCE_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED',
|
|
137
|
-
domain: ErrorDomain.STORAGE,
|
|
138
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
139
|
-
details: { workflowName, runId },
|
|
140
|
-
},
|
|
141
|
-
error,
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async getWorkflowRunById(args: { runId: string; workflowName?: string }): Promise<{
|
|
147
|
-
workflowName: string;
|
|
148
|
-
runId: string;
|
|
149
|
-
snapshot: any;
|
|
150
|
-
createdAt: Date;
|
|
151
|
-
updatedAt: Date;
|
|
152
|
-
} | null> {
|
|
153
|
-
try {
|
|
154
|
-
const table = await this.client.openTable(TABLE_WORKFLOW_SNAPSHOT);
|
|
155
|
-
let whereClause = `run_id = '${args.runId}'`;
|
|
156
|
-
if (args.workflowName) {
|
|
157
|
-
whereClause += ` AND workflow_name = '${args.workflowName}'`;
|
|
158
|
-
}
|
|
159
|
-
const query = table.query().where(whereClause);
|
|
160
|
-
const records = await query.toArray();
|
|
161
|
-
if (records.length === 0) return null;
|
|
162
|
-
const record = records[0];
|
|
163
|
-
return parseWorkflowRun(record);
|
|
164
|
-
} catch (error: any) {
|
|
165
|
-
throw new MastraError(
|
|
166
|
-
{
|
|
167
|
-
id: 'LANCE_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED',
|
|
168
|
-
domain: ErrorDomain.STORAGE,
|
|
169
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
170
|
-
details: { runId: args.runId, workflowName: args.workflowName ?? '' },
|
|
171
|
-
},
|
|
172
|
-
error,
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async getWorkflowRuns(args?: {
|
|
178
|
-
namespace?: string;
|
|
179
|
-
resourceId?: string;
|
|
180
|
-
workflowName?: string;
|
|
181
|
-
fromDate?: Date;
|
|
182
|
-
toDate?: Date;
|
|
183
|
-
limit?: number;
|
|
184
|
-
offset?: number;
|
|
185
|
-
}): Promise<WorkflowRuns> {
|
|
186
|
-
try {
|
|
187
|
-
const table = await this.client.openTable(TABLE_WORKFLOW_SNAPSHOT);
|
|
188
|
-
|
|
189
|
-
let query = table.query();
|
|
190
|
-
|
|
191
|
-
const conditions: string[] = [];
|
|
192
|
-
|
|
193
|
-
if (args?.workflowName) {
|
|
194
|
-
conditions.push(`workflow_name = '${args.workflowName.replace(/'/g, "''")}'`);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (args?.resourceId) {
|
|
198
|
-
conditions.push(`\`resourceId\` = '${args.resourceId}'`);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (args?.fromDate instanceof Date) {
|
|
202
|
-
conditions.push(`\`createdAt\` >= ${args.fromDate.getTime()}`);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (args?.toDate instanceof Date) {
|
|
206
|
-
conditions.push(`\`createdAt\` <= ${args.toDate.getTime()}`);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
let total = 0;
|
|
210
|
-
|
|
211
|
-
// Apply all conditions
|
|
212
|
-
if (conditions.length > 0) {
|
|
213
|
-
query = query.where(conditions.join(' AND '));
|
|
214
|
-
total = await table.countRows(conditions.join(' AND '));
|
|
215
|
-
} else {
|
|
216
|
-
total = await table.countRows();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (args?.limit) {
|
|
220
|
-
query.limit(args.limit);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (args?.offset) {
|
|
224
|
-
query.offset(args.offset);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const records = await query.toArray();
|
|
228
|
-
|
|
229
|
-
return {
|
|
230
|
-
runs: records.map(record => parseWorkflowRun(record)),
|
|
231
|
-
total: total || records.length,
|
|
232
|
-
};
|
|
233
|
-
} catch (error: any) {
|
|
234
|
-
throw new MastraError(
|
|
235
|
-
{
|
|
236
|
-
id: 'LANCE_STORE_GET_WORKFLOW_RUNS_FAILED',
|
|
237
|
-
domain: ErrorDomain.STORAGE,
|
|
238
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
239
|
-
details: { namespace: args?.namespace ?? '', workflowName: args?.workflowName ?? '' },
|
|
240
|
-
},
|
|
241
|
-
error,
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createTestSuite } from '@internal/storage-test-utils';
|
|
2
|
-
import { vi } from 'vitest';
|
|
3
|
-
import { LanceStorage } from './index';
|
|
4
|
-
|
|
5
|
-
// Increase timeout for all tests in this file to 30 seconds
|
|
6
|
-
vi.setConfig({ testTimeout: 200_000, hookTimeout: 200_000 });
|
|
7
|
-
|
|
8
|
-
const storage = await LanceStorage.create('test', 'lancedb-storage');
|
|
9
|
-
|
|
10
|
-
createTestSuite(storage);
|