@mastra/lance 0.0.0-fix-generate-title-20250616171351 → 0.0.0-fix-fetch-workflow-runs-20250624231457

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.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var lancedb = require('@lancedb/lancedb');
4
4
  var agent = require('@mastra/core/agent');
5
+ var error = require('@mastra/core/error');
5
6
  var storage = require('@mastra/core/storage');
6
7
  var apacheArrow = require('apache-arrow');
7
8
  var vector = require('@mastra/core/vector');
@@ -38,8 +39,26 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
38
39
  instance.lanceClient = await lancedb.connect(uri, options);
39
40
  return instance;
40
41
  } catch (e) {
41
- throw new Error(`Failed to connect to LanceDB: ${e}`);
42
+ throw new error.MastraError(
43
+ {
44
+ id: "STORAGE_LANCE_STORAGE_CONNECT_FAILED",
45
+ domain: error.ErrorDomain.STORAGE,
46
+ category: error.ErrorCategory.THIRD_PARTY,
47
+ text: `Failed to connect to LanceDB: ${e.message || e}`,
48
+ details: { uri, optionsProvided: !!options }
49
+ },
50
+ e
51
+ );
52
+ }
53
+ }
54
+ getPrimaryKeys(tableName) {
55
+ let primaryId = ["id"];
56
+ if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
57
+ primaryId = ["workflow_name", "run_id"];
58
+ } else if (tableName === storage.TABLE_EVALS) {
59
+ primaryId = ["agent_name", "metric_name", "run_id"];
42
60
  }
61
+ return primaryId;
43
62
  }
44
63
  /**
45
64
  * @internal
@@ -52,11 +71,40 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
52
71
  tableName,
53
72
  schema
54
73
  }) {
74
+ try {
75
+ if (!this.lanceClient) {
76
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
77
+ }
78
+ if (!tableName) {
79
+ throw new Error("tableName is required for createTable.");
80
+ }
81
+ if (!schema) {
82
+ throw new Error("schema is required for createTable.");
83
+ }
84
+ } catch (error$1) {
85
+ throw new error.MastraError(
86
+ {
87
+ id: "STORAGE_LANCE_STORAGE_CREATE_TABLE_INVALID_ARGS",
88
+ domain: error.ErrorDomain.STORAGE,
89
+ category: error.ErrorCategory.USER,
90
+ details: { tableName }
91
+ },
92
+ error$1
93
+ );
94
+ }
55
95
  try {
56
96
  const arrowSchema = this.translateSchema(schema);
57
97
  await this.lanceClient.createEmptyTable(tableName, arrowSchema);
58
- } catch (error) {
59
- throw new Error(`Failed to create table: ${error}`);
98
+ } catch (error$1) {
99
+ throw new error.MastraError(
100
+ {
101
+ id: "STORAGE_LANCE_STORAGE_CREATE_TABLE_FAILED",
102
+ domain: error.ErrorDomain.STORAGE,
103
+ category: error.ErrorCategory.THIRD_PARTY,
104
+ details: { tableName }
105
+ },
106
+ error$1
107
+ );
60
108
  }
61
109
  }
62
110
  translateSchema(schema) {
@@ -99,14 +147,41 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
99
147
  * @param tableName Name of the table to drop
100
148
  */
101
149
  async dropTable(tableName) {
150
+ try {
151
+ if (!this.lanceClient) {
152
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
153
+ }
154
+ if (!tableName) {
155
+ throw new Error("tableName is required for dropTable.");
156
+ }
157
+ } catch (validationError) {
158
+ throw new error.MastraError(
159
+ {
160
+ id: "STORAGE_LANCE_STORAGE_DROP_TABLE_INVALID_ARGS",
161
+ domain: error.ErrorDomain.STORAGE,
162
+ category: error.ErrorCategory.USER,
163
+ text: validationError.message,
164
+ details: { tableName }
165
+ },
166
+ validationError
167
+ );
168
+ }
102
169
  try {
103
170
  await this.lanceClient.dropTable(tableName);
104
- } catch (error) {
105
- if (error.toString().includes("was not found")) {
171
+ } catch (error$1) {
172
+ if (error$1.toString().includes("was not found") || error$1.message?.includes("Table not found")) {
106
173
  this.logger.debug(`Table '${tableName}' does not exist, skipping drop`);
107
174
  return;
108
175
  }
109
- throw new Error(`Failed to drop table: ${error}`);
176
+ throw new error.MastraError(
177
+ {
178
+ id: "STORAGE_LANCE_STORAGE_DROP_TABLE_FAILED",
179
+ domain: error.ErrorDomain.STORAGE,
180
+ category: error.ErrorCategory.THIRD_PARTY,
181
+ details: { tableName }
182
+ },
183
+ error$1
184
+ );
110
185
  }
111
186
  }
112
187
  /**
@@ -115,6 +190,25 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
115
190
  * @returns Table schema
116
191
  */
117
192
  async getTableSchema(tableName) {
193
+ try {
194
+ if (!this.lanceClient) {
195
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
196
+ }
197
+ if (!tableName) {
198
+ throw new Error("tableName is required for getTableSchema.");
199
+ }
200
+ } catch (validationError) {
201
+ throw new error.MastraError(
202
+ {
203
+ id: "STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_INVALID_ARGS",
204
+ domain: error.ErrorDomain.STORAGE,
205
+ category: error.ErrorCategory.USER,
206
+ text: validationError.message,
207
+ details: { tableName }
208
+ },
209
+ validationError
210
+ );
211
+ }
118
212
  try {
119
213
  const table = await this.lanceClient.openTable(tableName);
120
214
  const rawSchema = await table.schema();
@@ -126,8 +220,16 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
126
220
  return fields.map((field) => field.name);
127
221
  }
128
222
  };
129
- } catch (error) {
130
- throw new Error(`Failed to get table schema: ${error}`);
223
+ } catch (error$1) {
224
+ throw new error.MastraError(
225
+ {
226
+ id: "STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_FAILED",
227
+ domain: error.ErrorDomain.STORAGE,
228
+ category: error.ErrorCategory.THIRD_PARTY,
229
+ details: { tableName }
230
+ },
231
+ error$1
232
+ );
131
233
  }
132
234
  }
133
235
  getDefaultValue(type) {
@@ -158,32 +260,101 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
158
260
  schema,
159
261
  ifNotExists
160
262
  }) {
161
- const table = await this.lanceClient.openTable(tableName);
162
- const currentSchema = await table.schema();
163
- const existingFields = new Set(currentSchema.fields.map((f) => f.name));
164
- const typeMap = {
165
- text: "string",
166
- integer: "int",
167
- bigint: "bigint",
168
- timestamp: "timestamp",
169
- jsonb: "string",
170
- uuid: "string"
171
- };
172
- const columnsToAdd = ifNotExists.filter((col) => schema[col] && !existingFields.has(col)).map((col) => {
173
- const colDef = schema[col];
174
- return {
175
- name: col,
176
- valueSql: colDef?.nullable ? `cast(NULL as ${typeMap[colDef.type ?? "text"]})` : `cast(${this.getDefaultValue(colDef?.type ?? "text")} as ${typeMap[colDef?.type ?? "text"]})`
263
+ try {
264
+ if (!this.lanceClient) {
265
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
266
+ }
267
+ if (!tableName) {
268
+ throw new Error("tableName is required for alterTable.");
269
+ }
270
+ if (!schema) {
271
+ throw new Error("schema is required for alterTable.");
272
+ }
273
+ if (!ifNotExists || ifNotExists.length === 0) {
274
+ this.logger.debug("No columns specified to add in alterTable, skipping.");
275
+ return;
276
+ }
277
+ } catch (validationError) {
278
+ throw new error.MastraError(
279
+ {
280
+ id: "STORAGE_LANCE_STORAGE_ALTER_TABLE_INVALID_ARGS",
281
+ domain: error.ErrorDomain.STORAGE,
282
+ category: error.ErrorCategory.USER,
283
+ text: validationError.message,
284
+ details: { tableName }
285
+ },
286
+ validationError
287
+ );
288
+ }
289
+ try {
290
+ const table = await this.lanceClient.openTable(tableName);
291
+ const currentSchema = await table.schema();
292
+ const existingFields = new Set(currentSchema.fields.map((f) => f.name));
293
+ const typeMap = {
294
+ text: "string",
295
+ integer: "int",
296
+ bigint: "bigint",
297
+ timestamp: "timestamp",
298
+ jsonb: "string",
299
+ uuid: "string"
177
300
  };
178
- });
179
- if (columnsToAdd.length > 0) {
180
- await table.addColumns(columnsToAdd);
181
- this.logger?.info?.(`Added columns [${columnsToAdd.map((c) => c.name).join(", ")}] to table ${tableName}`);
301
+ const columnsToAdd = ifNotExists.filter((col) => schema[col] && !existingFields.has(col)).map((col) => {
302
+ const colDef = schema[col];
303
+ return {
304
+ name: col,
305
+ valueSql: colDef?.nullable ? `cast(NULL as ${typeMap[colDef.type ?? "text"]})` : `cast(${this.getDefaultValue(colDef?.type ?? "text")} as ${typeMap[colDef?.type ?? "text"]})`
306
+ };
307
+ });
308
+ if (columnsToAdd.length > 0) {
309
+ await table.addColumns(columnsToAdd);
310
+ this.logger?.info?.(`Added columns [${columnsToAdd.map((c) => c.name).join(", ")}] to table ${tableName}`);
311
+ }
312
+ } catch (error$1) {
313
+ throw new error.MastraError(
314
+ {
315
+ id: "STORAGE_LANCE_STORAGE_ALTER_TABLE_FAILED",
316
+ domain: error.ErrorDomain.STORAGE,
317
+ category: error.ErrorCategory.THIRD_PARTY,
318
+ details: { tableName }
319
+ },
320
+ error$1
321
+ );
182
322
  }
183
323
  }
184
324
  async clearTable({ tableName }) {
185
- const table = await this.lanceClient.openTable(tableName);
186
- await table.delete("1=1");
325
+ try {
326
+ if (!this.lanceClient) {
327
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
328
+ }
329
+ if (!tableName) {
330
+ throw new Error("tableName is required for clearTable.");
331
+ }
332
+ } catch (validationError) {
333
+ throw new error.MastraError(
334
+ {
335
+ id: "STORAGE_LANCE_STORAGE_CLEAR_TABLE_INVALID_ARGS",
336
+ domain: error.ErrorDomain.STORAGE,
337
+ category: error.ErrorCategory.USER,
338
+ text: validationError.message,
339
+ details: { tableName }
340
+ },
341
+ validationError
342
+ );
343
+ }
344
+ try {
345
+ const table = await this.lanceClient.openTable(tableName);
346
+ await table.delete("1=1");
347
+ } catch (error$1) {
348
+ throw new error.MastraError(
349
+ {
350
+ id: "STORAGE_LANCE_STORAGE_CLEAR_TABLE_FAILED",
351
+ domain: error.ErrorDomain.STORAGE,
352
+ category: error.ErrorCategory.THIRD_PARTY,
353
+ details: { tableName }
354
+ },
355
+ error$1
356
+ );
357
+ }
187
358
  }
188
359
  /**
189
360
  * 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.
@@ -191,8 +362,31 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
191
362
  * @param record The record to insert.
192
363
  */
193
364
  async insert({ tableName, record }) {
365
+ try {
366
+ if (!this.lanceClient) {
367
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
368
+ }
369
+ if (!tableName) {
370
+ throw new Error("tableName is required for insert.");
371
+ }
372
+ if (!record || Object.keys(record).length === 0) {
373
+ throw new Error("record is required and cannot be empty for insert.");
374
+ }
375
+ } catch (validationError) {
376
+ throw new error.MastraError(
377
+ {
378
+ id: "STORAGE_LANCE_STORAGE_INSERT_INVALID_ARGS",
379
+ domain: error.ErrorDomain.STORAGE,
380
+ category: error.ErrorCategory.USER,
381
+ text: validationError.message,
382
+ details: { tableName }
383
+ },
384
+ validationError
385
+ );
386
+ }
194
387
  try {
195
388
  const table = await this.lanceClient.openTable(tableName);
389
+ const primaryId = this.getPrimaryKeys(tableName);
196
390
  const processedRecord = { ...record };
197
391
  for (const key in processedRecord) {
198
392
  if (processedRecord[key] !== null && typeof processedRecord[key] === "object" && !(processedRecord[key] instanceof Date)) {
@@ -200,9 +394,17 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
200
394
  processedRecord[key] = JSON.stringify(processedRecord[key]);
201
395
  }
202
396
  }
203
- await table.add([processedRecord], { mode: "overwrite" });
204
- } catch (error) {
205
- throw new Error(`Failed to insert record: ${error}`);
397
+ await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([processedRecord]);
398
+ } catch (error$1) {
399
+ throw new error.MastraError(
400
+ {
401
+ id: "STORAGE_LANCE_STORAGE_INSERT_FAILED",
402
+ domain: error.ErrorDomain.STORAGE,
403
+ category: error.ErrorCategory.THIRD_PARTY,
404
+ details: { tableName }
405
+ },
406
+ error$1
407
+ );
206
408
  }
207
409
  }
208
410
  /**
@@ -211,8 +413,31 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
211
413
  * @param records The records to insert.
212
414
  */
213
415
  async batchInsert({ tableName, records }) {
416
+ try {
417
+ if (!this.lanceClient) {
418
+ throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
419
+ }
420
+ if (!tableName) {
421
+ throw new Error("tableName is required for batchInsert.");
422
+ }
423
+ if (!records || records.length === 0) {
424
+ throw new Error("records array is required and cannot be empty for batchInsert.");
425
+ }
426
+ } catch (validationError) {
427
+ throw new error.MastraError(
428
+ {
429
+ id: "STORAGE_LANCE_STORAGE_BATCH_INSERT_INVALID_ARGS",
430
+ domain: error.ErrorDomain.STORAGE,
431
+ category: error.ErrorCategory.USER,
432
+ text: validationError.message,
433
+ details: { tableName }
434
+ },
435
+ validationError
436
+ );
437
+ }
214
438
  try {
215
439
  const table = await this.lanceClient.openTable(tableName);
440
+ const primaryId = this.getPrimaryKeys(tableName);
216
441
  const processedRecords = records.map((record) => {
217
442
  const processedRecord = { ...record };
218
443
  for (const key in processedRecord) {
@@ -223,9 +448,17 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
223
448
  }
224
449
  return processedRecord;
225
450
  });
226
- await table.add(processedRecords, { mode: "overwrite" });
227
- } catch (error) {
228
- throw new Error(`Failed to batch insert records: ${error}`);
451
+ await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(processedRecords);
452
+ } catch (error$1) {
453
+ throw new error.MastraError(
454
+ {
455
+ id: "STORAGE_LANCE_STORAGE_BATCH_INSERT_FAILED",
456
+ domain: error.ErrorDomain.STORAGE,
457
+ category: error.ErrorCategory.THIRD_PARTY,
458
+ details: { tableName }
459
+ },
460
+ error$1
461
+ );
229
462
  }
230
463
  }
231
464
  /**
@@ -236,6 +469,28 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
236
469
  * @returns The loaded record with proper type conversions, or null if not found
237
470
  */
238
471
  async load({ tableName, keys }) {
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 load.");
478
+ }
479
+ if (!keys || Object.keys(keys).length === 0) {
480
+ throw new Error("keys are required and cannot be empty for load.");
481
+ }
482
+ } catch (validationError) {
483
+ throw new error.MastraError(
484
+ {
485
+ id: "STORAGE_LANCE_STORAGE_LOAD_INVALID_ARGS",
486
+ domain: error.ErrorDomain.STORAGE,
487
+ category: error.ErrorCategory.USER,
488
+ text: validationError.message,
489
+ details: { tableName }
490
+ },
491
+ validationError
492
+ );
493
+ }
239
494
  try {
240
495
  const table = await this.lanceClient.openTable(tableName);
241
496
  const tableSchema = await this.getTableSchema(tableName);
@@ -262,8 +517,17 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
262
517
  return null;
263
518
  }
264
519
  return this.processResultWithTypeConversion(result[0], tableSchema);
265
- } catch (error) {
266
- throw new Error(`Failed to load record: ${error}`);
520
+ } catch (error$1) {
521
+ if (error$1 instanceof error.MastraError) throw error$1;
522
+ throw new error.MastraError(
523
+ {
524
+ id: "STORAGE_LANCE_STORAGE_LOAD_FAILED",
525
+ domain: error.ErrorDomain.STORAGE,
526
+ category: error.ErrorCategory.THIRD_PARTY,
527
+ details: { tableName, keyCount: Object.keys(keys).length, firstKey: Object.keys(keys)[0] ?? "" }
528
+ },
529
+ error$1
530
+ );
267
531
  }
268
532
  }
269
533
  /**
@@ -337,8 +601,15 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
337
601
  getThreadById({ threadId }) {
338
602
  try {
339
603
  return this.load({ tableName: storage.TABLE_THREADS, keys: { id: threadId } });
340
- } catch (error) {
341
- throw new Error(`Failed to get thread by ID: ${error}`);
604
+ } catch (error$1) {
605
+ throw new error.MastraError(
606
+ {
607
+ id: "LANCE_STORE_GET_THREAD_BY_ID_FAILED",
608
+ domain: error.ErrorDomain.STORAGE,
609
+ category: error.ErrorCategory.THIRD_PARTY
610
+ },
611
+ error$1
612
+ );
342
613
  }
343
614
  }
344
615
  async getThreadsByResourceId({ resourceId }) {
@@ -350,8 +621,15 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
350
621
  records,
351
622
  await this.getTableSchema(storage.TABLE_THREADS)
352
623
  );
353
- } catch (error) {
354
- throw new Error(`Failed to get threads by resource ID: ${error}`);
624
+ } catch (error$1) {
625
+ throw new error.MastraError(
626
+ {
627
+ id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
628
+ domain: error.ErrorDomain.STORAGE,
629
+ category: error.ErrorCategory.THIRD_PARTY
630
+ },
631
+ error$1
632
+ );
355
633
  }
356
634
  }
357
635
  /**
@@ -365,8 +643,15 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
365
643
  const table = await this.lanceClient.openTable(storage.TABLE_THREADS);
366
644
  await table.add([record], { mode: "append" });
367
645
  return thread;
368
- } catch (error) {
369
- throw new Error(`Failed to save thread: ${error}`);
646
+ } catch (error$1) {
647
+ throw new error.MastraError(
648
+ {
649
+ id: "LANCE_STORE_SAVE_THREAD_FAILED",
650
+ domain: error.ErrorDomain.STORAGE,
651
+ category: error.ErrorCategory.THIRD_PARTY
652
+ },
653
+ error$1
654
+ );
370
655
  }
371
656
  }
372
657
  async updateThread({
@@ -377,23 +662,37 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
377
662
  try {
378
663
  const record = { id, title, metadata: JSON.stringify(metadata) };
379
664
  const table = await this.lanceClient.openTable(storage.TABLE_THREADS);
380
- await table.add([record], { mode: "overwrite" });
665
+ await table.mergeInsert("id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([record]);
381
666
  const query = table.query().where(`id = '${id}'`);
382
667
  const records = await query.toArray();
383
668
  return this.processResultWithTypeConversion(
384
669
  records[0],
385
670
  await this.getTableSchema(storage.TABLE_THREADS)
386
671
  );
387
- } catch (error) {
388
- throw new Error(`Failed to update thread: ${error}`);
672
+ } catch (error$1) {
673
+ throw new error.MastraError(
674
+ {
675
+ id: "LANCE_STORE_UPDATE_THREAD_FAILED",
676
+ domain: error.ErrorDomain.STORAGE,
677
+ category: error.ErrorCategory.THIRD_PARTY
678
+ },
679
+ error$1
680
+ );
389
681
  }
390
682
  }
391
683
  async deleteThread({ threadId }) {
392
684
  try {
393
685
  const table = await this.lanceClient.openTable(storage.TABLE_THREADS);
394
686
  await table.delete(`id = '${threadId}'`);
395
- } catch (error) {
396
- throw new Error(`Failed to delete thread: ${error}`);
687
+ } catch (error$1) {
688
+ throw new error.MastraError(
689
+ {
690
+ id: "LANCE_STORE_DELETE_THREAD_FAILED",
691
+ domain: error.ErrorDomain.STORAGE,
692
+ category: error.ErrorCategory.THIRD_PARTY
693
+ },
694
+ error$1
695
+ );
397
696
  }
398
697
  }
399
698
  /**
@@ -455,6 +754,7 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
455
754
  if (threadConfig) {
456
755
  throw new Error("ThreadConfig is not supported by LanceDB storage");
457
756
  }
757
+ const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
458
758
  const table = await this.lanceClient.openTable(storage.TABLE_MESSAGES);
459
759
  let query = table.query().where(`\`threadId\` = '${threadId}'`);
460
760
  if (selectBy) {
@@ -473,8 +773,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
473
773
  if (selectBy?.include && selectBy.include.length > 0) {
474
774
  records = this.processMessagesWithContext(records, selectBy.include);
475
775
  }
476
- if (selectBy?.last !== void 0 && selectBy.last !== false) {
477
- records = records.slice(-selectBy.last);
776
+ if (limit !== Number.MAX_SAFE_INTEGER) {
777
+ records = records.slice(-limit);
478
778
  }
479
779
  const messages = this.processResultWithTypeConversion(records, await this.getTableSchema(storage.TABLE_MESSAGES));
480
780
  const normalized = messages.map((msg) => ({
@@ -490,8 +790,15 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
490
790
  const list = new agent.MessageList({ threadId, resourceId }).add(normalized, "memory");
491
791
  if (format === "v2") return list.get.all.v2();
492
792
  return list.get.all.v1();
493
- } catch (error) {
494
- throw new Error(`Failed to get messages: ${error}`);
793
+ } catch (error$1) {
794
+ throw new error.MastraError(
795
+ {
796
+ id: "LANCE_STORE_GET_MESSAGES_FAILED",
797
+ domain: error.ErrorDomain.STORAGE,
798
+ category: error.ErrorCategory.THIRD_PARTY
799
+ },
800
+ error$1
801
+ );
495
802
  }
496
803
  }
497
804
  async saveMessages(args) {
@@ -509,12 +816,19 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
509
816
  content: JSON.stringify(message.content)
510
817
  }));
511
818
  const table = await this.lanceClient.openTable(storage.TABLE_MESSAGES);
512
- await table.add(transformedMessages, { mode: "overwrite" });
819
+ await table.mergeInsert("id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(transformedMessages);
513
820
  const list = new agent.MessageList().add(messages, "memory");
514
821
  if (format === `v2`) return list.get.all.v2();
515
822
  return list.get.all.v1();
516
- } catch (error) {
517
- throw new Error(`Failed to save messages: ${error}`);
823
+ } catch (error$1) {
824
+ throw new error.MastraError(
825
+ {
826
+ id: "LANCE_STORE_SAVE_MESSAGES_FAILED",
827
+ domain: error.ErrorDomain.STORAGE,
828
+ category: error.ErrorCategory.THIRD_PARTY
829
+ },
830
+ error$1
831
+ );
518
832
  }
519
833
  }
520
834
  async saveTrace({ trace }) {
@@ -530,8 +844,15 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
530
844
  };
531
845
  await table.add([record], { mode: "append" });
532
846
  return trace;
533
- } catch (error) {
534
- throw new Error(`Failed to save trace: ${error}`);
847
+ } catch (error$1) {
848
+ throw new error.MastraError(
849
+ {
850
+ id: "LANCE_STORE_SAVE_TRACE_FAILED",
851
+ domain: error.ErrorDomain.STORAGE,
852
+ category: error.ErrorCategory.THIRD_PARTY
853
+ },
854
+ error$1
855
+ );
535
856
  }
536
857
  }
537
858
  async getTraceById({ traceId }) {
@@ -540,8 +861,15 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
540
861
  const query = table.query().where(`id = '${traceId}'`);
541
862
  const records = await query.toArray();
542
863
  return this.processResultWithTypeConversion(records[0], await this.getTableSchema(storage.TABLE_TRACES));
543
- } catch (error) {
544
- throw new Error(`Failed to get trace by ID: ${error}`);
864
+ } catch (error$1) {
865
+ throw new error.MastraError(
866
+ {
867
+ id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
868
+ domain: error.ErrorDomain.STORAGE,
869
+ category: error.ErrorCategory.THIRD_PARTY
870
+ },
871
+ error$1
872
+ );
545
873
  }
546
874
  }
547
875
  async getTraces({
@@ -582,8 +910,16 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
582
910
  createdAt: new Date(record.createdAt)
583
911
  };
584
912
  });
585
- } catch (error) {
586
- throw new Error(`Failed to get traces: ${error}`);
913
+ } catch (error$1) {
914
+ throw new error.MastraError(
915
+ {
916
+ id: "LANCE_STORE_GET_TRACES_FAILED",
917
+ domain: error.ErrorDomain.STORAGE,
918
+ category: error.ErrorCategory.THIRD_PARTY,
919
+ details: { name: name ?? "", scope: scope ?? "" }
920
+ },
921
+ error$1
922
+ );
587
923
  }
588
924
  }
589
925
  async saveEvals({ evals }) {
@@ -603,8 +939,15 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
603
939
  }));
604
940
  await table.add(transformedEvals, { mode: "append" });
605
941
  return evals;
606
- } catch (error) {
607
- throw new Error(`Failed to save evals: ${error}`);
942
+ } catch (error$1) {
943
+ throw new error.MastraError(
944
+ {
945
+ id: "LANCE_STORE_SAVE_EVALS_FAILED",
946
+ domain: error.ErrorDomain.STORAGE,
947
+ category: error.ErrorCategory.THIRD_PARTY
948
+ },
949
+ error$1
950
+ );
608
951
  }
609
952
  }
610
953
  async getEvalsByAgentName(agentName, type) {
@@ -630,8 +973,16 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
630
973
  createdAt: new Date(record.created_at).toString()
631
974
  };
632
975
  });
633
- } catch (error) {
634
- throw new Error(`Failed to get evals by agent name: ${error}`);
976
+ } catch (error$1) {
977
+ throw new error.MastraError(
978
+ {
979
+ id: "LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
980
+ domain: error.ErrorDomain.STORAGE,
981
+ category: error.ErrorCategory.THIRD_PARTY,
982
+ details: { agentName }
983
+ },
984
+ error$1
985
+ );
635
986
  }
636
987
  }
637
988
  parseWorkflowRun(row) {
@@ -676,8 +1027,16 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
676
1027
  runs: records.map((record) => this.parseWorkflowRun(record)),
677
1028
  total: records.length
678
1029
  };
679
- } catch (error) {
680
- throw new Error(`Failed to get workflow runs: ${error}`);
1030
+ } catch (error$1) {
1031
+ throw new error.MastraError(
1032
+ {
1033
+ id: "LANCE_STORE_GET_WORKFLOW_RUNS_FAILED",
1034
+ domain: error.ErrorDomain.STORAGE,
1035
+ category: error.ErrorCategory.THIRD_PARTY,
1036
+ details: { namespace: args?.namespace ?? "", workflowName: args?.workflowName ?? "" }
1037
+ },
1038
+ error$1
1039
+ );
681
1040
  }
682
1041
  }
683
1042
  /**
@@ -697,8 +1056,16 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
697
1056
  if (records.length === 0) return null;
698
1057
  const record = records[0];
699
1058
  return this.parseWorkflowRun(record);
700
- } catch (error) {
701
- throw new Error(`Failed to get workflow run by id: ${error}`);
1059
+ } catch (error$1) {
1060
+ throw new error.MastraError(
1061
+ {
1062
+ id: "LANCE_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
1063
+ domain: error.ErrorDomain.STORAGE,
1064
+ category: error.ErrorCategory.THIRD_PARTY,
1065
+ details: { runId: args.runId, workflowName: args.workflowName ?? "" }
1066
+ },
1067
+ error$1
1068
+ );
702
1069
  }
703
1070
  }
704
1071
  async persistWorkflowSnapshot({
@@ -712,10 +1079,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
712
1079
  const records = await query.toArray();
713
1080
  let createdAt;
714
1081
  const now = Date.now();
715
- let mode = "append";
716
1082
  if (records.length > 0) {
717
1083
  createdAt = records[0].createdAt ?? now;
718
- mode = "overwrite";
719
1084
  } else {
720
1085
  createdAt = now;
721
1086
  }
@@ -726,9 +1091,17 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
726
1091
  createdAt,
727
1092
  updatedAt: now
728
1093
  };
729
- await table.add([record], { mode });
730
- } catch (error) {
731
- throw new Error(`Failed to persist workflow snapshot: ${error}`);
1094
+ await table.mergeInsert(["workflow_name", "run_id"]).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([record]);
1095
+ } catch (error$1) {
1096
+ throw new error.MastraError(
1097
+ {
1098
+ id: "LANCE_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
1099
+ domain: error.ErrorDomain.STORAGE,
1100
+ category: error.ErrorCategory.THIRD_PARTY,
1101
+ details: { workflowName, runId }
1102
+ },
1103
+ error$1
1104
+ );
732
1105
  }
733
1106
  }
734
1107
  async loadWorkflowSnapshot({
@@ -740,18 +1113,51 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
740
1113
  const query = table.query().where(`workflow_name = '${workflowName}' AND run_id = '${runId}'`);
741
1114
  const records = await query.toArray();
742
1115
  return records.length > 0 ? JSON.parse(records[0].snapshot) : null;
743
- } catch (error) {
744
- throw new Error(`Failed to load workflow snapshot: ${error}`);
1116
+ } catch (error$1) {
1117
+ throw new error.MastraError(
1118
+ {
1119
+ id: "LANCE_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
1120
+ domain: error.ErrorDomain.STORAGE,
1121
+ category: error.ErrorCategory.THIRD_PARTY,
1122
+ details: { workflowName, runId }
1123
+ },
1124
+ error$1
1125
+ );
745
1126
  }
746
1127
  }
747
1128
  async getTracesPaginated(_args) {
748
- throw new Error("Method not implemented.");
1129
+ throw new error.MastraError(
1130
+ {
1131
+ id: "LANCE_STORE_GET_TRACES_PAGINATED_FAILED",
1132
+ domain: error.ErrorDomain.STORAGE,
1133
+ category: error.ErrorCategory.THIRD_PARTY
1134
+ },
1135
+ "Method not implemented."
1136
+ );
749
1137
  }
750
1138
  async getThreadsByResourceIdPaginated(_args) {
751
- throw new Error("Method not implemented.");
1139
+ throw new error.MastraError(
1140
+ {
1141
+ id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED",
1142
+ domain: error.ErrorDomain.STORAGE,
1143
+ category: error.ErrorCategory.THIRD_PARTY
1144
+ },
1145
+ "Method not implemented."
1146
+ );
752
1147
  }
753
1148
  async getMessagesPaginated(_args) {
754
- throw new Error("Method not implemented.");
1149
+ throw new error.MastraError(
1150
+ {
1151
+ id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
1152
+ domain: error.ErrorDomain.STORAGE,
1153
+ category: error.ErrorCategory.THIRD_PARTY
1154
+ },
1155
+ "Method not implemented."
1156
+ );
1157
+ }
1158
+ async updateMessages(_args) {
1159
+ this.logger.error("updateMessages is not yet implemented in LanceStore");
1160
+ throw new Error("Method not implemented");
755
1161
  }
756
1162
  };
757
1163
  var LanceFilterTranslator = class extends filter.BaseFilterTranslator {
@@ -1105,7 +1511,15 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1105
1511
  instance.lanceClient = await lancedb.connect(uri, options);
1106
1512
  return instance;
1107
1513
  } catch (e) {
1108
- throw new Error(`Failed to connect to LanceDB: ${e}`);
1514
+ throw new error.MastraError(
1515
+ {
1516
+ id: "STORAGE_LANCE_VECTOR_CONNECT_FAILED",
1517
+ domain: error.ErrorDomain.STORAGE,
1518
+ category: error.ErrorCategory.THIRD_PARTY,
1519
+ details: { uri }
1520
+ },
1521
+ e
1522
+ );
1109
1523
  }
1110
1524
  }
1111
1525
  /**
@@ -1129,14 +1543,27 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1129
1543
  columns = [],
1130
1544
  includeAllColumns = false
1131
1545
  }) {
1132
- if (!this.lanceClient) {
1133
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1134
- }
1135
- if (!tableName) {
1136
- throw new Error("tableName is required");
1137
- }
1138
- if (!queryVector) {
1139
- throw new Error("queryVector is required");
1546
+ try {
1547
+ if (!this.lanceClient) {
1548
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1549
+ }
1550
+ if (!tableName) {
1551
+ throw new Error("tableName is required");
1552
+ }
1553
+ if (!queryVector) {
1554
+ throw new Error("queryVector is required");
1555
+ }
1556
+ } catch (error$1) {
1557
+ throw new error.MastraError(
1558
+ {
1559
+ id: "STORAGE_LANCE_VECTOR_QUERY_FAILED_INVALID_ARGS",
1560
+ domain: error.ErrorDomain.STORAGE,
1561
+ category: error.ErrorCategory.USER,
1562
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1563
+ details: { tableName }
1564
+ },
1565
+ error$1
1566
+ );
1140
1567
  }
1141
1568
  try {
1142
1569
  const table = await this.lanceClient.openTable(tableName);
@@ -1174,8 +1601,16 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1174
1601
  score: result._distance
1175
1602
  };
1176
1603
  });
1177
- } catch (error) {
1178
- throw new Error(`Failed to query vectors: ${error.message}`);
1604
+ } catch (error$1) {
1605
+ throw new error.MastraError(
1606
+ {
1607
+ id: "STORAGE_LANCE_VECTOR_QUERY_FAILED",
1608
+ domain: error.ErrorDomain.STORAGE,
1609
+ category: error.ErrorCategory.THIRD_PARTY,
1610
+ details: { tableName, includeVector, columnsCount: columns?.length, includeAllColumns }
1611
+ },
1612
+ error$1
1613
+ );
1179
1614
  }
1180
1615
  }
1181
1616
  filterTranslator(filter) {
@@ -1208,14 +1643,27 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1208
1643
  return translator.translate(prefixedFilter);
1209
1644
  }
1210
1645
  async upsert({ tableName, vectors, metadata = [], ids = [] }) {
1211
- if (!this.lanceClient) {
1212
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1213
- }
1214
- if (!tableName) {
1215
- throw new Error("tableName is required");
1216
- }
1217
- if (!vectors || !Array.isArray(vectors) || vectors.length === 0) {
1218
- throw new Error("vectors array is required and must not be empty");
1646
+ try {
1647
+ if (!this.lanceClient) {
1648
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1649
+ }
1650
+ if (!tableName) {
1651
+ throw new Error("tableName is required");
1652
+ }
1653
+ if (!vectors || !Array.isArray(vectors) || vectors.length === 0) {
1654
+ throw new Error("vectors array is required and must not be empty");
1655
+ }
1656
+ } catch (error$1) {
1657
+ throw new error.MastraError(
1658
+ {
1659
+ id: "STORAGE_LANCE_VECTOR_UPSERT_FAILED_INVALID_ARGS",
1660
+ domain: error.ErrorDomain.STORAGE,
1661
+ category: error.ErrorCategory.USER,
1662
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1663
+ details: { tableName }
1664
+ },
1665
+ error$1
1666
+ );
1219
1667
  }
1220
1668
  try {
1221
1669
  const tables = await this.lanceClient.tableNames();
@@ -1241,8 +1689,16 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1241
1689
  });
1242
1690
  await table.add(data, { mode: "overwrite" });
1243
1691
  return vectorIds;
1244
- } catch (error) {
1245
- throw new Error(`Failed to upsert vectors: ${error.message}`);
1692
+ } catch (error$1) {
1693
+ throw new error.MastraError(
1694
+ {
1695
+ id: "STORAGE_LANCE_VECTOR_UPSERT_FAILED",
1696
+ domain: error.ErrorDomain.STORAGE,
1697
+ category: error.ErrorCategory.THIRD_PARTY,
1698
+ details: { tableName, vectorCount: vectors.length, metadataCount: metadata.length, idsCount: ids.length }
1699
+ },
1700
+ error$1
1701
+ );
1246
1702
  }
1247
1703
  }
1248
1704
  /**
@@ -1262,29 +1718,78 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1262
1718
  }
1263
1719
  async createTable(tableName, data, options) {
1264
1720
  if (!this.lanceClient) {
1265
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1721
+ throw new error.MastraError({
1722
+ id: "STORAGE_LANCE_VECTOR_CREATE_TABLE_FAILED_INVALID_ARGS",
1723
+ domain: error.ErrorDomain.STORAGE,
1724
+ category: error.ErrorCategory.USER,
1725
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1726
+ details: { tableName }
1727
+ });
1728
+ }
1729
+ if (Array.isArray(data)) {
1730
+ data = data.map((record) => this.flattenObject(record));
1266
1731
  }
1267
1732
  try {
1268
- if (Array.isArray(data)) {
1269
- data = data.map((record) => this.flattenObject(record));
1270
- }
1271
1733
  return await this.lanceClient.createTable(tableName, data, options);
1272
- } catch (error) {
1273
- throw new Error(`Failed to create table: ${error.message}`);
1734
+ } catch (error$1) {
1735
+ throw new error.MastraError(
1736
+ {
1737
+ id: "STORAGE_LANCE_VECTOR_CREATE_TABLE_FAILED",
1738
+ domain: error.ErrorDomain.STORAGE,
1739
+ category: error.ErrorCategory.THIRD_PARTY,
1740
+ details: { tableName }
1741
+ },
1742
+ error$1
1743
+ );
1274
1744
  }
1275
1745
  }
1276
1746
  async listTables() {
1277
1747
  if (!this.lanceClient) {
1278
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1748
+ throw new error.MastraError({
1749
+ id: "STORAGE_LANCE_VECTOR_LIST_TABLES_FAILED_INVALID_ARGS",
1750
+ domain: error.ErrorDomain.STORAGE,
1751
+ category: error.ErrorCategory.USER,
1752
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1753
+ details: { methodName: "listTables" }
1754
+ });
1755
+ }
1756
+ try {
1757
+ return await this.lanceClient.tableNames();
1758
+ } catch (error$1) {
1759
+ throw new error.MastraError(
1760
+ {
1761
+ id: "STORAGE_LANCE_VECTOR_LIST_TABLES_FAILED",
1762
+ domain: error.ErrorDomain.STORAGE,
1763
+ category: error.ErrorCategory.THIRD_PARTY
1764
+ },
1765
+ error$1
1766
+ );
1279
1767
  }
1280
- return await this.lanceClient.tableNames();
1281
1768
  }
1282
1769
  async getTableSchema(tableName) {
1283
1770
  if (!this.lanceClient) {
1284
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1771
+ throw new error.MastraError({
1772
+ id: "STORAGE_LANCE_VECTOR_GET_TABLE_SCHEMA_FAILED_INVALID_ARGS",
1773
+ domain: error.ErrorDomain.STORAGE,
1774
+ category: error.ErrorCategory.USER,
1775
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1776
+ details: { tableName }
1777
+ });
1778
+ }
1779
+ try {
1780
+ const table = await this.lanceClient.openTable(tableName);
1781
+ return await table.schema();
1782
+ } catch (error$1) {
1783
+ throw new error.MastraError(
1784
+ {
1785
+ id: "STORAGE_LANCE_VECTOR_GET_TABLE_SCHEMA_FAILED",
1786
+ domain: error.ErrorDomain.STORAGE,
1787
+ category: error.ErrorCategory.THIRD_PARTY,
1788
+ details: { tableName }
1789
+ },
1790
+ error$1
1791
+ );
1285
1792
  }
1286
- const table = await this.lanceClient.openTable(tableName);
1287
- return await table.schema();
1288
1793
  }
1289
1794
  /**
1290
1795
  * indexName is actually a column name in a table in lanceDB
@@ -1296,10 +1801,10 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1296
1801
  metric = "cosine",
1297
1802
  indexConfig = {}
1298
1803
  }) {
1299
- if (!this.lanceClient) {
1300
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1301
- }
1302
1804
  try {
1805
+ if (!this.lanceClient) {
1806
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1807
+ }
1303
1808
  if (!tableName) {
1304
1809
  throw new Error("tableName is required");
1305
1810
  }
@@ -1309,6 +1814,18 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1309
1814
  if (typeof dimension !== "number" || dimension <= 0) {
1310
1815
  throw new Error("dimension must be a positive number");
1311
1816
  }
1817
+ } catch (err) {
1818
+ throw new error.MastraError(
1819
+ {
1820
+ id: "STORAGE_LANCE_VECTOR_CREATE_INDEX_FAILED_INVALID_ARGS",
1821
+ domain: error.ErrorDomain.STORAGE,
1822
+ category: error.ErrorCategory.USER,
1823
+ details: { tableName: tableName || "", indexName, dimension, metric }
1824
+ },
1825
+ err
1826
+ );
1827
+ }
1828
+ try {
1312
1829
  const tables = await this.lanceClient.tableNames();
1313
1830
  if (!tables.includes(tableName)) {
1314
1831
  throw new Error(
@@ -1342,13 +1859,27 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1342
1859
  })
1343
1860
  });
1344
1861
  }
1345
- } catch (error) {
1346
- throw new Error(`Failed to create index: ${error.message}`);
1862
+ } catch (error$1) {
1863
+ throw new error.MastraError(
1864
+ {
1865
+ id: "STORAGE_LANCE_VECTOR_CREATE_INDEX_FAILED",
1866
+ domain: error.ErrorDomain.STORAGE,
1867
+ category: error.ErrorCategory.THIRD_PARTY,
1868
+ details: { tableName: tableName || "", indexName, dimension }
1869
+ },
1870
+ error$1
1871
+ );
1347
1872
  }
1348
1873
  }
1349
1874
  async listIndexes() {
1350
1875
  if (!this.lanceClient) {
1351
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1876
+ throw new error.MastraError({
1877
+ id: "STORAGE_LANCE_VECTOR_LIST_INDEXES_FAILED_INVALID_ARGS",
1878
+ domain: error.ErrorDomain.STORAGE,
1879
+ category: error.ErrorCategory.USER,
1880
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
1881
+ details: { methodName: "listIndexes" }
1882
+ });
1352
1883
  }
1353
1884
  try {
1354
1885
  const tables = await this.lanceClient.tableNames();
@@ -1359,16 +1890,35 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1359
1890
  allIndices.push(...tableIndices.map((index) => index.name));
1360
1891
  }
1361
1892
  return allIndices;
1362
- } catch (error) {
1363
- throw new Error(`Failed to list indexes: ${error.message}`);
1893
+ } catch (error$1) {
1894
+ throw new error.MastraError(
1895
+ {
1896
+ id: "STORAGE_LANCE_VECTOR_LIST_INDEXES_FAILED",
1897
+ domain: error.ErrorDomain.STORAGE,
1898
+ category: error.ErrorCategory.THIRD_PARTY
1899
+ },
1900
+ error$1
1901
+ );
1364
1902
  }
1365
1903
  }
1366
1904
  async describeIndex({ indexName }) {
1367
- if (!this.lanceClient) {
1368
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1369
- }
1370
- if (!indexName) {
1371
- throw new Error("indexName is required");
1905
+ try {
1906
+ if (!this.lanceClient) {
1907
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1908
+ }
1909
+ if (!indexName) {
1910
+ throw new Error("indexName is required");
1911
+ }
1912
+ } catch (err) {
1913
+ throw new error.MastraError(
1914
+ {
1915
+ id: "STORAGE_LANCE_VECTOR_DESCRIBE_INDEX_FAILED_INVALID_ARGS",
1916
+ domain: error.ErrorDomain.STORAGE,
1917
+ category: error.ErrorCategory.USER,
1918
+ details: { indexName }
1919
+ },
1920
+ err
1921
+ );
1372
1922
  }
1373
1923
  try {
1374
1924
  const tables = await this.lanceClient.tableNames();
@@ -1394,16 +1944,36 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1394
1944
  }
1395
1945
  }
1396
1946
  throw new Error(`IndexName: ${indexName} not found`);
1397
- } catch (error) {
1398
- throw new Error(`Failed to describe index: ${error.message}`);
1947
+ } catch (error$1) {
1948
+ throw new error.MastraError(
1949
+ {
1950
+ id: "STORAGE_LANCE_VECTOR_DESCRIBE_INDEX_FAILED",
1951
+ domain: error.ErrorDomain.STORAGE,
1952
+ category: error.ErrorCategory.THIRD_PARTY,
1953
+ details: { indexName }
1954
+ },
1955
+ error$1
1956
+ );
1399
1957
  }
1400
1958
  }
1401
1959
  async deleteIndex({ indexName }) {
1402
- if (!this.lanceClient) {
1403
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1404
- }
1405
- if (!indexName) {
1406
- throw new Error("indexName is required");
1960
+ try {
1961
+ if (!this.lanceClient) {
1962
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1963
+ }
1964
+ if (!indexName) {
1965
+ throw new Error("indexName is required");
1966
+ }
1967
+ } catch (err) {
1968
+ throw new error.MastraError(
1969
+ {
1970
+ id: "STORAGE_LANCE_VECTOR_DELETE_INDEX_FAILED_INVALID_ARGS",
1971
+ domain: error.ErrorDomain.STORAGE,
1972
+ category: error.ErrorCategory.USER,
1973
+ details: { indexName }
1974
+ },
1975
+ err
1976
+ );
1407
1977
  }
1408
1978
  try {
1409
1979
  const tables = await this.lanceClient.tableNames();
@@ -1417,8 +1987,16 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1417
1987
  }
1418
1988
  }
1419
1989
  throw new Error(`Index ${indexName} not found`);
1420
- } catch (error) {
1421
- throw new Error(`Failed to delete index: ${error.message}`);
1990
+ } catch (error$1) {
1991
+ throw new error.MastraError(
1992
+ {
1993
+ id: "STORAGE_LANCE_VECTOR_DELETE_INDEX_FAILED",
1994
+ domain: error.ErrorDomain.STORAGE,
1995
+ category: error.ErrorCategory.THIRD_PARTY,
1996
+ details: { indexName }
1997
+ },
1998
+ error$1
1999
+ );
1422
2000
  }
1423
2001
  }
1424
2002
  /**
@@ -1426,33 +2004,73 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1426
2004
  */
1427
2005
  async deleteAllTables() {
1428
2006
  if (!this.lanceClient) {
1429
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
2007
+ throw new error.MastraError({
2008
+ id: "STORAGE_LANCE_VECTOR_DELETE_ALL_TABLES_FAILED_INVALID_ARGS",
2009
+ domain: error.ErrorDomain.STORAGE,
2010
+ category: error.ErrorCategory.USER,
2011
+ details: { methodName: "deleteAllTables" },
2012
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance"
2013
+ });
1430
2014
  }
1431
2015
  try {
1432
2016
  await this.lanceClient.dropAllTables();
1433
- } catch (error) {
1434
- throw new Error(`Failed to delete tables: ${error.message}`);
2017
+ } catch (error$1) {
2018
+ throw new error.MastraError(
2019
+ {
2020
+ id: "STORAGE_LANCE_VECTOR_DELETE_ALL_TABLES_FAILED",
2021
+ domain: error.ErrorDomain.STORAGE,
2022
+ category: error.ErrorCategory.THIRD_PARTY,
2023
+ details: { methodName: "deleteAllTables" }
2024
+ },
2025
+ error$1
2026
+ );
1435
2027
  }
1436
2028
  }
1437
2029
  async deleteTable(tableName) {
1438
2030
  if (!this.lanceClient) {
1439
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
2031
+ throw new error.MastraError({
2032
+ id: "STORAGE_LANCE_VECTOR_DELETE_TABLE_FAILED_INVALID_ARGS",
2033
+ domain: error.ErrorDomain.STORAGE,
2034
+ category: error.ErrorCategory.USER,
2035
+ details: { tableName },
2036
+ text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance"
2037
+ });
1440
2038
  }
1441
2039
  try {
1442
2040
  await this.lanceClient.dropTable(tableName);
1443
- } catch (error) {
1444
- throw new Error(`Failed to delete tables: ${error.message}`);
2041
+ } catch (error$1) {
2042
+ throw new error.MastraError(
2043
+ {
2044
+ id: "STORAGE_LANCE_VECTOR_DELETE_TABLE_FAILED",
2045
+ domain: error.ErrorDomain.STORAGE,
2046
+ category: error.ErrorCategory.THIRD_PARTY,
2047
+ details: { tableName }
2048
+ },
2049
+ error$1
2050
+ );
1445
2051
  }
1446
2052
  }
1447
2053
  async updateVector({ indexName, id, update }) {
1448
- if (!this.lanceClient) {
1449
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1450
- }
1451
- if (!indexName) {
1452
- throw new Error("indexName is required");
1453
- }
1454
- if (!id) {
1455
- throw new Error("id is required");
2054
+ try {
2055
+ if (!this.lanceClient) {
2056
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
2057
+ }
2058
+ if (!indexName) {
2059
+ throw new Error("indexName is required");
2060
+ }
2061
+ if (!id) {
2062
+ throw new Error("id is required");
2063
+ }
2064
+ } catch (err) {
2065
+ throw new error.MastraError(
2066
+ {
2067
+ id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED_INVALID_ARGS",
2068
+ domain: error.ErrorDomain.STORAGE,
2069
+ category: error.ErrorCategory.USER,
2070
+ details: { indexName, id }
2071
+ },
2072
+ err
2073
+ );
1456
2074
  }
1457
2075
  try {
1458
2076
  const tables = await this.lanceClient.tableNames();
@@ -1505,19 +2123,39 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1505
2123
  }
1506
2124
  }
1507
2125
  throw new Error(`No table found with column/index '${indexName}'`);
1508
- } catch (error) {
1509
- throw new Error(`Failed to update index: ${error.message}`);
2126
+ } catch (error$1) {
2127
+ throw new error.MastraError(
2128
+ {
2129
+ id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED",
2130
+ domain: error.ErrorDomain.STORAGE,
2131
+ category: error.ErrorCategory.THIRD_PARTY,
2132
+ details: { indexName, id, hasVector: !!update.vector, hasMetadata: !!update.metadata }
2133
+ },
2134
+ error$1
2135
+ );
1510
2136
  }
1511
2137
  }
1512
2138
  async deleteVector({ indexName, id }) {
1513
- if (!this.lanceClient) {
1514
- throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
1515
- }
1516
- if (!indexName) {
1517
- throw new Error("indexName is required");
1518
- }
1519
- if (!id) {
1520
- throw new Error("id is required");
2139
+ try {
2140
+ if (!this.lanceClient) {
2141
+ throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
2142
+ }
2143
+ if (!indexName) {
2144
+ throw new Error("indexName is required");
2145
+ }
2146
+ if (!id) {
2147
+ throw new Error("id is required");
2148
+ }
2149
+ } catch (err) {
2150
+ throw new error.MastraError(
2151
+ {
2152
+ id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED_INVALID_ARGS",
2153
+ domain: error.ErrorDomain.STORAGE,
2154
+ category: error.ErrorCategory.USER,
2155
+ details: { indexName, id }
2156
+ },
2157
+ err
2158
+ );
1521
2159
  }
1522
2160
  try {
1523
2161
  const tables = await this.lanceClient.tableNames();
@@ -1538,8 +2176,16 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
1538
2176
  }
1539
2177
  }
1540
2178
  throw new Error(`No table found with column/index '${indexName}'`);
1541
- } catch (error) {
1542
- throw new Error(`Failed to delete index: ${error.message}`);
2179
+ } catch (error$1) {
2180
+ throw new error.MastraError(
2181
+ {
2182
+ id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED",
2183
+ domain: error.ErrorDomain.STORAGE,
2184
+ category: error.ErrorCategory.THIRD_PARTY,
2185
+ details: { indexName, id }
2186
+ },
2187
+ error$1
2188
+ );
1543
2189
  }
1544
2190
  }
1545
2191
  /**