@mastra/lance 0.1.3-alpha.0 → 0.1.3-alpha.1
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +14 -0
- package/dist/index.cjs +786 -153
- package/dist/index.js +753 -120
- package/package.json +3 -3
- package/src/storage/index.test.ts +1 -1
- package/src/storage/index.ts +461 -61
- package/src/vector/index.test.ts +3 -3
- package/src/vector/index.ts +316 -75
package/src/storage/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { connect } from '@lancedb/lancedb';
|
|
|
2
2
|
import type { Connection, ConnectionOptions, SchemaLike, FieldLike } from '@lancedb/lancedb';
|
|
3
3
|
import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
4
4
|
import { MessageList } from '@mastra/core/agent';
|
|
5
|
+
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
5
6
|
import type { MastraMessageV1, MastraMessageV2, StorageThreadType, TraceType } from '@mastra/core/memory';
|
|
6
7
|
import {
|
|
7
8
|
MastraStorage,
|
|
@@ -57,7 +58,16 @@ export class LanceStorage extends MastraStorage {
|
|
|
57
58
|
instance.lanceClient = await connect(uri, options);
|
|
58
59
|
return instance;
|
|
59
60
|
} catch (e: any) {
|
|
60
|
-
throw new
|
|
61
|
+
throw new MastraError(
|
|
62
|
+
{
|
|
63
|
+
id: 'STORAGE_LANCE_STORAGE_CONNECT_FAILED',
|
|
64
|
+
domain: ErrorDomain.STORAGE,
|
|
65
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
66
|
+
text: `Failed to connect to LanceDB: ${e.message || e}`,
|
|
67
|
+
details: { uri, optionsProvided: !!options },
|
|
68
|
+
},
|
|
69
|
+
e,
|
|
70
|
+
);
|
|
61
71
|
}
|
|
62
72
|
}
|
|
63
73
|
|
|
@@ -76,11 +86,41 @@ export class LanceStorage extends MastraStorage {
|
|
|
76
86
|
tableName: TABLE_NAMES;
|
|
77
87
|
schema: Record<string, StorageColumn>;
|
|
78
88
|
}): Promise<void> {
|
|
89
|
+
try {
|
|
90
|
+
if (!this.lanceClient) {
|
|
91
|
+
throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
|
|
92
|
+
}
|
|
93
|
+
if (!tableName) {
|
|
94
|
+
throw new Error('tableName is required for createTable.');
|
|
95
|
+
}
|
|
96
|
+
if (!schema) {
|
|
97
|
+
throw new Error('schema is required for createTable.');
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new MastraError(
|
|
101
|
+
{
|
|
102
|
+
id: 'STORAGE_LANCE_STORAGE_CREATE_TABLE_INVALID_ARGS',
|
|
103
|
+
domain: ErrorDomain.STORAGE,
|
|
104
|
+
category: ErrorCategory.USER,
|
|
105
|
+
details: { tableName },
|
|
106
|
+
},
|
|
107
|
+
error,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
79
111
|
try {
|
|
80
112
|
const arrowSchema = this.translateSchema(schema);
|
|
81
113
|
await this.lanceClient.createEmptyTable(tableName, arrowSchema);
|
|
82
114
|
} catch (error: any) {
|
|
83
|
-
throw new
|
|
115
|
+
throw new MastraError(
|
|
116
|
+
{
|
|
117
|
+
id: 'STORAGE_LANCE_STORAGE_CREATE_TABLE_FAILED',
|
|
118
|
+
domain: ErrorDomain.STORAGE,
|
|
119
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
120
|
+
details: { tableName },
|
|
121
|
+
},
|
|
122
|
+
error,
|
|
123
|
+
);
|
|
84
124
|
}
|
|
85
125
|
}
|
|
86
126
|
|
|
@@ -130,15 +170,42 @@ export class LanceStorage extends MastraStorage {
|
|
|
130
170
|
* @param tableName Name of the table to drop
|
|
131
171
|
*/
|
|
132
172
|
async dropTable(tableName: TABLE_NAMES): Promise<void> {
|
|
173
|
+
try {
|
|
174
|
+
if (!this.lanceClient) {
|
|
175
|
+
throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
|
|
176
|
+
}
|
|
177
|
+
if (!tableName) {
|
|
178
|
+
throw new Error('tableName is required for dropTable.');
|
|
179
|
+
}
|
|
180
|
+
} catch (validationError: any) {
|
|
181
|
+
throw new MastraError(
|
|
182
|
+
{
|
|
183
|
+
id: 'STORAGE_LANCE_STORAGE_DROP_TABLE_INVALID_ARGS',
|
|
184
|
+
domain: ErrorDomain.STORAGE,
|
|
185
|
+
category: ErrorCategory.USER,
|
|
186
|
+
text: validationError.message,
|
|
187
|
+
details: { tableName },
|
|
188
|
+
},
|
|
189
|
+
validationError,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
133
193
|
try {
|
|
134
194
|
await this.lanceClient.dropTable(tableName);
|
|
135
195
|
} catch (error: any) {
|
|
136
|
-
|
|
137
|
-
if (error.toString().includes('was not found')) {
|
|
196
|
+
if (error.toString().includes('was not found') || error.message?.includes('Table not found')) {
|
|
138
197
|
this.logger.debug(`Table '${tableName}' does not exist, skipping drop`);
|
|
139
198
|
return;
|
|
140
199
|
}
|
|
141
|
-
throw new
|
|
200
|
+
throw new MastraError(
|
|
201
|
+
{
|
|
202
|
+
id: 'STORAGE_LANCE_STORAGE_DROP_TABLE_FAILED',
|
|
203
|
+
domain: ErrorDomain.STORAGE,
|
|
204
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
205
|
+
details: { tableName },
|
|
206
|
+
},
|
|
207
|
+
error,
|
|
208
|
+
);
|
|
142
209
|
}
|
|
143
210
|
}
|
|
144
211
|
|
|
@@ -148,6 +215,26 @@ export class LanceStorage extends MastraStorage {
|
|
|
148
215
|
* @returns Table schema
|
|
149
216
|
*/
|
|
150
217
|
async getTableSchema(tableName: TABLE_NAMES): Promise<SchemaLike> {
|
|
218
|
+
try {
|
|
219
|
+
if (!this.lanceClient) {
|
|
220
|
+
throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
|
|
221
|
+
}
|
|
222
|
+
if (!tableName) {
|
|
223
|
+
throw new Error('tableName is required for getTableSchema.');
|
|
224
|
+
}
|
|
225
|
+
} catch (validationError: any) {
|
|
226
|
+
throw new MastraError(
|
|
227
|
+
{
|
|
228
|
+
id: 'STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_INVALID_ARGS',
|
|
229
|
+
domain: ErrorDomain.STORAGE,
|
|
230
|
+
category: ErrorCategory.USER,
|
|
231
|
+
text: validationError.message,
|
|
232
|
+
details: { tableName },
|
|
233
|
+
},
|
|
234
|
+
validationError,
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
151
238
|
try {
|
|
152
239
|
const table = await this.lanceClient.openTable(tableName);
|
|
153
240
|
const rawSchema = await table.schema();
|
|
@@ -162,7 +249,15 @@ export class LanceStorage extends MastraStorage {
|
|
|
162
249
|
},
|
|
163
250
|
};
|
|
164
251
|
} catch (error: any) {
|
|
165
|
-
throw new
|
|
252
|
+
throw new MastraError(
|
|
253
|
+
{
|
|
254
|
+
id: 'STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_FAILED',
|
|
255
|
+
domain: ErrorDomain.STORAGE,
|
|
256
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
257
|
+
details: { tableName },
|
|
258
|
+
},
|
|
259
|
+
error,
|
|
260
|
+
);
|
|
166
261
|
}
|
|
167
262
|
}
|
|
168
263
|
|
|
@@ -199,43 +294,114 @@ export class LanceStorage extends MastraStorage {
|
|
|
199
294
|
schema: Record<string, StorageColumn>;
|
|
200
295
|
ifNotExists: string[];
|
|
201
296
|
}): Promise<void> {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
297
|
+
try {
|
|
298
|
+
if (!this.lanceClient) {
|
|
299
|
+
throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
|
|
300
|
+
}
|
|
301
|
+
if (!tableName) {
|
|
302
|
+
throw new Error('tableName is required for alterTable.');
|
|
303
|
+
}
|
|
304
|
+
if (!schema) {
|
|
305
|
+
throw new Error('schema is required for alterTable.');
|
|
306
|
+
}
|
|
307
|
+
if (!ifNotExists || ifNotExists.length === 0) {
|
|
308
|
+
this.logger.debug('No columns specified to add in alterTable, skipping.');
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
} catch (validationError: any) {
|
|
312
|
+
throw new MastraError(
|
|
313
|
+
{
|
|
314
|
+
id: 'STORAGE_LANCE_STORAGE_ALTER_TABLE_INVALID_ARGS',
|
|
315
|
+
domain: ErrorDomain.STORAGE,
|
|
316
|
+
category: ErrorCategory.USER,
|
|
317
|
+
text: validationError.message,
|
|
318
|
+
details: { tableName },
|
|
319
|
+
},
|
|
320
|
+
validationError,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
214
323
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
.map(
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
324
|
+
try {
|
|
325
|
+
const table = await this.lanceClient.openTable(tableName);
|
|
326
|
+
const currentSchema = await table.schema();
|
|
327
|
+
const existingFields = new Set(currentSchema.fields.map((f: any) => f.name));
|
|
328
|
+
|
|
329
|
+
const typeMap: Record<string, string> = {
|
|
330
|
+
text: 'string',
|
|
331
|
+
integer: 'int',
|
|
332
|
+
bigint: 'bigint',
|
|
333
|
+
timestamp: 'timestamp',
|
|
334
|
+
jsonb: 'string',
|
|
335
|
+
uuid: 'string',
|
|
336
|
+
};
|
|
227
337
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
338
|
+
// Find columns to add
|
|
339
|
+
const columnsToAdd = ifNotExists
|
|
340
|
+
.filter(col => schema[col] && !existingFields.has(col))
|
|
341
|
+
.map(col => {
|
|
342
|
+
const colDef = schema[col];
|
|
343
|
+
return {
|
|
344
|
+
name: col,
|
|
345
|
+
valueSql: colDef?.nullable
|
|
346
|
+
? `cast(NULL as ${typeMap[colDef.type ?? 'text']})`
|
|
347
|
+
: `cast(${this.getDefaultValue(colDef?.type ?? 'text')} as ${typeMap[colDef?.type ?? 'text']})`,
|
|
348
|
+
};
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
if (columnsToAdd.length > 0) {
|
|
352
|
+
await table.addColumns(columnsToAdd);
|
|
353
|
+
this.logger?.info?.(`Added columns [${columnsToAdd.map(c => c.name).join(', ')}] to table ${tableName}`);
|
|
354
|
+
}
|
|
355
|
+
} catch (error: any) {
|
|
356
|
+
throw new MastraError(
|
|
357
|
+
{
|
|
358
|
+
id: 'STORAGE_LANCE_STORAGE_ALTER_TABLE_FAILED',
|
|
359
|
+
domain: ErrorDomain.STORAGE,
|
|
360
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
361
|
+
details: { tableName },
|
|
362
|
+
},
|
|
363
|
+
error,
|
|
364
|
+
);
|
|
231
365
|
}
|
|
232
366
|
}
|
|
233
367
|
|
|
234
368
|
async clearTable({ tableName }: { tableName: TABLE_NAMES }): Promise<void> {
|
|
235
|
-
|
|
369
|
+
try {
|
|
370
|
+
if (!this.lanceClient) {
|
|
371
|
+
throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
|
|
372
|
+
}
|
|
373
|
+
if (!tableName) {
|
|
374
|
+
throw new Error('tableName is required for clearTable.');
|
|
375
|
+
}
|
|
376
|
+
} catch (validationError: any) {
|
|
377
|
+
throw new MastraError(
|
|
378
|
+
{
|
|
379
|
+
id: 'STORAGE_LANCE_STORAGE_CLEAR_TABLE_INVALID_ARGS',
|
|
380
|
+
domain: ErrorDomain.STORAGE,
|
|
381
|
+
category: ErrorCategory.USER,
|
|
382
|
+
text: validationError.message,
|
|
383
|
+
details: { tableName },
|
|
384
|
+
},
|
|
385
|
+
validationError,
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
try {
|
|
390
|
+
const table = await this.lanceClient.openTable(tableName);
|
|
236
391
|
|
|
237
|
-
|
|
238
|
-
|
|
392
|
+
// delete function always takes a predicate as an argument, so we use '1=1' to delete all records because it is always true.
|
|
393
|
+
await table.delete('1=1');
|
|
394
|
+
} catch (error: any) {
|
|
395
|
+
throw new MastraError(
|
|
396
|
+
{
|
|
397
|
+
id: 'STORAGE_LANCE_STORAGE_CLEAR_TABLE_FAILED',
|
|
398
|
+
domain: ErrorDomain.STORAGE,
|
|
399
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
400
|
+
details: { tableName },
|
|
401
|
+
},
|
|
402
|
+
error,
|
|
403
|
+
);
|
|
404
|
+
}
|
|
239
405
|
}
|
|
240
406
|
|
|
241
407
|
/**
|
|
@@ -244,6 +410,29 @@ export class LanceStorage extends MastraStorage {
|
|
|
244
410
|
* @param record The record to insert.
|
|
245
411
|
*/
|
|
246
412
|
async insert({ tableName, record }: { tableName: string; record: Record<string, any> }): Promise<void> {
|
|
413
|
+
try {
|
|
414
|
+
if (!this.lanceClient) {
|
|
415
|
+
throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
|
|
416
|
+
}
|
|
417
|
+
if (!tableName) {
|
|
418
|
+
throw new Error('tableName is required for insert.');
|
|
419
|
+
}
|
|
420
|
+
if (!record || Object.keys(record).length === 0) {
|
|
421
|
+
throw new Error('record is required and cannot be empty for insert.');
|
|
422
|
+
}
|
|
423
|
+
} catch (validationError: any) {
|
|
424
|
+
throw new MastraError(
|
|
425
|
+
{
|
|
426
|
+
id: 'STORAGE_LANCE_STORAGE_INSERT_INVALID_ARGS',
|
|
427
|
+
domain: ErrorDomain.STORAGE,
|
|
428
|
+
category: ErrorCategory.USER,
|
|
429
|
+
text: validationError.message,
|
|
430
|
+
details: { tableName },
|
|
431
|
+
},
|
|
432
|
+
validationError,
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
|
|
247
436
|
try {
|
|
248
437
|
const table = await this.lanceClient.openTable(tableName);
|
|
249
438
|
|
|
@@ -262,7 +451,15 @@ export class LanceStorage extends MastraStorage {
|
|
|
262
451
|
|
|
263
452
|
await table.add([processedRecord], { mode: 'overwrite' });
|
|
264
453
|
} catch (error: any) {
|
|
265
|
-
throw new
|
|
454
|
+
throw new MastraError(
|
|
455
|
+
{
|
|
456
|
+
id: 'STORAGE_LANCE_STORAGE_INSERT_FAILED',
|
|
457
|
+
domain: ErrorDomain.STORAGE,
|
|
458
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
459
|
+
details: { tableName },
|
|
460
|
+
},
|
|
461
|
+
error,
|
|
462
|
+
);
|
|
266
463
|
}
|
|
267
464
|
}
|
|
268
465
|
|
|
@@ -272,6 +469,29 @@ export class LanceStorage extends MastraStorage {
|
|
|
272
469
|
* @param records The records to insert.
|
|
273
470
|
*/
|
|
274
471
|
async batchInsert({ tableName, records }: { tableName: string; records: Record<string, any>[] }): Promise<void> {
|
|
472
|
+
try {
|
|
473
|
+
if (!this.lanceClient) {
|
|
474
|
+
throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
|
|
475
|
+
}
|
|
476
|
+
if (!tableName) {
|
|
477
|
+
throw new Error('tableName is required for batchInsert.');
|
|
478
|
+
}
|
|
479
|
+
if (!records || records.length === 0) {
|
|
480
|
+
throw new Error('records array is required and cannot be empty for batchInsert.');
|
|
481
|
+
}
|
|
482
|
+
} catch (validationError: any) {
|
|
483
|
+
throw new MastraError(
|
|
484
|
+
{
|
|
485
|
+
id: 'STORAGE_LANCE_STORAGE_BATCH_INSERT_INVALID_ARGS',
|
|
486
|
+
domain: ErrorDomain.STORAGE,
|
|
487
|
+
category: ErrorCategory.USER,
|
|
488
|
+
text: validationError.message,
|
|
489
|
+
details: { tableName },
|
|
490
|
+
},
|
|
491
|
+
validationError,
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
|
|
275
495
|
try {
|
|
276
496
|
const table = await this.lanceClient.openTable(tableName);
|
|
277
497
|
|
|
@@ -297,7 +517,15 @@ export class LanceStorage extends MastraStorage {
|
|
|
297
517
|
|
|
298
518
|
await table.add(processedRecords, { mode: 'overwrite' });
|
|
299
519
|
} catch (error: any) {
|
|
300
|
-
throw new
|
|
520
|
+
throw new MastraError(
|
|
521
|
+
{
|
|
522
|
+
id: 'STORAGE_LANCE_STORAGE_BATCH_INSERT_FAILED',
|
|
523
|
+
domain: ErrorDomain.STORAGE,
|
|
524
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
525
|
+
details: { tableName },
|
|
526
|
+
},
|
|
527
|
+
error,
|
|
528
|
+
);
|
|
301
529
|
}
|
|
302
530
|
}
|
|
303
531
|
|
|
@@ -309,6 +537,29 @@ export class LanceStorage extends MastraStorage {
|
|
|
309
537
|
* @returns The loaded record with proper type conversions, or null if not found
|
|
310
538
|
*/
|
|
311
539
|
async load({ tableName, keys }: { tableName: TABLE_NAMES; keys: Record<string, any> }): Promise<any> {
|
|
540
|
+
try {
|
|
541
|
+
if (!this.lanceClient) {
|
|
542
|
+
throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
|
|
543
|
+
}
|
|
544
|
+
if (!tableName) {
|
|
545
|
+
throw new Error('tableName is required for load.');
|
|
546
|
+
}
|
|
547
|
+
if (!keys || Object.keys(keys).length === 0) {
|
|
548
|
+
throw new Error('keys are required and cannot be empty for load.');
|
|
549
|
+
}
|
|
550
|
+
} catch (validationError: any) {
|
|
551
|
+
throw new MastraError(
|
|
552
|
+
{
|
|
553
|
+
id: 'STORAGE_LANCE_STORAGE_LOAD_INVALID_ARGS',
|
|
554
|
+
domain: ErrorDomain.STORAGE,
|
|
555
|
+
category: ErrorCategory.USER,
|
|
556
|
+
text: validationError.message,
|
|
557
|
+
details: { tableName },
|
|
558
|
+
},
|
|
559
|
+
validationError,
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
|
|
312
563
|
try {
|
|
313
564
|
const table = await this.lanceClient.openTable(tableName);
|
|
314
565
|
const tableSchema = await this.getTableSchema(tableName);
|
|
@@ -351,7 +602,17 @@ export class LanceStorage extends MastraStorage {
|
|
|
351
602
|
// Process the result with type conversions
|
|
352
603
|
return this.processResultWithTypeConversion(result[0], tableSchema);
|
|
353
604
|
} catch (error: any) {
|
|
354
|
-
|
|
605
|
+
// If it's already a MastraError (e.g. from validateKeyTypes if we change it later), rethrow
|
|
606
|
+
if (error instanceof MastraError) throw error;
|
|
607
|
+
throw new MastraError(
|
|
608
|
+
{
|
|
609
|
+
id: 'STORAGE_LANCE_STORAGE_LOAD_FAILED',
|
|
610
|
+
domain: ErrorDomain.STORAGE,
|
|
611
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
612
|
+
details: { tableName, keyCount: Object.keys(keys).length, firstKey: Object.keys(keys)[0] ?? '' },
|
|
613
|
+
},
|
|
614
|
+
error,
|
|
615
|
+
);
|
|
355
616
|
}
|
|
356
617
|
}
|
|
357
618
|
|
|
@@ -457,7 +718,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
457
718
|
try {
|
|
458
719
|
return this.load({ tableName: TABLE_THREADS, keys: { id: threadId } });
|
|
459
720
|
} catch (error: any) {
|
|
460
|
-
throw new
|
|
721
|
+
throw new MastraError(
|
|
722
|
+
{
|
|
723
|
+
id: 'LANCE_STORE_GET_THREAD_BY_ID_FAILED',
|
|
724
|
+
domain: ErrorDomain.STORAGE,
|
|
725
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
726
|
+
},
|
|
727
|
+
error,
|
|
728
|
+
);
|
|
461
729
|
}
|
|
462
730
|
}
|
|
463
731
|
|
|
@@ -473,7 +741,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
473
741
|
await this.getTableSchema(TABLE_THREADS),
|
|
474
742
|
) as StorageThreadType[];
|
|
475
743
|
} catch (error: any) {
|
|
476
|
-
throw new
|
|
744
|
+
throw new MastraError(
|
|
745
|
+
{
|
|
746
|
+
id: 'LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED',
|
|
747
|
+
domain: ErrorDomain.STORAGE,
|
|
748
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
749
|
+
},
|
|
750
|
+
error,
|
|
751
|
+
);
|
|
477
752
|
}
|
|
478
753
|
}
|
|
479
754
|
|
|
@@ -490,7 +765,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
490
765
|
|
|
491
766
|
return thread;
|
|
492
767
|
} catch (error: any) {
|
|
493
|
-
throw new
|
|
768
|
+
throw new MastraError(
|
|
769
|
+
{
|
|
770
|
+
id: 'LANCE_STORE_SAVE_THREAD_FAILED',
|
|
771
|
+
domain: ErrorDomain.STORAGE,
|
|
772
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
773
|
+
},
|
|
774
|
+
error,
|
|
775
|
+
);
|
|
494
776
|
}
|
|
495
777
|
}
|
|
496
778
|
|
|
@@ -516,7 +798,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
516
798
|
await this.getTableSchema(TABLE_THREADS),
|
|
517
799
|
) as StorageThreadType;
|
|
518
800
|
} catch (error: any) {
|
|
519
|
-
throw new
|
|
801
|
+
throw new MastraError(
|
|
802
|
+
{
|
|
803
|
+
id: 'LANCE_STORE_UPDATE_THREAD_FAILED',
|
|
804
|
+
domain: ErrorDomain.STORAGE,
|
|
805
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
806
|
+
},
|
|
807
|
+
error,
|
|
808
|
+
);
|
|
520
809
|
}
|
|
521
810
|
}
|
|
522
811
|
|
|
@@ -525,7 +814,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
525
814
|
const table = await this.lanceClient.openTable(TABLE_THREADS);
|
|
526
815
|
await table.delete(`id = '${threadId}'`);
|
|
527
816
|
} catch (error: any) {
|
|
528
|
-
throw new
|
|
817
|
+
throw new MastraError(
|
|
818
|
+
{
|
|
819
|
+
id: 'LANCE_STORE_DELETE_THREAD_FAILED',
|
|
820
|
+
domain: ErrorDomain.STORAGE,
|
|
821
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
822
|
+
},
|
|
823
|
+
error,
|
|
824
|
+
);
|
|
529
825
|
}
|
|
530
826
|
}
|
|
531
827
|
|
|
@@ -618,7 +914,7 @@ export class LanceStorage extends MastraStorage {
|
|
|
618
914
|
if (threadConfig) {
|
|
619
915
|
throw new Error('ThreadConfig is not supported by LanceDB storage');
|
|
620
916
|
}
|
|
621
|
-
|
|
917
|
+
const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
622
918
|
const table = await this.lanceClient.openTable(TABLE_MESSAGES);
|
|
623
919
|
let query = table.query().where(`\`threadId\` = '${threadId}'`);
|
|
624
920
|
|
|
@@ -653,8 +949,8 @@ export class LanceStorage extends MastraStorage {
|
|
|
653
949
|
}
|
|
654
950
|
|
|
655
951
|
// If we're fetching the last N messages, take only the last N after sorting
|
|
656
|
-
if (
|
|
657
|
-
records = records.slice(-
|
|
952
|
+
if (limit !== Number.MAX_SAFE_INTEGER) {
|
|
953
|
+
records = records.slice(-limit);
|
|
658
954
|
}
|
|
659
955
|
|
|
660
956
|
const messages = this.processResultWithTypeConversion(records, await this.getTableSchema(TABLE_MESSAGES));
|
|
@@ -675,7 +971,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
675
971
|
if (format === 'v2') return list.get.all.v2();
|
|
676
972
|
return list.get.all.v1();
|
|
677
973
|
} catch (error: any) {
|
|
678
|
-
throw new
|
|
974
|
+
throw new MastraError(
|
|
975
|
+
{
|
|
976
|
+
id: 'LANCE_STORE_GET_MESSAGES_FAILED',
|
|
977
|
+
domain: ErrorDomain.STORAGE,
|
|
978
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
979
|
+
},
|
|
980
|
+
error,
|
|
981
|
+
);
|
|
679
982
|
}
|
|
680
983
|
}
|
|
681
984
|
|
|
@@ -707,7 +1010,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
707
1010
|
if (format === `v2`) return list.get.all.v2();
|
|
708
1011
|
return list.get.all.v1();
|
|
709
1012
|
} catch (error: any) {
|
|
710
|
-
throw new
|
|
1013
|
+
throw new MastraError(
|
|
1014
|
+
{
|
|
1015
|
+
id: 'LANCE_STORE_SAVE_MESSAGES_FAILED',
|
|
1016
|
+
domain: ErrorDomain.STORAGE,
|
|
1017
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1018
|
+
},
|
|
1019
|
+
error,
|
|
1020
|
+
);
|
|
711
1021
|
}
|
|
712
1022
|
}
|
|
713
1023
|
|
|
@@ -726,7 +1036,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
726
1036
|
|
|
727
1037
|
return trace;
|
|
728
1038
|
} catch (error: any) {
|
|
729
|
-
throw new
|
|
1039
|
+
throw new MastraError(
|
|
1040
|
+
{
|
|
1041
|
+
id: 'LANCE_STORE_SAVE_TRACE_FAILED',
|
|
1042
|
+
domain: ErrorDomain.STORAGE,
|
|
1043
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1044
|
+
},
|
|
1045
|
+
error,
|
|
1046
|
+
);
|
|
730
1047
|
}
|
|
731
1048
|
}
|
|
732
1049
|
|
|
@@ -737,7 +1054,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
737
1054
|
const records = await query.toArray();
|
|
738
1055
|
return this.processResultWithTypeConversion(records[0], await this.getTableSchema(TABLE_TRACES)) as TraceType;
|
|
739
1056
|
} catch (error: any) {
|
|
740
|
-
throw new
|
|
1057
|
+
throw new MastraError(
|
|
1058
|
+
{
|
|
1059
|
+
id: 'LANCE_STORE_GET_TRACE_BY_ID_FAILED',
|
|
1060
|
+
domain: ErrorDomain.STORAGE,
|
|
1061
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1062
|
+
},
|
|
1063
|
+
error,
|
|
1064
|
+
);
|
|
741
1065
|
}
|
|
742
1066
|
}
|
|
743
1067
|
|
|
@@ -796,7 +1120,15 @@ export class LanceStorage extends MastraStorage {
|
|
|
796
1120
|
};
|
|
797
1121
|
}) as TraceType[];
|
|
798
1122
|
} catch (error: any) {
|
|
799
|
-
throw new
|
|
1123
|
+
throw new MastraError(
|
|
1124
|
+
{
|
|
1125
|
+
id: 'LANCE_STORE_GET_TRACES_FAILED',
|
|
1126
|
+
domain: ErrorDomain.STORAGE,
|
|
1127
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1128
|
+
details: { name: name ?? '', scope: scope ?? '' },
|
|
1129
|
+
},
|
|
1130
|
+
error,
|
|
1131
|
+
);
|
|
800
1132
|
}
|
|
801
1133
|
}
|
|
802
1134
|
|
|
@@ -819,7 +1151,14 @@ export class LanceStorage extends MastraStorage {
|
|
|
819
1151
|
await table.add(transformedEvals, { mode: 'append' });
|
|
820
1152
|
return evals;
|
|
821
1153
|
} catch (error: any) {
|
|
822
|
-
throw new
|
|
1154
|
+
throw new MastraError(
|
|
1155
|
+
{
|
|
1156
|
+
id: 'LANCE_STORE_SAVE_EVALS_FAILED',
|
|
1157
|
+
domain: ErrorDomain.STORAGE,
|
|
1158
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1159
|
+
},
|
|
1160
|
+
error,
|
|
1161
|
+
);
|
|
823
1162
|
}
|
|
824
1163
|
}
|
|
825
1164
|
|
|
@@ -847,7 +1186,15 @@ export class LanceStorage extends MastraStorage {
|
|
|
847
1186
|
};
|
|
848
1187
|
}) as EvalRow[];
|
|
849
1188
|
} catch (error: any) {
|
|
850
|
-
throw new
|
|
1189
|
+
throw new MastraError(
|
|
1190
|
+
{
|
|
1191
|
+
id: 'LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED',
|
|
1192
|
+
domain: ErrorDomain.STORAGE,
|
|
1193
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1194
|
+
details: { agentName },
|
|
1195
|
+
},
|
|
1196
|
+
error,
|
|
1197
|
+
);
|
|
851
1198
|
}
|
|
852
1199
|
}
|
|
853
1200
|
|
|
@@ -910,7 +1257,15 @@ export class LanceStorage extends MastraStorage {
|
|
|
910
1257
|
total: records.length,
|
|
911
1258
|
};
|
|
912
1259
|
} catch (error: any) {
|
|
913
|
-
throw new
|
|
1260
|
+
throw new MastraError(
|
|
1261
|
+
{
|
|
1262
|
+
id: 'LANCE_STORE_GET_WORKFLOW_RUNS_FAILED',
|
|
1263
|
+
domain: ErrorDomain.STORAGE,
|
|
1264
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1265
|
+
details: { namespace: args?.namespace ?? '', workflowName: args?.workflowName ?? '' },
|
|
1266
|
+
},
|
|
1267
|
+
error,
|
|
1268
|
+
);
|
|
914
1269
|
}
|
|
915
1270
|
}
|
|
916
1271
|
|
|
@@ -938,7 +1293,15 @@ export class LanceStorage extends MastraStorage {
|
|
|
938
1293
|
const record = records[0];
|
|
939
1294
|
return this.parseWorkflowRun(record);
|
|
940
1295
|
} catch (error: any) {
|
|
941
|
-
throw new
|
|
1296
|
+
throw new MastraError(
|
|
1297
|
+
{
|
|
1298
|
+
id: 'LANCE_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED',
|
|
1299
|
+
domain: ErrorDomain.STORAGE,
|
|
1300
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1301
|
+
details: { runId: args.runId, workflowName: args.workflowName ?? '' },
|
|
1302
|
+
},
|
|
1303
|
+
error,
|
|
1304
|
+
);
|
|
942
1305
|
}
|
|
943
1306
|
}
|
|
944
1307
|
|
|
@@ -978,7 +1341,15 @@ export class LanceStorage extends MastraStorage {
|
|
|
978
1341
|
|
|
979
1342
|
await table.add([record], { mode });
|
|
980
1343
|
} catch (error: any) {
|
|
981
|
-
throw new
|
|
1344
|
+
throw new MastraError(
|
|
1345
|
+
{
|
|
1346
|
+
id: 'LANCE_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED',
|
|
1347
|
+
domain: ErrorDomain.STORAGE,
|
|
1348
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1349
|
+
details: { workflowName, runId },
|
|
1350
|
+
},
|
|
1351
|
+
error,
|
|
1352
|
+
);
|
|
982
1353
|
}
|
|
983
1354
|
}
|
|
984
1355
|
async loadWorkflowSnapshot({
|
|
@@ -994,12 +1365,27 @@ export class LanceStorage extends MastraStorage {
|
|
|
994
1365
|
const records = await query.toArray();
|
|
995
1366
|
return records.length > 0 ? JSON.parse(records[0].snapshot) : null;
|
|
996
1367
|
} catch (error: any) {
|
|
997
|
-
throw new
|
|
1368
|
+
throw new MastraError(
|
|
1369
|
+
{
|
|
1370
|
+
id: 'LANCE_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED',
|
|
1371
|
+
domain: ErrorDomain.STORAGE,
|
|
1372
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1373
|
+
details: { workflowName, runId },
|
|
1374
|
+
},
|
|
1375
|
+
error,
|
|
1376
|
+
);
|
|
998
1377
|
}
|
|
999
1378
|
}
|
|
1000
1379
|
|
|
1001
1380
|
async getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & { traces: Trace[] }> {
|
|
1002
|
-
throw new
|
|
1381
|
+
throw new MastraError(
|
|
1382
|
+
{
|
|
1383
|
+
id: 'LANCE_STORE_GET_TRACES_PAGINATED_FAILED',
|
|
1384
|
+
domain: ErrorDomain.STORAGE,
|
|
1385
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1386
|
+
},
|
|
1387
|
+
'Method not implemented.',
|
|
1388
|
+
);
|
|
1003
1389
|
}
|
|
1004
1390
|
|
|
1005
1391
|
async getThreadsByResourceIdPaginated(_args: {
|
|
@@ -1007,13 +1393,27 @@ export class LanceStorage extends MastraStorage {
|
|
|
1007
1393
|
page?: number;
|
|
1008
1394
|
perPage?: number;
|
|
1009
1395
|
}): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
|
|
1010
|
-
throw new
|
|
1396
|
+
throw new MastraError(
|
|
1397
|
+
{
|
|
1398
|
+
id: 'LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED',
|
|
1399
|
+
domain: ErrorDomain.STORAGE,
|
|
1400
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1401
|
+
},
|
|
1402
|
+
'Method not implemented.',
|
|
1403
|
+
);
|
|
1011
1404
|
}
|
|
1012
1405
|
|
|
1013
1406
|
async getMessagesPaginated(
|
|
1014
1407
|
_args: StorageGetMessagesArg,
|
|
1015
1408
|
): Promise<PaginationInfo & { messages: MastraMessageV1[] | MastraMessageV2[] }> {
|
|
1016
|
-
throw new
|
|
1409
|
+
throw new MastraError(
|
|
1410
|
+
{
|
|
1411
|
+
id: 'LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED',
|
|
1412
|
+
domain: ErrorDomain.STORAGE,
|
|
1413
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1414
|
+
},
|
|
1415
|
+
'Method not implemented.',
|
|
1416
|
+
);
|
|
1017
1417
|
}
|
|
1018
1418
|
|
|
1019
1419
|
async updateMessages(_args: {
|