@mastra/lance 1.0.0-beta.11 → 1.0.0-beta.13

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/CHANGELOG.md CHANGED
@@ -1,5 +1,84 @@
1
1
  # @mastra/lance
2
2
 
3
+ ## 1.0.0-beta.13
4
+
5
+ ### Patch Changes
6
+
7
+ - Renamed MastraStorage to MastraCompositeStore for better clarity. The old MastraStorage name remains available as a deprecated alias for backward compatibility, but will be removed in a future version. ([#12093](https://github.com/mastra-ai/mastra/pull/12093))
8
+
9
+ **Migration:**
10
+
11
+ Update your imports and usage:
12
+
13
+ ```typescript
14
+ // Before
15
+ import { MastraStorage } from '@mastra/core/storage';
16
+
17
+ const storage = new MastraStorage({
18
+ id: 'composite',
19
+ domains: { ... }
20
+ });
21
+
22
+ // After
23
+ import { MastraCompositeStore } from '@mastra/core/storage';
24
+
25
+ const storage = new MastraCompositeStore({
26
+ id: 'composite',
27
+ domains: { ... }
28
+ });
29
+ ```
30
+
31
+ The new name better reflects that this is a composite storage implementation that routes different domains (workflows, traces, messages) to different underlying stores, avoiding confusion with the general "Mastra Storage" concept.
32
+
33
+ - Updated dependencies [[`026b848`](https://github.com/mastra-ai/mastra/commit/026b8483fbf5b6d977be8f7e6aac8d15c75558ac), [`ffa553a`](https://github.com/mastra-ai/mastra/commit/ffa553a3edc1bd17d73669fba66d6b6f4ac10897)]:
34
+ - @mastra/core@1.0.0-beta.26
35
+
36
+ ## 1.0.0-beta.12
37
+
38
+ ### Patch Changes
39
+
40
+ - Added new `listThreads` method for flexible thread filtering across all storage adapters. ([#11832](https://github.com/mastra-ai/mastra/pull/11832))
41
+
42
+ **New Features**
43
+ - Filter threads by `resourceId`, `metadata`, or both (with AND logic for metadata key-value pairs)
44
+ - All filter parameters are optional, allowing you to list all threads or filter as needed
45
+ - Full pagination and sorting support
46
+
47
+ **Example Usage**
48
+
49
+ ```typescript
50
+ // List all threads
51
+ const allThreads = await memory.listThreads({});
52
+
53
+ // Filter by resourceId only
54
+ const userThreads = await memory.listThreads({
55
+ filter: { resourceId: 'user-123' },
56
+ });
57
+
58
+ // Filter by metadata only
59
+ const supportThreads = await memory.listThreads({
60
+ filter: { metadata: { category: 'support' } },
61
+ });
62
+
63
+ // Filter by both with pagination
64
+ const filteredThreads = await memory.listThreads({
65
+ filter: {
66
+ resourceId: 'user-123',
67
+ metadata: { priority: 'high', status: 'open' },
68
+ },
69
+ orderBy: { field: 'updatedAt', direction: 'DESC' },
70
+ page: 0,
71
+ perPage: 20,
72
+ });
73
+ ```
74
+
75
+ **Security Improvements**
76
+ - Added validation to prevent SQL injection via malicious metadata keys
77
+ - Added pagination parameter validation to prevent integer overflow attacks
78
+
79
+ - Updated dependencies [[`ed3e3dd`](https://github.com/mastra-ai/mastra/commit/ed3e3ddec69d564fe2b125e083437f76331f1283), [`6833c69`](https://github.com/mastra-ai/mastra/commit/6833c69607418d257750bbcdd84638993d343539), [`47b1c16`](https://github.com/mastra-ai/mastra/commit/47b1c16a01c7ffb6765fe1e499b49092f8b7eba3), [`3a76a80`](https://github.com/mastra-ai/mastra/commit/3a76a80284cb71a0faa975abb3d4b2a9631e60cd), [`8538a0d`](https://github.com/mastra-ai/mastra/commit/8538a0d232619bf55dad7ddc2a8b0ca77c679a87), [`9312dcd`](https://github.com/mastra-ai/mastra/commit/9312dcd1c6f5b321929e7d382e763d95fdc030f5)]:
80
+ - @mastra/core@1.0.0-beta.25
81
+
3
82
  ## 1.0.0-beta.11
4
83
 
5
84
  ### Patch Changes
@@ -30,4 +30,4 @@ docs/
30
30
  ## Version
31
31
 
32
32
  Package: @mastra/lance
33
- Version: 1.0.0-beta.11
33
+ Version: 1.0.0-beta.13
@@ -5,7 +5,7 @@ description: Documentation for @mastra/lance. Includes links to type definitions
5
5
 
6
6
  # @mastra/lance Documentation
7
7
 
8
- > **Version**: 1.0.0-beta.11
8
+ > **Version**: 1.0.0-beta.13
9
9
  > **Package**: @mastra/lance
10
10
 
11
11
  ## Quick Navigation
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-beta.11",
2
+ "version": "1.0.0-beta.13",
3
3
  "package": "@mastra/lance",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -27,7 +27,7 @@ await store.upsert({
27
27
  });
28
28
  ```
29
29
 
30
- ### Using MongoDB Atlas Vector search
30
+ <h3>Using MongoDB Atlas Vector search</h3>
31
31
 
32
32
  For detailed setup instructions and best practices, see the [official MongoDB Atlas Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/?utm_campaign=devrel&utm_source=third-party-content&utm_medium=cta&utm_content=mastra-docs).
33
33
 
@@ -55,7 +55,7 @@ await store.upsert({
55
55
  });
56
56
  ```
57
57
 
58
- ### Using PostgreSQL with pgvector
58
+ <h3>Using PostgreSQL with pgvector</h3>
59
59
 
60
60
  PostgreSQL with the pgvector extension is a good solution for teams already using PostgreSQL who want to minimize infrastructure complexity.
61
61
  For detailed setup instructions and best practices, see the [official pgvector repository](https://github.com/pgvector/pgvector).
@@ -323,7 +323,7 @@ await store.upsert({
323
323
  });
324
324
  ```
325
325
 
326
- ### Using LanceDB
326
+ <h3>Using LanceDB</h3>
327
327
 
328
328
  LanceDB is an embedded vector database built on the Lance columnar format, suitable for local development or cloud deployment.
329
329
  For detailed setup instructions and best practices, see the [official LanceDB documentation](https://lancedb.github.io/lancedb/).
package/dist/index.cjs CHANGED
@@ -952,27 +952,63 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
952
952
  );
953
953
  }
954
954
  }
955
- async listThreadsByResourceId(args) {
955
+ async listThreads(args) {
956
+ const { page = 0, perPage: perPageInput, orderBy, filter } = args;
957
+ try {
958
+ this.validatePaginationInput(page, perPageInput ?? 100);
959
+ } catch (error$1) {
960
+ throw new error.MastraError(
961
+ {
962
+ id: storage.createStorageErrorId("LANCE", "LIST_THREADS", "INVALID_PAGE"),
963
+ domain: error.ErrorDomain.STORAGE,
964
+ category: error.ErrorCategory.USER,
965
+ details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
966
+ },
967
+ error$1 instanceof Error ? error$1 : new Error("Invalid pagination parameters")
968
+ );
969
+ }
970
+ const perPage = storage.normalizePerPage(perPageInput, 100);
971
+ try {
972
+ this.validateMetadataKeys(filter?.metadata);
973
+ } catch (error$1) {
974
+ throw new error.MastraError(
975
+ {
976
+ id: storage.createStorageErrorId("LANCE", "LIST_THREADS", "INVALID_METADATA_KEY"),
977
+ domain: error.ErrorDomain.STORAGE,
978
+ category: error.ErrorCategory.USER,
979
+ details: { metadataKeys: filter?.metadata ? Object.keys(filter.metadata).join(", ") : "" }
980
+ },
981
+ error$1 instanceof Error ? error$1 : new Error("Invalid metadata key")
982
+ );
983
+ }
956
984
  try {
957
- const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
958
- const perPage = storage.normalizePerPage(perPageInput, 100);
959
- if (page < 0) {
960
- throw new error.MastraError(
961
- {
962
- id: storage.createStorageErrorId("LANCE", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
963
- domain: error.ErrorDomain.STORAGE,
964
- category: error.ErrorCategory.USER,
965
- details: { page }
966
- },
967
- new Error("page must be >= 0")
968
- );
969
- }
970
985
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
971
986
  const { field, direction } = this.parseOrderBy(orderBy);
972
987
  const table = await this.client.openTable(storage.TABLE_THREADS);
973
- const total = await table.countRows(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
974
- const query = table.query().where(`\`resourceId\` = '${this.escapeSql(resourceId)}'`);
975
- const records = await query.toArray();
988
+ const whereClauses = [];
989
+ if (filter?.resourceId) {
990
+ whereClauses.push(`\`resourceId\` = '${this.escapeSql(filter.resourceId)}'`);
991
+ }
992
+ const whereClause = whereClauses.length > 0 ? whereClauses.join(" AND ") : "";
993
+ const query = whereClause ? table.query().where(whereClause) : table.query();
994
+ let records = await query.toArray();
995
+ if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
996
+ records = records.filter((record) => {
997
+ if (!record.metadata) return false;
998
+ let recordMeta;
999
+ if (typeof record.metadata === "string") {
1000
+ try {
1001
+ recordMeta = JSON.parse(record.metadata);
1002
+ } catch {
1003
+ return false;
1004
+ }
1005
+ } else {
1006
+ recordMeta = record.metadata;
1007
+ }
1008
+ return Object.entries(filter.metadata).every(([key, value]) => recordMeta[key] === value);
1009
+ });
1010
+ }
1011
+ const total = records.length;
976
1012
  records.sort((a, b) => {
977
1013
  const aValue = ["createdAt", "updatedAt"].includes(field) ? new Date(a[field]).getTime() : a[field];
978
1014
  const bValue = ["createdAt", "updatedAt"].includes(field) ? new Date(b[field]).getTime() : b[field];
@@ -999,7 +1035,7 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
999
1035
  } catch (error$1) {
1000
1036
  throw new error.MastraError(
1001
1037
  {
1002
- id: storage.createStorageErrorId("LANCE", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
1038
+ id: storage.createStorageErrorId("LANCE", "LIST_THREADS", "FAILED"),
1003
1039
  domain: error.ErrorDomain.STORAGE,
1004
1040
  category: error.ErrorCategory.THIRD_PARTY
1005
1041
  },
@@ -1858,7 +1894,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
1858
1894
  };
1859
1895
 
1860
1896
  // src/storage/index.ts
1861
- var LanceStorage = class _LanceStorage extends storage.MastraStorage {
1897
+ var LanceStorage = class _LanceStorage extends storage.MastraCompositeStore {
1862
1898
  stores;
1863
1899
  lanceClient;
1864
1900
  /**