@mastra/lance 0.0.0-fix-backport-setserver-20251201151948 → 0.0.0-fix-request-context-as-query-key-20251209093005

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,133 +1,17 @@
1
1
  import { connect, Index } from '@lancedb/lancedb';
2
2
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
3
- import { MastraStorage, StoreOperations, LegacyEvalsStorage, TABLE_EVALS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, resolveMessageLimit, TABLE_RESOURCES, ScoresStorage, TABLE_SCORERS, TracesStorage, TABLE_TRACES, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, ensureDate } from '@mastra/core/storage';
3
+ import { MastraStorage, createStorageErrorId, createVectorErrorId, StoreOperations, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, normalizePerPage, calculatePagination, TABLE_RESOURCES, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, ensureDate } from '@mastra/core/storage';
4
4
  import { MessageList } from '@mastra/core/agent';
5
5
  import { Utf8, Float64, Binary, Float32, Int32, Field, Schema } from 'apache-arrow';
6
- import { saveScorePayloadSchema } from '@mastra/core/scores';
6
+ import { saveScorePayloadSchema } from '@mastra/core/evals';
7
7
  import { MastraVector } from '@mastra/core/vector';
8
8
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
9
9
 
10
10
  // src/storage/index.ts
11
- var StoreLegacyEvalsLance = class extends LegacyEvalsStorage {
12
- client;
13
- constructor({ client }) {
14
- super();
15
- this.client = client;
16
- }
17
- async getEvalsByAgentName(agentName, type) {
18
- try {
19
- const table = await this.client.openTable(TABLE_EVALS);
20
- const query = table.query().where(`agent_name = '${agentName}'`);
21
- const records = await query.toArray();
22
- let filteredRecords = records;
23
- if (type === "live") {
24
- filteredRecords = records.filter((record) => record.test_info === null);
25
- } else if (type === "test") {
26
- filteredRecords = records.filter((record) => record.test_info !== null);
27
- }
28
- return filteredRecords.map((record) => {
29
- return {
30
- id: record.id,
31
- input: record.input,
32
- output: record.output,
33
- agentName: record.agent_name,
34
- metricName: record.metric_name,
35
- result: JSON.parse(record.result),
36
- instructions: record.instructions,
37
- testInfo: record.test_info ? JSON.parse(record.test_info) : null,
38
- globalRunId: record.global_run_id,
39
- runId: record.run_id,
40
- createdAt: new Date(record.created_at).toString()
41
- };
42
- });
43
- } catch (error) {
44
- throw new MastraError(
45
- {
46
- id: "LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
47
- domain: ErrorDomain.STORAGE,
48
- category: ErrorCategory.THIRD_PARTY,
49
- details: { agentName }
50
- },
51
- error
52
- );
53
- }
54
- }
55
- async getEvals(options) {
56
- try {
57
- const table = await this.client.openTable(TABLE_EVALS);
58
- const conditions = [];
59
- if (options.agentName) {
60
- conditions.push(`agent_name = '${options.agentName}'`);
61
- }
62
- if (options.type === "live") {
63
- conditions.push("test_info IS NULL");
64
- } else if (options.type === "test") {
65
- conditions.push("test_info IS NOT NULL");
66
- }
67
- const startDate = options.dateRange?.start || options.fromDate;
68
- const endDate = options.dateRange?.end || options.toDate;
69
- if (startDate) {
70
- conditions.push(`\`created_at\` >= ${startDate.getTime()}`);
71
- }
72
- if (endDate) {
73
- conditions.push(`\`created_at\` <= ${endDate.getTime()}`);
74
- }
75
- let total = 0;
76
- if (conditions.length > 0) {
77
- total = await table.countRows(conditions.join(" AND "));
78
- } else {
79
- total = await table.countRows();
80
- }
81
- const query = table.query();
82
- if (conditions.length > 0) {
83
- const whereClause = conditions.join(" AND ");
84
- query.where(whereClause);
85
- }
86
- const records = await query.toArray();
87
- const evals = records.sort((a, b) => b.created_at - a.created_at).map((record) => {
88
- return {
89
- id: record.id,
90
- input: record.input,
91
- output: record.output,
92
- agentName: record.agent_name,
93
- metricName: record.metric_name,
94
- result: JSON.parse(record.result),
95
- instructions: record.instructions,
96
- testInfo: record.test_info ? JSON.parse(record.test_info) : null,
97
- globalRunId: record.global_run_id,
98
- runId: record.run_id,
99
- createdAt: new Date(record.created_at).toISOString()
100
- };
101
- });
102
- const page = options.page || 0;
103
- const perPage = options.perPage || 10;
104
- const pagedEvals = evals.slice(page * perPage, (page + 1) * perPage);
105
- return {
106
- evals: pagedEvals,
107
- total,
108
- page,
109
- perPage,
110
- hasMore: total > (page + 1) * perPage
111
- };
112
- } catch (error) {
113
- throw new MastraError(
114
- {
115
- id: "LANCE_STORE_GET_EVALS_FAILED",
116
- domain: ErrorDomain.STORAGE,
117
- category: ErrorCategory.THIRD_PARTY,
118
- details: { agentName: options.agentName ?? "" }
119
- },
120
- error
121
- );
122
- }
123
- }
124
- };
125
11
  function getPrimaryKeys(tableName) {
126
12
  let primaryId = ["id"];
127
13
  if (tableName === TABLE_WORKFLOW_SNAPSHOT) {
128
14
  primaryId = ["workflow_name", "run_id"];
129
- } else if (tableName === TABLE_EVALS) {
130
- primaryId = ["agent_name", "metric_name", "run_id"];
131
15
  }
132
16
  return primaryId;
133
17
  }
@@ -205,7 +89,7 @@ async function getTableSchema({
205
89
  } catch (validationError) {
206
90
  throw new MastraError(
207
91
  {
208
- id: "STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_INVALID_ARGS",
92
+ id: createStorageErrorId("LANCE", "GET_TABLE_SCHEMA", "INVALID_ARGS"),
209
93
  domain: ErrorDomain.STORAGE,
210
94
  category: ErrorCategory.USER,
211
95
  text: validationError.message,
@@ -228,7 +112,7 @@ async function getTableSchema({
228
112
  } catch (error) {
229
113
  throw new MastraError(
230
114
  {
231
- id: "STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_FAILED",
115
+ id: createStorageErrorId("LANCE", "GET_TABLE_SCHEMA", "FAILED"),
232
116
  domain: ErrorDomain.STORAGE,
233
117
  category: ErrorCategory.THIRD_PARTY,
234
118
  details: { tableName }
@@ -247,6 +131,10 @@ var StoreMemoryLance = class extends MemoryStorage {
247
131
  this.client = client;
248
132
  this.operations = operations;
249
133
  }
134
+ // Utility to escape single quotes in SQL strings
135
+ escapeSql(str) {
136
+ return str.replace(/'/g, "''");
137
+ }
250
138
  async getThreadById({ threadId }) {
251
139
  try {
252
140
  const thread = await this.operations.load({ tableName: TABLE_THREADS, keys: { id: threadId } });
@@ -261,27 +149,7 @@ var StoreMemoryLance = class extends MemoryStorage {
261
149
  } catch (error) {
262
150
  throw new MastraError(
263
151
  {
264
- id: "LANCE_STORE_GET_THREAD_BY_ID_FAILED",
265
- domain: ErrorDomain.STORAGE,
266
- category: ErrorCategory.THIRD_PARTY
267
- },
268
- error
269
- );
270
- }
271
- }
272
- async getThreadsByResourceId({ resourceId }) {
273
- try {
274
- const table = await this.client.openTable(TABLE_THREADS);
275
- const query = table.query().where(`\`resourceId\` = '${resourceId}'`);
276
- const records = await query.toArray();
277
- return processResultWithTypeConversion(
278
- records,
279
- await getTableSchema({ tableName: TABLE_THREADS, client: this.client })
280
- );
281
- } catch (error) {
282
- throw new MastraError(
283
- {
284
- id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
152
+ id: createStorageErrorId("LANCE", "GET_THREAD_BY_ID", "FAILED"),
285
153
  domain: ErrorDomain.STORAGE,
286
154
  category: ErrorCategory.THIRD_PARTY
287
155
  },
@@ -303,7 +171,7 @@ var StoreMemoryLance = class extends MemoryStorage {
303
171
  } catch (error) {
304
172
  throw new MastraError(
305
173
  {
306
- id: "LANCE_STORE_SAVE_THREAD_FAILED",
174
+ id: createStorageErrorId("LANCE", "SAVE_THREAD", "FAILED"),
307
175
  domain: ErrorDomain.STORAGE,
308
176
  category: ErrorCategory.THIRD_PARTY
309
177
  },
@@ -345,7 +213,7 @@ var StoreMemoryLance = class extends MemoryStorage {
345
213
  }
346
214
  throw new MastraError(
347
215
  {
348
- id: "LANCE_STORE_UPDATE_THREAD_FAILED",
216
+ id: createStorageErrorId("LANCE", "UPDATE_THREAD", "FAILED"),
349
217
  domain: ErrorDomain.STORAGE,
350
218
  category: ErrorCategory.THIRD_PARTY
351
219
  },
@@ -355,7 +223,7 @@ var StoreMemoryLance = class extends MemoryStorage {
355
223
  }
356
224
  throw new MastraError(
357
225
  {
358
- id: "LANCE_STORE_UPDATE_THREAD_FAILED",
226
+ id: createStorageErrorId("LANCE", "UPDATE_THREAD", "FAILED"),
359
227
  domain: ErrorDomain.STORAGE,
360
228
  category: ErrorCategory.THIRD_PARTY
361
229
  },
@@ -371,7 +239,7 @@ var StoreMemoryLance = class extends MemoryStorage {
371
239
  } catch (error) {
372
240
  throw new MastraError(
373
241
  {
374
- id: "LANCE_STORE_DELETE_THREAD_FAILED",
242
+ id: createStorageErrorId("LANCE", "DELETE_THREAD", "FAILED"),
375
243
  domain: ErrorDomain.STORAGE,
376
244
  category: ErrorCategory.THIRD_PARTY
377
245
  },
@@ -393,100 +261,176 @@ var StoreMemoryLance = class extends MemoryStorage {
393
261
  })() : message.content
394
262
  };
395
263
  }
396
- async getMessages({
397
- threadId,
398
- resourceId,
399
- selectBy,
400
- format,
401
- threadConfig
402
- }) {
264
+ async listMessagesById({ messageIds }) {
265
+ if (messageIds.length === 0) return { messages: [] };
403
266
  try {
404
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
405
- if (threadConfig) {
406
- throw new Error("ThreadConfig is not supported by LanceDB storage");
407
- }
408
- const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
409
267
  const table = await this.client.openTable(TABLE_MESSAGES);
410
- let allRecords = [];
411
- if (selectBy?.include && selectBy.include.length > 0) {
412
- const threadIds = [...new Set(selectBy.include.map((item) => item.threadId))];
413
- for (const threadId2 of threadIds) {
414
- const threadQuery = table.query().where(`thread_id = '${threadId2}'`);
415
- let threadRecords = await threadQuery.toArray();
416
- allRecords.push(...threadRecords);
417
- }
418
- } else {
419
- let query = table.query().where(`\`thread_id\` = '${threadId}'`);
420
- allRecords = await query.toArray();
421
- }
422
- allRecords.sort((a, b) => {
423
- const dateA = new Date(a.createdAt).getTime();
424
- const dateB = new Date(b.createdAt).getTime();
425
- return dateA - dateB;
426
- });
427
- if (selectBy?.include && selectBy.include.length > 0) {
428
- allRecords = this.processMessagesWithContext(allRecords, selectBy.include);
429
- }
430
- if (limit !== Number.MAX_SAFE_INTEGER) {
431
- allRecords = allRecords.slice(-limit);
432
- }
268
+ const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
269
+ const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
433
270
  const messages = processResultWithTypeConversion(
434
271
  allRecords,
435
272
  await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
436
273
  );
437
- const list = new MessageList({ threadId, resourceId }).add(messages.map(this.normalizeMessage), "memory");
438
- if (format === "v2") return list.get.all.v2();
439
- return list.get.all.v1();
274
+ const list = new MessageList().add(
275
+ messages.map(this.normalizeMessage),
276
+ "memory"
277
+ );
278
+ return { messages: list.get.all.db() };
440
279
  } catch (error) {
441
280
  throw new MastraError(
442
281
  {
443
- id: "LANCE_STORE_GET_MESSAGES_FAILED",
282
+ id: createStorageErrorId("LANCE", "LIST_MESSAGES_BY_ID", "FAILED"),
444
283
  domain: ErrorDomain.STORAGE,
445
284
  category: ErrorCategory.THIRD_PARTY,
446
285
  details: {
447
- threadId,
448
- resourceId: resourceId ?? ""
286
+ messageIds: JSON.stringify(messageIds)
449
287
  }
450
288
  },
451
289
  error
452
290
  );
453
291
  }
454
292
  }
455
- async getMessagesById({
456
- messageIds,
457
- format
458
- }) {
459
- if (messageIds.length === 0) return [];
293
+ async listMessages(args) {
294
+ const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
295
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
296
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
297
+ throw new MastraError(
298
+ {
299
+ id: createStorageErrorId("LANCE", "LIST_MESSAGES", "INVALID_THREAD_ID"),
300
+ domain: ErrorDomain.STORAGE,
301
+ category: ErrorCategory.THIRD_PARTY,
302
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
303
+ },
304
+ new Error("threadId must be a non-empty string or array of non-empty strings")
305
+ );
306
+ }
307
+ const perPage = normalizePerPage(perPageInput, 40);
308
+ const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
460
309
  try {
310
+ if (page < 0) {
311
+ throw new MastraError(
312
+ {
313
+ id: createStorageErrorId("LANCE", "LIST_MESSAGES", "INVALID_PAGE"),
314
+ domain: ErrorDomain.STORAGE,
315
+ category: ErrorCategory.USER,
316
+ details: { page }
317
+ },
318
+ new Error("page must be >= 0")
319
+ );
320
+ }
321
+ const { field, direction } = this.parseOrderBy(orderBy, "ASC");
461
322
  const table = await this.client.openTable(TABLE_MESSAGES);
462
- const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
463
- const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
464
- const messages = processResultWithTypeConversion(
465
- allRecords,
466
- await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
467
- );
468
- const list = new MessageList().add(messages.map(this.normalizeMessage), "memory");
469
- if (format === `v1`) return list.get.all.v1();
470
- return list.get.all.v2();
323
+ const threadCondition = threadIds.length === 1 ? `thread_id = '${this.escapeSql(threadIds[0])}'` : `thread_id IN (${threadIds.map((t) => `'${this.escapeSql(t)}'`).join(", ")})`;
324
+ const conditions = [threadCondition];
325
+ if (resourceId) {
326
+ conditions.push(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
327
+ }
328
+ if (filter?.dateRange?.start) {
329
+ const startTime = filter.dateRange.start instanceof Date ? filter.dateRange.start.getTime() : new Date(filter.dateRange.start).getTime();
330
+ conditions.push(`\`createdAt\` >= ${startTime}`);
331
+ }
332
+ if (filter?.dateRange?.end) {
333
+ const endTime = filter.dateRange.end instanceof Date ? filter.dateRange.end.getTime() : new Date(filter.dateRange.end).getTime();
334
+ conditions.push(`\`createdAt\` <= ${endTime}`);
335
+ }
336
+ const whereClause = conditions.join(" AND ");
337
+ const total = await table.countRows(whereClause);
338
+ const query = table.query().where(whereClause);
339
+ let allRecords = await query.toArray();
340
+ allRecords.sort((a, b) => {
341
+ const aValue = field === "createdAt" ? a.createdAt : a[field];
342
+ const bValue = field === "createdAt" ? b.createdAt : b[field];
343
+ if (aValue == null && bValue == null) return 0;
344
+ if (aValue == null) return direction === "ASC" ? -1 : 1;
345
+ if (bValue == null) return direction === "ASC" ? 1 : -1;
346
+ if (typeof aValue === "string" && typeof bValue === "string") {
347
+ return direction === "ASC" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
348
+ }
349
+ return direction === "ASC" ? aValue - bValue : bValue - aValue;
350
+ });
351
+ const paginatedRecords = allRecords.slice(offset, offset + perPage);
352
+ const messages = paginatedRecords.map((row) => this.normalizeMessage(row));
353
+ if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
354
+ return {
355
+ messages: [],
356
+ total: 0,
357
+ page,
358
+ perPage: perPageForResponse,
359
+ hasMore: false
360
+ };
361
+ }
362
+ const messageIds = new Set(messages.map((m) => m.id));
363
+ if (include && include.length > 0) {
364
+ const threadIds2 = [...new Set(include.map((item) => item.threadId || threadId))];
365
+ const allThreadMessages = [];
366
+ for (const tid of threadIds2) {
367
+ const threadQuery = table.query().where(`thread_id = '${tid}'`);
368
+ let threadRecords = await threadQuery.toArray();
369
+ allThreadMessages.push(...threadRecords);
370
+ }
371
+ allThreadMessages.sort((a, b) => a.createdAt - b.createdAt);
372
+ const contextMessages = this.processMessagesWithContext(allThreadMessages, include);
373
+ const includedMessages = contextMessages.map((row) => this.normalizeMessage(row));
374
+ for (const includeMsg of includedMessages) {
375
+ if (!messageIds.has(includeMsg.id)) {
376
+ messages.push(includeMsg);
377
+ messageIds.add(includeMsg.id);
378
+ }
379
+ }
380
+ }
381
+ const list = new MessageList().add(messages, "memory");
382
+ let finalMessages = list.get.all.db();
383
+ finalMessages = finalMessages.sort((a, b) => {
384
+ const aValue = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
385
+ const bValue = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
386
+ if (aValue == null && bValue == null) return 0;
387
+ if (aValue == null) return direction === "ASC" ? -1 : 1;
388
+ if (bValue == null) return direction === "ASC" ? 1 : -1;
389
+ if (typeof aValue === "string" && typeof bValue === "string") {
390
+ return direction === "ASC" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
391
+ }
392
+ return direction === "ASC" ? aValue - bValue : bValue - aValue;
393
+ });
394
+ const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
395
+ const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
396
+ const fetchedAll = perPageInput === false || allThreadMessagesReturned;
397
+ const hasMore = !fetchedAll && offset + perPage < total;
398
+ return {
399
+ messages: finalMessages,
400
+ total,
401
+ page,
402
+ perPage: perPageForResponse,
403
+ hasMore
404
+ };
471
405
  } catch (error) {
472
- throw new MastraError(
406
+ const mastraError = new MastraError(
473
407
  {
474
- id: "LANCE_STORE_GET_MESSAGES_BY_ID_FAILED",
408
+ id: createStorageErrorId("LANCE", "LIST_MESSAGES", "FAILED"),
475
409
  domain: ErrorDomain.STORAGE,
476
410
  category: ErrorCategory.THIRD_PARTY,
477
411
  details: {
478
- messageIds: JSON.stringify(messageIds)
412
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
413
+ resourceId: resourceId ?? ""
479
414
  }
480
415
  },
481
416
  error
482
417
  );
418
+ this.logger?.error?.(mastraError.toString());
419
+ this.logger?.trackException?.(mastraError);
420
+ return {
421
+ messages: [],
422
+ total: 0,
423
+ page,
424
+ perPage: perPageForResponse,
425
+ hasMore: false
426
+ };
483
427
  }
484
428
  }
485
429
  async saveMessages(args) {
486
430
  try {
487
- const { messages, format = "v1" } = args;
431
+ const { messages } = args;
488
432
  if (messages.length === 0) {
489
- return [];
433
+ return { messages: [] };
490
434
  }
491
435
  const threadId = messages[0]?.threadId;
492
436
  if (!threadId) {
@@ -522,12 +466,11 @@ var StoreMemoryLance = class extends MemoryStorage {
522
466
  const updateRecord = { id: threadId, updatedAt: currentTime };
523
467
  await threadsTable.mergeInsert("id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([updateRecord]);
524
468
  const list = new MessageList().add(messages, "memory");
525
- if (format === `v2`) return list.get.all.v2();
526
- return list.get.all.v1();
469
+ return { messages: list.get.all.db() };
527
470
  } catch (error) {
528
471
  throw new MastraError(
529
472
  {
530
- id: "LANCE_STORE_SAVE_MESSAGES_FAILED",
473
+ id: createStorageErrorId("LANCE", "SAVE_MESSAGES", "FAILED"),
531
474
  domain: ErrorDomain.STORAGE,
532
475
  category: ErrorCategory.THIRD_PARTY
533
476
  },
@@ -535,32 +478,54 @@ var StoreMemoryLance = class extends MemoryStorage {
535
478
  );
536
479
  }
537
480
  }
538
- async getThreadsByResourceIdPaginated(args) {
481
+ async listThreadsByResourceId(args) {
539
482
  try {
540
- const { resourceId, page = 0, perPage = 10 } = args;
541
- const table = await this.client.openTable(TABLE_THREADS);
542
- const total = await table.countRows(`\`resourceId\` = '${resourceId}'`);
543
- const query = table.query().where(`\`resourceId\` = '${resourceId}'`);
544
- const offset = page * perPage;
545
- query.limit(perPage);
546
- if (offset > 0) {
547
- query.offset(offset);
483
+ const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
484
+ const perPage = normalizePerPage(perPageInput, 100);
485
+ if (page < 0) {
486
+ throw new MastraError(
487
+ {
488
+ id: createStorageErrorId("LANCE", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
489
+ domain: ErrorDomain.STORAGE,
490
+ category: ErrorCategory.USER,
491
+ details: { page }
492
+ },
493
+ new Error("page must be >= 0")
494
+ );
548
495
  }
496
+ const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
497
+ const { field, direction } = this.parseOrderBy(orderBy);
498
+ const table = await this.client.openTable(TABLE_THREADS);
499
+ const total = await table.countRows(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
500
+ const query = table.query().where(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
549
501
  const records = await query.toArray();
550
- records.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
502
+ records.sort((a, b) => {
503
+ const aValue = ["createdAt", "updatedAt"].includes(field) ? new Date(a[field]).getTime() : a[field];
504
+ const bValue = ["createdAt", "updatedAt"].includes(field) ? new Date(b[field]).getTime() : b[field];
505
+ if (aValue == null && bValue == null) return 0;
506
+ if (aValue == null) return direction === "ASC" ? -1 : 1;
507
+ if (bValue == null) return direction === "ASC" ? 1 : -1;
508
+ if (typeof aValue === "string" && typeof bValue === "string") {
509
+ return direction === "ASC" ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
510
+ }
511
+ return direction === "ASC" ? aValue - bValue : bValue - aValue;
512
+ });
513
+ const paginatedRecords = records.slice(offset, offset + perPage);
551
514
  const schema = await getTableSchema({ tableName: TABLE_THREADS, client: this.client });
552
- const threads = records.map((record) => processResultWithTypeConversion(record, schema));
515
+ const threads = paginatedRecords.map(
516
+ (record) => processResultWithTypeConversion(record, schema)
517
+ );
553
518
  return {
554
519
  threads,
555
520
  total,
556
521
  page,
557
- perPage,
558
- hasMore: total > (page + 1) * perPage
522
+ perPage: perPageForResponse,
523
+ hasMore: offset + perPage < total
559
524
  };
560
525
  } catch (error) {
561
526
  throw new MastraError(
562
527
  {
563
- id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED",
528
+ id: createStorageErrorId("LANCE", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
564
529
  domain: ErrorDomain.STORAGE,
565
530
  category: ErrorCategory.THIRD_PARTY
566
531
  },
@@ -616,132 +581,8 @@ var StoreMemoryLance = class extends MemoryStorage {
616
581
  });
617
582
  return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
618
583
  }
619
- async getMessagesPaginated(args) {
620
- const { threadId, resourceId, selectBy, format = "v1" } = args;
621
- const page = selectBy?.pagination?.page ?? 0;
622
- const perPage = selectBy?.pagination?.perPage ?? 10;
623
- try {
624
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
625
- const dateRange = selectBy?.pagination?.dateRange;
626
- const fromDate = dateRange?.start;
627
- const toDate = dateRange?.end;
628
- const table = await this.client.openTable(TABLE_MESSAGES);
629
- const messages = [];
630
- if (selectBy?.include && Array.isArray(selectBy.include)) {
631
- const threadIds = [...new Set(selectBy.include.map((item) => item.threadId))];
632
- const allThreadMessages = [];
633
- for (const threadId2 of threadIds) {
634
- const threadQuery = table.query().where(`thread_id = '${threadId2}'`);
635
- let threadRecords = await threadQuery.toArray();
636
- if (fromDate) threadRecords = threadRecords.filter((m) => m.createdAt >= fromDate.getTime());
637
- if (toDate) threadRecords = threadRecords.filter((m) => m.createdAt <= toDate.getTime());
638
- allThreadMessages.push(...threadRecords);
639
- }
640
- allThreadMessages.sort((a, b) => a.createdAt - b.createdAt);
641
- const contextMessages = this.processMessagesWithContext(allThreadMessages, selectBy.include);
642
- messages.push(...contextMessages);
643
- }
644
- const conditions = [`thread_id = '${threadId}'`];
645
- if (resourceId) {
646
- conditions.push(`\`resourceId\` = '${resourceId}'`);
647
- }
648
- if (fromDate) {
649
- conditions.push(`\`createdAt\` >= ${fromDate.getTime()}`);
650
- }
651
- if (toDate) {
652
- conditions.push(`\`createdAt\` <= ${toDate.getTime()}`);
653
- }
654
- let total = 0;
655
- if (conditions.length > 0) {
656
- total = await table.countRows(conditions.join(" AND "));
657
- } else {
658
- total = await table.countRows();
659
- }
660
- if (total === 0 && messages.length === 0) {
661
- return {
662
- messages: [],
663
- total: 0,
664
- page,
665
- perPage,
666
- hasMore: false
667
- };
668
- }
669
- const excludeIds = messages.map((m) => m.id);
670
- let selectedMessages = [];
671
- if (selectBy?.last && selectBy.last > 0) {
672
- const query = table.query();
673
- if (conditions.length > 0) {
674
- query.where(conditions.join(" AND "));
675
- }
676
- let records = await query.toArray();
677
- records = records.sort((a, b) => a.createdAt - b.createdAt);
678
- if (excludeIds.length > 0) {
679
- records = records.filter((m) => !excludeIds.includes(m.id));
680
- }
681
- selectedMessages = records.slice(-selectBy.last);
682
- } else {
683
- const query = table.query();
684
- if (conditions.length > 0) {
685
- query.where(conditions.join(" AND "));
686
- }
687
- let records = await query.toArray();
688
- records = records.sort((a, b) => a.createdAt - b.createdAt);
689
- if (excludeIds.length > 0) {
690
- records = records.filter((m) => !excludeIds.includes(m.id));
691
- }
692
- selectedMessages = records.slice(page * perPage, (page + 1) * perPage);
693
- }
694
- const allMessages = [...messages, ...selectedMessages];
695
- const seen = /* @__PURE__ */ new Set();
696
- const dedupedMessages = allMessages.filter((m) => {
697
- const key = `${m.id}:${m.thread_id}`;
698
- if (seen.has(key)) return false;
699
- seen.add(key);
700
- return true;
701
- });
702
- const formattedMessages = dedupedMessages.map((msg) => {
703
- const { thread_id, ...rest } = msg;
704
- return {
705
- ...rest,
706
- threadId: thread_id,
707
- content: typeof msg.content === "string" ? (() => {
708
- try {
709
- return JSON.parse(msg.content);
710
- } catch {
711
- return msg.content;
712
- }
713
- })() : msg.content
714
- };
715
- });
716
- const list = new MessageList().add(formattedMessages, "memory");
717
- return {
718
- messages: format === "v2" ? list.get.all.v2() : list.get.all.v1(),
719
- total,
720
- // Total should be the count of messages matching the filters
721
- page,
722
- perPage,
723
- hasMore: total > (page + 1) * perPage
724
- };
725
- } catch (error) {
726
- const mastraError = new MastraError(
727
- {
728
- id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
729
- domain: ErrorDomain.STORAGE,
730
- category: ErrorCategory.THIRD_PARTY,
731
- details: {
732
- threadId,
733
- resourceId: resourceId ?? ""
734
- }
735
- },
736
- error
737
- );
738
- this.logger?.trackException?.(mastraError);
739
- this.logger?.error?.(mastraError.toString());
740
- return { messages: [], total: 0, page, perPage, hasMore: false };
741
- }
742
- }
743
584
  /**
744
- * Parse message data from LanceDB record format to MastraMessageV2 format
585
+ * Parse message data from LanceDB record format to MastraDBMessage format
745
586
  */
746
587
  parseMessageData(data) {
747
588
  const { thread_id, ...rest } = data;
@@ -819,7 +660,7 @@ var StoreMemoryLance = class extends MemoryStorage {
819
660
  } catch (error) {
820
661
  throw new MastraError(
821
662
  {
822
- id: "LANCE_STORE_UPDATE_MESSAGES_FAILED",
663
+ id: createStorageErrorId("LANCE", "UPDATE_MESSAGES", "FAILED"),
823
664
  domain: ErrorDomain.STORAGE,
824
665
  category: ErrorCategory.THIRD_PARTY,
825
666
  details: { count: messages.length }
@@ -896,7 +737,7 @@ var StoreMemoryLance = class extends MemoryStorage {
896
737
  } catch (error) {
897
738
  throw new MastraError(
898
739
  {
899
- id: "LANCE_STORE_GET_RESOURCE_BY_ID_FAILED",
740
+ id: createStorageErrorId("LANCE", "GET_RESOURCE_BY_ID", "FAILED"),
900
741
  domain: ErrorDomain.STORAGE,
901
742
  category: ErrorCategory.THIRD_PARTY
902
743
  },
@@ -920,7 +761,7 @@ var StoreMemoryLance = class extends MemoryStorage {
920
761
  } catch (error) {
921
762
  throw new MastraError(
922
763
  {
923
- id: "LANCE_STORE_SAVE_RESOURCE_FAILED",
764
+ id: createStorageErrorId("LANCE", "SAVE_RESOURCE", "FAILED"),
924
765
  domain: ErrorDomain.STORAGE,
925
766
  category: ErrorCategory.THIRD_PARTY
926
767
  },
@@ -974,7 +815,7 @@ var StoreMemoryLance = class extends MemoryStorage {
974
815
  }
975
816
  throw new MastraError(
976
817
  {
977
- id: "LANCE_STORE_UPDATE_RESOURCE_FAILED",
818
+ id: createStorageErrorId("LANCE", "UPDATE_RESOURCE", "FAILED"),
978
819
  domain: ErrorDomain.STORAGE,
979
820
  category: ErrorCategory.THIRD_PARTY
980
821
  },
@@ -1065,7 +906,7 @@ var StoreOperationsLance = class extends StoreOperations {
1065
906
  } catch (error) {
1066
907
  throw new MastraError(
1067
908
  {
1068
- id: "STORAGE_LANCE_STORAGE_CREATE_TABLE_INVALID_ARGS",
909
+ id: createStorageErrorId("LANCE", "CREATE_TABLE", "INVALID_ARGS"),
1069
910
  domain: ErrorDomain.STORAGE,
1070
911
  category: ErrorCategory.USER,
1071
912
  details: { tableName }
@@ -1083,7 +924,7 @@ var StoreOperationsLance = class extends StoreOperations {
1083
924
  }
1084
925
  throw new MastraError(
1085
926
  {
1086
- id: "STORAGE_LANCE_STORAGE_CREATE_TABLE_FAILED",
927
+ id: createStorageErrorId("LANCE", "CREATE_TABLE", "FAILED"),
1087
928
  domain: ErrorDomain.STORAGE,
1088
929
  category: ErrorCategory.THIRD_PARTY,
1089
930
  details: { tableName }
@@ -1103,7 +944,7 @@ var StoreOperationsLance = class extends StoreOperations {
1103
944
  } catch (validationError) {
1104
945
  throw new MastraError(
1105
946
  {
1106
- id: "STORAGE_LANCE_STORAGE_DROP_TABLE_INVALID_ARGS",
947
+ id: createStorageErrorId("LANCE", "DROP_TABLE", "INVALID_ARGS"),
1107
948
  domain: ErrorDomain.STORAGE,
1108
949
  category: ErrorCategory.USER,
1109
950
  text: validationError.message,
@@ -1121,7 +962,7 @@ var StoreOperationsLance = class extends StoreOperations {
1121
962
  }
1122
963
  throw new MastraError(
1123
964
  {
1124
- id: "STORAGE_LANCE_STORAGE_DROP_TABLE_FAILED",
965
+ id: createStorageErrorId("LANCE", "DROP_TABLE", "FAILED"),
1125
966
  domain: ErrorDomain.STORAGE,
1126
967
  category: ErrorCategory.THIRD_PARTY,
1127
968
  details: { tableName }
@@ -1152,7 +993,7 @@ var StoreOperationsLance = class extends StoreOperations {
1152
993
  } catch (validationError) {
1153
994
  throw new MastraError(
1154
995
  {
1155
- id: "STORAGE_LANCE_STORAGE_ALTER_TABLE_INVALID_ARGS",
996
+ id: createStorageErrorId("LANCE", "ALTER_TABLE", "INVALID_ARGS"),
1156
997
  domain: ErrorDomain.STORAGE,
1157
998
  category: ErrorCategory.USER,
1158
999
  text: validationError.message,
@@ -1187,7 +1028,7 @@ var StoreOperationsLance = class extends StoreOperations {
1187
1028
  } catch (error) {
1188
1029
  throw new MastraError(
1189
1030
  {
1190
- id: "STORAGE_LANCE_STORAGE_ALTER_TABLE_FAILED",
1031
+ id: createStorageErrorId("LANCE", "ALTER_TABLE", "FAILED"),
1191
1032
  domain: ErrorDomain.STORAGE,
1192
1033
  category: ErrorCategory.THIRD_PARTY,
1193
1034
  details: { tableName }
@@ -1207,7 +1048,7 @@ var StoreOperationsLance = class extends StoreOperations {
1207
1048
  } catch (validationError) {
1208
1049
  throw new MastraError(
1209
1050
  {
1210
- id: "STORAGE_LANCE_STORAGE_CLEAR_TABLE_INVALID_ARGS",
1051
+ id: createStorageErrorId("LANCE", "CLEAR_TABLE", "INVALID_ARGS"),
1211
1052
  domain: ErrorDomain.STORAGE,
1212
1053
  category: ErrorCategory.USER,
1213
1054
  text: validationError.message,
@@ -1222,7 +1063,7 @@ var StoreOperationsLance = class extends StoreOperations {
1222
1063
  } catch (error) {
1223
1064
  throw new MastraError(
1224
1065
  {
1225
- id: "STORAGE_LANCE_STORAGE_CLEAR_TABLE_FAILED",
1066
+ id: createStorageErrorId("LANCE", "CLEAR_TABLE", "FAILED"),
1226
1067
  domain: ErrorDomain.STORAGE,
1227
1068
  category: ErrorCategory.THIRD_PARTY,
1228
1069
  details: { tableName }
@@ -1245,7 +1086,7 @@ var StoreOperationsLance = class extends StoreOperations {
1245
1086
  } catch (validationError) {
1246
1087
  throw new MastraError(
1247
1088
  {
1248
- id: "STORAGE_LANCE_STORAGE_INSERT_INVALID_ARGS",
1089
+ id: createStorageErrorId("LANCE", "INSERT", "INVALID_ARGS"),
1249
1090
  domain: ErrorDomain.STORAGE,
1250
1091
  category: ErrorCategory.USER,
1251
1092
  text: validationError.message,
@@ -1264,12 +1105,11 @@ var StoreOperationsLance = class extends StoreOperations {
1264
1105
  processedRecord[key] = JSON.stringify(processedRecord[key]);
1265
1106
  }
1266
1107
  }
1267
- console.info(await table.schema());
1268
1108
  await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([processedRecord]);
1269
1109
  } catch (error) {
1270
1110
  throw new MastraError(
1271
1111
  {
1272
- id: "STORAGE_LANCE_STORAGE_INSERT_FAILED",
1112
+ id: createStorageErrorId("LANCE", "INSERT", "FAILED"),
1273
1113
  domain: ErrorDomain.STORAGE,
1274
1114
  category: ErrorCategory.THIRD_PARTY,
1275
1115
  details: { tableName }
@@ -1292,7 +1132,7 @@ var StoreOperationsLance = class extends StoreOperations {
1292
1132
  } catch (validationError) {
1293
1133
  throw new MastraError(
1294
1134
  {
1295
- id: "STORAGE_LANCE_STORAGE_BATCH_INSERT_INVALID_ARGS",
1135
+ id: createStorageErrorId("LANCE", "BATCH_INSERT", "INVALID_ARGS"),
1296
1136
  domain: ErrorDomain.STORAGE,
1297
1137
  category: ErrorCategory.USER,
1298
1138
  text: validationError.message,
@@ -1318,7 +1158,7 @@ var StoreOperationsLance = class extends StoreOperations {
1318
1158
  } catch (error) {
1319
1159
  throw new MastraError(
1320
1160
  {
1321
- id: "STORAGE_LANCE_STORAGE_BATCH_INSERT_FAILED",
1161
+ id: createStorageErrorId("LANCE", "BATCH_INSERT", "FAILED"),
1322
1162
  domain: ErrorDomain.STORAGE,
1323
1163
  category: ErrorCategory.THIRD_PARTY,
1324
1164
  details: { tableName }
@@ -1341,7 +1181,7 @@ var StoreOperationsLance = class extends StoreOperations {
1341
1181
  } catch (validationError) {
1342
1182
  throw new MastraError(
1343
1183
  {
1344
- id: "STORAGE_LANCE_STORAGE_LOAD_INVALID_ARGS",
1184
+ id: createStorageErrorId("LANCE", "LOAD", "INVALID_ARGS"),
1345
1185
  domain: ErrorDomain.STORAGE,
1346
1186
  category: ErrorCategory.USER,
1347
1187
  text: validationError.message,
@@ -1380,7 +1220,7 @@ var StoreOperationsLance = class extends StoreOperations {
1380
1220
  if (error instanceof MastraError) throw error;
1381
1221
  throw new MastraError(
1382
1222
  {
1383
- id: "STORAGE_LANCE_STORAGE_LOAD_FAILED",
1223
+ id: createStorageErrorId("LANCE", "LOAD", "FAILED"),
1384
1224
  domain: ErrorDomain.STORAGE,
1385
1225
  category: ErrorCategory.THIRD_PARTY,
1386
1226
  details: { tableName, keyCount: Object.keys(keys).length, firstKey: Object.keys(keys)[0] ?? "" }
@@ -1403,39 +1243,47 @@ var StoreScoresLance = class extends ScoresStorage {
1403
1243
  } catch (error) {
1404
1244
  throw new MastraError(
1405
1245
  {
1406
- id: "LANCE_STORAGE_SAVE_SCORE_FAILED",
1246
+ id: createStorageErrorId("LANCE", "SAVE_SCORE", "VALIDATION_FAILED"),
1407
1247
  text: "Failed to save score in LanceStorage",
1408
1248
  domain: ErrorDomain.STORAGE,
1409
- category: ErrorCategory.THIRD_PARTY
1249
+ category: ErrorCategory.USER,
1250
+ details: {
1251
+ scorer: score.scorer?.id ?? "unknown",
1252
+ entityId: score.entityId ?? "unknown",
1253
+ entityType: score.entityType ?? "unknown",
1254
+ traceId: score.traceId ?? "",
1255
+ spanId: score.spanId ?? ""
1256
+ }
1410
1257
  },
1411
1258
  error
1412
1259
  );
1413
1260
  }
1261
+ const id = crypto.randomUUID();
1262
+ const now = /* @__PURE__ */ new Date();
1414
1263
  try {
1415
- const id = crypto.randomUUID();
1416
1264
  const table = await this.client.openTable(TABLE_SCORERS);
1417
1265
  const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
1418
1266
  const allowedFields = new Set(schema.fields.map((f) => f.name));
1419
1267
  const filteredScore = {};
1420
- Object.keys(validatedScore).forEach((key) => {
1268
+ for (const key of Object.keys(validatedScore)) {
1421
1269
  if (allowedFields.has(key)) {
1422
- filteredScore[key] = score[key];
1270
+ filteredScore[key] = validatedScore[key];
1423
1271
  }
1424
- });
1272
+ }
1425
1273
  for (const key in filteredScore) {
1426
1274
  if (filteredScore[key] !== null && typeof filteredScore[key] === "object" && !(filteredScore[key] instanceof Date)) {
1427
1275
  filteredScore[key] = JSON.stringify(filteredScore[key]);
1428
1276
  }
1429
1277
  }
1430
- filteredScore.createdAt = /* @__PURE__ */ new Date();
1431
- filteredScore.updatedAt = /* @__PURE__ */ new Date();
1432
1278
  filteredScore.id = id;
1279
+ filteredScore.createdAt = now;
1280
+ filteredScore.updatedAt = now;
1433
1281
  await table.add([filteredScore], { mode: "append" });
1434
- return { score };
1282
+ return { score: { ...validatedScore, id, createdAt: now, updatedAt: now } };
1435
1283
  } catch (error) {
1436
1284
  throw new MastraError(
1437
1285
  {
1438
- id: "LANCE_STORAGE_SAVE_SCORE_FAILED",
1286
+ id: createStorageErrorId("LANCE", "SAVE_SCORE", "FAILED"),
1439
1287
  text: "Failed to save score in LanceStorage",
1440
1288
  domain: ErrorDomain.STORAGE,
1441
1289
  category: ErrorCategory.THIRD_PARTY,
@@ -1451,12 +1299,11 @@ var StoreScoresLance = class extends ScoresStorage {
1451
1299
  const query = table.query().where(`id = '${id}'`).limit(1);
1452
1300
  const records = await query.toArray();
1453
1301
  if (records.length === 0) return null;
1454
- const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
1455
- return processResultWithTypeConversion(records[0], schema);
1302
+ return await this.transformScoreRow(records[0]);
1456
1303
  } catch (error) {
1457
1304
  throw new MastraError(
1458
1305
  {
1459
- id: "LANCE_STORAGE_GET_SCORE_BY_ID_FAILED",
1306
+ id: createStorageErrorId("LANCE", "GET_SCORE_BY_ID", "FAILED"),
1460
1307
  text: "Failed to get score by id in LanceStorage",
1461
1308
  domain: ErrorDomain.STORAGE,
1462
1309
  category: ErrorCategory.THIRD_PARTY,
@@ -1466,7 +1313,23 @@ var StoreScoresLance = class extends ScoresStorage {
1466
1313
  );
1467
1314
  }
1468
1315
  }
1469
- async getScoresByScorerId({
1316
+ /**
1317
+ * LanceDB-specific score row transformation.
1318
+ *
1319
+ * Note: This implementation does NOT use coreTransformScoreRow because:
1320
+ * 1. LanceDB stores schema information in the table itself (requires async fetch)
1321
+ * 2. Uses processResultWithTypeConversion utility for LanceDB-specific type handling
1322
+ */
1323
+ async transformScoreRow(row) {
1324
+ const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
1325
+ const transformed = processResultWithTypeConversion(row, schema);
1326
+ return {
1327
+ ...transformed,
1328
+ createdAt: row.createdAt,
1329
+ updatedAt: row.updatedAt
1330
+ };
1331
+ }
1332
+ async listScoresByScorerId({
1470
1333
  scorerId,
1471
1334
  pagination,
1472
1335
  entityId,
@@ -1474,9 +1337,10 @@ var StoreScoresLance = class extends ScoresStorage {
1474
1337
  source
1475
1338
  }) {
1476
1339
  try {
1340
+ const { page, perPage: perPageInput } = pagination;
1341
+ const perPage = normalizePerPage(perPageInput, 100);
1342
+ const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1477
1343
  const table = await this.client.openTable(TABLE_SCORERS);
1478
- const { page = 0, perPage = 10 } = pagination || {};
1479
- const offset = page * perPage;
1480
1344
  let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
1481
1345
  if (source) {
1482
1346
  query = query.where(`\`source\` = '${source}'`);
@@ -1487,30 +1351,38 @@ var StoreScoresLance = class extends ScoresStorage {
1487
1351
  if (entityType) {
1488
1352
  query = query.where(`\`entityType\` = '${entityType}'`);
1489
1353
  }
1490
- query = query.limit(perPage);
1491
- if (offset > 0) query.offset(offset);
1492
- const records = await query.toArray();
1493
- const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
1494
- const scores = processResultWithTypeConversion(records, schema);
1495
1354
  let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
1496
1355
  if (source) {
1497
1356
  totalQuery = totalQuery.where(`\`source\` = '${source}'`);
1498
1357
  }
1358
+ if (entityId) {
1359
+ totalQuery = totalQuery.where(`\`entityId\` = '${entityId}'`);
1360
+ }
1361
+ if (entityType) {
1362
+ totalQuery = totalQuery.where(`\`entityType\` = '${entityType}'`);
1363
+ }
1499
1364
  const allRecords = await totalQuery.toArray();
1500
1365
  const total = allRecords.length;
1366
+ const end = perPageInput === false ? total : start + perPage;
1367
+ if (perPageInput !== false) {
1368
+ query = query.limit(perPage);
1369
+ if (start > 0) query = query.offset(start);
1370
+ }
1371
+ const records = await query.toArray();
1372
+ const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
1501
1373
  return {
1502
1374
  pagination: {
1503
1375
  page,
1504
- perPage,
1376
+ perPage: perPageForResponse,
1505
1377
  total,
1506
- hasMore: offset + scores.length < total
1378
+ hasMore: end < total
1507
1379
  },
1508
1380
  scores
1509
1381
  };
1510
1382
  } catch (error) {
1511
1383
  throw new MastraError(
1512
1384
  {
1513
- id: "LANCE_STORAGE_GET_SCORES_BY_SCORER_ID_FAILED",
1385
+ id: createStorageErrorId("LANCE", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
1514
1386
  text: "Failed to get scores by scorerId in LanceStorage",
1515
1387
  domain: ErrorDomain.STORAGE,
1516
1388
  category: ErrorCategory.THIRD_PARTY,
@@ -1520,34 +1392,38 @@ var StoreScoresLance = class extends ScoresStorage {
1520
1392
  );
1521
1393
  }
1522
1394
  }
1523
- async getScoresByRunId({
1395
+ async listScoresByRunId({
1524
1396
  runId,
1525
1397
  pagination
1526
1398
  }) {
1527
1399
  try {
1400
+ const { page, perPage: perPageInput } = pagination;
1401
+ const perPage = normalizePerPage(perPageInput, 100);
1402
+ const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1528
1403
  const table = await this.client.openTable(TABLE_SCORERS);
1529
- const { page = 0, perPage = 10 } = pagination || {};
1530
- const offset = page * perPage;
1531
- const query = table.query().where(`\`runId\` = '${runId}'`).limit(perPage);
1532
- if (offset > 0) query.offset(offset);
1533
- const records = await query.toArray();
1534
- const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
1535
- const scores = processResultWithTypeConversion(records, schema);
1536
1404
  const allRecords = await table.query().where(`\`runId\` = '${runId}'`).toArray();
1537
1405
  const total = allRecords.length;
1406
+ const end = perPageInput === false ? total : start + perPage;
1407
+ let query = table.query().where(`\`runId\` = '${runId}'`);
1408
+ if (perPageInput !== false) {
1409
+ query = query.limit(perPage);
1410
+ if (start > 0) query = query.offset(start);
1411
+ }
1412
+ const records = await query.toArray();
1413
+ const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
1538
1414
  return {
1539
1415
  pagination: {
1540
1416
  page,
1541
- perPage,
1417
+ perPage: perPageForResponse,
1542
1418
  total,
1543
- hasMore: offset + scores.length < total
1419
+ hasMore: end < total
1544
1420
  },
1545
1421
  scores
1546
1422
  };
1547
1423
  } catch (error) {
1548
1424
  throw new MastraError(
1549
1425
  {
1550
- id: "LANCE_STORAGE_GET_SCORES_BY_RUN_ID_FAILED",
1426
+ id: createStorageErrorId("LANCE", "LIST_SCORES_BY_RUN_ID", "FAILED"),
1551
1427
  text: "Failed to get scores by runId in LanceStorage",
1552
1428
  domain: ErrorDomain.STORAGE,
1553
1429
  category: ErrorCategory.THIRD_PARTY,
@@ -1557,35 +1433,39 @@ var StoreScoresLance = class extends ScoresStorage {
1557
1433
  );
1558
1434
  }
1559
1435
  }
1560
- async getScoresByEntityId({
1436
+ async listScoresByEntityId({
1561
1437
  entityId,
1562
1438
  entityType,
1563
1439
  pagination
1564
1440
  }) {
1565
1441
  try {
1442
+ const { page, perPage: perPageInput } = pagination;
1443
+ const perPage = normalizePerPage(perPageInput, 100);
1444
+ const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1566
1445
  const table = await this.client.openTable(TABLE_SCORERS);
1567
- const { page = 0, perPage = 10 } = pagination || {};
1568
- const offset = page * perPage;
1569
- const query = table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).limit(perPage);
1570
- if (offset > 0) query.offset(offset);
1571
- const records = await query.toArray();
1572
- const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
1573
- const scores = processResultWithTypeConversion(records, schema);
1574
1446
  const allRecords = await table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).toArray();
1575
1447
  const total = allRecords.length;
1448
+ const end = perPageInput === false ? total : start + perPage;
1449
+ let query = table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`);
1450
+ if (perPageInput !== false) {
1451
+ query = query.limit(perPage);
1452
+ if (start > 0) query = query.offset(start);
1453
+ }
1454
+ const records = await query.toArray();
1455
+ const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
1576
1456
  return {
1577
1457
  pagination: {
1578
1458
  page,
1579
- perPage,
1459
+ perPage: perPageForResponse,
1580
1460
  total,
1581
- hasMore: offset + scores.length < total
1461
+ hasMore: end < total
1582
1462
  },
1583
1463
  scores
1584
1464
  };
1585
1465
  } catch (error) {
1586
1466
  throw new MastraError(
1587
1467
  {
1588
- id: "LANCE_STORAGE_GET_SCORES_BY_ENTITY_ID_FAILED",
1468
+ id: createStorageErrorId("LANCE", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
1589
1469
  text: "Failed to get scores by entityId and entityType in LanceStorage",
1590
1470
  domain: ErrorDomain.STORAGE,
1591
1471
  category: ErrorCategory.THIRD_PARTY,
@@ -1595,35 +1475,39 @@ var StoreScoresLance = class extends ScoresStorage {
1595
1475
  );
1596
1476
  }
1597
1477
  }
1598
- async getScoresBySpan({
1478
+ async listScoresBySpan({
1599
1479
  traceId,
1600
1480
  spanId,
1601
1481
  pagination
1602
1482
  }) {
1603
1483
  try {
1484
+ const { page, perPage: perPageInput } = pagination;
1485
+ const perPage = normalizePerPage(perPageInput, 100);
1486
+ const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1604
1487
  const table = await this.client.openTable(TABLE_SCORERS);
1605
- const { page = 0, perPage = 10 } = pagination || {};
1606
- const offset = page * perPage;
1607
- const query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).limit(perPage);
1608
- if (offset > 0) query.offset(offset);
1609
- const records = await query.toArray();
1610
- const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
1611
- const scores = processResultWithTypeConversion(records, schema);
1612
1488
  const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
1613
1489
  const total = allRecords.length;
1490
+ const end = perPageInput === false ? total : start + perPage;
1491
+ let query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`);
1492
+ if (perPageInput !== false) {
1493
+ query = query.limit(perPage);
1494
+ if (start > 0) query = query.offset(start);
1495
+ }
1496
+ const records = await query.toArray();
1497
+ const scores = await Promise.all(records.map(async (record) => await this.transformScoreRow(record)));
1614
1498
  return {
1615
1499
  pagination: {
1616
1500
  page,
1617
- perPage,
1501
+ perPage: perPageForResponse,
1618
1502
  total,
1619
- hasMore: offset + scores.length < total
1503
+ hasMore: end < total
1620
1504
  },
1621
1505
  scores
1622
1506
  };
1623
1507
  } catch (error) {
1624
1508
  throw new MastraError(
1625
1509
  {
1626
- id: "LANCE_STORAGE_GET_SCORES_BY_SPAN_FAILED",
1510
+ id: createStorageErrorId("LANCE", "LIST_SCORES_BY_SPAN", "FAILED"),
1627
1511
  text: "Failed to get scores by traceId and spanId in LanceStorage",
1628
1512
  domain: ErrorDomain.STORAGE,
1629
1513
  category: ErrorCategory.THIRD_PARTY,
@@ -1634,198 +1518,6 @@ var StoreScoresLance = class extends ScoresStorage {
1634
1518
  }
1635
1519
  }
1636
1520
  };
1637
- var StoreTracesLance = class extends TracesStorage {
1638
- client;
1639
- operations;
1640
- constructor({ client, operations }) {
1641
- super();
1642
- this.client = client;
1643
- this.operations = operations;
1644
- }
1645
- async saveTrace({ trace }) {
1646
- try {
1647
- const table = await this.client.openTable(TABLE_TRACES);
1648
- const record = {
1649
- ...trace,
1650
- attributes: JSON.stringify(trace.attributes),
1651
- status: JSON.stringify(trace.status),
1652
- events: JSON.stringify(trace.events),
1653
- links: JSON.stringify(trace.links),
1654
- other: JSON.stringify(trace.other)
1655
- };
1656
- await table.add([record], { mode: "append" });
1657
- return trace;
1658
- } catch (error) {
1659
- throw new MastraError(
1660
- {
1661
- id: "LANCE_STORE_SAVE_TRACE_FAILED",
1662
- domain: ErrorDomain.STORAGE,
1663
- category: ErrorCategory.THIRD_PARTY
1664
- },
1665
- error
1666
- );
1667
- }
1668
- }
1669
- async getTraceById({ traceId }) {
1670
- try {
1671
- const table = await this.client.openTable(TABLE_TRACES);
1672
- const query = table.query().where(`id = '${traceId}'`);
1673
- const records = await query.toArray();
1674
- return records[0];
1675
- } catch (error) {
1676
- throw new MastraError(
1677
- {
1678
- id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
1679
- domain: ErrorDomain.STORAGE,
1680
- category: ErrorCategory.THIRD_PARTY
1681
- },
1682
- error
1683
- );
1684
- }
1685
- }
1686
- async getTraces({
1687
- name,
1688
- scope,
1689
- page = 1,
1690
- perPage = 10,
1691
- attributes
1692
- }) {
1693
- try {
1694
- const table = await this.client.openTable(TABLE_TRACES);
1695
- const query = table.query();
1696
- if (name) {
1697
- query.where(`name = '${name}'`);
1698
- }
1699
- if (scope) {
1700
- query.where(`scope = '${scope}'`);
1701
- }
1702
- if (attributes) {
1703
- query.where(`attributes = '${JSON.stringify(attributes)}'`);
1704
- }
1705
- const offset = (page - 1) * perPage;
1706
- query.limit(perPage);
1707
- if (offset > 0) {
1708
- query.offset(offset);
1709
- }
1710
- const records = await query.toArray();
1711
- return records.map((record) => {
1712
- const processed = {
1713
- ...record,
1714
- attributes: record.attributes ? JSON.parse(record.attributes) : {},
1715
- status: record.status ? JSON.parse(record.status) : {},
1716
- events: record.events ? JSON.parse(record.events) : [],
1717
- links: record.links ? JSON.parse(record.links) : [],
1718
- other: record.other ? JSON.parse(record.other) : {},
1719
- startTime: new Date(record.startTime),
1720
- endTime: new Date(record.endTime),
1721
- createdAt: new Date(record.createdAt)
1722
- };
1723
- if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
1724
- processed.parentSpanId = "";
1725
- } else {
1726
- processed.parentSpanId = String(processed.parentSpanId);
1727
- }
1728
- return processed;
1729
- });
1730
- } catch (error) {
1731
- throw new MastraError(
1732
- {
1733
- id: "LANCE_STORE_GET_TRACES_FAILED",
1734
- domain: ErrorDomain.STORAGE,
1735
- category: ErrorCategory.THIRD_PARTY,
1736
- details: { name: name ?? "", scope: scope ?? "" }
1737
- },
1738
- error
1739
- );
1740
- }
1741
- }
1742
- async getTracesPaginated(args) {
1743
- try {
1744
- const table = await this.client.openTable(TABLE_TRACES);
1745
- const query = table.query();
1746
- const conditions = [];
1747
- if (args.name) {
1748
- conditions.push(`name = '${args.name}'`);
1749
- }
1750
- if (args.scope) {
1751
- conditions.push(`scope = '${args.scope}'`);
1752
- }
1753
- if (args.attributes) {
1754
- const attributesStr = JSON.stringify(args.attributes);
1755
- conditions.push(`attributes LIKE '%${attributesStr.replace(/"/g, '\\"')}%'`);
1756
- }
1757
- if (args.dateRange?.start) {
1758
- conditions.push(`\`createdAt\` >= ${args.dateRange.start.getTime()}`);
1759
- }
1760
- if (args.dateRange?.end) {
1761
- conditions.push(`\`createdAt\` <= ${args.dateRange.end.getTime()}`);
1762
- }
1763
- if (conditions.length > 0) {
1764
- const whereClause = conditions.join(" AND ");
1765
- query.where(whereClause);
1766
- }
1767
- let total = 0;
1768
- if (conditions.length > 0) {
1769
- const countQuery = table.query().where(conditions.join(" AND "));
1770
- const allRecords = await countQuery.toArray();
1771
- total = allRecords.length;
1772
- } else {
1773
- total = await table.countRows();
1774
- }
1775
- const page = args.page || 0;
1776
- const perPage = args.perPage || 10;
1777
- const offset = page * perPage;
1778
- query.limit(perPage);
1779
- if (offset > 0) {
1780
- query.offset(offset);
1781
- }
1782
- const records = await query.toArray();
1783
- const traces = records.map((record) => {
1784
- const processed = {
1785
- ...record,
1786
- attributes: record.attributes ? JSON.parse(record.attributes) : {},
1787
- status: record.status ? JSON.parse(record.status) : {},
1788
- events: record.events ? JSON.parse(record.events) : [],
1789
- links: record.links ? JSON.parse(record.links) : [],
1790
- other: record.other ? JSON.parse(record.other) : {},
1791
- startTime: new Date(record.startTime),
1792
- endTime: new Date(record.endTime),
1793
- createdAt: new Date(record.createdAt)
1794
- };
1795
- if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
1796
- processed.parentSpanId = "";
1797
- } else {
1798
- processed.parentSpanId = String(processed.parentSpanId);
1799
- }
1800
- return processed;
1801
- });
1802
- return {
1803
- traces,
1804
- total,
1805
- page,
1806
- perPage,
1807
- hasMore: total > (page + 1) * perPage
1808
- };
1809
- } catch (error) {
1810
- throw new MastraError(
1811
- {
1812
- id: "LANCE_STORE_GET_TRACES_PAGINATED_FAILED",
1813
- domain: ErrorDomain.STORAGE,
1814
- category: ErrorCategory.THIRD_PARTY,
1815
- details: { name: args.name ?? "", scope: args.scope ?? "" }
1816
- },
1817
- error
1818
- );
1819
- }
1820
- }
1821
- async batchTraceInsert({ records }) {
1822
- this.logger.debug("Batch inserting traces", { count: records.length });
1823
- await this.operations.batchInsert({
1824
- tableName: TABLE_TRACES,
1825
- records
1826
- });
1827
- }
1828
- };
1829
1521
  function parseWorkflowRun(row) {
1830
1522
  let parsedSnapshot = row.snapshot;
1831
1523
  if (typeof parsedSnapshot === "string") {
@@ -1855,7 +1547,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1855
1547
  // runId,
1856
1548
  // stepId,
1857
1549
  // result,
1858
- // runtimeContext,
1550
+ // requestContext,
1859
1551
  }) {
1860
1552
  throw new Error("Method not implemented.");
1861
1553
  }
@@ -1883,11 +1575,13 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1883
1575
  } else {
1884
1576
  createdAt = now;
1885
1577
  }
1578
+ const { status, value, ...rest } = snapshot;
1886
1579
  const record = {
1887
1580
  workflow_name: workflowName,
1888
1581
  run_id: runId,
1889
1582
  resourceId,
1890
- snapshot: JSON.stringify(snapshot),
1583
+ snapshot: JSON.stringify({ status, value, ...rest }),
1584
+ // this is to ensure status is always just before value, for when querying the db by status
1891
1585
  createdAt,
1892
1586
  updatedAt: now
1893
1587
  };
@@ -1895,7 +1589,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1895
1589
  } catch (error) {
1896
1590
  throw new MastraError(
1897
1591
  {
1898
- id: "LANCE_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
1592
+ id: createStorageErrorId("LANCE", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
1899
1593
  domain: ErrorDomain.STORAGE,
1900
1594
  category: ErrorCategory.THIRD_PARTY,
1901
1595
  details: { workflowName, runId }
@@ -1916,7 +1610,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1916
1610
  } catch (error) {
1917
1611
  throw new MastraError(
1918
1612
  {
1919
- id: "LANCE_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
1613
+ id: createStorageErrorId("LANCE", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
1920
1614
  domain: ErrorDomain.STORAGE,
1921
1615
  category: ErrorCategory.THIRD_PARTY,
1922
1616
  details: { workflowName, runId }
@@ -1940,7 +1634,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1940
1634
  } catch (error) {
1941
1635
  throw new MastraError(
1942
1636
  {
1943
- id: "LANCE_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
1637
+ id: createStorageErrorId("LANCE", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
1944
1638
  domain: ErrorDomain.STORAGE,
1945
1639
  category: ErrorCategory.THIRD_PARTY,
1946
1640
  details: { runId: args.runId, workflowName: args.workflowName ?? "" }
@@ -1949,7 +1643,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1949
1643
  );
1950
1644
  }
1951
1645
  }
1952
- async getWorkflowRuns(args) {
1646
+ async listWorkflowRuns(args) {
1953
1647
  try {
1954
1648
  const table = await this.client.openTable(TABLE_WORKFLOW_SNAPSHOT);
1955
1649
  let query = table.query();
@@ -1957,6 +1651,10 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1957
1651
  if (args?.workflowName) {
1958
1652
  conditions.push(`workflow_name = '${args.workflowName.replace(/'/g, "''")}'`);
1959
1653
  }
1654
+ if (args?.status) {
1655
+ const escapedStatus = args.status.replace(/\\/g, "\\\\").replace(/'/g, "''").replace(/%/g, "\\%").replace(/_/g, "\\_");
1656
+ conditions.push(`\`snapshot\` LIKE '%"status":"${escapedStatus}","value"%'`);
1657
+ }
1960
1658
  if (args?.resourceId) {
1961
1659
  conditions.push(`\`resourceId\` = '${args.resourceId}'`);
1962
1660
  }
@@ -1973,11 +1671,22 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1973
1671
  } else {
1974
1672
  total = await table.countRows();
1975
1673
  }
1976
- if (args?.limit) {
1977
- query.limit(args.limit);
1978
- }
1979
- if (args?.offset) {
1980
- query.offset(args.offset);
1674
+ if (args?.perPage !== void 0 && args?.page !== void 0) {
1675
+ const normalizedPerPage = normalizePerPage(args.perPage, Number.MAX_SAFE_INTEGER);
1676
+ if (args.page < 0 || !Number.isInteger(args.page)) {
1677
+ throw new MastraError(
1678
+ {
1679
+ id: createStorageErrorId("LANCE", "LIST_WORKFLOW_RUNS", "INVALID_PAGINATION"),
1680
+ domain: ErrorDomain.STORAGE,
1681
+ category: ErrorCategory.USER,
1682
+ details: { page: args.page, perPage: args.perPage }
1683
+ },
1684
+ new Error(`Invalid pagination parameters: page=${args.page}, perPage=${args.perPage}`)
1685
+ );
1686
+ }
1687
+ const offset = args.page * normalizedPerPage;
1688
+ query.limit(normalizedPerPage);
1689
+ query.offset(offset);
1981
1690
  }
1982
1691
  const records = await query.toArray();
1983
1692
  return {
@@ -1987,10 +1696,10 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1987
1696
  } catch (error) {
1988
1697
  throw new MastraError(
1989
1698
  {
1990
- id: "LANCE_STORE_GET_WORKFLOW_RUNS_FAILED",
1699
+ id: createStorageErrorId("LANCE", "LIST_WORKFLOW_RUNS", "FAILED"),
1991
1700
  domain: ErrorDomain.STORAGE,
1992
1701
  category: ErrorCategory.THIRD_PARTY,
1993
- details: { namespace: args?.namespace ?? "", workflowName: args?.workflowName ?? "" }
1702
+ details: { resourceId: args?.resourceId ?? "", workflowName: args?.workflowName ?? "" }
1994
1703
  },
1995
1704
  error
1996
1705
  );
@@ -2004,48 +1713,54 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2004
1713
  lanceClient;
2005
1714
  /**
2006
1715
  * Creates a new instance of LanceStorage
1716
+ * @param id The unique identifier for this storage instance
1717
+ * @param name The name for this storage instance
2007
1718
  * @param uri The URI to connect to LanceDB
2008
- * @param options connection options
1719
+ * @param connectionOptions connection options for LanceDB
1720
+ * @param storageOptions storage options including disableInit
2009
1721
  *
2010
1722
  * Usage:
2011
1723
  *
2012
1724
  * Connect to a local database
2013
1725
  * ```ts
2014
- * const store = await LanceStorage.create('/path/to/db');
1726
+ * const store = await LanceStorage.create('my-storage-id', 'MyStorage', '/path/to/db');
2015
1727
  * ```
2016
1728
  *
2017
1729
  * Connect to a LanceDB cloud database
2018
1730
  * ```ts
2019
- * const store = await LanceStorage.create('db://host:port');
1731
+ * const store = await LanceStorage.create('my-storage-id', 'MyStorage', 'db://host:port');
2020
1732
  * ```
2021
1733
  *
2022
1734
  * Connect to a cloud database
2023
1735
  * ```ts
2024
- * const store = await LanceStorage.create('s3://bucket/db', { storageOptions: { timeout: '60s' } });
1736
+ * const store = await LanceStorage.create('my-storage-id', 'MyStorage', 's3://bucket/db', { storageOptions: { timeout: '60s' } });
1737
+ * ```
1738
+ *
1739
+ * Disable auto-init for runtime (after CI/CD has run migrations)
1740
+ * ```ts
1741
+ * const store = await LanceStorage.create('my-storage-id', 'MyStorage', '/path/to/db', undefined, { disableInit: true });
2025
1742
  * ```
2026
1743
  */
2027
- static async create(name, uri, options) {
2028
- const instance = new _LanceStorage(name);
1744
+ static async create(id, name, uri, connectionOptions, storageOptions) {
1745
+ const instance = new _LanceStorage(id, name, storageOptions?.disableInit);
2029
1746
  try {
2030
- instance.lanceClient = await connect(uri, options);
1747
+ instance.lanceClient = await connect(uri, connectionOptions);
2031
1748
  const operations = new StoreOperationsLance({ client: instance.lanceClient });
2032
1749
  instance.stores = {
2033
1750
  operations: new StoreOperationsLance({ client: instance.lanceClient }),
2034
1751
  workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
2035
- traces: new StoreTracesLance({ client: instance.lanceClient, operations }),
2036
1752
  scores: new StoreScoresLance({ client: instance.lanceClient }),
2037
- memory: new StoreMemoryLance({ client: instance.lanceClient, operations }),
2038
- legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
1753
+ memory: new StoreMemoryLance({ client: instance.lanceClient, operations })
2039
1754
  };
2040
1755
  return instance;
2041
1756
  } catch (e) {
2042
1757
  throw new MastraError(
2043
1758
  {
2044
- id: "STORAGE_LANCE_STORAGE_CONNECT_FAILED",
1759
+ id: createStorageErrorId("LANCE", "CONNECT", "FAILED"),
2045
1760
  domain: ErrorDomain.STORAGE,
2046
1761
  category: ErrorCategory.THIRD_PARTY,
2047
1762
  text: `Failed to connect to LanceDB: ${e.message || e}`,
2048
- details: { uri, optionsProvided: !!options }
1763
+ details: { uri, optionsProvided: !!connectionOptions }
2049
1764
  },
2050
1765
  e
2051
1766
  );
@@ -2055,15 +1770,13 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2055
1770
  * @internal
2056
1771
  * Private constructor to enforce using the create factory method
2057
1772
  */
2058
- constructor(name) {
2059
- super({ name });
1773
+ constructor(id, name, disableInit) {
1774
+ super({ id, name, disableInit });
2060
1775
  const operations = new StoreOperationsLance({ client: this.lanceClient });
2061
1776
  this.stores = {
2062
1777
  operations: new StoreOperationsLance({ client: this.lanceClient }),
2063
1778
  workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
2064
- traces: new StoreTracesLance({ client: this.lanceClient, operations }),
2065
1779
  scores: new StoreScoresLance({ client: this.lanceClient }),
2066
- legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
2067
1780
  memory: new StoreMemoryLance({ client: this.lanceClient, operations })
2068
1781
  };
2069
1782
  }
@@ -2098,9 +1811,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2098
1811
  async getThreadById({ threadId }) {
2099
1812
  return this.stores.memory.getThreadById({ threadId });
2100
1813
  }
2101
- async getThreadsByResourceId({ resourceId }) {
2102
- return this.stores.memory.getThreadsByResourceId({ resourceId });
2103
- }
2104
1814
  /**
2105
1815
  * Saves a thread to the database. This function doesn't overwrite existing threads.
2106
1816
  * @param thread - The thread to save
@@ -2126,7 +1836,7 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2126
1836
  hasColumn: true,
2127
1837
  createTable: true,
2128
1838
  deleteMessages: false,
2129
- getScoresBySpan: true
1839
+ listScoresBySpan: true
2130
1840
  };
2131
1841
  }
2132
1842
  async getResourceById({ resourceId }) {
@@ -2190,50 +1900,17 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2190
1900
  });
2191
1901
  return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
2192
1902
  }
2193
- async getMessages({
2194
- threadId,
2195
- resourceId,
2196
- selectBy,
2197
- format,
2198
- threadConfig
2199
- }) {
2200
- return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
2201
- }
2202
- async getMessagesById({
2203
- messageIds,
2204
- format
2205
- }) {
2206
- return this.stores.memory.getMessagesById({ messageIds, format });
1903
+ async listMessagesById({ messageIds }) {
1904
+ return this.stores.memory.listMessagesById({ messageIds });
2207
1905
  }
2208
1906
  async saveMessages(args) {
2209
1907
  return this.stores.memory.saveMessages(args);
2210
1908
  }
2211
- async getThreadsByResourceIdPaginated(args) {
2212
- return this.stores.memory.getThreadsByResourceIdPaginated(args);
2213
- }
2214
- async getMessagesPaginated(args) {
2215
- return this.stores.memory.getMessagesPaginated(args);
2216
- }
2217
1909
  async updateMessages(_args) {
2218
1910
  return this.stores.memory.updateMessages(_args);
2219
1911
  }
2220
- async getTraceById(args) {
2221
- return this.stores.traces.getTraceById(args);
2222
- }
2223
- async getTraces(args) {
2224
- return this.stores.traces.getTraces(args);
2225
- }
2226
- async getTracesPaginated(args) {
2227
- return this.stores.traces.getTracesPaginated(args);
2228
- }
2229
- async getEvalsByAgentName(agentName, type) {
2230
- return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
2231
- }
2232
- async getEvals(options) {
2233
- return this.stores.legacyEvals.getEvals(options);
2234
- }
2235
- async getWorkflowRuns(args) {
2236
- return this.stores.workflows.getWorkflowRuns(args);
1912
+ async listWorkflowRuns(args) {
1913
+ return this.stores.workflows.listWorkflowRuns(args);
2237
1914
  }
2238
1915
  async getWorkflowRunById(args) {
2239
1916
  return this.stores.workflows.getWorkflowRunById(args);
@@ -2243,9 +1920,9 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2243
1920
  runId,
2244
1921
  stepId,
2245
1922
  result,
2246
- runtimeContext
1923
+ requestContext
2247
1924
  }) {
2248
- return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
1925
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
2249
1926
  }
2250
1927
  async updateWorkflowState({
2251
1928
  workflowName,
@@ -2271,37 +1948,37 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2271
1948
  async getScoreById({ id: _id }) {
2272
1949
  return this.stores.scores.getScoreById({ id: _id });
2273
1950
  }
2274
- async getScoresByScorerId({
1951
+ async listScoresByScorerId({
2275
1952
  scorerId,
2276
1953
  source,
2277
1954
  entityId,
2278
1955
  entityType,
2279
1956
  pagination
2280
1957
  }) {
2281
- return this.stores.scores.getScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
1958
+ return this.stores.scores.listScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
2282
1959
  }
2283
- async saveScore(_score) {
2284
- return this.stores.scores.saveScore(_score);
1960
+ async saveScore(score) {
1961
+ return this.stores.scores.saveScore(score);
2285
1962
  }
2286
- async getScoresByRunId({
1963
+ async listScoresByRunId({
2287
1964
  runId,
2288
1965
  pagination
2289
1966
  }) {
2290
- return this.stores.scores.getScoresByRunId({ runId, pagination });
1967
+ return this.stores.scores.listScoresByRunId({ runId, pagination });
2291
1968
  }
2292
- async getScoresByEntityId({
1969
+ async listScoresByEntityId({
2293
1970
  entityId,
2294
1971
  entityType,
2295
1972
  pagination
2296
1973
  }) {
2297
- return this.stores.scores.getScoresByEntityId({ entityId, entityType, pagination });
1974
+ return this.stores.scores.listScoresByEntityId({ entityId, entityType, pagination });
2298
1975
  }
2299
- async getScoresBySpan({
1976
+ async listScoresBySpan({
2300
1977
  traceId,
2301
1978
  spanId,
2302
1979
  pagination
2303
1980
  }) {
2304
- return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
1981
+ return this.stores.scores.listScoresBySpan({ traceId, spanId, pagination });
2305
1982
  }
2306
1983
  };
2307
1984
  var LanceFilterTranslator = class extends BaseFilterTranslator {
@@ -2650,14 +2327,14 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2650
2327
  * ```
2651
2328
  */
2652
2329
  static async create(uri, options) {
2653
- const instance = new _LanceVectorStore();
2330
+ const instance = new _LanceVectorStore(options?.id || crypto.randomUUID());
2654
2331
  try {
2655
2332
  instance.lanceClient = await connect(uri, options);
2656
2333
  return instance;
2657
2334
  } catch (e) {
2658
2335
  throw new MastraError(
2659
2336
  {
2660
- id: "STORAGE_LANCE_VECTOR_CONNECT_FAILED",
2337
+ id: createVectorErrorId("LANCE", "CONNECT", "FAILED"),
2661
2338
  domain: ErrorDomain.STORAGE,
2662
2339
  category: ErrorCategory.THIRD_PARTY,
2663
2340
  details: { uri }
@@ -2670,8 +2347,8 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2670
2347
  * @internal
2671
2348
  * Private constructor to enforce using the create factory method
2672
2349
  */
2673
- constructor() {
2674
- super();
2350
+ constructor(id) {
2351
+ super({ id });
2675
2352
  }
2676
2353
  close() {
2677
2354
  if (this.lanceClient) {
@@ -2700,7 +2377,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2700
2377
  } catch (error) {
2701
2378
  throw new MastraError(
2702
2379
  {
2703
- id: "STORAGE_LANCE_VECTOR_QUERY_FAILED_INVALID_ARGS",
2380
+ id: createVectorErrorId("LANCE", "QUERY", "INVALID_ARGS"),
2704
2381
  domain: ErrorDomain.STORAGE,
2705
2382
  category: ErrorCategory.USER,
2706
2383
  text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
@@ -2748,7 +2425,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2748
2425
  } catch (error) {
2749
2426
  throw new MastraError(
2750
2427
  {
2751
- id: "STORAGE_LANCE_VECTOR_QUERY_FAILED",
2428
+ id: createVectorErrorId("LANCE", "QUERY", "FAILED"),
2752
2429
  domain: ErrorDomain.STORAGE,
2753
2430
  category: ErrorCategory.THIRD_PARTY,
2754
2431
  details: { tableName, includeVector, columnsCount: columns?.length, includeAllColumns }
@@ -2800,7 +2477,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2800
2477
  } catch (error) {
2801
2478
  throw new MastraError(
2802
2479
  {
2803
- id: "STORAGE_LANCE_VECTOR_UPSERT_FAILED_INVALID_ARGS",
2480
+ id: createVectorErrorId("LANCE", "UPSERT", "INVALID_ARGS"),
2804
2481
  domain: ErrorDomain.STORAGE,
2805
2482
  category: ErrorCategory.USER,
2806
2483
  text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
@@ -2836,7 +2513,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2836
2513
  } catch (error) {
2837
2514
  throw new MastraError(
2838
2515
  {
2839
- id: "STORAGE_LANCE_VECTOR_UPSERT_FAILED",
2516
+ id: createVectorErrorId("LANCE", "UPSERT", "FAILED"),
2840
2517
  domain: ErrorDomain.STORAGE,
2841
2518
  category: ErrorCategory.THIRD_PARTY,
2842
2519
  details: { tableName, vectorCount: vectors.length, metadataCount: metadata.length, idsCount: ids.length }
@@ -2863,7 +2540,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2863
2540
  async createTable(tableName, data, options) {
2864
2541
  if (!this.lanceClient) {
2865
2542
  throw new MastraError({
2866
- id: "STORAGE_LANCE_VECTOR_CREATE_TABLE_FAILED_INVALID_ARGS",
2543
+ id: createVectorErrorId("LANCE", "CREATE_TABLE", "INVALID_ARGS"),
2867
2544
  domain: ErrorDomain.STORAGE,
2868
2545
  category: ErrorCategory.USER,
2869
2546
  text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
@@ -2878,7 +2555,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2878
2555
  } catch (error) {
2879
2556
  throw new MastraError(
2880
2557
  {
2881
- id: "STORAGE_LANCE_VECTOR_CREATE_TABLE_FAILED",
2558
+ id: createVectorErrorId("LANCE", "CREATE_TABLE", "FAILED"),
2882
2559
  domain: ErrorDomain.STORAGE,
2883
2560
  category: ErrorCategory.THIRD_PARTY,
2884
2561
  details: { tableName }
@@ -2890,7 +2567,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2890
2567
  async listTables() {
2891
2568
  if (!this.lanceClient) {
2892
2569
  throw new MastraError({
2893
- id: "STORAGE_LANCE_VECTOR_LIST_TABLES_FAILED_INVALID_ARGS",
2570
+ id: createVectorErrorId("LANCE", "LIST_TABLES", "INVALID_ARGS"),
2894
2571
  domain: ErrorDomain.STORAGE,
2895
2572
  category: ErrorCategory.USER,
2896
2573
  text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
@@ -2902,7 +2579,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2902
2579
  } catch (error) {
2903
2580
  throw new MastraError(
2904
2581
  {
2905
- id: "STORAGE_LANCE_VECTOR_LIST_TABLES_FAILED",
2582
+ id: createVectorErrorId("LANCE", "LIST_TABLES", "FAILED"),
2906
2583
  domain: ErrorDomain.STORAGE,
2907
2584
  category: ErrorCategory.THIRD_PARTY
2908
2585
  },
@@ -2913,7 +2590,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2913
2590
  async getTableSchema(tableName) {
2914
2591
  if (!this.lanceClient) {
2915
2592
  throw new MastraError({
2916
- id: "STORAGE_LANCE_VECTOR_GET_TABLE_SCHEMA_FAILED_INVALID_ARGS",
2593
+ id: createVectorErrorId("LANCE", "GET_TABLE_SCHEMA", "INVALID_ARGS"),
2917
2594
  domain: ErrorDomain.STORAGE,
2918
2595
  category: ErrorCategory.USER,
2919
2596
  text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
@@ -2926,7 +2603,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2926
2603
  } catch (error) {
2927
2604
  throw new MastraError(
2928
2605
  {
2929
- id: "STORAGE_LANCE_VECTOR_GET_TABLE_SCHEMA_FAILED",
2606
+ id: createVectorErrorId("LANCE", "GET_TABLE_SCHEMA", "FAILED"),
2930
2607
  domain: ErrorDomain.STORAGE,
2931
2608
  category: ErrorCategory.THIRD_PARTY,
2932
2609
  details: { tableName }
@@ -2961,7 +2638,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
2961
2638
  } catch (err) {
2962
2639
  throw new MastraError(
2963
2640
  {
2964
- id: "STORAGE_LANCE_VECTOR_CREATE_INDEX_FAILED_INVALID_ARGS",
2641
+ id: createVectorErrorId("LANCE", "CREATE_INDEX", "INVALID_ARGS"),
2965
2642
  domain: ErrorDomain.STORAGE,
2966
2643
  category: ErrorCategory.USER,
2967
2644
  details: { tableName: tableName || "", indexName, dimension, metric }
@@ -3006,7 +2683,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3006
2683
  } catch (error) {
3007
2684
  throw new MastraError(
3008
2685
  {
3009
- id: "STORAGE_LANCE_VECTOR_CREATE_INDEX_FAILED",
2686
+ id: createVectorErrorId("LANCE", "CREATE_INDEX", "FAILED"),
3010
2687
  domain: ErrorDomain.STORAGE,
3011
2688
  category: ErrorCategory.THIRD_PARTY,
3012
2689
  details: { tableName: tableName || "", indexName, dimension }
@@ -3018,7 +2695,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3018
2695
  async listIndexes() {
3019
2696
  if (!this.lanceClient) {
3020
2697
  throw new MastraError({
3021
- id: "STORAGE_LANCE_VECTOR_LIST_INDEXES_FAILED_INVALID_ARGS",
2698
+ id: createVectorErrorId("LANCE", "LIST_INDEXES", "INVALID_ARGS"),
3022
2699
  domain: ErrorDomain.STORAGE,
3023
2700
  category: ErrorCategory.USER,
3024
2701
  text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
@@ -3037,7 +2714,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3037
2714
  } catch (error) {
3038
2715
  throw new MastraError(
3039
2716
  {
3040
- id: "STORAGE_LANCE_VECTOR_LIST_INDEXES_FAILED",
2717
+ id: createVectorErrorId("LANCE", "LIST_INDEXES", "FAILED"),
3041
2718
  domain: ErrorDomain.STORAGE,
3042
2719
  category: ErrorCategory.THIRD_PARTY
3043
2720
  },
@@ -3056,7 +2733,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3056
2733
  } catch (err) {
3057
2734
  throw new MastraError(
3058
2735
  {
3059
- id: "STORAGE_LANCE_VECTOR_DESCRIBE_INDEX_FAILED_INVALID_ARGS",
2736
+ id: createVectorErrorId("LANCE", "DESCRIBE_INDEX", "INVALID_ARGS"),
3060
2737
  domain: ErrorDomain.STORAGE,
3061
2738
  category: ErrorCategory.USER,
3062
2739
  details: { indexName }
@@ -3091,7 +2768,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3091
2768
  } catch (error) {
3092
2769
  throw new MastraError(
3093
2770
  {
3094
- id: "STORAGE_LANCE_VECTOR_DESCRIBE_INDEX_FAILED",
2771
+ id: createVectorErrorId("LANCE", "DESCRIBE_INDEX", "FAILED"),
3095
2772
  domain: ErrorDomain.STORAGE,
3096
2773
  category: ErrorCategory.THIRD_PARTY,
3097
2774
  details: { indexName }
@@ -3111,7 +2788,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3111
2788
  } catch (err) {
3112
2789
  throw new MastraError(
3113
2790
  {
3114
- id: "STORAGE_LANCE_VECTOR_DELETE_INDEX_FAILED_INVALID_ARGS",
2791
+ id: createVectorErrorId("LANCE", "DELETE_INDEX", "INVALID_ARGS"),
3115
2792
  domain: ErrorDomain.STORAGE,
3116
2793
  category: ErrorCategory.USER,
3117
2794
  details: { indexName }
@@ -3134,7 +2811,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3134
2811
  } catch (error) {
3135
2812
  throw new MastraError(
3136
2813
  {
3137
- id: "STORAGE_LANCE_VECTOR_DELETE_INDEX_FAILED",
2814
+ id: createVectorErrorId("LANCE", "DELETE_INDEX", "FAILED"),
3138
2815
  domain: ErrorDomain.STORAGE,
3139
2816
  category: ErrorCategory.THIRD_PARTY,
3140
2817
  details: { indexName }
@@ -3149,7 +2826,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3149
2826
  async deleteAllTables() {
3150
2827
  if (!this.lanceClient) {
3151
2828
  throw new MastraError({
3152
- id: "STORAGE_LANCE_VECTOR_DELETE_ALL_TABLES_FAILED_INVALID_ARGS",
2829
+ id: createVectorErrorId("LANCE", "DELETE_ALL_TABLES", "INVALID_ARGS"),
3153
2830
  domain: ErrorDomain.STORAGE,
3154
2831
  category: ErrorCategory.USER,
3155
2832
  details: { methodName: "deleteAllTables" },
@@ -3161,7 +2838,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3161
2838
  } catch (error) {
3162
2839
  throw new MastraError(
3163
2840
  {
3164
- id: "STORAGE_LANCE_VECTOR_DELETE_ALL_TABLES_FAILED",
2841
+ id: createVectorErrorId("LANCE", "DELETE_ALL_TABLES", "FAILED"),
3165
2842
  domain: ErrorDomain.STORAGE,
3166
2843
  category: ErrorCategory.THIRD_PARTY,
3167
2844
  details: { methodName: "deleteAllTables" }
@@ -3173,7 +2850,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3173
2850
  async deleteTable(tableName) {
3174
2851
  if (!this.lanceClient) {
3175
2852
  throw new MastraError({
3176
- id: "STORAGE_LANCE_VECTOR_DELETE_TABLE_FAILED_INVALID_ARGS",
2853
+ id: createVectorErrorId("LANCE", "DELETE_TABLE", "INVALID_ARGS"),
3177
2854
  domain: ErrorDomain.STORAGE,
3178
2855
  category: ErrorCategory.USER,
3179
2856
  details: { tableName },
@@ -3185,7 +2862,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3185
2862
  } catch (error) {
3186
2863
  throw new MastraError(
3187
2864
  {
3188
- id: "STORAGE_LANCE_VECTOR_DELETE_TABLE_FAILED",
2865
+ id: createVectorErrorId("LANCE", "DELETE_TABLE", "FAILED"),
3189
2866
  domain: ErrorDomain.STORAGE,
3190
2867
  category: ErrorCategory.THIRD_PARTY,
3191
2868
  details: { tableName }
@@ -3198,7 +2875,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3198
2875
  const { indexName, update } = params;
3199
2876
  if ("id" in params && "filter" in params && params.id && params.filter) {
3200
2877
  throw new MastraError({
3201
- id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
2878
+ id: createVectorErrorId("LANCE", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
3202
2879
  domain: ErrorDomain.STORAGE,
3203
2880
  category: ErrorCategory.USER,
3204
2881
  text: "id and filter are mutually exclusive",
@@ -3207,7 +2884,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3207
2884
  }
3208
2885
  if (!("id" in params || "filter" in params) || !params.id && !params.filter) {
3209
2886
  throw new MastraError({
3210
- id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
2887
+ id: createVectorErrorId("LANCE", "UPDATE_VECTOR", "NO_TARGET"),
3211
2888
  domain: ErrorDomain.STORAGE,
3212
2889
  category: ErrorCategory.USER,
3213
2890
  text: "Either id or filter must be provided",
@@ -3216,7 +2893,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3216
2893
  }
3217
2894
  if ("filter" in params && params.filter && Object.keys(params.filter).length === 0) {
3218
2895
  throw new MastraError({
3219
- id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
2896
+ id: createVectorErrorId("LANCE", "UPDATE_VECTOR", "EMPTY_FILTER"),
3220
2897
  domain: ErrorDomain.STORAGE,
3221
2898
  category: ErrorCategory.USER,
3222
2899
  text: "Cannot update with empty filter",
@@ -3225,7 +2902,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3225
2902
  }
3226
2903
  if (!update.vector && !update.metadata) {
3227
2904
  throw new MastraError({
3228
- id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
2905
+ id: createVectorErrorId("LANCE", "UPDATE_VECTOR", "NO_PAYLOAD"),
3229
2906
  domain: ErrorDomain.STORAGE,
3230
2907
  category: ErrorCategory.USER,
3231
2908
  text: "No updates provided",
@@ -3320,7 +2997,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3320
2997
  if (error instanceof MastraError) throw error;
3321
2998
  throw new MastraError(
3322
2999
  {
3323
- id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED",
3000
+ id: createVectorErrorId("LANCE", "UPDATE_VECTOR", "FAILED"),
3324
3001
  domain: ErrorDomain.STORAGE,
3325
3002
  category: ErrorCategory.THIRD_PARTY,
3326
3003
  details: {
@@ -3349,7 +3026,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3349
3026
  } catch (err) {
3350
3027
  throw new MastraError(
3351
3028
  {
3352
- id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED_INVALID_ARGS",
3029
+ id: createVectorErrorId("LANCE", "DELETE_VECTOR", "INVALID_ARGS"),
3353
3030
  domain: ErrorDomain.STORAGE,
3354
3031
  category: ErrorCategory.USER,
3355
3032
  details: {
@@ -3382,7 +3059,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3382
3059
  } catch (error) {
3383
3060
  throw new MastraError(
3384
3061
  {
3385
- id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED",
3062
+ id: createVectorErrorId("LANCE", "DELETE_VECTOR", "FAILED"),
3386
3063
  domain: ErrorDomain.STORAGE,
3387
3064
  category: ErrorCategory.THIRD_PARTY,
3388
3065
  details: {
@@ -3422,7 +3099,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3422
3099
  async deleteVectors({ indexName, filter, ids }) {
3423
3100
  if (ids && filter) {
3424
3101
  throw new MastraError({
3425
- id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
3102
+ id: createVectorErrorId("LANCE", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
3426
3103
  domain: ErrorDomain.STORAGE,
3427
3104
  category: ErrorCategory.USER,
3428
3105
  text: "ids and filter are mutually exclusive",
@@ -3431,7 +3108,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3431
3108
  }
3432
3109
  if (!ids && !filter) {
3433
3110
  throw new MastraError({
3434
- id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
3111
+ id: createVectorErrorId("LANCE", "DELETE_VECTORS", "NO_TARGET"),
3435
3112
  domain: ErrorDomain.STORAGE,
3436
3113
  category: ErrorCategory.USER,
3437
3114
  text: "Either filter or ids must be provided",
@@ -3440,7 +3117,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3440
3117
  }
3441
3118
  if (ids && ids.length === 0) {
3442
3119
  throw new MastraError({
3443
- id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
3120
+ id: createVectorErrorId("LANCE", "DELETE_VECTORS", "EMPTY_IDS"),
3444
3121
  domain: ErrorDomain.STORAGE,
3445
3122
  category: ErrorCategory.USER,
3446
3123
  text: "Cannot delete with empty ids array",
@@ -3449,7 +3126,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3449
3126
  }
3450
3127
  if (filter && Object.keys(filter).length === 0) {
3451
3128
  throw new MastraError({
3452
- id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
3129
+ id: createVectorErrorId("LANCE", "DELETE_VECTORS", "EMPTY_FILTER"),
3453
3130
  domain: ErrorDomain.STORAGE,
3454
3131
  category: ErrorCategory.USER,
3455
3132
  text: "Cannot delete with empty filter",
@@ -3509,7 +3186,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
3509
3186
  if (error instanceof MastraError) throw error;
3510
3187
  throw new MastraError(
3511
3188
  {
3512
- id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_FAILED",
3189
+ id: createVectorErrorId("LANCE", "DELETE_VECTORS", "FAILED"),
3513
3190
  domain: ErrorDomain.STORAGE,
3514
3191
  category: ErrorCategory.THIRD_PARTY,
3515
3192
  details: {