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

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,51 @@
1
1
  # @mastra/lance
2
2
 
3
+ ## 1.0.0-beta.12
4
+
5
+ ### Patch Changes
6
+
7
+ - Added new `listThreads` method for flexible thread filtering across all storage adapters. ([#11832](https://github.com/mastra-ai/mastra/pull/11832))
8
+
9
+ **New Features**
10
+ - Filter threads by `resourceId`, `metadata`, or both (with AND logic for metadata key-value pairs)
11
+ - All filter parameters are optional, allowing you to list all threads or filter as needed
12
+ - Full pagination and sorting support
13
+
14
+ **Example Usage**
15
+
16
+ ```typescript
17
+ // List all threads
18
+ const allThreads = await memory.listThreads({});
19
+
20
+ // Filter by resourceId only
21
+ const userThreads = await memory.listThreads({
22
+ filter: { resourceId: 'user-123' },
23
+ });
24
+
25
+ // Filter by metadata only
26
+ const supportThreads = await memory.listThreads({
27
+ filter: { metadata: { category: 'support' } },
28
+ });
29
+
30
+ // Filter by both with pagination
31
+ const filteredThreads = await memory.listThreads({
32
+ filter: {
33
+ resourceId: 'user-123',
34
+ metadata: { priority: 'high', status: 'open' },
35
+ },
36
+ orderBy: { field: 'updatedAt', direction: 'DESC' },
37
+ page: 0,
38
+ perPage: 20,
39
+ });
40
+ ```
41
+
42
+ **Security Improvements**
43
+ - Added validation to prevent SQL injection via malicious metadata keys
44
+ - Added pagination parameter validation to prevent integer overflow attacks
45
+
46
+ - 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)]:
47
+ - @mastra/core@1.0.0-beta.25
48
+
3
49
  ## 1.0.0-beta.11
4
50
 
5
51
  ### 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.12
@@ -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.12
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.12",
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
  },