@mastra/lance 0.0.0-tsconfig-compile-20250703214351 → 0.0.0-workflow-deno-20250616130925

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.
@@ -1,8 +1,6 @@
1
1
  import { connect } from '@lancedb/lancedb';
2
2
  import type { Connection, ConnectionOptions, SchemaLike, FieldLike } from '@lancedb/lancedb';
3
- import type { MastraMessageContentV2 } from '@mastra/core/agent';
4
3
  import { MessageList } from '@mastra/core/agent';
5
- import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
6
4
  import type { MastraMessageV1, MastraMessageV2, StorageThreadType, TraceType } from '@mastra/core/memory';
7
5
  import {
8
6
  MastraStorage,
@@ -58,30 +56,10 @@ export class LanceStorage extends MastraStorage {
58
56
  instance.lanceClient = await connect(uri, options);
59
57
  return instance;
60
58
  } catch (e: any) {
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
- );
59
+ throw new Error(`Failed to connect to LanceDB: ${e}`);
71
60
  }
72
61
  }
73
62
 
74
- private getPrimaryKeys(tableName: TABLE_NAMES): string[] {
75
- let primaryId: string[] = ['id'];
76
- if (tableName === TABLE_WORKFLOW_SNAPSHOT) {
77
- primaryId = ['workflow_name', 'run_id'];
78
- } else if (tableName === TABLE_EVALS) {
79
- primaryId = ['agent_name', 'metric_name', 'run_id'];
80
- }
81
-
82
- return primaryId;
83
- }
84
-
85
63
  /**
86
64
  * @internal
87
65
  * Private constructor to enforce using the create factory method
@@ -97,41 +75,11 @@ export class LanceStorage extends MastraStorage {
97
75
  tableName: TABLE_NAMES;
98
76
  schema: Record<string, StorageColumn>;
99
77
  }): Promise<void> {
100
- try {
101
- if (!this.lanceClient) {
102
- throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
103
- }
104
- if (!tableName) {
105
- throw new Error('tableName is required for createTable.');
106
- }
107
- if (!schema) {
108
- throw new Error('schema is required for createTable.');
109
- }
110
- } catch (error) {
111
- throw new MastraError(
112
- {
113
- id: 'STORAGE_LANCE_STORAGE_CREATE_TABLE_INVALID_ARGS',
114
- domain: ErrorDomain.STORAGE,
115
- category: ErrorCategory.USER,
116
- details: { tableName },
117
- },
118
- error,
119
- );
120
- }
121
-
122
78
  try {
123
79
  const arrowSchema = this.translateSchema(schema);
124
80
  await this.lanceClient.createEmptyTable(tableName, arrowSchema);
125
81
  } catch (error: any) {
126
- throw new MastraError(
127
- {
128
- id: 'STORAGE_LANCE_STORAGE_CREATE_TABLE_FAILED',
129
- domain: ErrorDomain.STORAGE,
130
- category: ErrorCategory.THIRD_PARTY,
131
- details: { tableName },
132
- },
133
- error,
134
- );
82
+ throw new Error(`Failed to create table: ${error}`);
135
83
  }
136
84
  }
137
85
 
@@ -181,42 +129,15 @@ export class LanceStorage extends MastraStorage {
181
129
  * @param tableName Name of the table to drop
182
130
  */
183
131
  async dropTable(tableName: TABLE_NAMES): Promise<void> {
184
- try {
185
- if (!this.lanceClient) {
186
- throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
187
- }
188
- if (!tableName) {
189
- throw new Error('tableName is required for dropTable.');
190
- }
191
- } catch (validationError: any) {
192
- throw new MastraError(
193
- {
194
- id: 'STORAGE_LANCE_STORAGE_DROP_TABLE_INVALID_ARGS',
195
- domain: ErrorDomain.STORAGE,
196
- category: ErrorCategory.USER,
197
- text: validationError.message,
198
- details: { tableName },
199
- },
200
- validationError,
201
- );
202
- }
203
-
204
132
  try {
205
133
  await this.lanceClient.dropTable(tableName);
206
134
  } catch (error: any) {
207
- if (error.toString().includes('was not found') || error.message?.includes('Table not found')) {
135
+ // Don't throw if the table doesn't exist
136
+ if (error.toString().includes('was not found')) {
208
137
  this.logger.debug(`Table '${tableName}' does not exist, skipping drop`);
209
138
  return;
210
139
  }
211
- throw new MastraError(
212
- {
213
- id: 'STORAGE_LANCE_STORAGE_DROP_TABLE_FAILED',
214
- domain: ErrorDomain.STORAGE,
215
- category: ErrorCategory.THIRD_PARTY,
216
- details: { tableName },
217
- },
218
- error,
219
- );
140
+ throw new Error(`Failed to drop table: ${error}`);
220
141
  }
221
142
  }
222
143
 
@@ -226,26 +147,6 @@ export class LanceStorage extends MastraStorage {
226
147
  * @returns Table schema
227
148
  */
228
149
  async getTableSchema(tableName: TABLE_NAMES): Promise<SchemaLike> {
229
- try {
230
- if (!this.lanceClient) {
231
- throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
232
- }
233
- if (!tableName) {
234
- throw new Error('tableName is required for getTableSchema.');
235
- }
236
- } catch (validationError: any) {
237
- throw new MastraError(
238
- {
239
- id: 'STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_INVALID_ARGS',
240
- domain: ErrorDomain.STORAGE,
241
- category: ErrorCategory.USER,
242
- text: validationError.message,
243
- details: { tableName },
244
- },
245
- validationError,
246
- );
247
- }
248
-
249
150
  try {
250
151
  const table = await this.lanceClient.openTable(tableName);
251
152
  const rawSchema = await table.schema();
@@ -260,15 +161,7 @@ export class LanceStorage extends MastraStorage {
260
161
  },
261
162
  };
262
163
  } catch (error: any) {
263
- throw new MastraError(
264
- {
265
- id: 'STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_FAILED',
266
- domain: ErrorDomain.STORAGE,
267
- category: ErrorCategory.THIRD_PARTY,
268
- details: { tableName },
269
- },
270
- error,
271
- );
164
+ throw new Error(`Failed to get table schema: ${error}`);
272
165
  }
273
166
  }
274
167
 
@@ -305,114 +198,43 @@ export class LanceStorage extends MastraStorage {
305
198
  schema: Record<string, StorageColumn>;
306
199
  ifNotExists: string[];
307
200
  }): Promise<void> {
308
- try {
309
- if (!this.lanceClient) {
310
- throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
311
- }
312
- if (!tableName) {
313
- throw new Error('tableName is required for alterTable.');
314
- }
315
- if (!schema) {
316
- throw new Error('schema is required for alterTable.');
317
- }
318
- if (!ifNotExists || ifNotExists.length === 0) {
319
- this.logger.debug('No columns specified to add in alterTable, skipping.');
320
- return;
321
- }
322
- } catch (validationError: any) {
323
- throw new MastraError(
324
- {
325
- id: 'STORAGE_LANCE_STORAGE_ALTER_TABLE_INVALID_ARGS',
326
- domain: ErrorDomain.STORAGE,
327
- category: ErrorCategory.USER,
328
- text: validationError.message,
329
- details: { tableName },
330
- },
331
- validationError,
332
- );
333
- }
201
+ const table = await this.lanceClient.openTable(tableName);
202
+ const currentSchema = await table.schema();
203
+ const existingFields = new Set(currentSchema.fields.map((f: any) => f.name));
204
+
205
+ const typeMap: Record<string, string> = {
206
+ text: 'string',
207
+ integer: 'int',
208
+ bigint: 'bigint',
209
+ timestamp: 'timestamp',
210
+ jsonb: 'string',
211
+ uuid: 'string',
212
+ };
334
213
 
335
- try {
336
- const table = await this.lanceClient.openTable(tableName);
337
- const currentSchema = await table.schema();
338
- const existingFields = new Set(currentSchema.fields.map((f: any) => f.name));
339
-
340
- const typeMap: Record<string, string> = {
341
- text: 'string',
342
- integer: 'int',
343
- bigint: 'bigint',
344
- timestamp: 'timestamp',
345
- jsonb: 'string',
346
- uuid: 'string',
347
- };
214
+ // Find columns to add
215
+ const columnsToAdd = ifNotExists
216
+ .filter(col => schema[col] && !existingFields.has(col))
217
+ .map(col => {
218
+ const colDef = schema[col];
219
+ return {
220
+ name: col,
221
+ valueSql: colDef?.nullable
222
+ ? `cast(NULL as ${typeMap[colDef.type ?? 'text']})`
223
+ : `cast(${this.getDefaultValue(colDef?.type ?? 'text')} as ${typeMap[colDef?.type ?? 'text']})`,
224
+ };
225
+ });
348
226
 
349
- // Find columns to add
350
- const columnsToAdd = ifNotExists
351
- .filter(col => schema[col] && !existingFields.has(col))
352
- .map(col => {
353
- const colDef = schema[col];
354
- return {
355
- name: col,
356
- valueSql: colDef?.nullable
357
- ? `cast(NULL as ${typeMap[colDef.type ?? 'text']})`
358
- : `cast(${this.getDefaultValue(colDef?.type ?? 'text')} as ${typeMap[colDef?.type ?? 'text']})`,
359
- };
360
- });
361
-
362
- if (columnsToAdd.length > 0) {
363
- await table.addColumns(columnsToAdd);
364
- this.logger?.info?.(`Added columns [${columnsToAdd.map(c => c.name).join(', ')}] to table ${tableName}`);
365
- }
366
- } catch (error: any) {
367
- throw new MastraError(
368
- {
369
- id: 'STORAGE_LANCE_STORAGE_ALTER_TABLE_FAILED',
370
- domain: ErrorDomain.STORAGE,
371
- category: ErrorCategory.THIRD_PARTY,
372
- details: { tableName },
373
- },
374
- error,
375
- );
227
+ if (columnsToAdd.length > 0) {
228
+ await table.addColumns(columnsToAdd);
229
+ this.logger?.info?.(`Added columns [${columnsToAdd.map(c => c.name).join(', ')}] to table ${tableName}`);
376
230
  }
377
231
  }
378
232
 
379
233
  async clearTable({ tableName }: { tableName: TABLE_NAMES }): Promise<void> {
380
- try {
381
- if (!this.lanceClient) {
382
- throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
383
- }
384
- if (!tableName) {
385
- throw new Error('tableName is required for clearTable.');
386
- }
387
- } catch (validationError: any) {
388
- throw new MastraError(
389
- {
390
- id: 'STORAGE_LANCE_STORAGE_CLEAR_TABLE_INVALID_ARGS',
391
- domain: ErrorDomain.STORAGE,
392
- category: ErrorCategory.USER,
393
- text: validationError.message,
394
- details: { tableName },
395
- },
396
- validationError,
397
- );
398
- }
399
-
400
- try {
401
- const table = await this.lanceClient.openTable(tableName);
234
+ const table = await this.lanceClient.openTable(tableName);
402
235
 
403
- // delete function always takes a predicate as an argument, so we use '1=1' to delete all records because it is always true.
404
- await table.delete('1=1');
405
- } catch (error: any) {
406
- throw new MastraError(
407
- {
408
- id: 'STORAGE_LANCE_STORAGE_CLEAR_TABLE_FAILED',
409
- domain: ErrorDomain.STORAGE,
410
- category: ErrorCategory.THIRD_PARTY,
411
- details: { tableName },
412
- },
413
- error,
414
- );
415
- }
236
+ // delete function always takes a predicate as an argument, so we use '1=1' to delete all records because it is always true.
237
+ await table.delete('1=1');
416
238
  }
417
239
 
418
240
  /**
@@ -421,34 +243,9 @@ export class LanceStorage extends MastraStorage {
421
243
  * @param record The record to insert.
422
244
  */
423
245
  async insert({ tableName, record }: { tableName: string; record: Record<string, any> }): Promise<void> {
424
- try {
425
- if (!this.lanceClient) {
426
- throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
427
- }
428
- if (!tableName) {
429
- throw new Error('tableName is required for insert.');
430
- }
431
- if (!record || Object.keys(record).length === 0) {
432
- throw new Error('record is required and cannot be empty for insert.');
433
- }
434
- } catch (validationError: any) {
435
- throw new MastraError(
436
- {
437
- id: 'STORAGE_LANCE_STORAGE_INSERT_INVALID_ARGS',
438
- domain: ErrorDomain.STORAGE,
439
- category: ErrorCategory.USER,
440
- text: validationError.message,
441
- details: { tableName },
442
- },
443
- validationError,
444
- );
445
- }
446
-
447
246
  try {
448
247
  const table = await this.lanceClient.openTable(tableName);
449
248
 
450
- const primaryId = this.getPrimaryKeys(tableName as TABLE_NAMES);
451
-
452
249
  const processedRecord = { ...record };
453
250
 
454
251
  for (const key in processedRecord) {
@@ -462,17 +259,9 @@ export class LanceStorage extends MastraStorage {
462
259
  }
463
260
  }
464
261
 
465
- await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([processedRecord]);
262
+ await table.add([processedRecord], { mode: 'overwrite' });
466
263
  } catch (error: any) {
467
- throw new MastraError(
468
- {
469
- id: 'STORAGE_LANCE_STORAGE_INSERT_FAILED',
470
- domain: ErrorDomain.STORAGE,
471
- category: ErrorCategory.THIRD_PARTY,
472
- details: { tableName },
473
- },
474
- error,
475
- );
264
+ throw new Error(`Failed to insert record: ${error}`);
476
265
  }
477
266
  }
478
267
 
@@ -482,34 +271,9 @@ export class LanceStorage extends MastraStorage {
482
271
  * @param records The records to insert.
483
272
  */
484
273
  async batchInsert({ tableName, records }: { tableName: string; records: Record<string, any>[] }): Promise<void> {
485
- try {
486
- if (!this.lanceClient) {
487
- throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
488
- }
489
- if (!tableName) {
490
- throw new Error('tableName is required for batchInsert.');
491
- }
492
- if (!records || records.length === 0) {
493
- throw new Error('records array is required and cannot be empty for batchInsert.');
494
- }
495
- } catch (validationError: any) {
496
- throw new MastraError(
497
- {
498
- id: 'STORAGE_LANCE_STORAGE_BATCH_INSERT_INVALID_ARGS',
499
- domain: ErrorDomain.STORAGE,
500
- category: ErrorCategory.USER,
501
- text: validationError.message,
502
- details: { tableName },
503
- },
504
- validationError,
505
- );
506
- }
507
-
508
274
  try {
509
275
  const table = await this.lanceClient.openTable(tableName);
510
276
 
511
- const primaryId = this.getPrimaryKeys(tableName as TABLE_NAMES);
512
-
513
277
  const processedRecords = records.map(record => {
514
278
  const processedRecord = { ...record };
515
279
 
@@ -530,17 +294,9 @@ export class LanceStorage extends MastraStorage {
530
294
  return processedRecord;
531
295
  });
532
296
 
533
- await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(processedRecords);
297
+ await table.add(processedRecords, { mode: 'overwrite' });
534
298
  } catch (error: any) {
535
- throw new MastraError(
536
- {
537
- id: 'STORAGE_LANCE_STORAGE_BATCH_INSERT_FAILED',
538
- domain: ErrorDomain.STORAGE,
539
- category: ErrorCategory.THIRD_PARTY,
540
- details: { tableName },
541
- },
542
- error,
543
- );
299
+ throw new Error(`Failed to batch insert records: ${error}`);
544
300
  }
545
301
  }
546
302
 
@@ -552,29 +308,6 @@ export class LanceStorage extends MastraStorage {
552
308
  * @returns The loaded record with proper type conversions, or null if not found
553
309
  */
554
310
  async load({ tableName, keys }: { tableName: TABLE_NAMES; keys: Record<string, any> }): Promise<any> {
555
- try {
556
- if (!this.lanceClient) {
557
- throw new Error('LanceDB client not initialized. Call LanceStorage.create() first.');
558
- }
559
- if (!tableName) {
560
- throw new Error('tableName is required for load.');
561
- }
562
- if (!keys || Object.keys(keys).length === 0) {
563
- throw new Error('keys are required and cannot be empty for load.');
564
- }
565
- } catch (validationError: any) {
566
- throw new MastraError(
567
- {
568
- id: 'STORAGE_LANCE_STORAGE_LOAD_INVALID_ARGS',
569
- domain: ErrorDomain.STORAGE,
570
- category: ErrorCategory.USER,
571
- text: validationError.message,
572
- details: { tableName },
573
- },
574
- validationError,
575
- );
576
- }
577
-
578
311
  try {
579
312
  const table = await this.lanceClient.openTable(tableName);
580
313
  const tableSchema = await this.getTableSchema(tableName);
@@ -617,17 +350,7 @@ export class LanceStorage extends MastraStorage {
617
350
  // Process the result with type conversions
618
351
  return this.processResultWithTypeConversion(result[0], tableSchema);
619
352
  } catch (error: any) {
620
- // If it's already a MastraError (e.g. from validateKeyTypes if we change it later), rethrow
621
- if (error instanceof MastraError) throw error;
622
- throw new MastraError(
623
- {
624
- id: 'STORAGE_LANCE_STORAGE_LOAD_FAILED',
625
- domain: ErrorDomain.STORAGE,
626
- category: ErrorCategory.THIRD_PARTY,
627
- details: { tableName, keyCount: Object.keys(keys).length, firstKey: Object.keys(keys)[0] ?? '' },
628
- },
629
- error,
630
- );
353
+ throw new Error(`Failed to load record: ${error}`);
631
354
  }
632
355
  }
633
356
 
@@ -733,14 +456,7 @@ export class LanceStorage extends MastraStorage {
733
456
  try {
734
457
  return this.load({ tableName: TABLE_THREADS, keys: { id: threadId } });
735
458
  } catch (error: any) {
736
- throw new MastraError(
737
- {
738
- id: 'LANCE_STORE_GET_THREAD_BY_ID_FAILED',
739
- domain: ErrorDomain.STORAGE,
740
- category: ErrorCategory.THIRD_PARTY,
741
- },
742
- error,
743
- );
459
+ throw new Error(`Failed to get thread by ID: ${error}`);
744
460
  }
745
461
  }
746
462
 
@@ -756,14 +472,7 @@ export class LanceStorage extends MastraStorage {
756
472
  await this.getTableSchema(TABLE_THREADS),
757
473
  ) as StorageThreadType[];
758
474
  } catch (error: any) {
759
- throw new MastraError(
760
- {
761
- id: 'LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED',
762
- domain: ErrorDomain.STORAGE,
763
- category: ErrorCategory.THIRD_PARTY,
764
- },
765
- error,
766
- );
475
+ throw new Error(`Failed to get threads by resource ID: ${error}`);
767
476
  }
768
477
  }
769
478
 
@@ -780,14 +489,7 @@ export class LanceStorage extends MastraStorage {
780
489
 
781
490
  return thread;
782
491
  } catch (error: any) {
783
- throw new MastraError(
784
- {
785
- id: 'LANCE_STORE_SAVE_THREAD_FAILED',
786
- domain: ErrorDomain.STORAGE,
787
- category: ErrorCategory.THIRD_PARTY,
788
- },
789
- error,
790
- );
492
+ throw new Error(`Failed to save thread: ${error}`);
791
493
  }
792
494
  }
793
495
 
@@ -803,7 +505,7 @@ export class LanceStorage extends MastraStorage {
803
505
  try {
804
506
  const record = { id, title, metadata: JSON.stringify(metadata) };
805
507
  const table = await this.lanceClient.openTable(TABLE_THREADS);
806
- await table.mergeInsert('id').whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([record]);
508
+ await table.add([record], { mode: 'overwrite' });
807
509
 
808
510
  const query = table.query().where(`id = '${id}'`);
809
511
 
@@ -813,14 +515,7 @@ export class LanceStorage extends MastraStorage {
813
515
  await this.getTableSchema(TABLE_THREADS),
814
516
  ) as StorageThreadType;
815
517
  } catch (error: any) {
816
- throw new MastraError(
817
- {
818
- id: 'LANCE_STORE_UPDATE_THREAD_FAILED',
819
- domain: ErrorDomain.STORAGE,
820
- category: ErrorCategory.THIRD_PARTY,
821
- },
822
- error,
823
- );
518
+ throw new Error(`Failed to update thread: ${error}`);
824
519
  }
825
520
  }
826
521
 
@@ -829,14 +524,7 @@ export class LanceStorage extends MastraStorage {
829
524
  const table = await this.lanceClient.openTable(TABLE_THREADS);
830
525
  await table.delete(`id = '${threadId}'`);
831
526
  } catch (error: any) {
832
- throw new MastraError(
833
- {
834
- id: 'LANCE_STORE_DELETE_THREAD_FAILED',
835
- domain: ErrorDomain.STORAGE,
836
- category: ErrorCategory.THIRD_PARTY,
837
- },
838
- error,
839
- );
527
+ throw new Error(`Failed to delete thread: ${error}`);
840
528
  }
841
529
  }
842
530
 
@@ -929,7 +617,7 @@ export class LanceStorage extends MastraStorage {
929
617
  if (threadConfig) {
930
618
  throw new Error('ThreadConfig is not supported by LanceDB storage');
931
619
  }
932
- const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
620
+
933
621
  const table = await this.lanceClient.openTable(TABLE_MESSAGES);
934
622
  let query = table.query().where(`\`threadId\` = '${threadId}'`);
935
623
 
@@ -964,8 +652,8 @@ export class LanceStorage extends MastraStorage {
964
652
  }
965
653
 
966
654
  // If we're fetching the last N messages, take only the last N after sorting
967
- if (limit !== Number.MAX_SAFE_INTEGER) {
968
- records = records.slice(-limit);
655
+ if (selectBy?.last !== undefined && selectBy.last !== false) {
656
+ records = records.slice(-selectBy.last);
969
657
  }
970
658
 
971
659
  const messages = this.processResultWithTypeConversion(records, await this.getTableSchema(TABLE_MESSAGES));
@@ -986,14 +674,7 @@ export class LanceStorage extends MastraStorage {
986
674
  if (format === 'v2') return list.get.all.v2();
987
675
  return list.get.all.v1();
988
676
  } catch (error: any) {
989
- throw new MastraError(
990
- {
991
- id: 'LANCE_STORE_GET_MESSAGES_FAILED',
992
- domain: ErrorDomain.STORAGE,
993
- category: ErrorCategory.THIRD_PARTY,
994
- },
995
- error,
996
- );
677
+ throw new Error(`Failed to get messages: ${error}`);
997
678
  }
998
679
  }
999
680
 
@@ -1020,20 +701,12 @@ export class LanceStorage extends MastraStorage {
1020
701
  }));
1021
702
 
1022
703
  const table = await this.lanceClient.openTable(TABLE_MESSAGES);
1023
- await table.mergeInsert('id').whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(transformedMessages);
1024
-
704
+ await table.add(transformedMessages, { mode: 'overwrite' });
1025
705
  const list = new MessageList().add(messages, 'memory');
1026
706
  if (format === `v2`) return list.get.all.v2();
1027
707
  return list.get.all.v1();
1028
708
  } catch (error: any) {
1029
- throw new MastraError(
1030
- {
1031
- id: 'LANCE_STORE_SAVE_MESSAGES_FAILED',
1032
- domain: ErrorDomain.STORAGE,
1033
- category: ErrorCategory.THIRD_PARTY,
1034
- },
1035
- error,
1036
- );
709
+ throw new Error(`Failed to save messages: ${error}`);
1037
710
  }
1038
711
  }
1039
712
 
@@ -1052,14 +725,7 @@ export class LanceStorage extends MastraStorage {
1052
725
 
1053
726
  return trace;
1054
727
  } catch (error: any) {
1055
- throw new MastraError(
1056
- {
1057
- id: 'LANCE_STORE_SAVE_TRACE_FAILED',
1058
- domain: ErrorDomain.STORAGE,
1059
- category: ErrorCategory.THIRD_PARTY,
1060
- },
1061
- error,
1062
- );
728
+ throw new Error(`Failed to save trace: ${error}`);
1063
729
  }
1064
730
  }
1065
731
 
@@ -1070,14 +736,7 @@ export class LanceStorage extends MastraStorage {
1070
736
  const records = await query.toArray();
1071
737
  return this.processResultWithTypeConversion(records[0], await this.getTableSchema(TABLE_TRACES)) as TraceType;
1072
738
  } catch (error: any) {
1073
- throw new MastraError(
1074
- {
1075
- id: 'LANCE_STORE_GET_TRACE_BY_ID_FAILED',
1076
- domain: ErrorDomain.STORAGE,
1077
- category: ErrorCategory.THIRD_PARTY,
1078
- },
1079
- error,
1080
- );
739
+ throw new Error(`Failed to get trace by ID: ${error}`);
1081
740
  }
1082
741
  }
1083
742
 
@@ -1136,15 +795,7 @@ export class LanceStorage extends MastraStorage {
1136
795
  };
1137
796
  }) as TraceType[];
1138
797
  } catch (error: any) {
1139
- throw new MastraError(
1140
- {
1141
- id: 'LANCE_STORE_GET_TRACES_FAILED',
1142
- domain: ErrorDomain.STORAGE,
1143
- category: ErrorCategory.THIRD_PARTY,
1144
- details: { name: name ?? '', scope: scope ?? '' },
1145
- },
1146
- error,
1147
- );
798
+ throw new Error(`Failed to get traces: ${error}`);
1148
799
  }
1149
800
  }
1150
801
 
@@ -1167,14 +818,7 @@ export class LanceStorage extends MastraStorage {
1167
818
  await table.add(transformedEvals, { mode: 'append' });
1168
819
  return evals;
1169
820
  } catch (error: any) {
1170
- throw new MastraError(
1171
- {
1172
- id: 'LANCE_STORE_SAVE_EVALS_FAILED',
1173
- domain: ErrorDomain.STORAGE,
1174
- category: ErrorCategory.THIRD_PARTY,
1175
- },
1176
- error,
1177
- );
821
+ throw new Error(`Failed to save evals: ${error}`);
1178
822
  }
1179
823
  }
1180
824
 
@@ -1202,15 +846,7 @@ export class LanceStorage extends MastraStorage {
1202
846
  };
1203
847
  }) as EvalRow[];
1204
848
  } catch (error: any) {
1205
- throw new MastraError(
1206
- {
1207
- id: 'LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED',
1208
- domain: ErrorDomain.STORAGE,
1209
- category: ErrorCategory.THIRD_PARTY,
1210
- details: { agentName },
1211
- },
1212
- error,
1213
- );
849
+ throw new Error(`Failed to get evals by agent name: ${error}`);
1214
850
  }
1215
851
  }
1216
852
 
@@ -1273,15 +909,7 @@ export class LanceStorage extends MastraStorage {
1273
909
  total: records.length,
1274
910
  };
1275
911
  } catch (error: any) {
1276
- throw new MastraError(
1277
- {
1278
- id: 'LANCE_STORE_GET_WORKFLOW_RUNS_FAILED',
1279
- domain: ErrorDomain.STORAGE,
1280
- category: ErrorCategory.THIRD_PARTY,
1281
- details: { namespace: args?.namespace ?? '', workflowName: args?.workflowName ?? '' },
1282
- },
1283
- error,
1284
- );
912
+ throw new Error(`Failed to get workflow runs: ${error}`);
1285
913
  }
1286
914
  }
1287
915
 
@@ -1309,15 +937,7 @@ export class LanceStorage extends MastraStorage {
1309
937
  const record = records[0];
1310
938
  return this.parseWorkflowRun(record);
1311
939
  } catch (error: any) {
1312
- throw new MastraError(
1313
- {
1314
- id: 'LANCE_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED',
1315
- domain: ErrorDomain.STORAGE,
1316
- category: ErrorCategory.THIRD_PARTY,
1317
- details: { runId: args.runId, workflowName: args.workflowName ?? '' },
1318
- },
1319
- error,
1320
- );
940
+ throw new Error(`Failed to get workflow run by id: ${error}`);
1321
941
  }
1322
942
  }
1323
943
 
@@ -1338,9 +958,11 @@ export class LanceStorage extends MastraStorage {
1338
958
  const records = await query.toArray();
1339
959
  let createdAt: number;
1340
960
  const now = Date.now();
961
+ let mode: 'append' | 'overwrite' = 'append';
1341
962
 
1342
963
  if (records.length > 0) {
1343
964
  createdAt = records[0].createdAt ?? now;
965
+ mode = 'overwrite';
1344
966
  } else {
1345
967
  createdAt = now;
1346
968
  }
@@ -1353,21 +975,9 @@ export class LanceStorage extends MastraStorage {
1353
975
  updatedAt: now,
1354
976
  };
1355
977
 
1356
- await table
1357
- .mergeInsert(['workflow_name', 'run_id'])
1358
- .whenMatchedUpdateAll()
1359
- .whenNotMatchedInsertAll()
1360
- .execute([record]);
978
+ await table.add([record], { mode });
1361
979
  } catch (error: any) {
1362
- throw new MastraError(
1363
- {
1364
- id: 'LANCE_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED',
1365
- domain: ErrorDomain.STORAGE,
1366
- category: ErrorCategory.THIRD_PARTY,
1367
- details: { workflowName, runId },
1368
- },
1369
- error,
1370
- );
980
+ throw new Error(`Failed to persist workflow snapshot: ${error}`);
1371
981
  }
1372
982
  }
1373
983
  async loadWorkflowSnapshot({
@@ -1383,27 +993,12 @@ export class LanceStorage extends MastraStorage {
1383
993
  const records = await query.toArray();
1384
994
  return records.length > 0 ? JSON.parse(records[0].snapshot) : null;
1385
995
  } catch (error: any) {
1386
- throw new MastraError(
1387
- {
1388
- id: 'LANCE_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED',
1389
- domain: ErrorDomain.STORAGE,
1390
- category: ErrorCategory.THIRD_PARTY,
1391
- details: { workflowName, runId },
1392
- },
1393
- error,
1394
- );
996
+ throw new Error(`Failed to load workflow snapshot: ${error}`);
1395
997
  }
1396
998
  }
1397
999
 
1398
1000
  async getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & { traces: Trace[] }> {
1399
- throw new MastraError(
1400
- {
1401
- id: 'LANCE_STORE_GET_TRACES_PAGINATED_FAILED',
1402
- domain: ErrorDomain.STORAGE,
1403
- category: ErrorCategory.THIRD_PARTY,
1404
- },
1405
- 'Method not implemented.',
1406
- );
1001
+ throw new Error('Method not implemented.');
1407
1002
  }
1408
1003
 
1409
1004
  async getThreadsByResourceIdPaginated(_args: {
@@ -1411,37 +1006,12 @@ export class LanceStorage extends MastraStorage {
1411
1006
  page?: number;
1412
1007
  perPage?: number;
1413
1008
  }): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
1414
- throw new MastraError(
1415
- {
1416
- id: 'LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED',
1417
- domain: ErrorDomain.STORAGE,
1418
- category: ErrorCategory.THIRD_PARTY,
1419
- },
1420
- 'Method not implemented.',
1421
- );
1009
+ throw new Error('Method not implemented.');
1422
1010
  }
1423
1011
 
1424
1012
  async getMessagesPaginated(
1425
1013
  _args: StorageGetMessagesArg,
1426
1014
  ): Promise<PaginationInfo & { messages: MastraMessageV1[] | MastraMessageV2[] }> {
1427
- throw new MastraError(
1428
- {
1429
- id: 'LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED',
1430
- domain: ErrorDomain.STORAGE,
1431
- category: ErrorCategory.THIRD_PARTY,
1432
- },
1433
- 'Method not implemented.',
1434
- );
1435
- }
1436
-
1437
- async updateMessages(_args: {
1438
- messages: Partial<Omit<MastraMessageV2, 'createdAt'>> &
1439
- {
1440
- id: string;
1441
- content?: { metadata?: MastraMessageContentV2['metadata']; content?: MastraMessageContentV2['content'] };
1442
- }[];
1443
- }): Promise<MastraMessageV2[]> {
1444
- this.logger.error('updateMessages is not yet implemented in LanceStore');
1445
- throw new Error('Method not implemented');
1015
+ throw new Error('Method not implemented.');
1446
1016
  }
1447
1017
  }