@mastra/convex 1.0.11 → 1.1.0

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 (49) hide show
  1. package/CHANGELOG.md +138 -0
  2. package/README.md +76 -4
  3. package/dist/cache/client.d.ts +21 -0
  4. package/dist/cache/client.d.ts.map +1 -0
  5. package/dist/cache/index.d.ts +35 -0
  6. package/dist/cache/index.d.ts.map +1 -0
  7. package/dist/cache/types.d.ts +46 -0
  8. package/dist/cache/types.d.ts.map +1 -0
  9. package/dist/{chunk-FTVDAP6U.cjs → chunk-CV23JOCS.cjs} +44 -2
  10. package/dist/chunk-CV23JOCS.cjs.map +1 -0
  11. package/dist/chunk-EEELVBWO.cjs +893 -0
  12. package/dist/chunk-EEELVBWO.cjs.map +1 -0
  13. package/dist/chunk-FZDLZ4S3.js +887 -0
  14. package/dist/chunk-FZDLZ4S3.js.map +1 -0
  15. package/dist/{chunk-G5FLGAPE.js → chunk-JPWDG4L3.js} +42 -3
  16. package/dist/chunk-JPWDG4L3.js.map +1 -0
  17. package/dist/docs/SKILL.md +1 -1
  18. package/dist/docs/assets/SOURCE_MAP.json +44 -15
  19. package/dist/docs/references/reference-storage-convex.md +74 -12
  20. package/dist/docs/references/reference-vectors-convex.md +129 -7
  21. package/dist/index.cjs +515 -36
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +471 -23
  26. package/dist/index.js.map +1 -1
  27. package/dist/schema.cjs +29 -17
  28. package/dist/schema.d.ts +76 -0
  29. package/dist/schema.d.ts.map +1 -1
  30. package/dist/schema.js +1 -1
  31. package/dist/server/cache.d.ts +5 -0
  32. package/dist/server/cache.d.ts.map +1 -0
  33. package/dist/server/index.cjs +44 -16
  34. package/dist/server/index.d.ts +3 -1
  35. package/dist/server/index.d.ts.map +1 -1
  36. package/dist/server/index.js +2 -2
  37. package/dist/server/native-vector.d.ts +17 -0
  38. package/dist/server/native-vector.d.ts.map +1 -0
  39. package/dist/storage/client.d.ts +5 -0
  40. package/dist/storage/client.d.ts.map +1 -1
  41. package/dist/vector/native.d.ts +111 -0
  42. package/dist/vector/native.d.ts.map +1 -0
  43. package/package.json +5 -5
  44. package/dist/chunk-C6QDNSBM.cjs +0 -425
  45. package/dist/chunk-C6QDNSBM.cjs.map +0 -1
  46. package/dist/chunk-FTVDAP6U.cjs.map +0 -1
  47. package/dist/chunk-G5FLGAPE.js.map +0 -1
  48. package/dist/chunk-NXNW2MK5.js +0 -423
  49. package/dist/chunk-NXNW2MK5.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkC6QDNSBM_cjs = require('./chunk-C6QDNSBM.cjs');
4
- var chunkFTVDAP6U_cjs = require('./chunk-FTVDAP6U.cjs');
3
+ var chunkEEELVBWO_cjs = require('./chunk-EEELVBWO.cjs');
4
+ var chunkCV23JOCS_cjs = require('./chunk-CV23JOCS.cjs');
5
+ var cache = require('@mastra/core/cache');
5
6
  var storage = require('@mastra/core/storage');
6
7
  var crypto = require('crypto');
7
8
  var base = require('@mastra/core/base');
@@ -13,6 +14,186 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
14
 
14
15
  var crypto__default = /*#__PURE__*/_interopDefault(crypto);
15
16
 
17
+ // src/cache/client.ts
18
+ var DEFAULT_CACHE_FUNCTION = "mastra/cache:handle";
19
+ var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
20
+ var trimTrailingSlashes = (value) => {
21
+ let end = value.length;
22
+ while (end > 0 && value.charCodeAt(end - 1) === 47) {
23
+ end -= 1;
24
+ }
25
+ return value.slice(0, end);
26
+ };
27
+ var ConvexCacheClient = class {
28
+ deploymentUrl;
29
+ adminAuthToken;
30
+ cacheFunction;
31
+ requestTimeoutMs;
32
+ constructor({ deploymentUrl, adminAuthToken, cacheFunction, requestTimeoutMs }) {
33
+ const normalizedDeploymentUrl = deploymentUrl.trim();
34
+ const normalizedAdminAuthToken = adminAuthToken.trim();
35
+ const normalizedCacheFunction = cacheFunction?.trim();
36
+ if (!normalizedDeploymentUrl) {
37
+ throw new Error("ConvexCacheClient: deploymentUrl is required.");
38
+ }
39
+ if (!normalizedAdminAuthToken) {
40
+ throw new Error("ConvexCacheClient: adminAuthToken is required.");
41
+ }
42
+ if (requestTimeoutMs !== void 0 && requestTimeoutMs < 0) {
43
+ throw new Error("ConvexCacheClient: requestTimeoutMs must be greater than or equal to 0.");
44
+ }
45
+ this.deploymentUrl = trimTrailingSlashes(normalizedDeploymentUrl);
46
+ this.adminAuthToken = normalizedAdminAuthToken;
47
+ this.cacheFunction = normalizedCacheFunction || DEFAULT_CACHE_FUNCTION;
48
+ this.requestTimeoutMs = requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
49
+ }
50
+ async callCacheRaw(request) {
51
+ const controller = this.requestTimeoutMs > 0 ? new AbortController() : void 0;
52
+ const timeoutId = controller ? setTimeout(() => controller.abort(), this.requestTimeoutMs) : void 0;
53
+ let response;
54
+ try {
55
+ response = await fetch(`${this.deploymentUrl}/api/mutation`, {
56
+ method: "POST",
57
+ headers: {
58
+ "Content-Type": "application/json",
59
+ Authorization: `Convex ${this.adminAuthToken}`
60
+ },
61
+ body: JSON.stringify({
62
+ path: this.cacheFunction,
63
+ args: request,
64
+ format: "json"
65
+ }),
66
+ signal: controller?.signal
67
+ });
68
+ } catch (error) {
69
+ if (controller?.signal.aborted) {
70
+ throw new Error(`Convex cache request timed out after ${this.requestTimeoutMs} ms.`);
71
+ }
72
+ throw error;
73
+ } finally {
74
+ if (timeoutId) clearTimeout(timeoutId);
75
+ }
76
+ if (!response.ok) {
77
+ const text = await response.text();
78
+ throw new Error(`Convex API error: ${response.status} ${text}`);
79
+ }
80
+ const result = await response.json();
81
+ if (result.status === "error") {
82
+ const error = new Error(result.errorMessage || "Unknown Convex error");
83
+ error.code = result.errorCode ?? result.code;
84
+ error.details = result.details;
85
+ throw error;
86
+ }
87
+ const cacheResponse = result.value;
88
+ if (!cacheResponse?.ok) {
89
+ const errResponse = cacheResponse;
90
+ const error = new Error(errResponse?.error || "Unknown Convex cache error");
91
+ error.code = errResponse?.code;
92
+ error.details = errResponse?.details;
93
+ throw error;
94
+ }
95
+ return {
96
+ result: cacheResponse.result,
97
+ hasMore: cacheResponse.hasMore
98
+ };
99
+ }
100
+ async callCache(request) {
101
+ const { result } = await this.callCacheRaw(request);
102
+ return result;
103
+ }
104
+ };
105
+
106
+ // src/cache/index.ts
107
+ var DEFAULT_KEY_PREFIX = "mastra:cache:";
108
+ var DEFAULT_TTL_MS = 3e5;
109
+ var MAX_CACHE_OPERATION_BATCHES = 1e3;
110
+ var isClientConfig = (config) => "client" in config;
111
+ var ConvexServerCache = class extends cache.MastraServerCache {
112
+ client;
113
+ keyPrefix;
114
+ ttlMs;
115
+ constructor(config) {
116
+ super({ name: "ConvexServerCache" });
117
+ this.client = isClientConfig(config) ? config.client : new ConvexCacheClient(config);
118
+ this.keyPrefix = config.keyPrefix ?? DEFAULT_KEY_PREFIX;
119
+ this.ttlMs = config.ttlMs ?? DEFAULT_TTL_MS;
120
+ }
121
+ getKey(key) {
122
+ return `${this.keyPrefix}${key}`;
123
+ }
124
+ getExpiresAt(ttlMs) {
125
+ const effectiveTtlMs = ttlMs ?? this.ttlMs;
126
+ return effectiveTtlMs > 0 ? Date.now() + effectiveTtlMs : null;
127
+ }
128
+ async callUntilSettled(request) {
129
+ for (let batch = 0; batch < MAX_CACHE_OPERATION_BATCHES; batch += 1) {
130
+ const response = await this.client.callCacheRaw({
131
+ ...request()
132
+ });
133
+ if (!response.hasMore) return response.result;
134
+ }
135
+ throw new Error(`ConvexServerCache operation exceeded ${MAX_CACHE_OPERATION_BATCHES} batches.`);
136
+ }
137
+ async get(key) {
138
+ return this.callUntilSettled(() => ({
139
+ op: "get",
140
+ key: this.getKey(key)
141
+ }));
142
+ }
143
+ async set(key, value, ttlMs) {
144
+ await this.callUntilSettled(() => ({
145
+ op: "set",
146
+ key: this.getKey(key),
147
+ keyPrefix: this.keyPrefix,
148
+ value,
149
+ expiresAt: this.getExpiresAt(ttlMs)
150
+ }));
151
+ }
152
+ async listLength(key) {
153
+ return this.callUntilSettled(() => ({
154
+ op: "listLength",
155
+ key: this.getKey(key)
156
+ }));
157
+ }
158
+ async listPush(key, value) {
159
+ await this.callUntilSettled(() => ({
160
+ op: "listPush",
161
+ key: this.getKey(key),
162
+ keyPrefix: this.keyPrefix,
163
+ value,
164
+ expiresAt: this.getExpiresAt()
165
+ }));
166
+ }
167
+ async listFromTo(key, from, to = -1) {
168
+ return this.callUntilSettled(() => ({
169
+ op: "listFromTo",
170
+ key: this.getKey(key),
171
+ from,
172
+ to
173
+ }));
174
+ }
175
+ async delete(key) {
176
+ await this.callUntilSettled(() => ({
177
+ op: "delete",
178
+ key: this.getKey(key)
179
+ }));
180
+ }
181
+ async clear() {
182
+ await this.callUntilSettled(() => ({
183
+ op: "clear",
184
+ keyPrefix: this.keyPrefix
185
+ }));
186
+ }
187
+ async increment(key) {
188
+ return this.callUntilSettled(() => ({
189
+ op: "increment",
190
+ key: this.getKey(key),
191
+ keyPrefix: this.keyPrefix,
192
+ expiresAt: this.getExpiresAt()
193
+ }));
194
+ }
195
+ };
196
+
16
197
  // src/storage/client.ts
17
198
  var DEFAULT_STORAGE_FUNCTION = "mastra/storage:handle";
18
199
  var ConvexAdminClient = class {
@@ -35,7 +216,39 @@ var ConvexAdminClient = class {
35
216
  * Use this for operations that may need multiple calls (e.g., clearTable).
36
217
  */
37
218
  async callStorageRaw(request) {
38
- const url = `${this.deploymentUrl}/api/mutation`;
219
+ const result = await this.callConvexFunction("mutation", this.storageFunction, request);
220
+ const storageResponse = result.value;
221
+ if (!storageResponse?.ok) {
222
+ const errResponse = storageResponse;
223
+ const error = new Error(errResponse?.error || "Unknown Convex storage error");
224
+ error.code = errResponse?.code;
225
+ error.details = errResponse?.details;
226
+ throw error;
227
+ }
228
+ return {
229
+ result: storageResponse.result,
230
+ hasMore: storageResponse.hasMore
231
+ };
232
+ }
233
+ async callStorage(request) {
234
+ const { result } = await this.callStorageRaw(request);
235
+ return result;
236
+ }
237
+ async callAction(path, args) {
238
+ return this.callFunction("action", path, args);
239
+ }
240
+ async callMutation(path, args) {
241
+ return this.callFunction("mutation", path, args);
242
+ }
243
+ async callQuery(path, args) {
244
+ return this.callFunction("query", path, args);
245
+ }
246
+ async callFunction(kind, path, args) {
247
+ const result = await this.callConvexFunction(kind, path, args);
248
+ return result.value;
249
+ }
250
+ async callConvexFunction(kind, path, args) {
251
+ const url = `${this.deploymentUrl}/api/${kind}`;
39
252
  const response = await fetch(url, {
40
253
  method: "POST",
41
254
  headers: {
@@ -43,8 +256,8 @@ var ConvexAdminClient = class {
43
256
  Authorization: `Convex ${this.adminAuthToken}`
44
257
  },
45
258
  body: JSON.stringify({
46
- path: this.storageFunction,
47
- args: request,
259
+ path,
260
+ args,
48
261
  format: "json"
49
262
  })
50
263
  });
@@ -55,24 +268,15 @@ var ConvexAdminClient = class {
55
268
  const result = await response.json();
56
269
  if (result.status === "error") {
57
270
  const error = new Error(result.errorMessage || "Unknown Convex error");
58
- error.code = result.errorCode;
271
+ error.details = result.errorData;
59
272
  throw error;
60
273
  }
61
- const storageResponse = result.value;
62
- if (!storageResponse?.ok) {
63
- const errResponse = storageResponse;
64
- const error = new Error(errResponse?.error || "Unknown Convex storage error");
65
- error.code = errResponse?.code;
66
- error.details = errResponse?.details;
67
- throw error;
274
+ if (result.status !== "success") {
275
+ throw new Error(`Convex ${kind} ${path} returned an invalid response`);
276
+ }
277
+ if (result.value === void 0) {
278
+ throw new Error(`Convex ${kind} ${path} returned no value`);
68
279
  }
69
- return {
70
- result: storageResponse.result,
71
- hasMore: storageResponse.hasMore
72
- };
73
- }
74
- async callStorage(request) {
75
- const { result } = await this.callStorageRaw(request);
76
280
  return result;
77
281
  }
78
282
  };
@@ -87,6 +291,7 @@ var ConvexDB = class extends base.MastraBase {
87
291
  super({ name: "convex-db" });
88
292
  this.client = client;
89
293
  }
294
+ client;
90
295
  async hasColumn(_table, _column) {
91
296
  return true;
92
297
  }
@@ -1066,13 +1271,13 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
1066
1271
  };
1067
1272
 
1068
1273
  // src/storage/index.ts
1069
- var isClientConfig = (config) => {
1274
+ var isClientConfig2 = (config) => {
1070
1275
  return "client" in config;
1071
1276
  };
1072
1277
  var ConvexStore = class extends storage.MastraCompositeStore {
1073
1278
  constructor(config) {
1074
1279
  super({ id: config.id, name: config.name ?? "ConvexStore", disableInit: config.disableInit });
1075
- const client = isClientConfig(config) ? config.client : new ConvexAdminClient(config);
1280
+ const client = isClientConfig2(config) ? config.client : new ConvexAdminClient(config);
1076
1281
  const domainConfig = { client };
1077
1282
  const memory = new MemoryConvex(domainConfig);
1078
1283
  const workflows = new WorkflowsConvex(domainConfig);
@@ -1396,63 +1601,337 @@ function cosineSimilarity(a, b) {
1396
1601
  }
1397
1602
  return dot / (Math.sqrt(magA) * Math.sqrt(magB));
1398
1603
  }
1604
+ var DEFAULT_VECTOR_INDEX = "by_embedding";
1605
+ var DEFAULT_ID_FIELD = "id";
1606
+ var DEFAULT_ID_INDEX = "by_record_id";
1607
+ var DEFAULT_VECTOR_FIELD = "embedding";
1608
+ var DEFAULT_METADATA_FIELD = "metadata";
1609
+ var DEFAULT_NATIVE_ACTION = "mastra/nativeVector:query";
1610
+ var DEFAULT_NATIVE_QUERY = "mastra/nativeVector:read";
1611
+ var DEFAULT_NATIVE_MUTATION = "mastra/nativeVector:write";
1612
+ var MAX_CONVEX_VECTOR_RESULTS = 256;
1613
+ var NATIVE_VECTOR_UPSERT_BATCH_SIZE = 100;
1614
+ function isMetadataRecord(value) {
1615
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1616
+ }
1617
+ var ConvexNativeVector = class extends vector.MastraVector {
1618
+ client;
1619
+ indexes;
1620
+ nativeVectorAction;
1621
+ nativeVectorQuery;
1622
+ nativeVectorMutation;
1623
+ describeCountLimit;
1624
+ constructor(config) {
1625
+ super({ id: config.id });
1626
+ this.client = new ConvexAdminClient(config);
1627
+ this.indexes = Object.fromEntries(
1628
+ Object.entries(config.indexes).map(([indexName, index]) => [
1629
+ indexName,
1630
+ {
1631
+ tableName: index.tableName,
1632
+ vectorIndexName: index.vectorIndexName ?? DEFAULT_VECTOR_INDEX,
1633
+ dimension: index.dimension,
1634
+ idField: index.idField ?? DEFAULT_ID_FIELD,
1635
+ idIndexName: index.idIndexName ?? DEFAULT_ID_INDEX,
1636
+ vectorField: index.vectorField ?? DEFAULT_VECTOR_FIELD,
1637
+ metadataField: index.metadataField ?? DEFAULT_METADATA_FIELD,
1638
+ filterFields: index.filterFields ?? []
1639
+ }
1640
+ ])
1641
+ );
1642
+ this.nativeVectorAction = config.nativeVectorAction ?? DEFAULT_NATIVE_ACTION;
1643
+ this.nativeVectorQuery = config.nativeVectorQuery ?? DEFAULT_NATIVE_QUERY;
1644
+ this.nativeVectorMutation = config.nativeVectorMutation ?? DEFAULT_NATIVE_MUTATION;
1645
+ this.describeCountLimit = config.describeCountLimit ?? 1e4;
1646
+ }
1647
+ async createIndex({ indexName, dimension, metric = "cosine" }) {
1648
+ const index = this.getIndex(indexName);
1649
+ if (index.dimension !== dimension) {
1650
+ throw new Error(
1651
+ `ConvexNativeVector.createIndex: deployed Convex index "${indexName}" has ${index.dimension} dimensions, but ${dimension} were requested`
1652
+ );
1653
+ }
1654
+ if (metric !== "cosine") {
1655
+ throw new Error("ConvexNativeVector.createIndex: Convex native vector search currently supports cosine only");
1656
+ }
1657
+ }
1658
+ async listIndexes() {
1659
+ return Object.keys(this.indexes);
1660
+ }
1661
+ async describeIndex({ indexName }) {
1662
+ const index = this.getIndex(indexName);
1663
+ const result = await this.client.callQuery(this.nativeVectorQuery, {
1664
+ op: "describe",
1665
+ config: index,
1666
+ countLimit: this.describeCountLimit
1667
+ });
1668
+ if (result.countIsLimited) {
1669
+ this.logger.warn(
1670
+ `ConvexNativeVector.describeIndex: count for "${indexName}" reached ${this.describeCountLimit}; reported count is capped.`
1671
+ );
1672
+ }
1673
+ return {
1674
+ dimension: index.dimension,
1675
+ count: result.count,
1676
+ metric: "cosine"
1677
+ };
1678
+ }
1679
+ async upsert({ indexName, vectors, ids, metadata, deleteFilter }) {
1680
+ if (deleteFilter) {
1681
+ throw new Error("ConvexNativeVector.upsert: deleteFilter is not supported. Delete by IDs before upserting.");
1682
+ }
1683
+ const index = this.getIndex(indexName);
1684
+ if (ids && ids.length !== vectors.length) {
1685
+ throw new Error(
1686
+ `ConvexNativeVector.upsert: ids length (${ids.length}) must match vectors length (${vectors.length})`
1687
+ );
1688
+ }
1689
+ if (metadata && metadata.length !== vectors.length) {
1690
+ throw new Error(
1691
+ `ConvexNativeVector.upsert: metadata length (${metadata.length}) must match vectors length (${vectors.length})`
1692
+ );
1693
+ }
1694
+ if (metadata && !metadata.every(isMetadataRecord)) {
1695
+ throw new Error("ConvexNativeVector.upsert: metadata entries must be objects when provided");
1696
+ }
1697
+ const vectorIds = ids ?? vectors.map(() => crypto__default.default.randomUUID());
1698
+ if (new Set(vectorIds).size !== vectorIds.length) {
1699
+ throw new Error("ConvexNativeVector.upsert: ids must be unique");
1700
+ }
1701
+ for (let start = 0; start < vectors.length; start += NATIVE_VECTOR_UPSERT_BATCH_SIZE) {
1702
+ const end = start + NATIVE_VECTOR_UPSERT_BATCH_SIZE;
1703
+ await this.client.callMutation(this.nativeVectorMutation, {
1704
+ op: "upsert",
1705
+ config: index,
1706
+ ids: vectorIds.slice(start, end),
1707
+ vectors: vectors.slice(start, end),
1708
+ ...metadata ? { metadata: metadata.slice(start, end) } : {}
1709
+ });
1710
+ }
1711
+ return vectorIds;
1712
+ }
1713
+ async query({
1714
+ indexName,
1715
+ queryVector,
1716
+ topK = 10,
1717
+ includeVector = false,
1718
+ filter
1719
+ }) {
1720
+ if (!queryVector) {
1721
+ throw new error.MastraError({
1722
+ id: storage.createVectorErrorId("CONVEX_NATIVE", "QUERY", "MISSING_VECTOR"),
1723
+ text: "queryVector is required for Convex native vector queries.",
1724
+ domain: error.ErrorDomain.STORAGE,
1725
+ category: error.ErrorCategory.USER,
1726
+ details: { indexName }
1727
+ });
1728
+ }
1729
+ if (!Number.isFinite(topK) || !Number.isInteger(topK) || topK < 1 || topK > MAX_CONVEX_VECTOR_RESULTS) {
1730
+ throw new Error(`ConvexNativeVector.query: topK must be an integer between 1 and ${MAX_CONVEX_VECTOR_RESULTS}`);
1731
+ }
1732
+ const index = this.getIndex(indexName);
1733
+ const nativeFilter = this.toNativeFilter(filter, index);
1734
+ const searchResults = await this.client.callAction(this.nativeVectorAction, {
1735
+ config: index,
1736
+ vector: queryVector,
1737
+ limit: topK,
1738
+ ...nativeFilter ? { filter: nativeFilter } : {}
1739
+ });
1740
+ if (searchResults.length === 0) return [];
1741
+ const docs = await this.client.callQuery(this.nativeVectorQuery, {
1742
+ op: "getByConvexIds",
1743
+ config: index,
1744
+ ids: searchResults.map((result) => result.id),
1745
+ includeVector
1746
+ });
1747
+ const scoresByConvexId = new Map(searchResults.map((result) => [result.id, result.score]));
1748
+ return docs.flatMap((doc) => {
1749
+ if (!doc?._id) return [];
1750
+ return [
1751
+ {
1752
+ id: String(doc[index.idField]),
1753
+ score: scoresByConvexId.get(String(doc._id)) ?? 0,
1754
+ metadata: doc[index.metadataField],
1755
+ ...includeVector ? { vector: doc[index.vectorField] } : {}
1756
+ }
1757
+ ];
1758
+ });
1759
+ }
1760
+ async updateVector(params) {
1761
+ if ("filter" in params && params.filter !== void 0) {
1762
+ throw new Error("ConvexNativeVector.updateVector: filter-based updates are not supported. Update by ID instead.");
1763
+ }
1764
+ if (params.update.metadata !== void 0 && !isMetadataRecord(params.update.metadata)) {
1765
+ throw new Error("ConvexNativeVector.updateVector: metadata must be an object when provided");
1766
+ }
1767
+ const index = this.getIndex(params.indexName);
1768
+ await this.client.callMutation(this.nativeVectorMutation, {
1769
+ op: "updateById",
1770
+ config: index,
1771
+ id: params.id,
1772
+ vector: params.update.vector,
1773
+ metadata: params.update.metadata
1774
+ });
1775
+ }
1776
+ async deleteVector({ indexName, id }) {
1777
+ const index = this.getIndex(indexName);
1778
+ await this.client.callMutation(this.nativeVectorMutation, {
1779
+ op: "deleteByIds",
1780
+ config: index,
1781
+ ids: [id]
1782
+ });
1783
+ }
1784
+ async deleteVectors(params) {
1785
+ if (params.filter !== void 0) {
1786
+ throw new Error(
1787
+ "ConvexNativeVector.deleteVectors: filter-based deletes are not supported. Delete by IDs instead."
1788
+ );
1789
+ }
1790
+ if (!params.ids || params.ids.length === 0) {
1791
+ throw new Error("ConvexNativeVector.deleteVectors: ids are required");
1792
+ }
1793
+ const index = this.getIndex(params.indexName);
1794
+ await this.client.callMutation(this.nativeVectorMutation, {
1795
+ op: "deleteByIds",
1796
+ config: index,
1797
+ ids: params.ids
1798
+ });
1799
+ }
1800
+ async deleteIndex({ indexName }) {
1801
+ this.getIndex(indexName);
1802
+ throw new Error("ConvexNativeVector.deleteIndex: Convex native vector indexes are managed in convex/schema.ts.");
1803
+ }
1804
+ getIndex(indexName) {
1805
+ const index = this.indexes[indexName];
1806
+ if (!index) {
1807
+ throw new Error(`ConvexNativeVector: index "${indexName}" is not configured`);
1808
+ }
1809
+ return index;
1810
+ }
1811
+ toNativeFilter(filter, index) {
1812
+ if (!filter || Object.keys(filter).length === 0) return void 0;
1813
+ if (this.isOrFilter(filter)) {
1814
+ const clauses = filter.$or.map((branch) => this.toSingleClause(branch, index));
1815
+ return { $or: clauses };
1816
+ }
1817
+ const fieldFilter = this.isMetadataFilter(filter) ? filter.metadata : filter;
1818
+ return this.toSingleClause(fieldFilter, index);
1819
+ }
1820
+ toSingleClause(filter, index) {
1821
+ const entries = Object.entries(filter).filter(([, value2]) => value2 !== void 0);
1822
+ if (entries.length !== 1) {
1823
+ throw new Error(
1824
+ "ConvexNativeVector.query: native Convex filters support one equality field or $or of equality fields"
1825
+ );
1826
+ }
1827
+ const [field, rawValue] = entries[0];
1828
+ if (!index.filterFields.includes(field)) {
1829
+ throw new Error(`ConvexNativeVector.query: field "${field}" is not configured as a Convex vector filter field`);
1830
+ }
1831
+ const value = typeof rawValue === "object" && rawValue !== null && "$eq" in rawValue ? rawValue.$eq : rawValue;
1832
+ if (!["string", "number", "boolean"].includes(typeof value) && value !== null) {
1833
+ throw new Error(
1834
+ "ConvexNativeVector.query: native Convex filters support string, number, boolean, and null values"
1835
+ );
1836
+ }
1837
+ return { field, value };
1838
+ }
1839
+ isOrFilter(filter) {
1840
+ return Array.isArray(filter.$or);
1841
+ }
1842
+ isMetadataFilter(filter) {
1843
+ const metadata = filter.metadata;
1844
+ return typeof metadata === "object" && metadata !== null && !Array.isArray(metadata);
1845
+ }
1846
+ };
1399
1847
 
1848
+ Object.defineProperty(exports, "mastraCache", {
1849
+ enumerable: true,
1850
+ get: function () { return chunkEEELVBWO_cjs.mastraCache; }
1851
+ });
1852
+ Object.defineProperty(exports, "mastraNativeVectorAction", {
1853
+ enumerable: true,
1854
+ get: function () { return chunkEEELVBWO_cjs.mastraNativeVectorAction; }
1855
+ });
1856
+ Object.defineProperty(exports, "mastraNativeVectorMutation", {
1857
+ enumerable: true,
1858
+ get: function () { return chunkEEELVBWO_cjs.mastraNativeVectorMutation; }
1859
+ });
1860
+ Object.defineProperty(exports, "mastraNativeVectorQuery", {
1861
+ enumerable: true,
1862
+ get: function () { return chunkEEELVBWO_cjs.mastraNativeVectorQuery; }
1863
+ });
1400
1864
  Object.defineProperty(exports, "mastraStorage", {
1401
1865
  enumerable: true,
1402
- get: function () { return chunkC6QDNSBM_cjs.mastraStorage; }
1866
+ get: function () { return chunkEEELVBWO_cjs.mastraStorage; }
1403
1867
  });
1404
1868
  Object.defineProperty(exports, "TABLE_MESSAGES", {
1405
1869
  enumerable: true,
1406
- get: function () { return chunkFTVDAP6U_cjs.TABLE_MESSAGES; }
1870
+ get: function () { return chunkCV23JOCS_cjs.TABLE_MESSAGES; }
1407
1871
  });
1408
1872
  Object.defineProperty(exports, "TABLE_RESOURCES", {
1409
1873
  enumerable: true,
1410
- get: function () { return chunkFTVDAP6U_cjs.TABLE_RESOURCES; }
1874
+ get: function () { return chunkCV23JOCS_cjs.TABLE_RESOURCES; }
1411
1875
  });
1412
1876
  Object.defineProperty(exports, "TABLE_SCORERS", {
1413
1877
  enumerable: true,
1414
- get: function () { return chunkFTVDAP6U_cjs.TABLE_SCORERS; }
1878
+ get: function () { return chunkCV23JOCS_cjs.TABLE_SCORERS; }
1415
1879
  });
1416
1880
  Object.defineProperty(exports, "TABLE_THREADS", {
1417
1881
  enumerable: true,
1418
- get: function () { return chunkFTVDAP6U_cjs.TABLE_THREADS; }
1882
+ get: function () { return chunkCV23JOCS_cjs.TABLE_THREADS; }
1419
1883
  });
1420
1884
  Object.defineProperty(exports, "TABLE_WORKFLOW_SNAPSHOT", {
1421
1885
  enumerable: true,
1422
- get: function () { return chunkFTVDAP6U_cjs.TABLE_WORKFLOW_SNAPSHOT; }
1886
+ get: function () { return chunkCV23JOCS_cjs.TABLE_WORKFLOW_SNAPSHOT; }
1887
+ });
1888
+ Object.defineProperty(exports, "defineMastraNativeVectorTable", {
1889
+ enumerable: true,
1890
+ get: function () { return chunkCV23JOCS_cjs.defineMastraNativeVectorTable; }
1891
+ });
1892
+ Object.defineProperty(exports, "mastraCacheListItemsTable", {
1893
+ enumerable: true,
1894
+ get: function () { return chunkCV23JOCS_cjs.mastraCacheListItemsTable; }
1895
+ });
1896
+ Object.defineProperty(exports, "mastraCacheTable", {
1897
+ enumerable: true,
1898
+ get: function () { return chunkCV23JOCS_cjs.mastraCacheTable; }
1423
1899
  });
1424
1900
  Object.defineProperty(exports, "mastraDocumentsTable", {
1425
1901
  enumerable: true,
1426
- get: function () { return chunkFTVDAP6U_cjs.mastraDocumentsTable; }
1902
+ get: function () { return chunkCV23JOCS_cjs.mastraDocumentsTable; }
1427
1903
  });
1428
1904
  Object.defineProperty(exports, "mastraMessagesTable", {
1429
1905
  enumerable: true,
1430
- get: function () { return chunkFTVDAP6U_cjs.mastraMessagesTable; }
1906
+ get: function () { return chunkCV23JOCS_cjs.mastraMessagesTable; }
1431
1907
  });
1432
1908
  Object.defineProperty(exports, "mastraResourcesTable", {
1433
1909
  enumerable: true,
1434
- get: function () { return chunkFTVDAP6U_cjs.mastraResourcesTable; }
1910
+ get: function () { return chunkCV23JOCS_cjs.mastraResourcesTable; }
1435
1911
  });
1436
1912
  Object.defineProperty(exports, "mastraScoresTable", {
1437
1913
  enumerable: true,
1438
- get: function () { return chunkFTVDAP6U_cjs.mastraScoresTable; }
1914
+ get: function () { return chunkCV23JOCS_cjs.mastraScoresTable; }
1439
1915
  });
1440
1916
  Object.defineProperty(exports, "mastraThreadsTable", {
1441
1917
  enumerable: true,
1442
- get: function () { return chunkFTVDAP6U_cjs.mastraThreadsTable; }
1918
+ get: function () { return chunkCV23JOCS_cjs.mastraThreadsTable; }
1443
1919
  });
1444
1920
  Object.defineProperty(exports, "mastraVectorIndexesTable", {
1445
1921
  enumerable: true,
1446
- get: function () { return chunkFTVDAP6U_cjs.mastraVectorIndexesTable; }
1922
+ get: function () { return chunkCV23JOCS_cjs.mastraVectorIndexesTable; }
1447
1923
  });
1448
1924
  Object.defineProperty(exports, "mastraVectorsTable", {
1449
1925
  enumerable: true,
1450
- get: function () { return chunkFTVDAP6U_cjs.mastraVectorsTable; }
1926
+ get: function () { return chunkCV23JOCS_cjs.mastraVectorsTable; }
1451
1927
  });
1452
1928
  Object.defineProperty(exports, "mastraWorkflowSnapshotsTable", {
1453
1929
  enumerable: true,
1454
- get: function () { return chunkFTVDAP6U_cjs.mastraWorkflowSnapshotsTable; }
1930
+ get: function () { return chunkCV23JOCS_cjs.mastraWorkflowSnapshotsTable; }
1455
1931
  });
1932
+ exports.ConvexCacheClient = ConvexCacheClient;
1933
+ exports.ConvexNativeVector = ConvexNativeVector;
1934
+ exports.ConvexServerCache = ConvexServerCache;
1456
1935
  exports.ConvexStore = ConvexStore;
1457
1936
  exports.ConvexVector = ConvexVector;
1458
1937
  //# sourceMappingURL=index.cjs.map