@mastra/lance 0.0.0-transpile-packages-20250731152758 → 0.0.0-unified-sidebar-20251010130811

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 (41) hide show
  1. package/CHANGELOG.md +375 -8
  2. package/README.md +3 -3
  3. package/dist/index.cjs +196 -35
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +196 -35
  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/operations/index.d.ts.map +1 -1
  11. package/dist/storage/domains/scores/index.d.ts +13 -2
  12. package/dist/storage/domains/scores/index.d.ts.map +1 -1
  13. package/dist/storage/domains/traces/index.d.ts +1 -1
  14. package/dist/storage/domains/utils.d.ts.map +1 -1
  15. package/dist/storage/domains/workflows/index.d.ts +21 -2
  16. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  17. package/dist/storage/index.d.ts +43 -4
  18. package/dist/storage/index.d.ts.map +1 -1
  19. package/dist/vector/index.d.ts +3 -3
  20. package/dist/vector/index.d.ts.map +1 -1
  21. package/package.json +22 -8
  22. package/eslint.config.js +0 -6
  23. package/src/index.ts +0 -2
  24. package/src/storage/domains/legacy-evals/index.ts +0 -156
  25. package/src/storage/domains/memory/index.ts +0 -947
  26. package/src/storage/domains/operations/index.ts +0 -489
  27. package/src/storage/domains/scores/index.ts +0 -221
  28. package/src/storage/domains/traces/index.ts +0 -212
  29. package/src/storage/domains/utils.ts +0 -158
  30. package/src/storage/domains/workflows/index.ts +0 -207
  31. package/src/storage/index.test.ts +0 -10
  32. package/src/storage/index.ts +0 -442
  33. package/src/vector/filter.test.ts +0 -295
  34. package/src/vector/filter.ts +0 -443
  35. package/src/vector/index.test.ts +0 -1493
  36. package/src/vector/index.ts +0 -941
  37. package/src/vector/types.ts +0 -16
  38. package/tsconfig.build.json +0 -9
  39. package/tsconfig.json +0 -5
  40. package/tsup.config.ts +0 -22
  41. package/vitest.config.ts +0 -11
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ var error = require('@mastra/core/error');
5
5
  var storage = require('@mastra/core/storage');
6
6
  var agent = require('@mastra/core/agent');
7
7
  var apacheArrow = require('apache-arrow');
8
+ var scores = require('@mastra/core/scores');
8
9
  var vector = require('@mastra/core/vector');
9
10
  var filter = require('@mastra/core/vector/filter');
10
11
 
@@ -189,7 +190,6 @@ function processResultWithTypeConversion(rawResult, tableSchema) {
189
190
  } else if (fieldTypeStr.includes("float64") && ["createdAt", "updatedAt"].includes(key)) {
190
191
  processedResult[key] = new Date(processedResult[key]);
191
192
  }
192
- console.log(key, "processedResult", processedResult);
193
193
  }
194
194
  return processedResult;
195
195
  }
@@ -381,6 +381,20 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
381
381
  );
382
382
  }
383
383
  }
384
+ normalizeMessage(message) {
385
+ const { thread_id, ...rest } = message;
386
+ return {
387
+ ...rest,
388
+ threadId: thread_id,
389
+ content: typeof message.content === "string" ? (() => {
390
+ try {
391
+ return JSON.parse(message.content);
392
+ } catch {
393
+ return message.content;
394
+ }
395
+ })() : message.content
396
+ };
397
+ }
384
398
  async getMessages({
385
399
  threadId,
386
400
  resourceId,
@@ -389,6 +403,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
389
403
  threadConfig
390
404
  }) {
391
405
  try {
406
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
392
407
  if (threadConfig) {
393
408
  throw new Error("ThreadConfig is not supported by LanceDB storage");
394
409
  }
@@ -421,21 +436,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
421
436
  allRecords,
422
437
  await getTableSchema({ tableName: storage.TABLE_MESSAGES, client: this.client })
423
438
  );
424
- const normalized = messages.map((msg) => {
425
- const { thread_id, ...rest } = msg;
426
- return {
427
- ...rest,
428
- threadId: thread_id,
429
- content: typeof msg.content === "string" ? (() => {
430
- try {
431
- return JSON.parse(msg.content);
432
- } catch {
433
- return msg.content;
434
- }
435
- })() : msg.content
436
- };
437
- });
438
- const list = new agent.MessageList({ threadId, resourceId }).add(normalized, "memory");
439
+ const list = new agent.MessageList({ threadId, resourceId }).add(messages.map(this.normalizeMessage), "memory");
439
440
  if (format === "v2") return list.get.all.v2();
440
441
  return list.get.all.v1();
441
442
  } catch (error$1) {
@@ -443,7 +444,41 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
443
444
  {
444
445
  id: "LANCE_STORE_GET_MESSAGES_FAILED",
445
446
  domain: error.ErrorDomain.STORAGE,
446
- category: error.ErrorCategory.THIRD_PARTY
447
+ category: error.ErrorCategory.THIRD_PARTY,
448
+ details: {
449
+ threadId,
450
+ resourceId: resourceId ?? ""
451
+ }
452
+ },
453
+ error$1
454
+ );
455
+ }
456
+ }
457
+ async getMessagesById({
458
+ messageIds,
459
+ format
460
+ }) {
461
+ if (messageIds.length === 0) return [];
462
+ try {
463
+ const table = await this.client.openTable(storage.TABLE_MESSAGES);
464
+ const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
465
+ const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
466
+ const messages = processResultWithTypeConversion(
467
+ allRecords,
468
+ await getTableSchema({ tableName: storage.TABLE_MESSAGES, client: this.client })
469
+ );
470
+ const list = new agent.MessageList().add(messages.map(this.normalizeMessage), "memory");
471
+ if (format === `v1`) return list.get.all.v1();
472
+ return list.get.all.v2();
473
+ } catch (error$1) {
474
+ throw new error.MastraError(
475
+ {
476
+ id: "LANCE_STORE_GET_MESSAGES_BY_ID_FAILED",
477
+ domain: error.ErrorDomain.STORAGE,
478
+ category: error.ErrorCategory.THIRD_PARTY,
479
+ details: {
480
+ messageIds: JSON.stringify(messageIds)
481
+ }
447
482
  },
448
483
  error$1
449
484
  );
@@ -584,13 +619,11 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
584
619
  return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
585
620
  }
586
621
  async getMessagesPaginated(args) {
622
+ const { threadId, resourceId, selectBy, format = "v1" } = args;
623
+ const page = selectBy?.pagination?.page ?? 0;
624
+ const perPage = selectBy?.pagination?.perPage ?? 10;
587
625
  try {
588
- const { threadId, resourceId, selectBy, format = "v1" } = args;
589
- if (!threadId) {
590
- throw new Error("Thread ID is required for getMessagesPaginated");
591
- }
592
- const page = selectBy?.pagination?.page ?? 0;
593
- const perPage = selectBy?.pagination?.perPage ?? 10;
626
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
594
627
  const dateRange = selectBy?.pagination?.dateRange;
595
628
  const fromDate = dateRange?.start;
596
629
  const toDate = dateRange?.end;
@@ -692,14 +725,21 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
692
725
  hasMore: total > (page + 1) * perPage
693
726
  };
694
727
  } catch (error$1) {
695
- throw new error.MastraError(
728
+ const mastraError = new error.MastraError(
696
729
  {
697
730
  id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
698
731
  domain: error.ErrorDomain.STORAGE,
699
- category: error.ErrorCategory.THIRD_PARTY
732
+ category: error.ErrorCategory.THIRD_PARTY,
733
+ details: {
734
+ threadId,
735
+ resourceId: resourceId ?? ""
736
+ }
700
737
  },
701
738
  error$1
702
739
  );
740
+ this.logger?.trackException?.(mastraError);
741
+ this.logger?.error?.(mastraError.toString());
742
+ return { messages: [], total: 0, page, perPage, hasMore: false };
703
743
  }
704
744
  }
705
745
  /**
@@ -1226,7 +1266,7 @@ var StoreOperationsLance = class extends storage.StoreOperations {
1226
1266
  processedRecord[key] = JSON.stringify(processedRecord[key]);
1227
1267
  }
1228
1268
  }
1229
- console.log(await table.schema());
1269
+ console.info(await table.schema());
1230
1270
  await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([processedRecord]);
1231
1271
  } catch (error$1) {
1232
1272
  throw new error.MastraError(
@@ -1276,7 +1316,6 @@ var StoreOperationsLance = class extends storage.StoreOperations {
1276
1316
  }
1277
1317
  return processedRecord;
1278
1318
  });
1279
- console.log(processedRecords);
1280
1319
  await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(processedRecords);
1281
1320
  } catch (error$1) {
1282
1321
  throw new error.MastraError(
@@ -1360,12 +1399,27 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1360
1399
  this.client = client;
1361
1400
  }
1362
1401
  async saveScore(score) {
1402
+ let validatedScore;
1403
+ try {
1404
+ validatedScore = scores.saveScorePayloadSchema.parse(score);
1405
+ } catch (error$1) {
1406
+ throw new error.MastraError(
1407
+ {
1408
+ id: "LANCE_STORAGE_SAVE_SCORE_FAILED",
1409
+ text: "Failed to save score in LanceStorage",
1410
+ domain: error.ErrorDomain.STORAGE,
1411
+ category: error.ErrorCategory.THIRD_PARTY
1412
+ },
1413
+ error$1
1414
+ );
1415
+ }
1363
1416
  try {
1417
+ const id = crypto.randomUUID();
1364
1418
  const table = await this.client.openTable(storage.TABLE_SCORERS);
1365
1419
  const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
1366
1420
  const allowedFields = new Set(schema.fields.map((f) => f.name));
1367
1421
  const filteredScore = {};
1368
- Object.keys(score).forEach((key) => {
1422
+ Object.keys(validatedScore).forEach((key) => {
1369
1423
  if (allowedFields.has(key)) {
1370
1424
  filteredScore[key] = score[key];
1371
1425
  }
@@ -1375,7 +1429,7 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1375
1429
  filteredScore[key] = JSON.stringify(filteredScore[key]);
1376
1430
  }
1377
1431
  }
1378
- console.log("Saving score to LanceStorage:", filteredScore);
1432
+ filteredScore.id = id;
1379
1433
  await table.add([filteredScore], { mode: "append" });
1380
1434
  return { score };
1381
1435
  } catch (error$1) {
@@ -1414,18 +1468,35 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1414
1468
  }
1415
1469
  async getScoresByScorerId({
1416
1470
  scorerId,
1417
- pagination
1471
+ pagination,
1472
+ entityId,
1473
+ entityType,
1474
+ source
1418
1475
  }) {
1419
1476
  try {
1420
1477
  const table = await this.client.openTable(storage.TABLE_SCORERS);
1421
1478
  const { page = 0, perPage = 10 } = pagination || {};
1422
1479
  const offset = page * perPage;
1423
- const query = table.query().where(`\`scorerId\` = '${scorerId}'`).limit(perPage);
1480
+ let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
1481
+ if (source) {
1482
+ query = query.where(`\`source\` = '${source}'`);
1483
+ }
1484
+ if (entityId) {
1485
+ query = query.where(`\`entityId\` = '${entityId}'`);
1486
+ }
1487
+ if (entityType) {
1488
+ query = query.where(`\`entityType\` = '${entityType}'`);
1489
+ }
1490
+ query = query.limit(perPage);
1424
1491
  if (offset > 0) query.offset(offset);
1425
1492
  const records = await query.toArray();
1426
1493
  const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
1427
1494
  const scores = processResultWithTypeConversion(records, schema);
1428
- const allRecords = await table.query().where(`\`scorerId\` = '${scorerId}'`).toArray();
1495
+ let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
1496
+ if (source) {
1497
+ totalQuery = totalQuery.where(`\`source\` = '${source}'`);
1498
+ }
1499
+ const allRecords = await totalQuery.toArray();
1429
1500
  const total = allRecords.length;
1430
1501
  return {
1431
1502
  pagination: {
@@ -1524,6 +1595,44 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1524
1595
  );
1525
1596
  }
1526
1597
  }
1598
+ async getScoresBySpan({
1599
+ traceId,
1600
+ spanId,
1601
+ pagination
1602
+ }) {
1603
+ try {
1604
+ const table = await this.client.openTable(storage.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: storage.TABLE_SCORERS, client: this.client });
1611
+ const scores = processResultWithTypeConversion(records, schema);
1612
+ const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
1613
+ const total = allRecords.length;
1614
+ return {
1615
+ pagination: {
1616
+ page,
1617
+ perPage,
1618
+ total,
1619
+ hasMore: offset + scores.length < total
1620
+ },
1621
+ scores
1622
+ };
1623
+ } catch (error$1) {
1624
+ throw new error.MastraError(
1625
+ {
1626
+ id: "LANCE_STORAGE_GET_SCORES_BY_SPAN_FAILED",
1627
+ text: "Failed to get scores by traceId and spanId in LanceStorage",
1628
+ domain: error.ErrorDomain.STORAGE,
1629
+ category: error.ErrorCategory.THIRD_PARTY,
1630
+ details: { error: error$1?.message }
1631
+ },
1632
+ error$1
1633
+ );
1634
+ }
1635
+ }
1527
1636
  };
1528
1637
  var StoreTracesLance = class extends storage.TracesStorage {
1529
1638
  client;
@@ -1741,9 +1850,26 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
1741
1850
  super();
1742
1851
  this.client = client;
1743
1852
  }
1853
+ updateWorkflowResults({
1854
+ // workflowName,
1855
+ // runId,
1856
+ // stepId,
1857
+ // result,
1858
+ // runtimeContext,
1859
+ }) {
1860
+ throw new Error("Method not implemented.");
1861
+ }
1862
+ updateWorkflowState({
1863
+ // workflowName,
1864
+ // runId,
1865
+ // opts,
1866
+ }) {
1867
+ throw new Error("Method not implemented.");
1868
+ }
1744
1869
  async persistWorkflowSnapshot({
1745
1870
  workflowName,
1746
1871
  runId,
1872
+ resourceId,
1747
1873
  snapshot
1748
1874
  }) {
1749
1875
  try {
@@ -1760,6 +1886,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
1760
1886
  const record = {
1761
1887
  workflow_name: workflowName,
1762
1888
  run_id: runId,
1889
+ resourceId,
1763
1890
  snapshot: JSON.stringify(snapshot),
1764
1891
  createdAt,
1765
1892
  updatedAt: now
@@ -1998,7 +2125,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
1998
2125
  resourceWorkingMemory: true,
1999
2126
  hasColumn: true,
2000
2127
  createTable: true,
2001
- deleteMessages: false
2128
+ deleteMessages: false,
2129
+ getScoresBySpan: true
2002
2130
  };
2003
2131
  }
2004
2132
  async getResourceById({ resourceId }) {
@@ -2071,6 +2199,12 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
2071
2199
  }) {
2072
2200
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
2073
2201
  }
2202
+ async getMessagesById({
2203
+ messageIds,
2204
+ format
2205
+ }) {
2206
+ return this.stores.memory.getMessagesById({ messageIds, format });
2207
+ }
2074
2208
  async saveMessages(args) {
2075
2209
  return this.stores.memory.saveMessages(args);
2076
2210
  }
@@ -2104,12 +2238,29 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
2104
2238
  async getWorkflowRunById(args) {
2105
2239
  return this.stores.workflows.getWorkflowRunById(args);
2106
2240
  }
2241
+ async updateWorkflowResults({
2242
+ workflowName,
2243
+ runId,
2244
+ stepId,
2245
+ result,
2246
+ runtimeContext
2247
+ }) {
2248
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
2249
+ }
2250
+ async updateWorkflowState({
2251
+ workflowName,
2252
+ runId,
2253
+ opts
2254
+ }) {
2255
+ return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
2256
+ }
2107
2257
  async persistWorkflowSnapshot({
2108
2258
  workflowName,
2109
2259
  runId,
2260
+ resourceId,
2110
2261
  snapshot
2111
2262
  }) {
2112
- return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
2263
+ return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
2113
2264
  }
2114
2265
  async loadWorkflowSnapshot({
2115
2266
  workflowName,
@@ -2122,9 +2273,12 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
2122
2273
  }
2123
2274
  async getScoresByScorerId({
2124
2275
  scorerId,
2276
+ source,
2277
+ entityId,
2278
+ entityType,
2125
2279
  pagination
2126
2280
  }) {
2127
- return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
2281
+ return this.stores.scores.getScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
2128
2282
  }
2129
2283
  async saveScore(_score) {
2130
2284
  return this.stores.scores.saveScore(_score);
@@ -2142,6 +2296,13 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
2142
2296
  }) {
2143
2297
  return this.stores.scores.getScoresByEntityId({ entityId, entityType, pagination });
2144
2298
  }
2299
+ async getScoresBySpan({
2300
+ traceId,
2301
+ spanId,
2302
+ pagination
2303
+ }) {
2304
+ return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
2305
+ }
2145
2306
  };
2146
2307
  var LanceFilterTranslator = class extends filter.BaseFilterTranslator {
2147
2308
  translate(filter) {