@mastra/lance 0.1.2 → 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/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { connect, Index } from '@lancedb/lancedb';
2
2
  import { MessageList } from '@mastra/core/agent';
3
+ import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
3
4
  import { MastraStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_EVALS, TABLE_WORKFLOW_SNAPSHOT } from '@mastra/core/storage';
4
5
  import { Utf8, Float64, Binary, Float32, Int32, Field, Schema } from 'apache-arrow';
5
6
  import { MastraVector } from '@mastra/core/vector';
@@ -36,7 +37,16 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
36
37
  instance.lanceClient = await connect(uri, options);
37
38
  return instance;
38
39
  } catch (e) {
39
- throw new Error(`Failed to connect to LanceDB: ${e}`);
40
+ throw new MastraError(
41
+ {
42
+ id: "STORAGE_LANCE_STORAGE_CONNECT_FAILED",
43
+ domain: ErrorDomain.STORAGE,
44
+ category: ErrorCategory.THIRD_PARTY,
45
+ text: `Failed to connect to LanceDB: ${e.message || e}`,
46
+ details: { uri, optionsProvided: !!options }
47
+ },
48
+ e
49
+ );
40
50
  }
41
51
  }
42
52
  /**
@@ -50,11 +60,40 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
50
60
  tableName,
51
61
  schema
52
62
  }) {
63
+ try {
64
+ if (!this.lanceClient) {
65
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
66
+ }
67
+ if (!tableName) {
68
+ throw new Error("tableName is required for createTable.");
69
+ }
70
+ if (!schema) {
71
+ throw new Error("schema is required for createTable.");
72
+ }
73
+ } catch (error) {
74
+ throw new MastraError(
75
+ {
76
+ id: "STORAGE_LANCE_STORAGE_CREATE_TABLE_INVALID_ARGS",
77
+ domain: ErrorDomain.STORAGE,
78
+ category: ErrorCategory.USER,
79
+ details: { tableName }
80
+ },
81
+ error
82
+ );
83
+ }
53
84
  try {
54
85
  const arrowSchema = this.translateSchema(schema);
55
86
  await this.lanceClient.createEmptyTable(tableName, arrowSchema);
56
87
  } catch (error) {
57
- throw new Error(`Failed to create table: ${error}`);
88
+ throw new MastraError(
89
+ {
90
+ id: "STORAGE_LANCE_STORAGE_CREATE_TABLE_FAILED",
91
+ domain: ErrorDomain.STORAGE,
92
+ category: ErrorCategory.THIRD_PARTY,
93
+ details: { tableName }
94
+ },
95
+ error
96
+ );
58
97
  }
59
98
  }
60
99
  translateSchema(schema) {
@@ -97,14 +136,41 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
97
136
  * @param tableName Name of the table to drop
98
137
  */
99
138
  async dropTable(tableName) {
139
+ try {
140
+ if (!this.lanceClient) {
141
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
142
+ }
143
+ if (!tableName) {
144
+ throw new Error("tableName is required for dropTable.");
145
+ }
146
+ } catch (validationError) {
147
+ throw new MastraError(
148
+ {
149
+ id: "STORAGE_LANCE_STORAGE_DROP_TABLE_INVALID_ARGS",
150
+ domain: ErrorDomain.STORAGE,
151
+ category: ErrorCategory.USER,
152
+ text: validationError.message,
153
+ details: { tableName }
154
+ },
155
+ validationError
156
+ );
157
+ }
100
158
  try {
101
159
  await this.lanceClient.dropTable(tableName);
102
160
  } catch (error) {
103
- if (error.toString().includes("was not found")) {
161
+ if (error.toString().includes("was not found") || error.message?.includes("Table not found")) {
104
162
  this.logger.debug(`Table '${tableName}' does not exist, skipping drop`);
105
163
  return;
106
164
  }
107
- throw new Error(`Failed to drop table: ${error}`);
165
+ throw new MastraError(
166
+ {
167
+ id: "STORAGE_LANCE_STORAGE_DROP_TABLE_FAILED",
168
+ domain: ErrorDomain.STORAGE,
169
+ category: ErrorCategory.THIRD_PARTY,
170
+ details: { tableName }
171
+ },
172
+ error
173
+ );
108
174
  }
109
175
  }
110
176
  /**
@@ -113,6 +179,25 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
113
179
  * @returns Table schema
114
180
  */
115
181
  async getTableSchema(tableName) {
182
+ try {
183
+ if (!this.lanceClient) {
184
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
185
+ }
186
+ if (!tableName) {
187
+ throw new Error("tableName is required for getTableSchema.");
188
+ }
189
+ } catch (validationError) {
190
+ throw new MastraError(
191
+ {
192
+ id: "STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_INVALID_ARGS",
193
+ domain: ErrorDomain.STORAGE,
194
+ category: ErrorCategory.USER,
195
+ text: validationError.message,
196
+ details: { tableName }
197
+ },
198
+ validationError
199
+ );
200
+ }
116
201
  try {
117
202
  const table = await this.lanceClient.openTable(tableName);
118
203
  const rawSchema = await table.schema();
@@ -125,7 +210,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
125
210
  }
126
211
  };
127
212
  } catch (error) {
128
- throw new Error(`Failed to get table schema: ${error}`);
213
+ throw new MastraError(
214
+ {
215
+ id: "STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_FAILED",
216
+ domain: ErrorDomain.STORAGE,
217
+ category: ErrorCategory.THIRD_PARTY,
218
+ details: { tableName }
219
+ },
220
+ error
221
+ );
129
222
  }
130
223
  }
131
224
  getDefaultValue(type) {
@@ -156,32 +249,101 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
156
249
  schema,
157
250
  ifNotExists
158
251
  }) {
159
- const table = await this.lanceClient.openTable(tableName);
160
- const currentSchema = await table.schema();
161
- const existingFields = new Set(currentSchema.fields.map((f) => f.name));
162
- const typeMap = {
163
- text: "string",
164
- integer: "int",
165
- bigint: "bigint",
166
- timestamp: "timestamp",
167
- jsonb: "string",
168
- uuid: "string"
169
- };
170
- const columnsToAdd = ifNotExists.filter((col) => schema[col] && !existingFields.has(col)).map((col) => {
171
- const colDef = schema[col];
172
- return {
173
- name: col,
174
- valueSql: colDef?.nullable ? `cast(NULL as ${typeMap[colDef.type ?? "text"]})` : `cast(${this.getDefaultValue(colDef?.type ?? "text")} as ${typeMap[colDef?.type ?? "text"]})`
252
+ try {
253
+ if (!this.lanceClient) {
254
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
255
+ }
256
+ if (!tableName) {
257
+ throw new Error("tableName is required for alterTable.");
258
+ }
259
+ if (!schema) {
260
+ throw new Error("schema is required for alterTable.");
261
+ }
262
+ if (!ifNotExists || ifNotExists.length === 0) {
263
+ this.logger.debug("No columns specified to add in alterTable, skipping.");
264
+ return;
265
+ }
266
+ } catch (validationError) {
267
+ throw new MastraError(
268
+ {
269
+ id: "STORAGE_LANCE_STORAGE_ALTER_TABLE_INVALID_ARGS",
270
+ domain: ErrorDomain.STORAGE,
271
+ category: ErrorCategory.USER,
272
+ text: validationError.message,
273
+ details: { tableName }
274
+ },
275
+ validationError
276
+ );
277
+ }
278
+ try {
279
+ const table = await this.lanceClient.openTable(tableName);
280
+ const currentSchema = await table.schema();
281
+ const existingFields = new Set(currentSchema.fields.map((f) => f.name));
282
+ const typeMap = {
283
+ text: "string",
284
+ integer: "int",
285
+ bigint: "bigint",
286
+ timestamp: "timestamp",
287
+ jsonb: "string",
288
+ uuid: "string"
175
289
  };
176
- });
177
- if (columnsToAdd.length > 0) {
178
- await table.addColumns(columnsToAdd);
179
- this.logger?.info?.(`Added columns [${columnsToAdd.map((c) => c.name).join(", ")}] to table ${tableName}`);
290
+ const columnsToAdd = ifNotExists.filter((col) => schema[col] && !existingFields.has(col)).map((col) => {
291
+ const colDef = schema[col];
292
+ return {
293
+ name: col,
294
+ valueSql: colDef?.nullable ? `cast(NULL as ${typeMap[colDef.type ?? "text"]})` : `cast(${this.getDefaultValue(colDef?.type ?? "text")} as ${typeMap[colDef?.type ?? "text"]})`
295
+ };
296
+ });
297
+ if (columnsToAdd.length > 0) {
298
+ await table.addColumns(columnsToAdd);
299
+ this.logger?.info?.(`Added columns [${columnsToAdd.map((c) => c.name).join(", ")}] to table ${tableName}`);
300
+ }
301
+ } catch (error) {
302
+ throw new MastraError(
303
+ {
304
+ id: "STORAGE_LANCE_STORAGE_ALTER_TABLE_FAILED",
305
+ domain: ErrorDomain.STORAGE,
306
+ category: ErrorCategory.THIRD_PARTY,
307
+ details: { tableName }
308
+ },
309
+ error
310
+ );
180
311
  }
181
312
  }
182
313
  async clearTable({ tableName }) {
183
- const table = await this.lanceClient.openTable(tableName);
184
- await table.delete("1=1");
314
+ try {
315
+ if (!this.lanceClient) {
316
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
317
+ }
318
+ if (!tableName) {
319
+ throw new Error("tableName is required for clearTable.");
320
+ }
321
+ } catch (validationError) {
322
+ throw new MastraError(
323
+ {
324
+ id: "STORAGE_LANCE_STORAGE_CLEAR_TABLE_INVALID_ARGS",
325
+ domain: ErrorDomain.STORAGE,
326
+ category: ErrorCategory.USER,
327
+ text: validationError.message,
328
+ details: { tableName }
329
+ },
330
+ validationError
331
+ );
332
+ }
333
+ try {
334
+ const table = await this.lanceClient.openTable(tableName);
335
+ await table.delete("1=1");
336
+ } catch (error) {
337
+ throw new MastraError(
338
+ {
339
+ id: "STORAGE_LANCE_STORAGE_CLEAR_TABLE_FAILED",
340
+ domain: ErrorDomain.STORAGE,
341
+ category: ErrorCategory.THIRD_PARTY,
342
+ details: { tableName }
343
+ },
344
+ error
345
+ );
346
+ }
185
347
  }
186
348
  /**
187
349
  * Insert a single record into a table. This function overwrites the existing record if it exists. Use this function for inserting records into tables with custom schemas.
@@ -189,6 +351,28 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
189
351
  * @param record The record to insert.
190
352
  */
191
353
  async insert({ tableName, record }) {
354
+ try {
355
+ if (!this.lanceClient) {
356
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
357
+ }
358
+ if (!tableName) {
359
+ throw new Error("tableName is required for insert.");
360
+ }
361
+ if (!record || Object.keys(record).length === 0) {
362
+ throw new Error("record is required and cannot be empty for insert.");
363
+ }
364
+ } catch (validationError) {
365
+ throw new MastraError(
366
+ {
367
+ id: "STORAGE_LANCE_STORAGE_INSERT_INVALID_ARGS",
368
+ domain: ErrorDomain.STORAGE,
369
+ category: ErrorCategory.USER,
370
+ text: validationError.message,
371
+ details: { tableName }
372
+ },
373
+ validationError
374
+ );
375
+ }
192
376
  try {
193
377
  const table = await this.lanceClient.openTable(tableName);
194
378
  const processedRecord = { ...record };
@@ -200,7 +384,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
200
384
  }
201
385
  await table.add([processedRecord], { mode: "overwrite" });
202
386
  } catch (error) {
203
- throw new Error(`Failed to insert record: ${error}`);
387
+ throw new MastraError(
388
+ {
389
+ id: "STORAGE_LANCE_STORAGE_INSERT_FAILED",
390
+ domain: ErrorDomain.STORAGE,
391
+ category: ErrorCategory.THIRD_PARTY,
392
+ details: { tableName }
393
+ },
394
+ error
395
+ );
204
396
  }
205
397
  }
206
398
  /**
@@ -209,6 +401,28 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
209
401
  * @param records The records to insert.
210
402
  */
211
403
  async batchInsert({ tableName, records }) {
404
+ try {
405
+ if (!this.lanceClient) {
406
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
407
+ }
408
+ if (!tableName) {
409
+ throw new Error("tableName is required for batchInsert.");
410
+ }
411
+ if (!records || records.length === 0) {
412
+ throw new Error("records array is required and cannot be empty for batchInsert.");
413
+ }
414
+ } catch (validationError) {
415
+ throw new MastraError(
416
+ {
417
+ id: "STORAGE_LANCE_STORAGE_BATCH_INSERT_INVALID_ARGS",
418
+ domain: ErrorDomain.STORAGE,
419
+ category: ErrorCategory.USER,
420
+ text: validationError.message,
421
+ details: { tableName }
422
+ },
423
+ validationError
424
+ );
425
+ }
212
426
  try {
213
427
  const table = await this.lanceClient.openTable(tableName);
214
428
  const processedRecords = records.map((record) => {
@@ -223,7 +437,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
223
437
  });
224
438
  await table.add(processedRecords, { mode: "overwrite" });
225
439
  } catch (error) {
226
- throw new Error(`Failed to batch insert records: ${error}`);
440
+ throw new MastraError(
441
+ {
442
+ id: "STORAGE_LANCE_STORAGE_BATCH_INSERT_FAILED",
443
+ domain: ErrorDomain.STORAGE,
444
+ category: ErrorCategory.THIRD_PARTY,
445
+ details: { tableName }
446
+ },
447
+ error
448
+ );
227
449
  }
228
450
  }
229
451
  /**
@@ -234,6 +456,28 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
234
456
  * @returns The loaded record with proper type conversions, or null if not found
235
457
  */
236
458
  async load({ tableName, keys }) {
459
+ try {
460
+ if (!this.lanceClient) {
461
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
462
+ }
463
+ if (!tableName) {
464
+ throw new Error("tableName is required for load.");
465
+ }
466
+ if (!keys || Object.keys(keys).length === 0) {
467
+ throw new Error("keys are required and cannot be empty for load.");
468
+ }
469
+ } catch (validationError) {
470
+ throw new MastraError(
471
+ {
472
+ id: "STORAGE_LANCE_STORAGE_LOAD_INVALID_ARGS",
473
+ domain: ErrorDomain.STORAGE,
474
+ category: ErrorCategory.USER,
475
+ text: validationError.message,
476
+ details: { tableName }
477
+ },
478
+ validationError
479
+ );
480
+ }
237
481
  try {
238
482
  const table = await this.lanceClient.openTable(tableName);
239
483
  const tableSchema = await this.getTableSchema(tableName);
@@ -261,7 +505,16 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
261
505
  }
262
506
  return this.processResultWithTypeConversion(result[0], tableSchema);
263
507
  } catch (error) {
264
- throw new Error(`Failed to load record: ${error}`);
508
+ if (error instanceof MastraError) throw error;
509
+ throw new MastraError(
510
+ {
511
+ id: "STORAGE_LANCE_STORAGE_LOAD_FAILED",
512
+ domain: ErrorDomain.STORAGE,
513
+ category: ErrorCategory.THIRD_PARTY,
514
+ details: { tableName, keyCount: Object.keys(keys).length, firstKey: Object.keys(keys)[0] ?? "" }
515
+ },
516
+ error
517
+ );
265
518
  }
266
519
  }
267
520
  /**
@@ -336,7 +589,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
336
589
  try {
337
590
  return this.load({ tableName: TABLE_THREADS, keys: { id: threadId } });
338
591
  } catch (error) {
339
- throw new Error(`Failed to get thread by ID: ${error}`);
592
+ throw new MastraError(
593
+ {
594
+ id: "LANCE_STORE_GET_THREAD_BY_ID_FAILED",
595
+ domain: ErrorDomain.STORAGE,
596
+ category: ErrorCategory.THIRD_PARTY
597
+ },
598
+ error
599
+ );
340
600
  }
341
601
  }
342
602
  async getThreadsByResourceId({ resourceId }) {
@@ -349,7 +609,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
349
609
  await this.getTableSchema(TABLE_THREADS)
350
610
  );
351
611
  } catch (error) {
352
- throw new Error(`Failed to get threads by resource ID: ${error}`);
612
+ throw new MastraError(
613
+ {
614
+ id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
615
+ domain: ErrorDomain.STORAGE,
616
+ category: ErrorCategory.THIRD_PARTY
617
+ },
618
+ error
619
+ );
353
620
  }
354
621
  }
355
622
  /**
@@ -364,7 +631,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
364
631
  await table.add([record], { mode: "append" });
365
632
  return thread;
366
633
  } catch (error) {
367
- throw new Error(`Failed to save thread: ${error}`);
634
+ throw new MastraError(
635
+ {
636
+ id: "LANCE_STORE_SAVE_THREAD_FAILED",
637
+ domain: ErrorDomain.STORAGE,
638
+ category: ErrorCategory.THIRD_PARTY
639
+ },
640
+ error
641
+ );
368
642
  }
369
643
  }
370
644
  async updateThread({
@@ -383,7 +657,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
383
657
  await this.getTableSchema(TABLE_THREADS)
384
658
  );
385
659
  } catch (error) {
386
- throw new Error(`Failed to update thread: ${error}`);
660
+ throw new MastraError(
661
+ {
662
+ id: "LANCE_STORE_UPDATE_THREAD_FAILED",
663
+ domain: ErrorDomain.STORAGE,
664
+ category: ErrorCategory.THIRD_PARTY
665
+ },
666
+ error
667
+ );
387
668
  }
388
669
  }
389
670
  async deleteThread({ threadId }) {
@@ -391,7 +672,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
391
672
  const table = await this.lanceClient.openTable(TABLE_THREADS);
392
673
  await table.delete(`id = '${threadId}'`);
393
674
  } catch (error) {
394
- throw new Error(`Failed to delete thread: ${error}`);
675
+ throw new MastraError(
676
+ {
677
+ id: "LANCE_STORE_DELETE_THREAD_FAILED",
678
+ domain: ErrorDomain.STORAGE,
679
+ category: ErrorCategory.THIRD_PARTY
680
+ },
681
+ error
682
+ );
395
683
  }
396
684
  }
397
685
  /**
@@ -453,6 +741,7 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
453
741
  if (threadConfig) {
454
742
  throw new Error("ThreadConfig is not supported by LanceDB storage");
455
743
  }
744
+ const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
456
745
  const table = await this.lanceClient.openTable(TABLE_MESSAGES);
457
746
  let query = table.query().where(`\`threadId\` = '${threadId}'`);
458
747
  if (selectBy) {
@@ -471,8 +760,8 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
471
760
  if (selectBy?.include && selectBy.include.length > 0) {
472
761
  records = this.processMessagesWithContext(records, selectBy.include);
473
762
  }
474
- if (selectBy?.last !== void 0 && selectBy.last !== false) {
475
- records = records.slice(-selectBy.last);
763
+ if (limit !== Number.MAX_SAFE_INTEGER) {
764
+ records = records.slice(-limit);
476
765
  }
477
766
  const messages = this.processResultWithTypeConversion(records, await this.getTableSchema(TABLE_MESSAGES));
478
767
  const normalized = messages.map((msg) => ({
@@ -489,7 +778,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
489
778
  if (format === "v2") return list.get.all.v2();
490
779
  return list.get.all.v1();
491
780
  } catch (error) {
492
- throw new Error(`Failed to get messages: ${error}`);
781
+ throw new MastraError(
782
+ {
783
+ id: "LANCE_STORE_GET_MESSAGES_FAILED",
784
+ domain: ErrorDomain.STORAGE,
785
+ category: ErrorCategory.THIRD_PARTY
786
+ },
787
+ error
788
+ );
493
789
  }
494
790
  }
495
791
  async saveMessages(args) {
@@ -512,7 +808,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
512
808
  if (format === `v2`) return list.get.all.v2();
513
809
  return list.get.all.v1();
514
810
  } catch (error) {
515
- throw new Error(`Failed to save messages: ${error}`);
811
+ throw new MastraError(
812
+ {
813
+ id: "LANCE_STORE_SAVE_MESSAGES_FAILED",
814
+ domain: ErrorDomain.STORAGE,
815
+ category: ErrorCategory.THIRD_PARTY
816
+ },
817
+ error
818
+ );
516
819
  }
517
820
  }
518
821
  async saveTrace({ trace }) {
@@ -529,7 +832,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
529
832
  await table.add([record], { mode: "append" });
530
833
  return trace;
531
834
  } catch (error) {
532
- throw new Error(`Failed to save trace: ${error}`);
835
+ throw new MastraError(
836
+ {
837
+ id: "LANCE_STORE_SAVE_TRACE_FAILED",
838
+ domain: ErrorDomain.STORAGE,
839
+ category: ErrorCategory.THIRD_PARTY
840
+ },
841
+ error
842
+ );
533
843
  }
534
844
  }
535
845
  async getTraceById({ traceId }) {
@@ -539,7 +849,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
539
849
  const records = await query.toArray();
540
850
  return this.processResultWithTypeConversion(records[0], await this.getTableSchema(TABLE_TRACES));
541
851
  } catch (error) {
542
- throw new Error(`Failed to get trace by ID: ${error}`);
852
+ throw new MastraError(
853
+ {
854
+ id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
855
+ domain: ErrorDomain.STORAGE,
856
+ category: ErrorCategory.THIRD_PARTY
857
+ },
858
+ error
859
+ );
543
860
  }
544
861
  }
545
862
  async getTraces({
@@ -581,7 +898,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
581
898
  };
582
899
  });
583
900
  } catch (error) {
584
- throw new Error(`Failed to get traces: ${error}`);
901
+ throw new MastraError(
902
+ {
903
+ id: "LANCE_STORE_GET_TRACES_FAILED",
904
+ domain: ErrorDomain.STORAGE,
905
+ category: ErrorCategory.THIRD_PARTY,
906
+ details: { name: name ?? "", scope: scope ?? "" }
907
+ },
908
+ error
909
+ );
585
910
  }
586
911
  }
587
912
  async saveEvals({ evals }) {
@@ -602,7 +927,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
602
927
  await table.add(transformedEvals, { mode: "append" });
603
928
  return evals;
604
929
  } catch (error) {
605
- throw new Error(`Failed to save evals: ${error}`);
930
+ throw new MastraError(
931
+ {
932
+ id: "LANCE_STORE_SAVE_EVALS_FAILED",
933
+ domain: ErrorDomain.STORAGE,
934
+ category: ErrorCategory.THIRD_PARTY
935
+ },
936
+ error
937
+ );
606
938
  }
607
939
  }
608
940
  async getEvalsByAgentName(agentName, type) {
@@ -629,7 +961,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
629
961
  };
630
962
  });
631
963
  } catch (error) {
632
- throw new Error(`Failed to get evals by agent name: ${error}`);
964
+ throw new MastraError(
965
+ {
966
+ id: "LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
967
+ domain: ErrorDomain.STORAGE,
968
+ category: ErrorCategory.THIRD_PARTY,
969
+ details: { agentName }
970
+ },
971
+ error
972
+ );
633
973
  }
634
974
  }
635
975
  parseWorkflowRun(row) {
@@ -675,7 +1015,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
675
1015
  total: records.length
676
1016
  };
677
1017
  } catch (error) {
678
- throw new Error(`Failed to get workflow runs: ${error}`);
1018
+ throw new MastraError(
1019
+ {
1020
+ id: "LANCE_STORE_GET_WORKFLOW_RUNS_FAILED",
1021
+ domain: ErrorDomain.STORAGE,
1022
+ category: ErrorCategory.THIRD_PARTY,
1023
+ details: { namespace: args?.namespace ?? "", workflowName: args?.workflowName ?? "" }
1024
+ },
1025
+ error
1026
+ );
679
1027
  }
680
1028
  }
681
1029
  /**
@@ -696,7 +1044,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
696
1044
  const record = records[0];
697
1045
  return this.parseWorkflowRun(record);
698
1046
  } catch (error) {
699
- throw new Error(`Failed to get workflow run by id: ${error}`);
1047
+ throw new MastraError(
1048
+ {
1049
+ id: "LANCE_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
1050
+ domain: ErrorDomain.STORAGE,
1051
+ category: ErrorCategory.THIRD_PARTY,
1052
+ details: { runId: args.runId, workflowName: args.workflowName ?? "" }
1053
+ },
1054
+ error
1055
+ );
700
1056
  }
701
1057
  }
702
1058
  async persistWorkflowSnapshot({
@@ -726,7 +1082,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
726
1082
  };
727
1083
  await table.add([record], { mode });
728
1084
  } catch (error) {
729
- throw new Error(`Failed to persist workflow snapshot: ${error}`);
1085
+ throw new MastraError(
1086
+ {
1087
+ id: "LANCE_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
1088
+ domain: ErrorDomain.STORAGE,
1089
+ category: ErrorCategory.THIRD_PARTY,
1090
+ details: { workflowName, runId }
1091
+ },
1092
+ error
1093
+ );
730
1094
  }
731
1095
  }
732
1096
  async loadWorkflowSnapshot({
@@ -739,17 +1103,50 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
739
1103
  const records = await query.toArray();
740
1104
  return records.length > 0 ? JSON.parse(records[0].snapshot) : null;
741
1105
  } catch (error) {
742
- throw new Error(`Failed to load workflow snapshot: ${error}`);
1106
+ throw new MastraError(
1107
+ {
1108
+ id: "LANCE_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
1109
+ domain: ErrorDomain.STORAGE,
1110
+ category: ErrorCategory.THIRD_PARTY,
1111
+ details: { workflowName, runId }
1112
+ },
1113
+ error
1114
+ );
743
1115
  }
744
1116
  }
745
1117
  async getTracesPaginated(_args) {
746
- throw new Error("Method not implemented.");
1118
+ throw new MastraError(
1119
+ {
1120
+ id: "LANCE_STORE_GET_TRACES_PAGINATED_FAILED",
1121
+ domain: ErrorDomain.STORAGE,
1122
+ category: ErrorCategory.THIRD_PARTY
1123
+ },
1124
+ "Method not implemented."
1125
+ );
747
1126
  }
748
1127
  async getThreadsByResourceIdPaginated(_args) {
749
- throw new Error("Method not implemented.");
1128
+ throw new MastraError(
1129
+ {
1130
+ id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED",
1131
+ domain: ErrorDomain.STORAGE,
1132
+ category: ErrorCategory.THIRD_PARTY
1133
+ },
1134
+ "Method not implemented."
1135
+ );
750
1136
  }
751
1137
  async getMessagesPaginated(_args) {
752
- throw new Error("Method not implemented.");
1138
+ throw new MastraError(
1139
+ {
1140
+ id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
1141
+ domain: ErrorDomain.STORAGE,
1142
+ category: ErrorCategory.THIRD_PARTY
1143
+ },
1144
+ "Method not implemented."
1145
+ );
1146
+ }
1147
+ async updateMessages(_args) {
1148
+ this.logger.error("updateMessages is not yet implemented in LanceStore");
1149
+ throw new Error("Method not implemented");
753
1150
  }
754
1151
  };
755
1152
  var LanceFilterTranslator = class extends BaseFilterTranslator {
@@ -1103,7 +1500,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1103
1500
  instance.lanceClient = await connect(uri, options);
1104
1501
  return instance;
1105
1502
  } catch (e) {
1106
- throw new Error(`Failed to connect to LanceDB: ${e}`);
1503
+ throw new MastraError(
1504
+ {
1505
+ id: "STORAGE_LANCE_VECTOR_CONNECT_FAILED",
1506
+ domain: ErrorDomain.STORAGE,
1507
+ category: ErrorCategory.THIRD_PARTY,
1508
+ details: { uri }
1509
+ },
1510
+ e
1511
+ );
1107
1512
  }
1108
1513
  }
1109
1514
  /**
@@ -1127,14 +1532,27 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1127
1532
  columns = [],
1128
1533
  includeAllColumns = false
1129
1534
  }) {
1130
- if (!this.lanceClient) {
1131
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1132
- }
1133
- if (!tableName) {
1134
- throw new Error("tableName is required");
1135
- }
1136
- if (!queryVector) {
1137
- throw new Error("queryVector is required");
1535
+ try {
1536
+ if (!this.lanceClient) {
1537
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1538
+ }
1539
+ if (!tableName) {
1540
+ throw new Error("tableName is required");
1541
+ }
1542
+ if (!queryVector) {
1543
+ throw new Error("queryVector is required");
1544
+ }
1545
+ } catch (error) {
1546
+ throw new MastraError(
1547
+ {
1548
+ id: "STORAGE_LANCE_VECTOR_QUERY_FAILED_INVALID_ARGS",
1549
+ domain: ErrorDomain.STORAGE,
1550
+ category: ErrorCategory.USER,
1551
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1552
+ details: { tableName }
1553
+ },
1554
+ error
1555
+ );
1138
1556
  }
1139
1557
  try {
1140
1558
  const table = await this.lanceClient.openTable(tableName);
@@ -1173,7 +1591,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1173
1591
  };
1174
1592
  });
1175
1593
  } catch (error) {
1176
- throw new Error(`Failed to query vectors: ${error.message}`);
1594
+ throw new MastraError(
1595
+ {
1596
+ id: "STORAGE_LANCE_VECTOR_QUERY_FAILED",
1597
+ domain: ErrorDomain.STORAGE,
1598
+ category: ErrorCategory.THIRD_PARTY,
1599
+ details: { tableName, includeVector, columnsCount: columns?.length, includeAllColumns }
1600
+ },
1601
+ error
1602
+ );
1177
1603
  }
1178
1604
  }
1179
1605
  filterTranslator(filter) {
@@ -1206,14 +1632,27 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1206
1632
  return translator.translate(prefixedFilter);
1207
1633
  }
1208
1634
  async upsert({ tableName, vectors, metadata = [], ids = [] }) {
1209
- if (!this.lanceClient) {
1210
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1211
- }
1212
- if (!tableName) {
1213
- throw new Error("tableName is required");
1214
- }
1215
- if (!vectors || !Array.isArray(vectors) || vectors.length === 0) {
1216
- throw new Error("vectors array is required and must not be empty");
1635
+ try {
1636
+ if (!this.lanceClient) {
1637
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1638
+ }
1639
+ if (!tableName) {
1640
+ throw new Error("tableName is required");
1641
+ }
1642
+ if (!vectors || !Array.isArray(vectors) || vectors.length === 0) {
1643
+ throw new Error("vectors array is required and must not be empty");
1644
+ }
1645
+ } catch (error) {
1646
+ throw new MastraError(
1647
+ {
1648
+ id: "STORAGE_LANCE_VECTOR_UPSERT_FAILED_INVALID_ARGS",
1649
+ domain: ErrorDomain.STORAGE,
1650
+ category: ErrorCategory.USER,
1651
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1652
+ details: { tableName }
1653
+ },
1654
+ error
1655
+ );
1217
1656
  }
1218
1657
  try {
1219
1658
  const tables = await this.lanceClient.tableNames();
@@ -1240,7 +1679,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1240
1679
  await table.add(data, { mode: "overwrite" });
1241
1680
  return vectorIds;
1242
1681
  } catch (error) {
1243
- throw new Error(`Failed to upsert vectors: ${error.message}`);
1682
+ throw new MastraError(
1683
+ {
1684
+ id: "STORAGE_LANCE_VECTOR_UPSERT_FAILED",
1685
+ domain: ErrorDomain.STORAGE,
1686
+ category: ErrorCategory.THIRD_PARTY,
1687
+ details: { tableName, vectorCount: vectors.length, metadataCount: metadata.length, idsCount: ids.length }
1688
+ },
1689
+ error
1690
+ );
1244
1691
  }
1245
1692
  }
1246
1693
  /**
@@ -1260,29 +1707,78 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1260
1707
  }
1261
1708
  async createTable(tableName, data, options) {
1262
1709
  if (!this.lanceClient) {
1263
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1710
+ throw new MastraError({
1711
+ id: "STORAGE_LANCE_VECTOR_CREATE_TABLE_FAILED_INVALID_ARGS",
1712
+ domain: ErrorDomain.STORAGE,
1713
+ category: ErrorCategory.USER,
1714
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1715
+ details: { tableName }
1716
+ });
1717
+ }
1718
+ if (Array.isArray(data)) {
1719
+ data = data.map((record) => this.flattenObject(record));
1264
1720
  }
1265
1721
  try {
1266
- if (Array.isArray(data)) {
1267
- data = data.map((record) => this.flattenObject(record));
1268
- }
1269
1722
  return await this.lanceClient.createTable(tableName, data, options);
1270
1723
  } catch (error) {
1271
- throw new Error(`Failed to create table: ${error.message}`);
1724
+ throw new MastraError(
1725
+ {
1726
+ id: "STORAGE_LANCE_VECTOR_CREATE_TABLE_FAILED",
1727
+ domain: ErrorDomain.STORAGE,
1728
+ category: ErrorCategory.THIRD_PARTY,
1729
+ details: { tableName }
1730
+ },
1731
+ error
1732
+ );
1272
1733
  }
1273
1734
  }
1274
1735
  async listTables() {
1275
1736
  if (!this.lanceClient) {
1276
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1737
+ throw new MastraError({
1738
+ id: "STORAGE_LANCE_VECTOR_LIST_TABLES_FAILED_INVALID_ARGS",
1739
+ domain: ErrorDomain.STORAGE,
1740
+ category: ErrorCategory.USER,
1741
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1742
+ details: { methodName: "listTables" }
1743
+ });
1744
+ }
1745
+ try {
1746
+ return await this.lanceClient.tableNames();
1747
+ } catch (error) {
1748
+ throw new MastraError(
1749
+ {
1750
+ id: "STORAGE_LANCE_VECTOR_LIST_TABLES_FAILED",
1751
+ domain: ErrorDomain.STORAGE,
1752
+ category: ErrorCategory.THIRD_PARTY
1753
+ },
1754
+ error
1755
+ );
1277
1756
  }
1278
- return await this.lanceClient.tableNames();
1279
1757
  }
1280
1758
  async getTableSchema(tableName) {
1281
1759
  if (!this.lanceClient) {
1282
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1760
+ throw new MastraError({
1761
+ id: "STORAGE_LANCE_VECTOR_GET_TABLE_SCHEMA_FAILED_INVALID_ARGS",
1762
+ domain: ErrorDomain.STORAGE,
1763
+ category: ErrorCategory.USER,
1764
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1765
+ details: { tableName }
1766
+ });
1767
+ }
1768
+ try {
1769
+ const table = await this.lanceClient.openTable(tableName);
1770
+ return await table.schema();
1771
+ } catch (error) {
1772
+ throw new MastraError(
1773
+ {
1774
+ id: "STORAGE_LANCE_VECTOR_GET_TABLE_SCHEMA_FAILED",
1775
+ domain: ErrorDomain.STORAGE,
1776
+ category: ErrorCategory.THIRD_PARTY,
1777
+ details: { tableName }
1778
+ },
1779
+ error
1780
+ );
1283
1781
  }
1284
- const table = await this.lanceClient.openTable(tableName);
1285
- return await table.schema();
1286
1782
  }
1287
1783
  /**
1288
1784
  * indexName is actually a column name in a table in lanceDB
@@ -1294,10 +1790,10 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1294
1790
  metric = "cosine",
1295
1791
  indexConfig = {}
1296
1792
  }) {
1297
- if (!this.lanceClient) {
1298
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1299
- }
1300
1793
  try {
1794
+ if (!this.lanceClient) {
1795
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1796
+ }
1301
1797
  if (!tableName) {
1302
1798
  throw new Error("tableName is required");
1303
1799
  }
@@ -1307,6 +1803,18 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1307
1803
  if (typeof dimension !== "number" || dimension <= 0) {
1308
1804
  throw new Error("dimension must be a positive number");
1309
1805
  }
1806
+ } catch (err) {
1807
+ throw new MastraError(
1808
+ {
1809
+ id: "STORAGE_LANCE_VECTOR_CREATE_INDEX_FAILED_INVALID_ARGS",
1810
+ domain: ErrorDomain.STORAGE,
1811
+ category: ErrorCategory.USER,
1812
+ details: { tableName: tableName || "", indexName, dimension, metric }
1813
+ },
1814
+ err
1815
+ );
1816
+ }
1817
+ try {
1310
1818
  const tables = await this.lanceClient.tableNames();
1311
1819
  if (!tables.includes(tableName)) {
1312
1820
  throw new Error(
@@ -1341,12 +1849,26 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1341
1849
  });
1342
1850
  }
1343
1851
  } catch (error) {
1344
- throw new Error(`Failed to create index: ${error.message}`);
1852
+ throw new MastraError(
1853
+ {
1854
+ id: "STORAGE_LANCE_VECTOR_CREATE_INDEX_FAILED",
1855
+ domain: ErrorDomain.STORAGE,
1856
+ category: ErrorCategory.THIRD_PARTY,
1857
+ details: { tableName: tableName || "", indexName, dimension }
1858
+ },
1859
+ error
1860
+ );
1345
1861
  }
1346
1862
  }
1347
1863
  async listIndexes() {
1348
1864
  if (!this.lanceClient) {
1349
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1865
+ throw new MastraError({
1866
+ id: "STORAGE_LANCE_VECTOR_LIST_INDEXES_FAILED_INVALID_ARGS",
1867
+ domain: ErrorDomain.STORAGE,
1868
+ category: ErrorCategory.USER,
1869
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1870
+ details: { methodName: "listIndexes" }
1871
+ });
1350
1872
  }
1351
1873
  try {
1352
1874
  const tables = await this.lanceClient.tableNames();
@@ -1358,15 +1880,34 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1358
1880
  }
1359
1881
  return allIndices;
1360
1882
  } catch (error) {
1361
- throw new Error(`Failed to list indexes: ${error.message}`);
1883
+ throw new MastraError(
1884
+ {
1885
+ id: "STORAGE_LANCE_VECTOR_LIST_INDEXES_FAILED",
1886
+ domain: ErrorDomain.STORAGE,
1887
+ category: ErrorCategory.THIRD_PARTY
1888
+ },
1889
+ error
1890
+ );
1362
1891
  }
1363
1892
  }
1364
1893
  async describeIndex({ indexName }) {
1365
- if (!this.lanceClient) {
1366
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1367
- }
1368
- if (!indexName) {
1369
- throw new Error("indexName is required");
1894
+ try {
1895
+ if (!this.lanceClient) {
1896
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1897
+ }
1898
+ if (!indexName) {
1899
+ throw new Error("indexName is required");
1900
+ }
1901
+ } catch (err) {
1902
+ throw new MastraError(
1903
+ {
1904
+ id: "STORAGE_LANCE_VECTOR_DESCRIBE_INDEX_FAILED_INVALID_ARGS",
1905
+ domain: ErrorDomain.STORAGE,
1906
+ category: ErrorCategory.USER,
1907
+ details: { indexName }
1908
+ },
1909
+ err
1910
+ );
1370
1911
  }
1371
1912
  try {
1372
1913
  const tables = await this.lanceClient.tableNames();
@@ -1393,15 +1934,35 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1393
1934
  }
1394
1935
  throw new Error(`IndexName: ${indexName} not found`);
1395
1936
  } catch (error) {
1396
- throw new Error(`Failed to describe index: ${error.message}`);
1937
+ throw new MastraError(
1938
+ {
1939
+ id: "STORAGE_LANCE_VECTOR_DESCRIBE_INDEX_FAILED",
1940
+ domain: ErrorDomain.STORAGE,
1941
+ category: ErrorCategory.THIRD_PARTY,
1942
+ details: { indexName }
1943
+ },
1944
+ error
1945
+ );
1397
1946
  }
1398
1947
  }
1399
1948
  async deleteIndex({ indexName }) {
1400
- if (!this.lanceClient) {
1401
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1402
- }
1403
- if (!indexName) {
1404
- throw new Error("indexName is required");
1949
+ try {
1950
+ if (!this.lanceClient) {
1951
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1952
+ }
1953
+ if (!indexName) {
1954
+ throw new Error("indexName is required");
1955
+ }
1956
+ } catch (err) {
1957
+ throw new MastraError(
1958
+ {
1959
+ id: "STORAGE_LANCE_VECTOR_DELETE_INDEX_FAILED_INVALID_ARGS",
1960
+ domain: ErrorDomain.STORAGE,
1961
+ category: ErrorCategory.USER,
1962
+ details: { indexName }
1963
+ },
1964
+ err
1965
+ );
1405
1966
  }
1406
1967
  try {
1407
1968
  const tables = await this.lanceClient.tableNames();
@@ -1416,7 +1977,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1416
1977
  }
1417
1978
  throw new Error(`Index ${indexName} not found`);
1418
1979
  } catch (error) {
1419
- throw new Error(`Failed to delete index: ${error.message}`);
1980
+ throw new MastraError(
1981
+ {
1982
+ id: "STORAGE_LANCE_VECTOR_DELETE_INDEX_FAILED",
1983
+ domain: ErrorDomain.STORAGE,
1984
+ category: ErrorCategory.THIRD_PARTY,
1985
+ details: { indexName }
1986
+ },
1987
+ error
1988
+ );
1420
1989
  }
1421
1990
  }
1422
1991
  /**
@@ -1424,33 +1993,73 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1424
1993
  */
1425
1994
  async deleteAllTables() {
1426
1995
  if (!this.lanceClient) {
1427
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1996
+ throw new MastraError({
1997
+ id: "STORAGE_LANCE_VECTOR_DELETE_ALL_TABLES_FAILED_INVALID_ARGS",
1998
+ domain: ErrorDomain.STORAGE,
1999
+ category: ErrorCategory.USER,
2000
+ details: { methodName: "deleteAllTables" },
2001
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance"
2002
+ });
1428
2003
  }
1429
2004
  try {
1430
2005
  await this.lanceClient.dropAllTables();
1431
2006
  } catch (error) {
1432
- throw new Error(`Failed to delete tables: ${error.message}`);
2007
+ throw new MastraError(
2008
+ {
2009
+ id: "STORAGE_LANCE_VECTOR_DELETE_ALL_TABLES_FAILED",
2010
+ domain: ErrorDomain.STORAGE,
2011
+ category: ErrorCategory.THIRD_PARTY,
2012
+ details: { methodName: "deleteAllTables" }
2013
+ },
2014
+ error
2015
+ );
1433
2016
  }
1434
2017
  }
1435
2018
  async deleteTable(tableName) {
1436
2019
  if (!this.lanceClient) {
1437
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
2020
+ throw new MastraError({
2021
+ id: "STORAGE_LANCE_VECTOR_DELETE_TABLE_FAILED_INVALID_ARGS",
2022
+ domain: ErrorDomain.STORAGE,
2023
+ category: ErrorCategory.USER,
2024
+ details: { tableName },
2025
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance"
2026
+ });
1438
2027
  }
1439
2028
  try {
1440
2029
  await this.lanceClient.dropTable(tableName);
1441
2030
  } catch (error) {
1442
- throw new Error(`Failed to delete tables: ${error.message}`);
2031
+ throw new MastraError(
2032
+ {
2033
+ id: "STORAGE_LANCE_VECTOR_DELETE_TABLE_FAILED",
2034
+ domain: ErrorDomain.STORAGE,
2035
+ category: ErrorCategory.THIRD_PARTY,
2036
+ details: { tableName }
2037
+ },
2038
+ error
2039
+ );
1443
2040
  }
1444
2041
  }
1445
2042
  async updateVector({ indexName, id, update }) {
1446
- if (!this.lanceClient) {
1447
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1448
- }
1449
- if (!indexName) {
1450
- throw new Error("indexName is required");
1451
- }
1452
- if (!id) {
1453
- throw new Error("id is required");
2043
+ try {
2044
+ if (!this.lanceClient) {
2045
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
2046
+ }
2047
+ if (!indexName) {
2048
+ throw new Error("indexName is required");
2049
+ }
2050
+ if (!id) {
2051
+ throw new Error("id is required");
2052
+ }
2053
+ } catch (err) {
2054
+ throw new MastraError(
2055
+ {
2056
+ id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED_INVALID_ARGS",
2057
+ domain: ErrorDomain.STORAGE,
2058
+ category: ErrorCategory.USER,
2059
+ details: { indexName, id }
2060
+ },
2061
+ err
2062
+ );
1454
2063
  }
1455
2064
  try {
1456
2065
  const tables = await this.lanceClient.tableNames();
@@ -1504,18 +2113,38 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1504
2113
  }
1505
2114
  throw new Error(`No table found with column/index '${indexName}'`);
1506
2115
  } catch (error) {
1507
- throw new Error(`Failed to update index: ${error.message}`);
2116
+ throw new MastraError(
2117
+ {
2118
+ id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED",
2119
+ domain: ErrorDomain.STORAGE,
2120
+ category: ErrorCategory.THIRD_PARTY,
2121
+ details: { indexName, id, hasVector: !!update.vector, hasMetadata: !!update.metadata }
2122
+ },
2123
+ error
2124
+ );
1508
2125
  }
1509
2126
  }
1510
2127
  async deleteVector({ indexName, id }) {
1511
- if (!this.lanceClient) {
1512
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1513
- }
1514
- if (!indexName) {
1515
- throw new Error("indexName is required");
1516
- }
1517
- if (!id) {
1518
- throw new Error("id is required");
2128
+ try {
2129
+ if (!this.lanceClient) {
2130
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
2131
+ }
2132
+ if (!indexName) {
2133
+ throw new Error("indexName is required");
2134
+ }
2135
+ if (!id) {
2136
+ throw new Error("id is required");
2137
+ }
2138
+ } catch (err) {
2139
+ throw new MastraError(
2140
+ {
2141
+ id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED_INVALID_ARGS",
2142
+ domain: ErrorDomain.STORAGE,
2143
+ category: ErrorCategory.USER,
2144
+ details: { indexName, id }
2145
+ },
2146
+ err
2147
+ );
1519
2148
  }
1520
2149
  try {
1521
2150
  const tables = await this.lanceClient.tableNames();
@@ -1537,7 +2166,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
1537
2166
  }
1538
2167
  throw new Error(`No table found with column/index '${indexName}'`);
1539
2168
  } catch (error) {
1540
- throw new Error(`Failed to delete index: ${error.message}`);
2169
+ throw new MastraError(
2170
+ {
2171
+ id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED",
2172
+ domain: ErrorDomain.STORAGE,
2173
+ category: ErrorCategory.THIRD_PARTY,
2174
+ details: { indexName, id }
2175
+ },
2176
+ error
2177
+ );
1541
2178
  }
1542
2179
  }
1543
2180
  /**