@mastra/convex 1.0.4 → 1.0.5
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 +44 -0
- package/LICENSE.md +15 -0
- package/dist/{chunk-YELPY4DF.cjs → chunk-PW7BUVK5.cjs} +81 -2
- package/dist/chunk-PW7BUVK5.cjs.map +1 -0
- package/dist/{chunk-2HJD4TC6.js → chunk-SDTI6G3V.js} +81 -2
- package/dist/chunk-SDTI6G3V.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +2 -2
- package/dist/index.cjs +13 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -37
- package/dist/index.js.map +1 -1
- package/dist/server/index-map.d.ts +30 -0
- package/dist/server/index-map.d.ts.map +1 -0
- package/dist/server/index.cjs +2 -2
- package/dist/server/index.js +1 -1
- package/dist/server/storage.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +3 -2
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-2HJD4TC6.js.map +0 -1
- package/dist/chunk-YELPY4DF.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @mastra/convex
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- `updateWorkflowResults` and `updateWorkflowState` now throw a not-implemented error. This storage backend does not support concurrent workflow updates. ([#12575](https://github.com/mastra-ai/mastra/pull/12575))
|
|
8
|
+
|
|
9
|
+
- fix: use existing indexes for queryTable operations instead of full table scans ([#13630](https://github.com/mastra-ai/mastra/pull/13630))
|
|
10
|
+
|
|
11
|
+
The `queryTable` handler in the Convex storage mutation now automatically
|
|
12
|
+
selects the best matching index based on equality filters. Previously, all
|
|
13
|
+
`queryTable` operations performed a full table scan (up to 10,000 documents)
|
|
14
|
+
and filtered in JavaScript, which hit Convex's 16MB/32K document read limit
|
|
15
|
+
when enough records accumulated across threads.
|
|
16
|
+
|
|
17
|
+
Now, when equality filters are provided (e.g., `thread_id` for message queries
|
|
18
|
+
or `resourceId` for thread queries), the handler matches them against the
|
|
19
|
+
existing schema indexes (`by_thread`, `by_thread_created`, `by_resource`, etc.)
|
|
20
|
+
and uses `.withIndex()` for efficient indexed queries.
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
|
|
23
|
+
- @mastra/core@1.9.0
|
|
24
|
+
|
|
25
|
+
## 1.0.5-alpha.0
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- `updateWorkflowResults` and `updateWorkflowState` now throw a not-implemented error. This storage backend does not support concurrent workflow updates. ([#12575](https://github.com/mastra-ai/mastra/pull/12575))
|
|
30
|
+
|
|
31
|
+
- fix: use existing indexes for queryTable operations instead of full table scans ([#13630](https://github.com/mastra-ai/mastra/pull/13630))
|
|
32
|
+
|
|
33
|
+
The `queryTable` handler in the Convex storage mutation now automatically
|
|
34
|
+
selects the best matching index based on equality filters. Previously, all
|
|
35
|
+
`queryTable` operations performed a full table scan (up to 10,000 documents)
|
|
36
|
+
and filtered in JavaScript, which hit Convex's 16MB/32K document read limit
|
|
37
|
+
when enough records accumulated across threads.
|
|
38
|
+
|
|
39
|
+
Now, when equality filters are provided (e.g., `thread_id` for message queries
|
|
40
|
+
or `resourceId` for thread queries), the handler matches them against the
|
|
41
|
+
existing schema indexes (`by_thread`, `by_thread_created`, `by_resource`, etc.)
|
|
42
|
+
and uses `.withIndex()` for efficient indexed queries.
|
|
43
|
+
|
|
44
|
+
- Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
|
|
45
|
+
- @mastra/core@1.9.0-alpha.0
|
|
46
|
+
|
|
3
47
|
## 1.0.4
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
package/LICENSE.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
1
16
|
# Apache License 2.0
|
|
2
17
|
|
|
3
18
|
Copyright (c) 2025 Kepler Software, Inc.
|
|
@@ -3,6 +3,72 @@
|
|
|
3
3
|
var constants = require('@mastra/core/storage/constants');
|
|
4
4
|
var server = require('convex/server');
|
|
5
5
|
|
|
6
|
+
// src/server/storage.ts
|
|
7
|
+
|
|
8
|
+
// src/server/index-map.ts
|
|
9
|
+
var TABLE_INDEX_MAP = {
|
|
10
|
+
mastra_messages: [
|
|
11
|
+
{ name: "by_thread_created", fields: ["thread_id", "createdAt"] },
|
|
12
|
+
{ name: "by_thread", fields: ["thread_id"] },
|
|
13
|
+
{ name: "by_resource", fields: ["resourceId"] },
|
|
14
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
15
|
+
],
|
|
16
|
+
mastra_threads: [
|
|
17
|
+
{ name: "by_resource", fields: ["resourceId"] },
|
|
18
|
+
{ name: "by_created", fields: ["createdAt"] },
|
|
19
|
+
{ name: "by_updated", fields: ["updatedAt"] },
|
|
20
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
21
|
+
],
|
|
22
|
+
mastra_resources: [
|
|
23
|
+
{ name: "by_updated", fields: ["updatedAt"] },
|
|
24
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
25
|
+
],
|
|
26
|
+
mastra_workflow_snapshots: [
|
|
27
|
+
{ name: "by_workflow_run", fields: ["workflow_name", "run_id"] },
|
|
28
|
+
{ name: "by_workflow", fields: ["workflow_name"] },
|
|
29
|
+
{ name: "by_resource", fields: ["resourceId"] },
|
|
30
|
+
{ name: "by_created", fields: ["createdAt"] },
|
|
31
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
32
|
+
],
|
|
33
|
+
mastra_scorers: [
|
|
34
|
+
{ name: "by_entity", fields: ["entityId", "entityType"] },
|
|
35
|
+
{ name: "by_scorer", fields: ["scorerId"] },
|
|
36
|
+
{ name: "by_run", fields: ["runId"] },
|
|
37
|
+
{ name: "by_created", fields: ["createdAt"] },
|
|
38
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
39
|
+
],
|
|
40
|
+
mastra_vector_indexes: [
|
|
41
|
+
{ name: "by_name", fields: ["indexName"] },
|
|
42
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
function findBestIndex(convexTable, filters) {
|
|
46
|
+
const indexes = TABLE_INDEX_MAP[convexTable];
|
|
47
|
+
if (!indexes || filters.length === 0) return null;
|
|
48
|
+
const filtersByField = /* @__PURE__ */ new Map();
|
|
49
|
+
for (const f of filters) {
|
|
50
|
+
filtersByField.set(f.field, f);
|
|
51
|
+
}
|
|
52
|
+
let best = null;
|
|
53
|
+
for (const index of indexes) {
|
|
54
|
+
let prefixLength = 0;
|
|
55
|
+
const indexedFilters = [];
|
|
56
|
+
for (const field of index.fields) {
|
|
57
|
+
const filter = filtersByField.get(field);
|
|
58
|
+
if (filter) {
|
|
59
|
+
prefixLength++;
|
|
60
|
+
indexedFilters.push(filter);
|
|
61
|
+
} else {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (prefixLength > 0 && (!best || prefixLength > best.prefixLength)) {
|
|
66
|
+
best = { indexName: index.name, indexedFilters, prefixLength };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return best ? { indexName: best.indexName, indexedFilters: best.indexedFilters } : null;
|
|
70
|
+
}
|
|
71
|
+
|
|
6
72
|
// src/server/storage.ts
|
|
7
73
|
var TABLE_VECTOR_INDEXES = "mastra_vector_indexes";
|
|
8
74
|
var VECTOR_TABLE_PREFIX = "mastra_vector_";
|
|
@@ -98,6 +164,19 @@ async function handleTypedOperation(ctx, convexTable, request) {
|
|
|
98
164
|
} else {
|
|
99
165
|
docs = await ctx.db.query(convexTable).take(maxDocs);
|
|
100
166
|
}
|
|
167
|
+
} else if (request.filters && request.filters.length > 0) {
|
|
168
|
+
const match = findBestIndex(convexTable, request.filters);
|
|
169
|
+
if (match) {
|
|
170
|
+
docs = await ctx.db.query(convexTable).withIndex(match.indexName, (q) => {
|
|
171
|
+
let builder = q;
|
|
172
|
+
for (const filter of match.indexedFilters) {
|
|
173
|
+
builder = builder.eq(filter.field, filter.value);
|
|
174
|
+
}
|
|
175
|
+
return builder;
|
|
176
|
+
}).take(maxDocs);
|
|
177
|
+
} else {
|
|
178
|
+
docs = await ctx.db.query(convexTable).take(maxDocs);
|
|
179
|
+
}
|
|
101
180
|
} else {
|
|
102
181
|
docs = await ctx.db.query(convexTable).take(maxDocs);
|
|
103
182
|
}
|
|
@@ -312,5 +391,5 @@ async function handleGenericOperation(ctx, request) {
|
|
|
312
391
|
}
|
|
313
392
|
|
|
314
393
|
exports.mastraStorage = mastraStorage;
|
|
315
|
-
//# sourceMappingURL=chunk-
|
|
316
|
-
//# sourceMappingURL=chunk-
|
|
394
|
+
//# sourceMappingURL=chunk-PW7BUVK5.cjs.map
|
|
395
|
+
//# sourceMappingURL=chunk-PW7BUVK5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/index-map.ts","../src/server/storage.ts"],"names":["TABLE_THREADS","TABLE_MESSAGES","TABLE_RESOURCES","TABLE_WORKFLOW_SNAPSHOT","TABLE_SCORERS","mutationGeneric"],"mappings":";;;;;;;;AAWO,IAAM,eAAA,GAA6E;AAAA,EACxF,eAAA,EAAiB;AAAA,IACf,EAAE,IAAA,EAAM,mBAAA,EAAqB,QAAQ,CAAC,WAAA,EAAa,WAAW,CAAA,EAAE;AAAA,IAChE,EAAE,IAAA,EAAM,WAAA,EAAa,MAAA,EAAQ,CAAC,WAAW,CAAA,EAAE;AAAA,IAC3C,EAAE,IAAA,EAAM,aAAA,EAAe,MAAA,EAAQ,CAAC,YAAY,CAAA,EAAE;AAAA,IAC9C,EAAE,IAAA,EAAM,cAAA,EAAgB,MAAA,EAAQ,CAAC,IAAI,CAAA;AAAE,GACzC;AAAA,EACA,cAAA,EAAgB;AAAA,IACd,EAAE,IAAA,EAAM,aAAA,EAAe,MAAA,EAAQ,CAAC,YAAY,CAAA,EAAE;AAAA,IAC9C,EAAE,IAAA,EAAM,YAAA,E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AA;AAEhF","file":"chunk-PW7BUVK5.cjs","sourcesContent":["/**\n * Index definitions for automatic query optimization.\n *\n * Maps each typed Convex table to its available indexes and their field lists.\n * Indexes with more fields are listed first so the best (most specific) match\n * is preferred during selection.\n *\n * These must stay in sync with the index definitions in schema.ts.\n */\nimport type { EqualityFilter } from '../storage/types';\n\nexport const TABLE_INDEX_MAP: Record<string, Array<{ name: string; fields: string[] }>> = {\n mastra_messages: [\n { name: 'by_thread_created', fields: ['thread_id', 'createdAt'] },\n { name: 'by_thread', fields: ['thread_id'] },\n { name: 'by_resource', fields: ['resourceId'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_threads: [\n { name: 'by_resource', fields: ['resourceId'] },\n { name: 'by_created', fields: ['createdAt'] },\n { name: 'by_updated', fields: ['updatedAt'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_resources: [\n { name: 'by_updated', fields: ['updatedAt'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_workflow_snapshots: [\n { name: 'by_workflow_run', fields: ['workflow_name', 'run_id'] },\n { name: 'by_workflow', fields: ['workflow_name'] },\n { name: 'by_resource', fields: ['resourceId'] },\n { name: 'by_created', fields: ['createdAt'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_scorers: [\n { name: 'by_entity', fields: ['entityId', 'entityType'] },\n { name: 'by_scorer', fields: ['scorerId'] },\n { name: 'by_run', fields: ['runId'] },\n { name: 'by_created', fields: ['createdAt'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_vector_indexes: [\n { name: 'by_name', fields: ['indexName'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n};\n\n/**\n * Finds the best matching index for the given equality filters on a Convex table.\n *\n * Returns the index name and the subset of filters that form the index prefix,\n * or null when no index matches.\n *\n * The \"best\" index is the one whose prefix has the most consecutive fields\n * covered by the provided filters. For example, given filters for `thread_id`\n * and `createdAt` on mastra_messages, the composite `by_thread_created` index\n * (fields: [thread_id, createdAt]) is preferred over `by_thread` (fields: [thread_id]).\n */\nexport function findBestIndex(\n convexTable: string,\n filters: EqualityFilter[],\n): { indexName: string; indexedFilters: EqualityFilter[] } | null {\n const indexes = TABLE_INDEX_MAP[convexTable];\n if (!indexes || filters.length === 0) return null;\n\n const filtersByField = new Map<string, EqualityFilter>();\n for (const f of filters) {\n filtersByField.set(f.field, f);\n }\n\n let best: { indexName: string; indexedFilters: EqualityFilter[]; prefixLength: number } | null = null;\n\n for (const index of indexes) {\n let prefixLength = 0;\n const indexedFilters: EqualityFilter[] = [];\n\n for (const field of index.fields) {\n const filter = filtersByField.get(field);\n if (filter) {\n prefixLength++;\n indexedFilters.push(filter);\n } else {\n break;\n }\n }\n\n if (prefixLength > 0 && (!best || prefixLength > best.prefixLength)) {\n best = { indexName: index.name, indexedFilters, prefixLength };\n }\n }\n\n return best ? { indexName: best.indexName, indexedFilters: best.indexedFilters } : null;\n}\n","import {\n TABLE_WORKFLOW_SNAPSHOT,\n TABLE_MESSAGES,\n TABLE_THREADS,\n TABLE_RESOURCES,\n TABLE_SCORERS,\n} from '@mastra/core/storage/constants';\nimport type { GenericMutationCtx as MutationCtx } from 'convex/server';\nimport { mutationGeneric } from 'convex/server';\n\nimport type { StorageRequest, StorageResponse } from '../storage/types';\nimport { findBestIndex } from './index-map';\n\n// Vector-specific table names (not in @mastra/core)\nconst TABLE_VECTOR_INDEXES = 'mastra_vector_indexes';\nconst VECTOR_TABLE_PREFIX = 'mastra_vector_';\n\n/**\n * Determines which Convex table to use based on the logical table name.\n * Returns the Convex table name and whether it's a typed table or fallback.\n */\nfunction resolveTable(tableName: string): { convexTable: string; isTyped: boolean } {\n switch (tableName) {\n case TABLE_THREADS:\n return { convexTable: 'mastra_threads', isTyped: true };\n case TABLE_MESSAGES:\n return { convexTable: 'mastra_messages', isTyped: true };\n case TABLE_RESOURCES:\n return { convexTable: 'mastra_resources', isTyped: true };\n case TABLE_WORKFLOW_SNAPSHOT:\n return { convexTable: 'mastra_workflow_snapshots', isTyped: true };\n case TABLE_SCORERS:\n return { convexTable: 'mastra_scorers', isTyped: true };\n case TABLE_VECTOR_INDEXES:\n return { convexTable: 'mastra_vector_indexes', isTyped: true };\n default:\n // Check if it's a vector data table\n if (tableName.startsWith(VECTOR_TABLE_PREFIX)) {\n return { convexTable: 'mastra_vectors', isTyped: true };\n }\n // Fallback to generic documents table for unknown tables\n return { convexTable: 'mastra_documents', isTyped: false };\n }\n}\n\n/**\n * Main storage mutation handler.\n * Routes operations to the appropriate typed table.\n */\nexport const mastraStorage = mutationGeneric(async (ctx, request: StorageRequest): Promise<StorageResponse> => {\n try {\n const { convexTable, isTyped } = resolveTable(request.tableName);\n\n // Handle vector data tables specially (but NOT vector_indexes which is a typed table)\n if (request.tableName.startsWith(VECTOR_TABLE_PREFIX) && request.tableName !== TABLE_VECTOR_INDEXES) {\n return handleVectorOperation(ctx, request);\n }\n\n // Handle typed tables\n if (isTyped) {\n return handleTypedOperation(ctx, convexTable, request);\n }\n\n // Fallback to generic table for unknown tables\n return handleGenericOperation(ctx, request);\n } catch (error) {\n const err = error as Error;\n return {\n ok: false,\n error: err.message,\n };\n }\n});\n\n/**\n * Handle operations on typed tables (threads, messages, etc.)\n * Records are stored with their `id` field as a regular field (not _id).\n * We query by the `id` field to find/update records.\n */\nasync function handleTypedOperation(\n ctx: MutationCtx<any>,\n convexTable: string,\n request: StorageRequest,\n): Promise<StorageResponse> {\n switch (request.op) {\n case 'insert': {\n const record = request.record;\n const id = record.id;\n if (!id) {\n throw new Error(`Record is missing an id`);\n }\n\n // Find existing record by id field using index\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_record_id', (q: any) => q.eq('id', id))\n .unique();\n\n if (existing) {\n // Update existing - don't include id in patch (it's already set)\n const { id: _, ...updateData } = record;\n await ctx.db.patch(existing._id, updateData);\n } else {\n // Insert new - include id as a regular field\n await ctx.db.insert(convexTable, record);\n }\n return { ok: true };\n }\n\n case 'batchInsert': {\n for (const record of request.records) {\n const id = record.id;\n if (!id) continue;\n\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_record_id', (q: any) => q.eq('id', id))\n .unique();\n\n if (existing) {\n const { id: _, ...updateData } = record;\n await ctx.db.patch(existing._id, updateData);\n } else {\n await ctx.db.insert(convexTable, record);\n }\n }\n return { ok: true };\n }\n\n case 'load': {\n const keys = request.keys;\n if (keys.id) {\n // Find by id field using index\n const doc = await ctx.db\n .query(convexTable)\n .withIndex('by_record_id', (q: any) => q.eq('id', keys.id))\n .unique();\n return { ok: true, result: doc || null };\n }\n\n // Query by other fields - use take() to avoid 32k limit\n const docs = await ctx.db.query(convexTable).take(10000);\n const match = docs.find((doc: any) => Object.entries(keys).every(([key, value]) => doc[key] === value));\n return { ok: true, result: match || null };\n }\n\n case 'queryTable': {\n // Use take() to avoid hitting Convex's 32k document limit\n const maxDocs = request.limit ? Math.min(request.limit * 2, 10000) : 10000;\n\n // Build query with index if hint provided for efficient filtering\n let docs: any[];\n if (request.indexHint) {\n const hint = request.indexHint;\n if (hint.index === 'by_workflow') {\n docs = await ctx.db\n .query(convexTable)\n .withIndex('by_workflow', (q: any) => q.eq('workflow_name', hint.workflowName))\n .take(maxDocs);\n } else if (hint.index === 'by_workflow_run') {\n docs = await ctx.db\n .query(convexTable)\n .withIndex('by_workflow_run', (q: any) => q.eq('workflow_name', hint.workflowName).eq('run_id', hint.runId))\n .take(maxDocs);\n } else {\n docs = await ctx.db.query(convexTable).take(maxDocs);\n }\n } else if (request.filters && request.filters.length > 0) {\n const match = findBestIndex(convexTable, request.filters);\n if (match) {\n docs = await ctx.db\n .query(convexTable)\n .withIndex(match.indexName, (q: any) => {\n let builder = q;\n for (const filter of match.indexedFilters) {\n builder = builder.eq(filter.field, filter.value);\n }\n return builder;\n })\n .take(maxDocs);\n } else {\n docs = await ctx.db.query(convexTable).take(maxDocs);\n }\n } else {\n docs = await ctx.db.query(convexTable).take(maxDocs);\n }\n\n // Apply additional filters if provided\n if (request.filters && request.filters.length > 0) {\n docs = docs.filter((doc: any) => request.filters!.every(filter => doc[filter.field] === filter.value));\n }\n\n // Apply limit if provided\n if (request.limit) {\n docs = docs.slice(0, request.limit);\n }\n\n return { ok: true, result: docs };\n }\n\n case 'clearTable':\n case 'dropTable': {\n // Delete a small batch per call to stay within Convex's 1-second mutation timeout.\n // Client must call repeatedly until hasMore is false.\n const BATCH_SIZE = 25;\n const docs = await ctx.db.query(convexTable).take(BATCH_SIZE + 1);\n const hasMore = docs.length > BATCH_SIZE;\n const docsToDelete = hasMore ? docs.slice(0, BATCH_SIZE) : docs;\n\n for (const doc of docsToDelete) {\n await ctx.db.delete(doc._id);\n }\n return { ok: true, hasMore };\n }\n\n case 'deleteMany': {\n for (const id of request.ids) {\n const doc = await ctx.db\n .query(convexTable)\n .withIndex('by_record_id', (q: any) => q.eq('id', id))\n .unique();\n if (doc) {\n await ctx.db.delete(doc._id);\n }\n }\n return { ok: true };\n }\n\n default:\n return { ok: false, error: `Unsupported operation ${(request as any).op}` };\n }\n}\n\n/**\n * Handle operations on the vectors table.\n * Vectors are stored with indexName to support multiple indexes.\n */\nasync function handleVectorOperation(ctx: MutationCtx<any>, request: StorageRequest): Promise<StorageResponse> {\n // Extract the index name from the table name (e.g., \"mastra_vector_myindex\" -> \"myindex\")\n const indexName = request.tableName.replace(VECTOR_TABLE_PREFIX, '');\n const convexTable = 'mastra_vectors';\n\n switch (request.op) {\n case 'insert': {\n const record = request.record;\n const id = record.id;\n if (!id) {\n throw new Error(`Vector record is missing an id`);\n }\n\n // Find existing by composite key (indexName, id) to scope per index\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_index_id', (q: any) => q.eq('indexName', indexName).eq('id', id))\n .unique();\n\n if (existing) {\n await ctx.db.patch(existing._id, {\n embedding: record.embedding,\n metadata: record.metadata,\n });\n } else {\n await ctx.db.insert(convexTable, {\n id,\n indexName,\n embedding: record.embedding,\n metadata: record.metadata,\n });\n }\n return { ok: true };\n }\n\n case 'batchInsert': {\n for (const record of request.records) {\n const id = record.id;\n if (!id) continue;\n\n // Find existing by composite key (indexName, id) to scope per index\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_index_id', (q: any) => q.eq('indexName', indexName).eq('id', id))\n .unique();\n\n if (existing) {\n await ctx.db.patch(existing._id, {\n embedding: record.embedding,\n metadata: record.metadata,\n });\n } else {\n await ctx.db.insert(convexTable, {\n id,\n indexName,\n embedding: record.embedding,\n metadata: record.metadata,\n });\n }\n }\n return { ok: true };\n }\n\n case 'load': {\n const keys = request.keys;\n if (keys.id) {\n // Use composite key (indexName, id) to scope lookup per index\n const doc = await ctx.db\n .query(convexTable)\n .withIndex('by_index_id', (q: any) => q.eq('indexName', indexName).eq('id', keys.id))\n .unique();\n return { ok: true, result: doc || null };\n }\n return { ok: true, result: null };\n }\n\n case 'queryTable': {\n // Use take() to avoid hitting Convex's 32k document limit\n const maxDocs = request.limit ? Math.min(request.limit * 2, 10000) : 10000;\n let docs = await ctx.db\n .query(convexTable)\n .withIndex('by_index', (q: any) => q.eq('indexName', indexName))\n .take(maxDocs);\n\n // Apply filters if provided\n if (request.filters && request.filters.length > 0) {\n docs = docs.filter((doc: any) => request.filters!.every(filter => doc[filter.field] === filter.value));\n }\n\n // Apply limit if provided\n if (request.limit) {\n docs = docs.slice(0, request.limit);\n }\n\n return { ok: true, result: docs };\n }\n\n case 'clearTable':\n case 'dropTable': {\n // Delete a small batch per call to stay within Convex's 1-second mutation timeout.\n // Client must call repeatedly until hasMore is false.\n const BATCH_SIZE = 25;\n const docs = await ctx.db\n .query(convexTable)\n .withIndex('by_index', (q: any) => q.eq('indexName', indexName))\n .take(BATCH_SIZE + 1);\n const hasMore = docs.length > BATCH_SIZE;\n const docsToDelete = hasMore ? docs.slice(0, BATCH_SIZE) : docs;\n\n for (const doc of docsToDelete) {\n await ctx.db.delete(doc._id);\n }\n return { ok: true, hasMore };\n }\n\n case 'deleteMany': {\n for (const id of request.ids) {\n // Use composite key (indexName, id) to scope deletion per index\n const doc = await ctx.db\n .query(convexTable)\n .withIndex('by_index_id', (q: any) => q.eq('indexName', indexName).eq('id', id))\n .unique();\n if (doc) {\n await ctx.db.delete(doc._id);\n }\n }\n return { ok: true };\n }\n\n default:\n return { ok: false, error: `Unsupported operation ${(request as any).op}` };\n }\n}\n\n/**\n * Handle operations on the generic documents table.\n * Used as fallback for unknown table names.\n */\nasync function handleGenericOperation(ctx: MutationCtx<any>, request: StorageRequest): Promise<StorageResponse> {\n const tableName = request.tableName;\n const convexTable = 'mastra_documents';\n\n switch (request.op) {\n case 'insert': {\n const record = request.record;\n if (!record.id) {\n throw new Error(`Record for table ${tableName} is missing an id`);\n }\n const primaryKey = String(record.id);\n\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_table_primary', (q: any) => q.eq('table', tableName).eq('primaryKey', primaryKey))\n .unique();\n\n if (existing) {\n await ctx.db.patch(existing._id, { record });\n } else {\n await ctx.db.insert(convexTable, {\n table: tableName,\n primaryKey,\n record,\n });\n }\n return { ok: true };\n }\n\n case 'batchInsert': {\n for (const record of request.records) {\n if (!record.id) continue;\n const primaryKey = String(record.id);\n\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_table_primary', (q: any) => q.eq('table', tableName).eq('primaryKey', primaryKey))\n .unique();\n\n if (existing) {\n await ctx.db.patch(existing._id, { record });\n } else {\n await ctx.db.insert(convexTable, {\n table: tableName,\n primaryKey,\n record,\n });\n }\n }\n return { ok: true };\n }\n\n case 'load': {\n const keys = request.keys;\n if (keys.id) {\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_table_primary', (q: any) => q.eq('table', tableName).eq('primaryKey', String(keys.id)))\n .unique();\n return { ok: true, result: existing ? existing.record : null };\n }\n\n const docs = await ctx.db\n .query(convexTable)\n .withIndex('by_table', (q: any) => q.eq('table', tableName))\n .take(10000);\n const match = docs.find((doc: any) => Object.entries(keys).every(([key, value]) => doc.record?.[key] === value));\n return { ok: true, result: match ? match.record : null };\n }\n\n case 'queryTable': {\n // Use take() to avoid hitting Convex's 32k document limit\n const maxDocs = request.limit ? Math.min(request.limit * 2, 10000) : 10000;\n const docs = await ctx.db\n .query(convexTable)\n .withIndex('by_table', (q: any) => q.eq('table', tableName))\n .take(maxDocs);\n\n let records = docs.map((doc: any) => doc.record);\n\n if (request.filters && request.filters.length > 0) {\n records = records.filter((record: any) =>\n request.filters!.every(filter => record?.[filter.field] === filter.value),\n );\n }\n\n if (request.limit) {\n records = records.slice(0, request.limit);\n }\n\n return { ok: true, result: records };\n }\n\n case 'clearTable':\n case 'dropTable': {\n // Delete a small batch per call to stay within Convex's 1-second mutation timeout.\n // Client must call repeatedly until hasMore is false.\n const BATCH_SIZE = 25;\n const docs = await ctx.db\n .query(convexTable)\n .withIndex('by_table', (q: any) => q.eq('table', tableName))\n .take(BATCH_SIZE + 1);\n const hasMore = docs.length > BATCH_SIZE;\n const docsToDelete = hasMore ? docs.slice(0, BATCH_SIZE) : docs;\n\n for (const doc of docsToDelete) {\n await ctx.db.delete(doc._id);\n }\n return { ok: true, hasMore };\n }\n\n case 'deleteMany': {\n for (const id of request.ids) {\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_table_primary', (q: any) => q.eq('table', tableName).eq('primaryKey', String(id)))\n .unique();\n if (existing) {\n await ctx.db.delete(existing._id);\n }\n }\n return { ok: true };\n }\n\n default:\n return { ok: false, error: `Unsupported operation ${(request as any).op}` };\n }\n}\n"]}
|
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
import { TABLE_SCORERS, TABLE_WORKFLOW_SNAPSHOT, TABLE_RESOURCES, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage/constants';
|
|
2
2
|
import { mutationGeneric } from 'convex/server';
|
|
3
3
|
|
|
4
|
+
// src/server/storage.ts
|
|
5
|
+
|
|
6
|
+
// src/server/index-map.ts
|
|
7
|
+
var TABLE_INDEX_MAP = {
|
|
8
|
+
mastra_messages: [
|
|
9
|
+
{ name: "by_thread_created", fields: ["thread_id", "createdAt"] },
|
|
10
|
+
{ name: "by_thread", fields: ["thread_id"] },
|
|
11
|
+
{ name: "by_resource", fields: ["resourceId"] },
|
|
12
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
13
|
+
],
|
|
14
|
+
mastra_threads: [
|
|
15
|
+
{ name: "by_resource", fields: ["resourceId"] },
|
|
16
|
+
{ name: "by_created", fields: ["createdAt"] },
|
|
17
|
+
{ name: "by_updated", fields: ["updatedAt"] },
|
|
18
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
19
|
+
],
|
|
20
|
+
mastra_resources: [
|
|
21
|
+
{ name: "by_updated", fields: ["updatedAt"] },
|
|
22
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
23
|
+
],
|
|
24
|
+
mastra_workflow_snapshots: [
|
|
25
|
+
{ name: "by_workflow_run", fields: ["workflow_name", "run_id"] },
|
|
26
|
+
{ name: "by_workflow", fields: ["workflow_name"] },
|
|
27
|
+
{ name: "by_resource", fields: ["resourceId"] },
|
|
28
|
+
{ name: "by_created", fields: ["createdAt"] },
|
|
29
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
30
|
+
],
|
|
31
|
+
mastra_scorers: [
|
|
32
|
+
{ name: "by_entity", fields: ["entityId", "entityType"] },
|
|
33
|
+
{ name: "by_scorer", fields: ["scorerId"] },
|
|
34
|
+
{ name: "by_run", fields: ["runId"] },
|
|
35
|
+
{ name: "by_created", fields: ["createdAt"] },
|
|
36
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
37
|
+
],
|
|
38
|
+
mastra_vector_indexes: [
|
|
39
|
+
{ name: "by_name", fields: ["indexName"] },
|
|
40
|
+
{ name: "by_record_id", fields: ["id"] }
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
function findBestIndex(convexTable, filters) {
|
|
44
|
+
const indexes = TABLE_INDEX_MAP[convexTable];
|
|
45
|
+
if (!indexes || filters.length === 0) return null;
|
|
46
|
+
const filtersByField = /* @__PURE__ */ new Map();
|
|
47
|
+
for (const f of filters) {
|
|
48
|
+
filtersByField.set(f.field, f);
|
|
49
|
+
}
|
|
50
|
+
let best = null;
|
|
51
|
+
for (const index of indexes) {
|
|
52
|
+
let prefixLength = 0;
|
|
53
|
+
const indexedFilters = [];
|
|
54
|
+
for (const field of index.fields) {
|
|
55
|
+
const filter = filtersByField.get(field);
|
|
56
|
+
if (filter) {
|
|
57
|
+
prefixLength++;
|
|
58
|
+
indexedFilters.push(filter);
|
|
59
|
+
} else {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (prefixLength > 0 && (!best || prefixLength > best.prefixLength)) {
|
|
64
|
+
best = { indexName: index.name, indexedFilters, prefixLength };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return best ? { indexName: best.indexName, indexedFilters: best.indexedFilters } : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
4
70
|
// src/server/storage.ts
|
|
5
71
|
var TABLE_VECTOR_INDEXES = "mastra_vector_indexes";
|
|
6
72
|
var VECTOR_TABLE_PREFIX = "mastra_vector_";
|
|
@@ -96,6 +162,19 @@ async function handleTypedOperation(ctx, convexTable, request) {
|
|
|
96
162
|
} else {
|
|
97
163
|
docs = await ctx.db.query(convexTable).take(maxDocs);
|
|
98
164
|
}
|
|
165
|
+
} else if (request.filters && request.filters.length > 0) {
|
|
166
|
+
const match = findBestIndex(convexTable, request.filters);
|
|
167
|
+
if (match) {
|
|
168
|
+
docs = await ctx.db.query(convexTable).withIndex(match.indexName, (q) => {
|
|
169
|
+
let builder = q;
|
|
170
|
+
for (const filter of match.indexedFilters) {
|
|
171
|
+
builder = builder.eq(filter.field, filter.value);
|
|
172
|
+
}
|
|
173
|
+
return builder;
|
|
174
|
+
}).take(maxDocs);
|
|
175
|
+
} else {
|
|
176
|
+
docs = await ctx.db.query(convexTable).take(maxDocs);
|
|
177
|
+
}
|
|
99
178
|
} else {
|
|
100
179
|
docs = await ctx.db.query(convexTable).take(maxDocs);
|
|
101
180
|
}
|
|
@@ -310,5 +389,5 @@ async function handleGenericOperation(ctx, request) {
|
|
|
310
389
|
}
|
|
311
390
|
|
|
312
391
|
export { mastraStorage };
|
|
313
|
-
//# sourceMappingURL=chunk-
|
|
314
|
-
//# sourceMappingURL=chunk-
|
|
392
|
+
//# sourceMappingURL=chunk-SDTI6G3V.js.map
|
|
393
|
+
//# sourceMappingURL=chunk-SDTI6G3V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/index-map.ts","../src/server/storage.ts"],"names":[],"mappings":";;;;;;AAWO,IAAM,eAAA,GAA6E;AAAA,EACxF,eAAA,EAAiB;AAAA,IACf,EAAE,IAAA,EAAM,mBAAA,EAAqB,QAAQ,CAAC,WAAA,EAAa,WAAW,CAAA,EAAE;AAAA,IAChE,EAAE,IAAA,EAAM,WAAA,EAAa,MAAA,EAAQ,CAAC,WAAW,CAAA,EAAE;AAAA,IAC3C,EAAE,IAAA,EAAM,aAAA,EAAe,MAAA,EAAQ,CAAC,YAAY,CAAA,EAAE;AAAA,IAC9C,EAAE,IAAA,EAAM,cAAA,EAAgB,MAAA,EAAQ,CAAC,IAAI,CAAA;AAAE,GACzC;AAAA,EACA,cAAA,EAAgB;AAAA,IACd,EAAE,IAAA,EAAM,aAAA,EAAe,MAAA,EAAQ,CAAC,YAAY,CAAA,EAAE;AAAA,IAC9C,EAAE,IAAA,EAAM,YAAA,EAAc,MAAA,EAAQ,CAAC,WAAW,CAAA,EAAE;AAAA,IAC5C,EAAE,IAAA,EAAM,YAAA,EAAc,MAAA,EAAQ,CAAC,WAAW,CAAA,EAAE;AAAA,IAC5C,EAAE,IAAA,EAAM,cAAA,EAAgB,MAAA,EAAQ,CAAC,IAAI,CAAA;AAAE,GACzC;AAAA,EACA,gBAAA,EAAkB;AAAA,IAChB,EAAE,IAAA,EAAM,YAAA,EAAc,MAAA,EAAQ,CAAC,WAAW,CAAA,EAAE;AAAA,IAC5C,EAAE,IAAA,EAAM,cAAA,EAAgB,MAAA,EAAQ,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AAA,KAAA,MAAW,OAAO,YAAA,EAAc;AAC9B,QAAA,MAAM,GAAA,CAAI,EAAA,CAAG,MAAA,CAAO,GAAA,CAAI,GAAG,CAAA;AAAA,MAC7B;AACA,MAAA,OAAO,EAAE,EAAA,EAAI,IAAA,EAAM,OAAA,EAAQ;AAAA,IAC7B;AAAA,IAEA,KAAK,YAAA,EAAc;AACjB,MAAA,KAAA,MAAW,EAAA,IAAM,QAAQ,GAAA,EAAK;AAC5B,QAAA,MAAM,QAAA,GAAW,MAAM,GAAA,CAAI,EAAA,CACxB,MAAM,WAAW,CAAA,CACjB,SAAA,CAAU,kBAAA,EAAoB,CAAC,CAAA,KAAW,EAAE,EAAA,CAAG,OAAA,EAAS,SAAS,CAAA,CAAE,EAAA,CAAG,YAAA,EAAc,OAAO,EAAE,CAAC,CAAC,CAAA,CAC/F,MAAA,EAAO;AACV,QAAA,IAAI,QAAA,EAAU;AACZ,UAAA,MAAM,GAAA,CAAI,EAAA,CAAG,MAAA,CAAO,QAAA,CAAS,GAAG,CAAA;AAAA,QAClC;AAAA,MACF;AACA,MAAA,OAAO,EAAE,IAAI,IAAA,EAAK;AAAA,IACpB;AAAA,IAEA;AACE,MAAA,OAAO,EAAE,EAAA,EAAI,KAAA,EAAO,OAAO,CAAA,sBAAA,EAA0B,OAAA,CAAgB,EAAE,CAAA,CAAA,EAAG;AAAA;AAEhF","file":"chunk-SDTI6G3V.js","sourcesContent":["/**\n * Index definitions for automatic query optimization.\n *\n * Maps each typed Convex table to its available indexes and their field lists.\n * Indexes with more fields are listed first so the best (most specific) match\n * is preferred during selection.\n *\n * These must stay in sync with the index definitions in schema.ts.\n */\nimport type { EqualityFilter } from '../storage/types';\n\nexport const TABLE_INDEX_MAP: Record<string, Array<{ name: string; fields: string[] }>> = {\n mastra_messages: [\n { name: 'by_thread_created', fields: ['thread_id', 'createdAt'] },\n { name: 'by_thread', fields: ['thread_id'] },\n { name: 'by_resource', fields: ['resourceId'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_threads: [\n { name: 'by_resource', fields: ['resourceId'] },\n { name: 'by_created', fields: ['createdAt'] },\n { name: 'by_updated', fields: ['updatedAt'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_resources: [\n { name: 'by_updated', fields: ['updatedAt'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_workflow_snapshots: [\n { name: 'by_workflow_run', fields: ['workflow_name', 'run_id'] },\n { name: 'by_workflow', fields: ['workflow_name'] },\n { name: 'by_resource', fields: ['resourceId'] },\n { name: 'by_created', fields: ['createdAt'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_scorers: [\n { name: 'by_entity', fields: ['entityId', 'entityType'] },\n { name: 'by_scorer', fields: ['scorerId'] },\n { name: 'by_run', fields: ['runId'] },\n { name: 'by_created', fields: ['createdAt'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n mastra_vector_indexes: [\n { name: 'by_name', fields: ['indexName'] },\n { name: 'by_record_id', fields: ['id'] },\n ],\n};\n\n/**\n * Finds the best matching index for the given equality filters on a Convex table.\n *\n * Returns the index name and the subset of filters that form the index prefix,\n * or null when no index matches.\n *\n * The \"best\" index is the one whose prefix has the most consecutive fields\n * covered by the provided filters. For example, given filters for `thread_id`\n * and `createdAt` on mastra_messages, the composite `by_thread_created` index\n * (fields: [thread_id, createdAt]) is preferred over `by_thread` (fields: [thread_id]).\n */\nexport function findBestIndex(\n convexTable: string,\n filters: EqualityFilter[],\n): { indexName: string; indexedFilters: EqualityFilter[] } | null {\n const indexes = TABLE_INDEX_MAP[convexTable];\n if (!indexes || filters.length === 0) return null;\n\n const filtersByField = new Map<string, EqualityFilter>();\n for (const f of filters) {\n filtersByField.set(f.field, f);\n }\n\n let best: { indexName: string; indexedFilters: EqualityFilter[]; prefixLength: number } | null = null;\n\n for (const index of indexes) {\n let prefixLength = 0;\n const indexedFilters: EqualityFilter[] = [];\n\n for (const field of index.fields) {\n const filter = filtersByField.get(field);\n if (filter) {\n prefixLength++;\n indexedFilters.push(filter);\n } else {\n break;\n }\n }\n\n if (prefixLength > 0 && (!best || prefixLength > best.prefixLength)) {\n best = { indexName: index.name, indexedFilters, prefixLength };\n }\n }\n\n return best ? { indexName: best.indexName, indexedFilters: best.indexedFilters } : null;\n}\n","import {\n TABLE_WORKFLOW_SNAPSHOT,\n TABLE_MESSAGES,\n TABLE_THREADS,\n TABLE_RESOURCES,\n TABLE_SCORERS,\n} from '@mastra/core/storage/constants';\nimport type { GenericMutationCtx as MutationCtx } from 'convex/server';\nimport { mutationGeneric } from 'convex/server';\n\nimport type { StorageRequest, StorageResponse } from '../storage/types';\nimport { findBestIndex } from './index-map';\n\n// Vector-specific table names (not in @mastra/core)\nconst TABLE_VECTOR_INDEXES = 'mastra_vector_indexes';\nconst VECTOR_TABLE_PREFIX = 'mastra_vector_';\n\n/**\n * Determines which Convex table to use based on the logical table name.\n * Returns the Convex table name and whether it's a typed table or fallback.\n */\nfunction resolveTable(tableName: string): { convexTable: string; isTyped: boolean } {\n switch (tableName) {\n case TABLE_THREADS:\n return { convexTable: 'mastra_threads', isTyped: true };\n case TABLE_MESSAGES:\n return { convexTable: 'mastra_messages', isTyped: true };\n case TABLE_RESOURCES:\n return { convexTable: 'mastra_resources', isTyped: true };\n case TABLE_WORKFLOW_SNAPSHOT:\n return { convexTable: 'mastra_workflow_snapshots', isTyped: true };\n case TABLE_SCORERS:\n return { convexTable: 'mastra_scorers', isTyped: true };\n case TABLE_VECTOR_INDEXES:\n return { convexTable: 'mastra_vector_indexes', isTyped: true };\n default:\n // Check if it's a vector data table\n if (tableName.startsWith(VECTOR_TABLE_PREFIX)) {\n return { convexTable: 'mastra_vectors', isTyped: true };\n }\n // Fallback to generic documents table for unknown tables\n return { convexTable: 'mastra_documents', isTyped: false };\n }\n}\n\n/**\n * Main storage mutation handler.\n * Routes operations to the appropriate typed table.\n */\nexport const mastraStorage = mutationGeneric(async (ctx, request: StorageRequest): Promise<StorageResponse> => {\n try {\n const { convexTable, isTyped } = resolveTable(request.tableName);\n\n // Handle vector data tables specially (but NOT vector_indexes which is a typed table)\n if (request.tableName.startsWith(VECTOR_TABLE_PREFIX) && request.tableName !== TABLE_VECTOR_INDEXES) {\n return handleVectorOperation(ctx, request);\n }\n\n // Handle typed tables\n if (isTyped) {\n return handleTypedOperation(ctx, convexTable, request);\n }\n\n // Fallback to generic table for unknown tables\n return handleGenericOperation(ctx, request);\n } catch (error) {\n const err = error as Error;\n return {\n ok: false,\n error: err.message,\n };\n }\n});\n\n/**\n * Handle operations on typed tables (threads, messages, etc.)\n * Records are stored with their `id` field as a regular field (not _id).\n * We query by the `id` field to find/update records.\n */\nasync function handleTypedOperation(\n ctx: MutationCtx<any>,\n convexTable: string,\n request: StorageRequest,\n): Promise<StorageResponse> {\n switch (request.op) {\n case 'insert': {\n const record = request.record;\n const id = record.id;\n if (!id) {\n throw new Error(`Record is missing an id`);\n }\n\n // Find existing record by id field using index\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_record_id', (q: any) => q.eq('id', id))\n .unique();\n\n if (existing) {\n // Update existing - don't include id in patch (it's already set)\n const { id: _, ...updateData } = record;\n await ctx.db.patch(existing._id, updateData);\n } else {\n // Insert new - include id as a regular field\n await ctx.db.insert(convexTable, record);\n }\n return { ok: true };\n }\n\n case 'batchInsert': {\n for (const record of request.records) {\n const id = record.id;\n if (!id) continue;\n\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_record_id', (q: any) => q.eq('id', id))\n .unique();\n\n if (existing) {\n const { id: _, ...updateData } = record;\n await ctx.db.patch(existing._id, updateData);\n } else {\n await ctx.db.insert(convexTable, record);\n }\n }\n return { ok: true };\n }\n\n case 'load': {\n const keys = request.keys;\n if (keys.id) {\n // Find by id field using index\n const doc = await ctx.db\n .query(convexTable)\n .withIndex('by_record_id', (q: any) => q.eq('id', keys.id))\n .unique();\n return { ok: true, result: doc || null };\n }\n\n // Query by other fields - use take() to avoid 32k limit\n const docs = await ctx.db.query(convexTable).take(10000);\n const match = docs.find((doc: any) => Object.entries(keys).every(([key, value]) => doc[key] === value));\n return { ok: true, result: match || null };\n }\n\n case 'queryTable': {\n // Use take() to avoid hitting Convex's 32k document limit\n const maxDocs = request.limit ? Math.min(request.limit * 2, 10000) : 10000;\n\n // Build query with index if hint provided for efficient filtering\n let docs: any[];\n if (request.indexHint) {\n const hint = request.indexHint;\n if (hint.index === 'by_workflow') {\n docs = await ctx.db\n .query(convexTable)\n .withIndex('by_workflow', (q: any) => q.eq('workflow_name', hint.workflowName))\n .take(maxDocs);\n } else if (hint.index === 'by_workflow_run') {\n docs = await ctx.db\n .query(convexTable)\n .withIndex('by_workflow_run', (q: any) => q.eq('workflow_name', hint.workflowName).eq('run_id', hint.runId))\n .take(maxDocs);\n } else {\n docs = await ctx.db.query(convexTable).take(maxDocs);\n }\n } else if (request.filters && request.filters.length > 0) {\n const match = findBestIndex(convexTable, request.filters);\n if (match) {\n docs = await ctx.db\n .query(convexTable)\n .withIndex(match.indexName, (q: any) => {\n let builder = q;\n for (const filter of match.indexedFilters) {\n builder = builder.eq(filter.field, filter.value);\n }\n return builder;\n })\n .take(maxDocs);\n } else {\n docs = await ctx.db.query(convexTable).take(maxDocs);\n }\n } else {\n docs = await ctx.db.query(convexTable).take(maxDocs);\n }\n\n // Apply additional filters if provided\n if (request.filters && request.filters.length > 0) {\n docs = docs.filter((doc: any) => request.filters!.every(filter => doc[filter.field] === filter.value));\n }\n\n // Apply limit if provided\n if (request.limit) {\n docs = docs.slice(0, request.limit);\n }\n\n return { ok: true, result: docs };\n }\n\n case 'clearTable':\n case 'dropTable': {\n // Delete a small batch per call to stay within Convex's 1-second mutation timeout.\n // Client must call repeatedly until hasMore is false.\n const BATCH_SIZE = 25;\n const docs = await ctx.db.query(convexTable).take(BATCH_SIZE + 1);\n const hasMore = docs.length > BATCH_SIZE;\n const docsToDelete = hasMore ? docs.slice(0, BATCH_SIZE) : docs;\n\n for (const doc of docsToDelete) {\n await ctx.db.delete(doc._id);\n }\n return { ok: true, hasMore };\n }\n\n case 'deleteMany': {\n for (const id of request.ids) {\n const doc = await ctx.db\n .query(convexTable)\n .withIndex('by_record_id', (q: any) => q.eq('id', id))\n .unique();\n if (doc) {\n await ctx.db.delete(doc._id);\n }\n }\n return { ok: true };\n }\n\n default:\n return { ok: false, error: `Unsupported operation ${(request as any).op}` };\n }\n}\n\n/**\n * Handle operations on the vectors table.\n * Vectors are stored with indexName to support multiple indexes.\n */\nasync function handleVectorOperation(ctx: MutationCtx<any>, request: StorageRequest): Promise<StorageResponse> {\n // Extract the index name from the table name (e.g., \"mastra_vector_myindex\" -> \"myindex\")\n const indexName = request.tableName.replace(VECTOR_TABLE_PREFIX, '');\n const convexTable = 'mastra_vectors';\n\n switch (request.op) {\n case 'insert': {\n const record = request.record;\n const id = record.id;\n if (!id) {\n throw new Error(`Vector record is missing an id`);\n }\n\n // Find existing by composite key (indexName, id) to scope per index\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_index_id', (q: any) => q.eq('indexName', indexName).eq('id', id))\n .unique();\n\n if (existing) {\n await ctx.db.patch(existing._id, {\n embedding: record.embedding,\n metadata: record.metadata,\n });\n } else {\n await ctx.db.insert(convexTable, {\n id,\n indexName,\n embedding: record.embedding,\n metadata: record.metadata,\n });\n }\n return { ok: true };\n }\n\n case 'batchInsert': {\n for (const record of request.records) {\n const id = record.id;\n if (!id) continue;\n\n // Find existing by composite key (indexName, id) to scope per index\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_index_id', (q: any) => q.eq('indexName', indexName).eq('id', id))\n .unique();\n\n if (existing) {\n await ctx.db.patch(existing._id, {\n embedding: record.embedding,\n metadata: record.metadata,\n });\n } else {\n await ctx.db.insert(convexTable, {\n id,\n indexName,\n embedding: record.embedding,\n metadata: record.metadata,\n });\n }\n }\n return { ok: true };\n }\n\n case 'load': {\n const keys = request.keys;\n if (keys.id) {\n // Use composite key (indexName, id) to scope lookup per index\n const doc = await ctx.db\n .query(convexTable)\n .withIndex('by_index_id', (q: any) => q.eq('indexName', indexName).eq('id', keys.id))\n .unique();\n return { ok: true, result: doc || null };\n }\n return { ok: true, result: null };\n }\n\n case 'queryTable': {\n // Use take() to avoid hitting Convex's 32k document limit\n const maxDocs = request.limit ? Math.min(request.limit * 2, 10000) : 10000;\n let docs = await ctx.db\n .query(convexTable)\n .withIndex('by_index', (q: any) => q.eq('indexName', indexName))\n .take(maxDocs);\n\n // Apply filters if provided\n if (request.filters && request.filters.length > 0) {\n docs = docs.filter((doc: any) => request.filters!.every(filter => doc[filter.field] === filter.value));\n }\n\n // Apply limit if provided\n if (request.limit) {\n docs = docs.slice(0, request.limit);\n }\n\n return { ok: true, result: docs };\n }\n\n case 'clearTable':\n case 'dropTable': {\n // Delete a small batch per call to stay within Convex's 1-second mutation timeout.\n // Client must call repeatedly until hasMore is false.\n const BATCH_SIZE = 25;\n const docs = await ctx.db\n .query(convexTable)\n .withIndex('by_index', (q: any) => q.eq('indexName', indexName))\n .take(BATCH_SIZE + 1);\n const hasMore = docs.length > BATCH_SIZE;\n const docsToDelete = hasMore ? docs.slice(0, BATCH_SIZE) : docs;\n\n for (const doc of docsToDelete) {\n await ctx.db.delete(doc._id);\n }\n return { ok: true, hasMore };\n }\n\n case 'deleteMany': {\n for (const id of request.ids) {\n // Use composite key (indexName, id) to scope deletion per index\n const doc = await ctx.db\n .query(convexTable)\n .withIndex('by_index_id', (q: any) => q.eq('indexName', indexName).eq('id', id))\n .unique();\n if (doc) {\n await ctx.db.delete(doc._id);\n }\n }\n return { ok: true };\n }\n\n default:\n return { ok: false, error: `Unsupported operation ${(request as any).op}` };\n }\n}\n\n/**\n * Handle operations on the generic documents table.\n * Used as fallback for unknown table names.\n */\nasync function handleGenericOperation(ctx: MutationCtx<any>, request: StorageRequest): Promise<StorageResponse> {\n const tableName = request.tableName;\n const convexTable = 'mastra_documents';\n\n switch (request.op) {\n case 'insert': {\n const record = request.record;\n if (!record.id) {\n throw new Error(`Record for table ${tableName} is missing an id`);\n }\n const primaryKey = String(record.id);\n\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_table_primary', (q: any) => q.eq('table', tableName).eq('primaryKey', primaryKey))\n .unique();\n\n if (existing) {\n await ctx.db.patch(existing._id, { record });\n } else {\n await ctx.db.insert(convexTable, {\n table: tableName,\n primaryKey,\n record,\n });\n }\n return { ok: true };\n }\n\n case 'batchInsert': {\n for (const record of request.records) {\n if (!record.id) continue;\n const primaryKey = String(record.id);\n\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_table_primary', (q: any) => q.eq('table', tableName).eq('primaryKey', primaryKey))\n .unique();\n\n if (existing) {\n await ctx.db.patch(existing._id, { record });\n } else {\n await ctx.db.insert(convexTable, {\n table: tableName,\n primaryKey,\n record,\n });\n }\n }\n return { ok: true };\n }\n\n case 'load': {\n const keys = request.keys;\n if (keys.id) {\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_table_primary', (q: any) => q.eq('table', tableName).eq('primaryKey', String(keys.id)))\n .unique();\n return { ok: true, result: existing ? existing.record : null };\n }\n\n const docs = await ctx.db\n .query(convexTable)\n .withIndex('by_table', (q: any) => q.eq('table', tableName))\n .take(10000);\n const match = docs.find((doc: any) => Object.entries(keys).every(([key, value]) => doc.record?.[key] === value));\n return { ok: true, result: match ? match.record : null };\n }\n\n case 'queryTable': {\n // Use take() to avoid hitting Convex's 32k document limit\n const maxDocs = request.limit ? Math.min(request.limit * 2, 10000) : 10000;\n const docs = await ctx.db\n .query(convexTable)\n .withIndex('by_table', (q: any) => q.eq('table', tableName))\n .take(maxDocs);\n\n let records = docs.map((doc: any) => doc.record);\n\n if (request.filters && request.filters.length > 0) {\n records = records.filter((record: any) =>\n request.filters!.every(filter => record?.[filter.field] === filter.value),\n );\n }\n\n if (request.limit) {\n records = records.slice(0, request.limit);\n }\n\n return { ok: true, result: records };\n }\n\n case 'clearTable':\n case 'dropTable': {\n // Delete a small batch per call to stay within Convex's 1-second mutation timeout.\n // Client must call repeatedly until hasMore is false.\n const BATCH_SIZE = 25;\n const docs = await ctx.db\n .query(convexTable)\n .withIndex('by_table', (q: any) => q.eq('table', tableName))\n .take(BATCH_SIZE + 1);\n const hasMore = docs.length > BATCH_SIZE;\n const docsToDelete = hasMore ? docs.slice(0, BATCH_SIZE) : docs;\n\n for (const doc of docsToDelete) {\n await ctx.db.delete(doc._id);\n }\n return { ok: true, hasMore };\n }\n\n case 'deleteMany': {\n for (const id of request.ids) {\n const existing = await ctx.db\n .query(convexTable)\n .withIndex('by_table_primary', (q: any) => q.eq('table', tableName).eq('primaryKey', String(id)))\n .unique();\n if (existing) {\n await ctx.db.delete(existing._id);\n }\n }\n return { ok: true };\n }\n\n default:\n return { ok: false, error: `Unsupported operation ${(request as any).op}` };\n }\n}\n"]}
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.5",
|
|
3
3
|
"package": "@mastra/convex",
|
|
4
4
|
"exports": {
|
|
5
5
|
"mastraStorage": {
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"implementation": "dist/chunk-
|
|
7
|
+
"implementation": "dist/chunk-SDTI6G3V.js"
|
|
8
8
|
},
|
|
9
9
|
"TABLE_MESSAGES": {
|
|
10
10
|
"types": "dist/index.d.ts",
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkPW7BUVK5_cjs = require('./chunk-PW7BUVK5.cjs');
|
|
4
4
|
var chunkFTVDAP6U_cjs = require('./chunk-FTVDAP6U.cjs');
|
|
5
5
|
var storage = require('@mastra/core/storage');
|
|
6
6
|
var agent = require('@mastra/core/agent');
|
|
@@ -732,48 +732,23 @@ var WorkflowsConvex = class extends storage.WorkflowsStorage {
|
|
|
732
732
|
const client = resolveConvexConfig(config);
|
|
733
733
|
this.#db = new ConvexDB(client);
|
|
734
734
|
}
|
|
735
|
+
supportsConcurrentUpdates() {
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
735
738
|
async init() {
|
|
736
739
|
}
|
|
737
740
|
async dangerouslyClearAll() {
|
|
738
741
|
await this.#db.clearTable({ tableName: storage.TABLE_WORKFLOW_SNAPSHOT });
|
|
739
742
|
}
|
|
740
|
-
async updateWorkflowResults({
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
result,
|
|
745
|
-
requestContext
|
|
746
|
-
}) {
|
|
747
|
-
const run = await this.getRun(workflowName, runId);
|
|
748
|
-
if (!run) return {};
|
|
749
|
-
const snapshot = this.ensureSnapshot(run);
|
|
750
|
-
snapshot.context = snapshot.context || {};
|
|
751
|
-
snapshot.context[stepId] = result;
|
|
752
|
-
snapshot.requestContext = { ...snapshot.requestContext || {}, ...requestContext };
|
|
753
|
-
await this.persistWorkflowSnapshot({
|
|
754
|
-
workflowName,
|
|
755
|
-
runId,
|
|
756
|
-
resourceId: run.resourceId,
|
|
757
|
-
snapshot
|
|
758
|
-
});
|
|
759
|
-
return JSON.parse(JSON.stringify(snapshot.context));
|
|
743
|
+
async updateWorkflowResults(_args) {
|
|
744
|
+
throw new Error(
|
|
745
|
+
"updateWorkflowResults is not implemented for Convex storage. Convex does not support atomic read-modify-write operations needed for concurrent workflow updates."
|
|
746
|
+
);
|
|
760
747
|
}
|
|
761
|
-
async updateWorkflowState({
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
}) {
|
|
766
|
-
const run = await this.getRun(workflowName, runId);
|
|
767
|
-
if (!run) return void 0;
|
|
768
|
-
const snapshot = this.ensureSnapshot(run);
|
|
769
|
-
const updated = { ...snapshot, ...opts };
|
|
770
|
-
await this.persistWorkflowSnapshot({
|
|
771
|
-
workflowName,
|
|
772
|
-
runId,
|
|
773
|
-
resourceId: run.resourceId,
|
|
774
|
-
snapshot: updated
|
|
775
|
-
});
|
|
776
|
-
return updated;
|
|
748
|
+
async updateWorkflowState(_args) {
|
|
749
|
+
throw new Error(
|
|
750
|
+
"updateWorkflowState is not implemented for Convex storage. Convex does not support atomic read-modify-write operations needed for concurrent workflow updates."
|
|
751
|
+
);
|
|
777
752
|
}
|
|
778
753
|
async persistWorkflowSnapshot({
|
|
779
754
|
workflowName,
|
|
@@ -1223,7 +1198,7 @@ function cosineSimilarity(a, b) {
|
|
|
1223
1198
|
|
|
1224
1199
|
Object.defineProperty(exports, "mastraStorage", {
|
|
1225
1200
|
enumerable: true,
|
|
1226
|
-
get: function () { return
|
|
1201
|
+
get: function () { return chunkPW7BUVK5_cjs.mastraStorage; }
|
|
1227
1202
|
});
|
|
1228
1203
|
Object.defineProperty(exports, "TABLE_MESSAGES", {
|
|
1229
1204
|
enumerable: true,
|