@mastra/convex 0.0.1 → 0.0.2-beta.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @mastra/convex
2
2
 
3
+ ## 0.0.2-beta.0
4
+
5
+ ### Patch Changes
6
+
7
+ - feat(storage): support querying messages from multiple threads ([#10663](https://github.com/mastra-ai/mastra/pull/10663))
8
+ - Fixed TypeScript errors where `threadId: string | string[]` was being passed to places expecting `Scalar` type
9
+ - Added proper multi-thread support for `listMessages` across all adapters when `threadId` is an array
10
+ - Updated `_getIncludedMessages` to look up message threadId by ID (since message IDs are globally unique)
11
+ - **upstash**: Added `msg-idx:{messageId}` index for O(1) message lookups (backwards compatible with fallback to scan for old messages, with automatic backfill)
12
+
13
+ - Convex storage and vector adapter improvements: ([#10421](https://github.com/mastra-ai/mastra/pull/10421))
14
+ - Refactored to use typed Convex tables for each Mastra domain (threads, messages, resources, workflows, scorers, vectors)
15
+ - All tables now include `id` field for Mastra record ID and `by_record_id` index for efficient lookups
16
+ - Fixed 32k document limit issues by using batched operations and indexed queries
17
+ - Updated `saveMessages` and `updateMessages` to automatically update thread `updatedAt` timestamps
18
+ - Fixed `listMessages` to properly fetch messages from different threads when using `include`
19
+ - Fixed `saveResource` to preserve `undefined` metadata instead of converting to empty object
20
+ - Rewrote `ConvexAdminClient` to use Convex HTTP API directly with proper admin authentication
21
+ - Added comprehensive documentation for storage and vector adapters
22
+ - Exported pre-built table definitions from `@mastra/convex/server` for easy schema setup
23
+
24
+ - Updated dependencies [[`ac0d2f4`](https://github.com/mastra-ai/mastra/commit/ac0d2f4ff8831f72c1c66c2be809706d17f65789), [`1a0d3fc`](https://github.com/mastra-ai/mastra/commit/1a0d3fc811482c9c376cdf79ee615c23bae9b2d6), [`85a628b`](https://github.com/mastra-ai/mastra/commit/85a628b1224a8f64cd82ea7f033774bf22df7a7e), [`c237233`](https://github.com/mastra-ai/mastra/commit/c23723399ccedf7f5744b3f40997b79246bfbe64), [`15f9e21`](https://github.com/mastra-ai/mastra/commit/15f9e216177201ea6e3f6d0bfb063fcc0953444f), [`ff94dea`](https://github.com/mastra-ai/mastra/commit/ff94dea935f4e34545c63bcb6c29804732698809), [`5b2ff46`](https://github.com/mastra-ai/mastra/commit/5b2ff4651df70c146523a7fca773f8eb0a2272f8), [`db41688`](https://github.com/mastra-ai/mastra/commit/db4168806d007417e2e60b4f68656dca4e5f40c9), [`5ca599d`](https://github.com/mastra-ai/mastra/commit/5ca599d0bb59a1595f19f58473fcd67cc71cef58), [`bff1145`](https://github.com/mastra-ai/mastra/commit/bff114556b3cbadad9b2768488708f8ad0e91475), [`5c8ca24`](https://github.com/mastra-ai/mastra/commit/5c8ca247094e0cc2cdbd7137822fb47241f86e77), [`e191844`](https://github.com/mastra-ai/mastra/commit/e1918444ca3f80e82feef1dad506cd4ec6e2875f), [`22553f1`](https://github.com/mastra-ai/mastra/commit/22553f11c63ee5e966a9c034a349822249584691), [`7237163`](https://github.com/mastra-ai/mastra/commit/72371635dbf96a87df4b073cc48fc655afbdce3d), [`2500740`](https://github.com/mastra-ai/mastra/commit/2500740ea23da067d6e50ec71c625ab3ce275e64), [`873ecbb`](https://github.com/mastra-ai/mastra/commit/873ecbb517586aa17d2f1e99283755b3ebb2863f), [`4f9bbe5`](https://github.com/mastra-ai/mastra/commit/4f9bbe5968f42c86f4930b8193de3c3c17e5bd36), [`02e51fe`](https://github.com/mastra-ai/mastra/commit/02e51feddb3d4155cfbcc42624fd0d0970d032c0), [`8f3fa3a`](https://github.com/mastra-ai/mastra/commit/8f3fa3a652bb77da092f913ec51ae46e3a7e27dc), [`cd29ad2`](https://github.com/mastra-ai/mastra/commit/cd29ad23a255534e8191f249593849ed29160886), [`bdf4d8c`](https://github.com/mastra-ai/mastra/commit/bdf4d8cdc656d8a2c21d81834bfa3bfa70f56c16), [`854e3da`](https://github.com/mastra-ai/mastra/commit/854e3dad5daac17a91a20986399d3a51f54bf68b), [`ce18d38`](https://github.com/mastra-ai/mastra/commit/ce18d38678c65870350d123955014a8432075fd9), [`cccf9c8`](https://github.com/mastra-ai/mastra/commit/cccf9c8b2d2dfc1a5e63919395b83d78c89682a0), [`61a5705`](https://github.com/mastra-ai/mastra/commit/61a570551278b6743e64243b3ce7d73de915ca8a), [`db70a48`](https://github.com/mastra-ai/mastra/commit/db70a48aeeeeb8e5f92007e8ede52c364ce15287), [`f0fdc14`](https://github.com/mastra-ai/mastra/commit/f0fdc14ee233d619266b3d2bbdeea7d25cfc6d13), [`db18bc9`](https://github.com/mastra-ai/mastra/commit/db18bc9c3825e2c1a0ad9a183cc9935f6691bfa1), [`9b37b56`](https://github.com/mastra-ai/mastra/commit/9b37b565e1f2a76c24f728945cc740c2b09be9da), [`41a23c3`](https://github.com/mastra-ai/mastra/commit/41a23c32f9877d71810f37e24930515df2ff7a0f), [`5d171ad`](https://github.com/mastra-ai/mastra/commit/5d171ad9ef340387276b77c2bb3e83e83332d729), [`f03ae60`](https://github.com/mastra-ai/mastra/commit/f03ae60500fe350c9d828621006cdafe1975fdd8), [`d1e74a0`](https://github.com/mastra-ai/mastra/commit/d1e74a0a293866dece31022047f5dbab65a304d0), [`39e7869`](https://github.com/mastra-ai/mastra/commit/39e7869bc7d0ee391077ce291474d8a84eedccff), [`5761926`](https://github.com/mastra-ai/mastra/commit/57619260c4a2cdd598763abbacd90de594c6bc76), [`c900fdd`](https://github.com/mastra-ai/mastra/commit/c900fdd504c41348efdffb205cfe80d48c38fa33), [`604a79f`](https://github.com/mastra-ai/mastra/commit/604a79fecf276e26a54a3fe01bb94e65315d2e0e), [`887f0b4`](https://github.com/mastra-ai/mastra/commit/887f0b4746cdbd7cb7d6b17ac9f82aeb58037ea5), [`2562143`](https://github.com/mastra-ai/mastra/commit/256214336b4faa78646c9c1776612393790d8784), [`ef11a61`](https://github.com/mastra-ai/mastra/commit/ef11a61920fa0ed08a5b7ceedd192875af119749)]:
25
+ - @mastra/core@1.0.0-beta.6
26
+
3
27
  ## Unreleased
4
28
 
5
29
  - Initial release.
package/dist/index.cjs CHANGED
@@ -169,23 +169,28 @@ var MemoryConvex = class extends storage.MemoryStorage {
169
169
  }
170
170
  async listMessages(args) {
171
171
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
172
- if (!threadId.trim()) {
172
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
173
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
173
174
  throw new error.MastraError(
174
175
  {
175
176
  id: "CONVEX_STORAGE_LIST_MESSAGES_INVALID_THREAD_ID",
176
177
  domain: error.ErrorDomain.STORAGE,
177
178
  category: error.ErrorCategory.USER,
178
- details: { threadId }
179
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
179
180
  },
180
- new Error("threadId must be a non-empty string")
181
+ new Error("threadId must be a non-empty string or array of non-empty strings")
181
182
  );
182
183
  }
183
184
  const perPage = storage.normalizePerPage(perPageInput, 40);
184
185
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
185
186
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
186
- let rows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
187
- { field: "thread_id", value: threadId }
188
- ]);
187
+ let rows = [];
188
+ for (const tid of threadIds) {
189
+ const threadRows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
190
+ { field: "thread_id", value: tid }
191
+ ]);
192
+ rows.push(...threadRows);
193
+ }
189
194
  if (resourceId) {
190
195
  rows = rows.filter((row) => row.resourceId === resourceId);
191
196
  }
@@ -212,21 +217,41 @@ var MemoryConvex = class extends storage.MemoryStorage {
212
217
  const messageIds = new Set(messages.map((msg) => msg.id));
213
218
  if (include && include.length > 0) {
214
219
  const threadMessagesCache = /* @__PURE__ */ new Map();
215
- threadMessagesCache.set(threadId, rows);
220
+ for (const tid of threadIds) {
221
+ const tidRows = rows.filter((r) => r.thread_id === tid);
222
+ threadMessagesCache.set(tid, tidRows);
223
+ }
216
224
  for (const includeItem of include) {
217
- const targetThreadId = includeItem.threadId || threadId;
218
- if (!threadMessagesCache.has(targetThreadId)) {
219
- const otherThreadRows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
220
- { field: "thread_id", value: targetThreadId }
225
+ let targetThreadId;
226
+ let target;
227
+ for (const [tid, cachedRows] of threadMessagesCache) {
228
+ target = cachedRows.find((row) => row.id === includeItem.id);
229
+ if (target) {
230
+ targetThreadId = tid;
231
+ break;
232
+ }
233
+ }
234
+ if (!target) {
235
+ const messageRows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
236
+ { field: "id", value: includeItem.id }
221
237
  ]);
222
- threadMessagesCache.set(targetThreadId, otherThreadRows);
238
+ if (messageRows.length > 0) {
239
+ target = messageRows[0];
240
+ targetThreadId = target.thread_id;
241
+ if (targetThreadId && !threadMessagesCache.has(targetThreadId)) {
242
+ const otherThreadRows = await this.operations.queryTable(storage.TABLE_MESSAGES, [
243
+ { field: "thread_id", value: targetThreadId }
244
+ ]);
245
+ threadMessagesCache.set(targetThreadId, otherThreadRows);
246
+ }
247
+ }
223
248
  }
224
- const targetThreadRows = threadMessagesCache.get(targetThreadId) || [];
225
- const target = targetThreadRows.find((row) => row.id === includeItem.id);
226
- if (target && !messageIds.has(target.id)) {
249
+ if (!target || !targetThreadId) continue;
250
+ if (!messageIds.has(target.id)) {
227
251
  messages.push(this.parseStoredMessage(target));
228
252
  messageIds.add(target.id);
229
253
  }
254
+ const targetThreadRows = threadMessagesCache.get(targetThreadId) || [];
230
255
  await this.addContextMessages({
231
256
  includeItem,
232
257
  allMessages: targetThreadRows,