@mastra/convex 1.5.2 → 1.5.3-alpha.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 +9 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +17 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -5
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +8 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1088,7 +1088,7 @@ var MemoryConvex = class extends MemoryStorage {
|
|
|
1088
1088
|
hasMore: false
|
|
1089
1089
|
};
|
|
1090
1090
|
if (perPage === 0 && include && include.length > 0) {
|
|
1091
|
-
const messages = await this._getIncludedMessages(include);
|
|
1091
|
+
const messages = await this._getIncludedMessages(include, void 0, resourceId);
|
|
1092
1092
|
const list = new MessageList().add(messages, "memory");
|
|
1093
1093
|
return {
|
|
1094
1094
|
messages: this._sortMessages(list.get.all.db(), field, direction),
|
|
@@ -1121,7 +1121,7 @@ var MemoryConvex = class extends MemoryStorage {
|
|
|
1121
1121
|
if (include && include.length > 0) {
|
|
1122
1122
|
const preloadedThreads = /* @__PURE__ */ new Map();
|
|
1123
1123
|
if (!resourceId && !filter?.dateRange && !metadataFilter) for (const tid of threadIds) preloadedThreads.set(tid, rows.filter((r) => r.thread_id === tid));
|
|
1124
|
-
const includedMessages = await this._getIncludedMessages(include, preloadedThreads);
|
|
1124
|
+
const includedMessages = await this._getIncludedMessages(include, preloadedThreads, resourceId);
|
|
1125
1125
|
for (const msg of includedMessages) if (!messageIds.has(msg.id)) {
|
|
1126
1126
|
messages.push(msg);
|
|
1127
1127
|
messageIds.add(msg.id);
|
|
@@ -1303,8 +1303,20 @@ var MemoryConvex = class extends MemoryStorage {
|
|
|
1303
1303
|
return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
|
|
1304
1304
|
});
|
|
1305
1305
|
}
|
|
1306
|
-
|
|
1306
|
+
/**
|
|
1307
|
+
* Fetches the messages named by `include` together with their surrounding context.
|
|
1308
|
+
*
|
|
1309
|
+
* @param include - Message ids to pin, each with an optional before/after window.
|
|
1310
|
+
* @param preloadedThreads - Thread snapshots already loaded by the caller, reused instead of re-querying.
|
|
1311
|
+
* @param resourceId - When set, restricts both the pinned messages and their context
|
|
1312
|
+
* to that resource so an id from another resource returns nothing.
|
|
1313
|
+
*/
|
|
1314
|
+
async _getIncludedMessages(include, preloadedThreads, resourceId) {
|
|
1307
1315
|
if (include.length === 0) return [];
|
|
1316
|
+
const resourceFilters = resourceId ? [{
|
|
1317
|
+
field: "resourceId",
|
|
1318
|
+
value: resourceId
|
|
1319
|
+
}] : [];
|
|
1308
1320
|
const messages = [];
|
|
1309
1321
|
const messageIds = /* @__PURE__ */ new Set();
|
|
1310
1322
|
const threadMessagesCache = new Map(preloadedThreads ?? []);
|
|
@@ -1325,7 +1337,7 @@ var MemoryConvex = class extends MemoryStorage {
|
|
|
1325
1337
|
const messageRows = await this.#db.queryTable(TABLE_MESSAGES$1, [{
|
|
1326
1338
|
field: "id",
|
|
1327
1339
|
value: includeItem.id
|
|
1328
|
-
}]);
|
|
1340
|
+
}, ...resourceFilters]);
|
|
1329
1341
|
if (messageRows.length > 0) {
|
|
1330
1342
|
target = messageRows[0];
|
|
1331
1343
|
targetThreadId = target.thread_id;
|
|
@@ -1333,7 +1345,7 @@ var MemoryConvex = class extends MemoryStorage {
|
|
|
1333
1345
|
const otherThreadRows = await this.#db.queryTable(TABLE_MESSAGES$1, [{
|
|
1334
1346
|
field: "thread_id",
|
|
1335
1347
|
value: targetThreadId
|
|
1336
|
-
}]);
|
|
1348
|
+
}, ...resourceFilters]);
|
|
1337
1349
|
threadMessagesCache.set(targetThreadId, otherThreadRows);
|
|
1338
1350
|
for (const row of otherThreadRows) cachedTargets.set(row.id, {
|
|
1339
1351
|
threadId: targetThreadId,
|