@mastra/mongodb 1.16.1 → 1.17.0-alpha.1
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 +54 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-composite.md +58 -0
- package/dist/index.cjs +69 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -46
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +7 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { MessageList } from "@mastra/core/agent";
|
|
|
9
9
|
import { saveScorePayloadSchema } from "@mastra/core/evals";
|
|
10
10
|
import { skillSnapshotFieldValuesEqual } from "@mastra/core/storage/domains/skills";
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "1.
|
|
12
|
+
var version = "1.17.0-alpha.1";
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/vector/filter.ts
|
|
15
15
|
/**
|
|
@@ -3666,6 +3666,12 @@ function transformExperimentRow(row) {
|
|
|
3666
3666
|
name: row.name ?? void 0,
|
|
3667
3667
|
description: row.description ?? void 0,
|
|
3668
3668
|
metadata: parseJsonField(row.metadata) ?? void 0,
|
|
3669
|
+
provenance: parseJsonField(row.provenance) ?? null,
|
|
3670
|
+
runnerAttestation: parseJsonField(row.runnerAttestation) ?? null,
|
|
3671
|
+
experimentSetId: row.experimentSetId ?? null,
|
|
3672
|
+
comparisonId: row.comparisonId ?? null,
|
|
3673
|
+
variantId: row.variantId ?? null,
|
|
3674
|
+
trialIndex: row.trialIndex != null ? Number(row.trialIndex) : null,
|
|
3669
3675
|
datasetId: row.datasetId ?? null,
|
|
3670
3676
|
datasetVersion: row.datasetVersion != null ? Number(row.datasetVersion) : null,
|
|
3671
3677
|
organizationId: row.organizationId ?? null,
|
|
@@ -3812,6 +3818,15 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
|
|
|
3812
3818
|
id: 1
|
|
3813
3819
|
}
|
|
3814
3820
|
},
|
|
3821
|
+
{
|
|
3822
|
+
collection: TABLE_EXPERIMENTS,
|
|
3823
|
+
keys: {
|
|
3824
|
+
experimentSetId: 1,
|
|
3825
|
+
comparisonId: 1,
|
|
3826
|
+
variantId: 1,
|
|
3827
|
+
trialIndex: 1
|
|
3828
|
+
}
|
|
3829
|
+
},
|
|
3815
3830
|
{
|
|
3816
3831
|
collection: TABLE_EXPERIMENTS,
|
|
3817
3832
|
keys: {
|
|
@@ -3885,6 +3900,12 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
|
|
|
3885
3900
|
name: input.name ?? null,
|
|
3886
3901
|
description: input.description ?? null,
|
|
3887
3902
|
metadata: input.metadata ?? null,
|
|
3903
|
+
provenance: input.provenance ?? null,
|
|
3904
|
+
runnerAttestation: input.runnerAttestation ?? null,
|
|
3905
|
+
experimentSetId: input.experimentSetId ?? null,
|
|
3906
|
+
comparisonId: input.comparisonId ?? null,
|
|
3907
|
+
variantId: input.variantId ?? null,
|
|
3908
|
+
trialIndex: input.trialIndex ?? null,
|
|
3888
3909
|
datasetId: input.datasetId ?? null,
|
|
3889
3910
|
datasetVersion: input.datasetVersion ?? null,
|
|
3890
3911
|
organizationId: input.organizationId ?? null,
|
|
@@ -3904,28 +3925,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
|
|
|
3904
3925
|
};
|
|
3905
3926
|
try {
|
|
3906
3927
|
await (await this.getCollection(TABLE_EXPERIMENTS)).insertOne(doc);
|
|
3907
|
-
return
|
|
3908
|
-
id,
|
|
3909
|
-
name: input.name,
|
|
3910
|
-
description: input.description,
|
|
3911
|
-
metadata: input.metadata,
|
|
3912
|
-
datasetId: input.datasetId ?? null,
|
|
3913
|
-
datasetVersion: input.datasetVersion ?? null,
|
|
3914
|
-
organizationId: input.organizationId ?? null,
|
|
3915
|
-
projectId: input.projectId ?? null,
|
|
3916
|
-
targetType: input.targetType,
|
|
3917
|
-
targetId: input.targetId,
|
|
3918
|
-
status: "pending",
|
|
3919
|
-
totalItems: input.totalItems,
|
|
3920
|
-
succeededCount: 0,
|
|
3921
|
-
failedCount: 0,
|
|
3922
|
-
skippedCount: 0,
|
|
3923
|
-
agentVersion: input.agentVersion ?? null,
|
|
3924
|
-
startedAt: null,
|
|
3925
|
-
completedAt: null,
|
|
3926
|
-
createdAt: now,
|
|
3927
|
-
updatedAt: now
|
|
3928
|
-
};
|
|
3928
|
+
return transformExperimentRow(structuredClone(doc));
|
|
3929
3929
|
} catch (error) {
|
|
3930
3930
|
throw new MastraError({
|
|
3931
3931
|
id: createStorageErrorId("MONGODB", "CREATE_EXPERIMENT", "FAILED"),
|
|
@@ -3992,6 +3992,10 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
|
|
|
3992
3992
|
if (args.targetId) filter.targetId = args.targetId;
|
|
3993
3993
|
if (args.agentVersion) filter.agentVersion = args.agentVersion;
|
|
3994
3994
|
if (args.status) filter.status = args.status;
|
|
3995
|
+
if (args.experimentSetId !== void 0) filter.experimentSetId = args.experimentSetId;
|
|
3996
|
+
if (args.comparisonId !== void 0) filter.comparisonId = args.comparisonId;
|
|
3997
|
+
if (args.variantId !== void 0) filter.variantId = args.variantId;
|
|
3998
|
+
if (args.trialIndex !== void 0) filter.trialIndex = args.trialIndex;
|
|
3995
3999
|
if (args.filters) {
|
|
3996
4000
|
const { organizationId, projectId } = args.filters;
|
|
3997
4001
|
if (organizationId !== void 0) filter.organizationId = organizationId;
|
|
@@ -5400,12 +5404,23 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5400
5404
|
return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
|
|
5401
5405
|
});
|
|
5402
5406
|
}
|
|
5403
|
-
|
|
5407
|
+
/**
|
|
5408
|
+
* Fetches the messages named by `include` together with their surrounding context.
|
|
5409
|
+
*
|
|
5410
|
+
* @param include - Message ids to pin, each with an optional before/after window.
|
|
5411
|
+
* @param resourceId - When set, restricts both the pinned messages and their context
|
|
5412
|
+
* to that resource so an id from another resource returns nothing.
|
|
5413
|
+
*/
|
|
5414
|
+
async _getIncludedMessages({ include, resourceId }) {
|
|
5404
5415
|
if (!include || include.length === 0) return null;
|
|
5405
5416
|
const collection = await this.getCollection(TABLE_MESSAGES);
|
|
5417
|
+
const resourceFilter = resourceId ? { resourceId } : {};
|
|
5406
5418
|
const targetIds = include.map((inc) => inc.id).filter(Boolean);
|
|
5407
5419
|
if (targetIds.length === 0) return null;
|
|
5408
|
-
const targetDocs = await collection.find({
|
|
5420
|
+
const targetDocs = await collection.find({
|
|
5421
|
+
id: { $in: targetIds },
|
|
5422
|
+
...resourceFilter
|
|
5423
|
+
}, { projection: {
|
|
5409
5424
|
id: 1,
|
|
5410
5425
|
thread_id: 1,
|
|
5411
5426
|
createdAt: 1
|
|
@@ -5422,7 +5437,8 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5422
5437
|
if (!target) continue;
|
|
5423
5438
|
const prevMessages = await collection.find({
|
|
5424
5439
|
thread_id: target.threadId,
|
|
5425
|
-
createdAt: { $lte: target.createdAt }
|
|
5440
|
+
createdAt: { $lte: target.createdAt },
|
|
5441
|
+
...resourceFilter
|
|
5426
5442
|
}).sort({
|
|
5427
5443
|
createdAt: -1,
|
|
5428
5444
|
id: -1
|
|
@@ -5431,7 +5447,8 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5431
5447
|
if (withNextMessages > 0) {
|
|
5432
5448
|
const nextMessages = await collection.find({
|
|
5433
5449
|
thread_id: target.threadId,
|
|
5434
|
-
createdAt: { $gt: target.createdAt }
|
|
5450
|
+
createdAt: { $gt: target.createdAt },
|
|
5451
|
+
...resourceFilter
|
|
5435
5452
|
}).sort({
|
|
5436
5453
|
createdAt: 1,
|
|
5437
5454
|
id: 1
|
|
@@ -5506,7 +5523,10 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5506
5523
|
hasMore: false
|
|
5507
5524
|
};
|
|
5508
5525
|
if (perPage === 0 && include && include.length > 0) {
|
|
5509
|
-
const includeMessages = await this._getIncludedMessages({
|
|
5526
|
+
const includeMessages = await this._getIncludedMessages({
|
|
5527
|
+
include,
|
|
5528
|
+
resourceId
|
|
5529
|
+
});
|
|
5510
5530
|
const list = new MessageList().add(includeMessages ?? [], "memory");
|
|
5511
5531
|
return {
|
|
5512
5532
|
messages: this._sortMessages(list.get.all.db(), field, direction),
|
|
@@ -5542,7 +5562,10 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5542
5562
|
};
|
|
5543
5563
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
5544
5564
|
if (include && include.length > 0) {
|
|
5545
|
-
const includeMessages = await this._getIncludedMessages({
|
|
5565
|
+
const includeMessages = await this._getIncludedMessages({
|
|
5566
|
+
include,
|
|
5567
|
+
resourceId
|
|
5568
|
+
});
|
|
5546
5569
|
if (includeMessages) {
|
|
5547
5570
|
for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
|
|
5548
5571
|
messages.push(includeMsg);
|
|
@@ -5563,6 +5586,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5563
5586
|
hasMore
|
|
5564
5587
|
};
|
|
5565
5588
|
} catch (error) {
|
|
5589
|
+
if (error instanceof MastraError && error.category === ErrorCategory.USER) throw error;
|
|
5566
5590
|
const mastraError = new MastraError({
|
|
5567
5591
|
id: createStorageErrorId("MONGODB", "LIST_MESSAGES", "FAILED"),
|
|
5568
5592
|
domain: ErrorDomain.STORAGE,
|
|
@@ -5574,13 +5598,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5574
5598
|
}, error);
|
|
5575
5599
|
this.logger?.error?.(mastraError.toString());
|
|
5576
5600
|
this.logger?.trackException?.(mastraError);
|
|
5577
|
-
|
|
5578
|
-
messages: [],
|
|
5579
|
-
total: 0,
|
|
5580
|
-
page,
|
|
5581
|
-
perPage: perPageForResponse,
|
|
5582
|
-
hasMore: false
|
|
5583
|
-
};
|
|
5601
|
+
throw mastraError;
|
|
5584
5602
|
}
|
|
5585
5603
|
}
|
|
5586
5604
|
async listMessagesByResourceId(args) {
|
|
@@ -5628,7 +5646,10 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5628
5646
|
hasMore: false
|
|
5629
5647
|
};
|
|
5630
5648
|
if (perPage === 0 && include && include.length > 0) {
|
|
5631
|
-
const includeMessages = await this._getIncludedMessages({
|
|
5649
|
+
const includeMessages = await this._getIncludedMessages({
|
|
5650
|
+
include,
|
|
5651
|
+
resourceId
|
|
5652
|
+
});
|
|
5632
5653
|
if (!includeMessages || includeMessages.length === 0) return {
|
|
5633
5654
|
messages: [],
|
|
5634
5655
|
total: 0,
|
|
@@ -5671,7 +5692,10 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5671
5692
|
};
|
|
5672
5693
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
5673
5694
|
if (include && include.length > 0) {
|
|
5674
|
-
const includeMessages = await this._getIncludedMessages({
|
|
5695
|
+
const includeMessages = await this._getIncludedMessages({
|
|
5696
|
+
include,
|
|
5697
|
+
resourceId
|
|
5698
|
+
});
|
|
5675
5699
|
if (includeMessages) {
|
|
5676
5700
|
for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
|
|
5677
5701
|
messages.push(includeMsg);
|
|
@@ -5690,6 +5714,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5690
5714
|
hasMore
|
|
5691
5715
|
};
|
|
5692
5716
|
} catch (error) {
|
|
5717
|
+
if (error instanceof MastraError && error.category === ErrorCategory.USER) throw error;
|
|
5693
5718
|
const mastraError = new MastraError({
|
|
5694
5719
|
id: createStorageErrorId("MONGODB", "LIST_MESSAGES_BY_RESOURCE_ID", "FAILED"),
|
|
5695
5720
|
domain: ErrorDomain.STORAGE,
|
|
@@ -5698,13 +5723,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5698
5723
|
}, error);
|
|
5699
5724
|
this.logger?.error?.(mastraError.toString());
|
|
5700
5725
|
this.logger?.trackException?.(mastraError);
|
|
5701
|
-
|
|
5702
|
-
messages: [],
|
|
5703
|
-
total: 0,
|
|
5704
|
-
page,
|
|
5705
|
-
perPage: perPageForResponse,
|
|
5706
|
-
hasMore: false
|
|
5707
|
-
};
|
|
5726
|
+
throw mastraError;
|
|
5708
5727
|
}
|
|
5709
5728
|
}
|
|
5710
5729
|
async saveMessages({ messages }) {
|
|
@@ -5938,7 +5957,8 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5938
5957
|
hasMore: perPageInput === false ? false : offset + perPage < total
|
|
5939
5958
|
};
|
|
5940
5959
|
} catch (error) {
|
|
5941
|
-
|
|
5960
|
+
if (error instanceof MastraError && error.category === ErrorCategory.USER) throw error;
|
|
5961
|
+
const mastraError = new MastraError({
|
|
5942
5962
|
id: createStorageErrorId("MONGODB", "LIST_THREADS", "FAILED"),
|
|
5943
5963
|
domain: ErrorDomain.STORAGE,
|
|
5944
5964
|
category: ErrorCategory.THIRD_PARTY,
|
|
@@ -5947,6 +5967,9 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5947
5967
|
hasMetadataFilter: !!filter?.metadata
|
|
5948
5968
|
}
|
|
5949
5969
|
}, error);
|
|
5970
|
+
this.logger?.error?.(mastraError.toString());
|
|
5971
|
+
this.logger?.trackException?.(mastraError);
|
|
5972
|
+
throw mastraError;
|
|
5950
5973
|
}
|
|
5951
5974
|
}
|
|
5952
5975
|
async saveThread({ thread }) {
|