@mastra/mongodb 1.14.0 → 1.15.0-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 +25 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +38 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -15
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/mongodb
|
|
2
2
|
|
|
3
|
+
## 1.15.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added exact metadata filtering to message history queries across Memory APIs and supported storage providers. ([#19991](https://github.com/mastra-ai/mastra/pull/19991))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const messages = await memory.recall({
|
|
11
|
+
threadId: 'thread-1',
|
|
12
|
+
filter: {
|
|
13
|
+
metadata: {
|
|
14
|
+
status: 'done',
|
|
15
|
+
priority: 'high',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Multiple fields use AND semantics. Supported values are strings, finite numbers, booleans, and `null`.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`0dca9d0`](https://github.com/mastra-ai/mastra/commit/0dca9d0b1356024a53b72ea6f040db528b126caa)]:
|
|
26
|
+
- @mastra/core@1.54.0-alpha.0
|
|
27
|
+
|
|
3
28
|
## 1.14.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -15,7 +15,7 @@ var skills = require('@mastra/core/storage/domains/skills');
|
|
|
15
15
|
|
|
16
16
|
// package.json
|
|
17
17
|
var package_default = {
|
|
18
|
-
version: "1.
|
|
18
|
+
version: "1.15.0-alpha.0"};
|
|
19
19
|
var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
20
20
|
getSupportedOperators() {
|
|
21
21
|
return {
|
|
@@ -5273,6 +5273,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5273
5273
|
}
|
|
5274
5274
|
async listMessages(args) {
|
|
5275
5275
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
5276
|
+
const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
|
|
5276
5277
|
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
5277
5278
|
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
5278
5279
|
throw new error.MastraError(
|
|
@@ -5328,16 +5329,27 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5328
5329
|
hasMore: false
|
|
5329
5330
|
};
|
|
5330
5331
|
}
|
|
5331
|
-
const total = await collection.countDocuments(query);
|
|
5332
5332
|
const messages = [];
|
|
5333
|
+
let total = 0;
|
|
5333
5334
|
if (perPage !== 0) {
|
|
5334
5335
|
const sortObj = { [field]: sortOrder };
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5336
|
+
if (metadataFilter) {
|
|
5337
|
+
const candidates = (await collection.find(query).sort(sortObj).toArray()).map((row) => this.parseRow(row)).filter((message) => storage.storageMessageMatchesMetadataFilter(message.content, metadataFilter));
|
|
5338
|
+
total = candidates.length;
|
|
5339
|
+
messages.push(...perPageInput === false ? candidates : candidates.slice(offset, offset + perPage));
|
|
5340
|
+
} else {
|
|
5341
|
+
total = await collection.countDocuments(query);
|
|
5342
|
+
let cursor = collection.find(query).sort(sortObj).skip(offset);
|
|
5343
|
+
if (perPageInput !== false) {
|
|
5344
|
+
cursor = cursor.limit(perPage);
|
|
5345
|
+
}
|
|
5346
|
+
const dataResult = await cursor.toArray();
|
|
5347
|
+
messages.push(...dataResult.map((row) => this.parseRow(row)));
|
|
5338
5348
|
}
|
|
5339
|
-
|
|
5340
|
-
|
|
5349
|
+
} else if (metadataFilter) {
|
|
5350
|
+
total = (await collection.find(query).toArray()).map((row) => this.parseRow(row)).filter((message) => storage.storageMessageMatchesMetadataFilter(message.content, metadataFilter)).length;
|
|
5351
|
+
} else {
|
|
5352
|
+
total = await collection.countDocuments(query);
|
|
5341
5353
|
}
|
|
5342
5354
|
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
5343
5355
|
return {
|
|
@@ -5367,7 +5379,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5367
5379
|
finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
|
|
5368
5380
|
);
|
|
5369
5381
|
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
5370
|
-
const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
5382
|
+
const hasMore = metadataFilter ? perPageInput !== false && offset + perPage < total : perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
5371
5383
|
return {
|
|
5372
5384
|
messages: finalMessages,
|
|
5373
5385
|
total,
|
|
@@ -5401,6 +5413,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5401
5413
|
}
|
|
5402
5414
|
async listMessagesByResourceId(args) {
|
|
5403
5415
|
const { resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
5416
|
+
const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
|
|
5404
5417
|
if (!resourceId || typeof resourceId !== "string" || resourceId.trim().length === 0) {
|
|
5405
5418
|
throw new error.MastraError(
|
|
5406
5419
|
{
|
|
@@ -5456,16 +5469,27 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5456
5469
|
hasMore: false
|
|
5457
5470
|
};
|
|
5458
5471
|
}
|
|
5459
|
-
const total = await collection.countDocuments(query);
|
|
5460
5472
|
const messages = [];
|
|
5473
|
+
let total = 0;
|
|
5461
5474
|
if (perPage !== 0) {
|
|
5462
5475
|
const sortObj = { [field]: sortOrder };
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5476
|
+
if (metadataFilter) {
|
|
5477
|
+
const candidates = (await collection.find(query).sort(sortObj).toArray()).map((row) => this.parseRow(row)).filter((message) => storage.storageMessageMatchesMetadataFilter(message.content, metadataFilter));
|
|
5478
|
+
total = candidates.length;
|
|
5479
|
+
messages.push(...perPageInput === false ? candidates : candidates.slice(offset, offset + perPage));
|
|
5480
|
+
} else {
|
|
5481
|
+
total = await collection.countDocuments(query);
|
|
5482
|
+
let cursor = collection.find(query).sort(sortObj).skip(offset);
|
|
5483
|
+
if (perPageInput !== false) {
|
|
5484
|
+
cursor = cursor.limit(perPage);
|
|
5485
|
+
}
|
|
5486
|
+
const dataResult = await cursor.toArray();
|
|
5487
|
+
messages.push(...dataResult.map((row) => this.parseRow(row)));
|
|
5466
5488
|
}
|
|
5467
|
-
|
|
5468
|
-
|
|
5489
|
+
} else if (metadataFilter) {
|
|
5490
|
+
total = (await collection.find(query).toArray()).map((row) => this.parseRow(row)).filter((message) => storage.storageMessageMatchesMetadataFilter(message.content, metadataFilter)).length;
|
|
5491
|
+
} else {
|
|
5492
|
+
total = await collection.countDocuments(query);
|
|
5469
5493
|
}
|
|
5470
5494
|
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
5471
5495
|
return {
|