@mastra/lance 0.0.0-new-scorer-api-20250801075530 → 0.0.0-remove-unused-import-20250909212718

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +271 -3
  2. package/README.md +3 -3
  3. package/dist/index.cjs +128 -29
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +128 -29
  7. package/dist/index.js.map +1 -1
  8. package/dist/storage/domains/memory/index.d.ts +10 -1
  9. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  10. package/dist/storage/domains/scores/index.d.ts +5 -2
  11. package/dist/storage/domains/scores/index.d.ts.map +1 -1
  12. package/dist/storage/domains/traces/index.d.ts +1 -1
  13. package/dist/storage/domains/workflows/index.d.ts +19 -1
  14. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  15. package/dist/storage/index.d.ts +32 -3
  16. package/dist/storage/index.d.ts.map +1 -1
  17. package/dist/vector/index.d.ts +3 -3
  18. package/dist/vector/index.d.ts.map +1 -1
  19. package/package.json +21 -7
  20. package/eslint.config.js +0 -6
  21. package/src/index.ts +0 -2
  22. package/src/storage/domains/legacy-evals/index.ts +0 -156
  23. package/src/storage/domains/memory/index.ts +0 -947
  24. package/src/storage/domains/operations/index.ts +0 -489
  25. package/src/storage/domains/scores/index.ts +0 -221
  26. package/src/storage/domains/traces/index.ts +0 -212
  27. package/src/storage/domains/utils.ts +0 -158
  28. package/src/storage/domains/workflows/index.ts +0 -207
  29. package/src/storage/index.test.ts +0 -10
  30. package/src/storage/index.ts +0 -442
  31. package/src/vector/filter.test.ts +0 -295
  32. package/src/vector/filter.ts +0 -443
  33. package/src/vector/index.test.ts +0 -1493
  34. package/src/vector/index.ts +0 -941
  35. package/src/vector/types.ts +0 -16
  36. package/tsconfig.build.json +0 -9
  37. package/tsconfig.json +0 -5
  38. package/tsup.config.ts +0 -22
  39. package/vitest.config.ts +0 -11
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './storage';
2
- export * from './vector';
1
+ export * from './storage/index.js';
2
+ export * from './vector/index.js';
3
3
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -379,6 +379,20 @@ var StoreMemoryLance = class extends MemoryStorage {
379
379
  );
380
380
  }
381
381
  }
382
+ normalizeMessage(message) {
383
+ const { thread_id, ...rest } = message;
384
+ return {
385
+ ...rest,
386
+ threadId: thread_id,
387
+ content: typeof message.content === "string" ? (() => {
388
+ try {
389
+ return JSON.parse(message.content);
390
+ } catch {
391
+ return message.content;
392
+ }
393
+ })() : message.content
394
+ };
395
+ }
382
396
  async getMessages({
383
397
  threadId,
384
398
  resourceId,
@@ -387,6 +401,7 @@ var StoreMemoryLance = class extends MemoryStorage {
387
401
  threadConfig
388
402
  }) {
389
403
  try {
404
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
390
405
  if (threadConfig) {
391
406
  throw new Error("ThreadConfig is not supported by LanceDB storage");
392
407
  }
@@ -419,21 +434,7 @@ var StoreMemoryLance = class extends MemoryStorage {
419
434
  allRecords,
420
435
  await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
421
436
  );
422
- const normalized = messages.map((msg) => {
423
- const { thread_id, ...rest } = msg;
424
- return {
425
- ...rest,
426
- threadId: thread_id,
427
- content: typeof msg.content === "string" ? (() => {
428
- try {
429
- return JSON.parse(msg.content);
430
- } catch {
431
- return msg.content;
432
- }
433
- })() : msg.content
434
- };
435
- });
436
- const list = new MessageList({ threadId, resourceId }).add(normalized, "memory");
437
+ const list = new MessageList({ threadId, resourceId }).add(messages.map(this.normalizeMessage), "memory");
437
438
  if (format === "v2") return list.get.all.v2();
438
439
  return list.get.all.v1();
439
440
  } catch (error) {
@@ -441,7 +442,41 @@ var StoreMemoryLance = class extends MemoryStorage {
441
442
  {
442
443
  id: "LANCE_STORE_GET_MESSAGES_FAILED",
443
444
  domain: ErrorDomain.STORAGE,
444
- category: ErrorCategory.THIRD_PARTY
445
+ category: ErrorCategory.THIRD_PARTY,
446
+ details: {
447
+ threadId,
448
+ resourceId: resourceId ?? ""
449
+ }
450
+ },
451
+ error
452
+ );
453
+ }
454
+ }
455
+ async getMessagesById({
456
+ messageIds,
457
+ format
458
+ }) {
459
+ if (messageIds.length === 0) return [];
460
+ try {
461
+ 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();
471
+ } catch (error) {
472
+ throw new MastraError(
473
+ {
474
+ id: "LANCE_STORE_GET_MESSAGES_BY_ID_FAILED",
475
+ domain: ErrorDomain.STORAGE,
476
+ category: ErrorCategory.THIRD_PARTY,
477
+ details: {
478
+ messageIds: JSON.stringify(messageIds)
479
+ }
445
480
  },
446
481
  error
447
482
  );
@@ -582,13 +617,11 @@ var StoreMemoryLance = class extends MemoryStorage {
582
617
  return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
583
618
  }
584
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;
585
623
  try {
586
- const { threadId, resourceId, selectBy, format = "v1" } = args;
587
- if (!threadId) {
588
- throw new Error("Thread ID is required for getMessagesPaginated");
589
- }
590
- const page = selectBy?.pagination?.page ?? 0;
591
- const perPage = selectBy?.pagination?.perPage ?? 10;
624
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
592
625
  const dateRange = selectBy?.pagination?.dateRange;
593
626
  const fromDate = dateRange?.start;
594
627
  const toDate = dateRange?.end;
@@ -690,14 +723,21 @@ var StoreMemoryLance = class extends MemoryStorage {
690
723
  hasMore: total > (page + 1) * perPage
691
724
  };
692
725
  } catch (error) {
693
- throw new MastraError(
726
+ const mastraError = new MastraError(
694
727
  {
695
728
  id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
696
729
  domain: ErrorDomain.STORAGE,
697
- category: ErrorCategory.THIRD_PARTY
730
+ category: ErrorCategory.THIRD_PARTY,
731
+ details: {
732
+ threadId,
733
+ resourceId: resourceId ?? ""
734
+ }
698
735
  },
699
736
  error
700
737
  );
738
+ this.logger?.trackException?.(mastraError);
739
+ this.logger?.error?.(mastraError.toString());
740
+ return { messages: [], total: 0, page, perPage, hasMore: false };
701
741
  }
702
742
  }
703
743
  /**
@@ -1359,6 +1399,7 @@ var StoreScoresLance = class extends ScoresStorage {
1359
1399
  }
1360
1400
  async saveScore(score) {
1361
1401
  try {
1402
+ const id = crypto.randomUUID();
1362
1403
  const table = await this.client.openTable(TABLE_SCORERS);
1363
1404
  const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
1364
1405
  const allowedFields = new Set(schema.fields.map((f) => f.name));
@@ -1373,7 +1414,7 @@ var StoreScoresLance = class extends ScoresStorage {
1373
1414
  filteredScore[key] = JSON.stringify(filteredScore[key]);
1374
1415
  }
1375
1416
  }
1376
- console.log("Saving score to LanceStorage:", filteredScore);
1417
+ filteredScore.id = id;
1377
1418
  await table.add([filteredScore], { mode: "append" });
1378
1419
  return { score };
1379
1420
  } catch (error) {
@@ -1412,18 +1453,35 @@ var StoreScoresLance = class extends ScoresStorage {
1412
1453
  }
1413
1454
  async getScoresByScorerId({
1414
1455
  scorerId,
1415
- pagination
1456
+ pagination,
1457
+ entityId,
1458
+ entityType,
1459
+ source
1416
1460
  }) {
1417
1461
  try {
1418
1462
  const table = await this.client.openTable(TABLE_SCORERS);
1419
1463
  const { page = 0, perPage = 10 } = pagination || {};
1420
1464
  const offset = page * perPage;
1421
- const query = table.query().where(`\`scorerId\` = '${scorerId}'`).limit(perPage);
1465
+ let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
1466
+ if (source) {
1467
+ query = query.where(`\`source\` = '${source}'`);
1468
+ }
1469
+ if (entityId) {
1470
+ query = query.where(`\`entityId\` = '${entityId}'`);
1471
+ }
1472
+ if (entityType) {
1473
+ query = query.where(`\`entityType\` = '${entityType}'`);
1474
+ }
1475
+ query = query.limit(perPage);
1422
1476
  if (offset > 0) query.offset(offset);
1423
1477
  const records = await query.toArray();
1424
1478
  const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
1425
1479
  const scores = processResultWithTypeConversion(records, schema);
1426
- const allRecords = await table.query().where(`\`scorerId\` = '${scorerId}'`).toArray();
1480
+ let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
1481
+ if (source) {
1482
+ totalQuery = totalQuery.where(`\`source\` = '${source}'`);
1483
+ }
1484
+ const allRecords = await totalQuery.toArray();
1427
1485
  const total = allRecords.length;
1428
1486
  return {
1429
1487
  pagination: {
@@ -1739,6 +1797,22 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
1739
1797
  super();
1740
1798
  this.client = client;
1741
1799
  }
1800
+ updateWorkflowResults({
1801
+ // workflowName,
1802
+ // runId,
1803
+ // stepId,
1804
+ // result,
1805
+ // runtimeContext,
1806
+ }) {
1807
+ throw new Error("Method not implemented.");
1808
+ }
1809
+ updateWorkflowState({
1810
+ // workflowName,
1811
+ // runId,
1812
+ // opts,
1813
+ }) {
1814
+ throw new Error("Method not implemented.");
1815
+ }
1742
1816
  async persistWorkflowSnapshot({
1743
1817
  workflowName,
1744
1818
  runId,
@@ -2069,6 +2143,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2069
2143
  }) {
2070
2144
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
2071
2145
  }
2146
+ async getMessagesById({
2147
+ messageIds,
2148
+ format
2149
+ }) {
2150
+ return this.stores.memory.getMessagesById({ messageIds, format });
2151
+ }
2072
2152
  async saveMessages(args) {
2073
2153
  return this.stores.memory.saveMessages(args);
2074
2154
  }
@@ -2102,6 +2182,22 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2102
2182
  async getWorkflowRunById(args) {
2103
2183
  return this.stores.workflows.getWorkflowRunById(args);
2104
2184
  }
2185
+ async updateWorkflowResults({
2186
+ workflowName,
2187
+ runId,
2188
+ stepId,
2189
+ result,
2190
+ runtimeContext
2191
+ }) {
2192
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
2193
+ }
2194
+ async updateWorkflowState({
2195
+ workflowName,
2196
+ runId,
2197
+ opts
2198
+ }) {
2199
+ return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
2200
+ }
2105
2201
  async persistWorkflowSnapshot({
2106
2202
  workflowName,
2107
2203
  runId,
@@ -2120,9 +2216,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
2120
2216
  }
2121
2217
  async getScoresByScorerId({
2122
2218
  scorerId,
2219
+ source,
2220
+ entityId,
2221
+ entityType,
2123
2222
  pagination
2124
2223
  }) {
2125
- return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
2224
+ return this.stores.scores.getScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
2126
2225
  }
2127
2226
  async saveScore(_score) {
2128
2227
  return this.stores.scores.saveScore(_score);