@mastra/mongodb 1.5.2 → 1.5.3

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,27 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 1.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Added atomic `updateWorkflowResults` and `updateWorkflowState` to safely merge concurrent step results into workflow snapshots. ([#12575](https://github.com/mastra-ai/mastra/pull/12575))
8
+
9
+ - Added `insertObservationalMemoryRecord()` to PostgreSQL, LibSQL, MongoDB, and Upstash adapters for OM cloning support. ([#13569](https://github.com/mastra-ai/mastra/pull/13569))
10
+
11
+ - 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)]:
12
+ - @mastra/core@1.9.0
13
+
14
+ ## 1.5.3-alpha.0
15
+
16
+ ### Patch Changes
17
+
18
+ - Added atomic `updateWorkflowResults` and `updateWorkflowState` to safely merge concurrent step results into workflow snapshots. ([#12575](https://github.com/mastra-ai/mastra/pull/12575))
19
+
20
+ - Added `insertObservationalMemoryRecord()` to PostgreSQL, LibSQL, MongoDB, and Upstash adapters for OM cloning support. ([#13569](https://github.com/mastra-ai/mastra/pull/13569))
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-alpha.0
24
+
3
25
  ## 1.5.2
4
26
 
5
27
  ### 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,7 +3,7 @@ name: mastra-mongodb
3
3
  description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mongodb"
6
- version: "1.5.2"
6
+ version: "1.5.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.2",
2
+ "version": "1.5.3",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -14,7 +14,7 @@ var evals = require('@mastra/core/evals');
14
14
 
15
15
  // package.json
16
16
  var package_default = {
17
- version: "1.5.2"};
17
+ version: "1.5.3"};
18
18
  var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
19
19
  getSupportedOperators() {
20
20
  return {
@@ -3642,6 +3642,141 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
3642
3642
  );
3643
3643
  }
3644
3644
  }
3645
+ async cloneThread(args) {
3646
+ const { sourceThreadId, newThreadId: providedThreadId, resourceId, title, metadata, options } = args;
3647
+ const sourceThread = await this.getThreadById({ threadId: sourceThreadId });
3648
+ if (!sourceThread) {
3649
+ throw new error.MastraError({
3650
+ id: storage.createStorageErrorId("MONGODB", "CLONE_THREAD", "SOURCE_NOT_FOUND"),
3651
+ domain: error.ErrorDomain.STORAGE,
3652
+ category: error.ErrorCategory.USER,
3653
+ text: `Source thread with id ${sourceThreadId} not found`,
3654
+ details: { sourceThreadId }
3655
+ });
3656
+ }
3657
+ const newThreadId = providedThreadId || crypto.randomUUID();
3658
+ const existingThread = await this.getThreadById({ threadId: newThreadId });
3659
+ if (existingThread) {
3660
+ throw new error.MastraError({
3661
+ id: storage.createStorageErrorId("MONGODB", "CLONE_THREAD", "THREAD_EXISTS"),
3662
+ domain: error.ErrorDomain.STORAGE,
3663
+ category: error.ErrorCategory.USER,
3664
+ text: `Thread with id ${newThreadId} already exists`,
3665
+ details: { newThreadId }
3666
+ });
3667
+ }
3668
+ try {
3669
+ const messagesCollection = await this.getCollection(storage.TABLE_MESSAGES);
3670
+ const filter = { thread_id: sourceThreadId };
3671
+ if (options?.messageFilter?.startDate) {
3672
+ filter.createdAt = filter.createdAt || {};
3673
+ filter.createdAt.$gte = options.messageFilter.startDate instanceof Date ? options.messageFilter.startDate : new Date(options.messageFilter.startDate);
3674
+ }
3675
+ if (options?.messageFilter?.endDate) {
3676
+ filter.createdAt = filter.createdAt || {};
3677
+ filter.createdAt.$lte = options.messageFilter.endDate instanceof Date ? options.messageFilter.endDate : new Date(options.messageFilter.endDate);
3678
+ }
3679
+ if (options?.messageFilter?.messageIds && options.messageFilter.messageIds.length > 0) {
3680
+ filter.id = { $in: options.messageFilter.messageIds };
3681
+ }
3682
+ let query = messagesCollection.find(filter).sort({ createdAt: 1 });
3683
+ let sourceMessages;
3684
+ if (options?.messageLimit && options.messageLimit > 0) {
3685
+ const limited = await messagesCollection.find(filter).sort({ createdAt: -1 }).limit(options.messageLimit).toArray();
3686
+ sourceMessages = limited.reverse();
3687
+ } else {
3688
+ sourceMessages = await query.toArray();
3689
+ }
3690
+ const now = /* @__PURE__ */ new Date();
3691
+ const targetResourceId = resourceId || sourceThread.resourceId;
3692
+ const lastMessageId = sourceMessages.length > 0 ? sourceMessages[sourceMessages.length - 1].id : void 0;
3693
+ const cloneMetadata = {
3694
+ sourceThreadId,
3695
+ clonedAt: now,
3696
+ ...lastMessageId && { lastMessageId }
3697
+ };
3698
+ const newThread = {
3699
+ id: newThreadId,
3700
+ resourceId: targetResourceId,
3701
+ title: title || (sourceThread.title ? `Clone of ${sourceThread.title}` : ""),
3702
+ metadata: {
3703
+ ...metadata,
3704
+ clone: cloneMetadata
3705
+ },
3706
+ createdAt: now,
3707
+ updatedAt: now
3708
+ };
3709
+ const threadsCollection = await this.getCollection(storage.TABLE_THREADS);
3710
+ await threadsCollection.insertOne({ ...newThread });
3711
+ const clonedMessages = [];
3712
+ const messageIdMap = {};
3713
+ if (sourceMessages.length > 0) {
3714
+ const messageDocs = [];
3715
+ for (const sourceMsg of sourceMessages) {
3716
+ const newMessageId = crypto.randomUUID();
3717
+ messageIdMap[sourceMsg.id] = newMessageId;
3718
+ let parsedContent = sourceMsg.content;
3719
+ if (typeof parsedContent === "string") {
3720
+ try {
3721
+ parsedContent = JSON.parse(parsedContent);
3722
+ } catch {
3723
+ parsedContent = { format: 2, parts: [{ type: "text", text: parsedContent }] };
3724
+ }
3725
+ }
3726
+ const newDoc = {
3727
+ id: newMessageId,
3728
+ thread_id: newThreadId,
3729
+ content: sourceMsg.content,
3730
+ role: sourceMsg.role,
3731
+ type: sourceMsg.type || "v2",
3732
+ createdAt: sourceMsg.createdAt,
3733
+ resourceId: targetResourceId
3734
+ };
3735
+ messageDocs.push(newDoc);
3736
+ clonedMessages.push({
3737
+ id: newMessageId,
3738
+ threadId: newThreadId,
3739
+ content: parsedContent,
3740
+ role: sourceMsg.role,
3741
+ type: sourceMsg.type || "v2",
3742
+ createdAt: formatDateForMongoDB(sourceMsg.createdAt),
3743
+ resourceId: targetResourceId
3744
+ });
3745
+ }
3746
+ try {
3747
+ await messagesCollection.insertMany(messageDocs);
3748
+ } catch (msgError) {
3749
+ try {
3750
+ await messagesCollection.deleteMany({ thread_id: newThreadId });
3751
+ } catch {
3752
+ }
3753
+ try {
3754
+ await threadsCollection.deleteOne({ id: newThreadId });
3755
+ } catch {
3756
+ }
3757
+ throw msgError;
3758
+ }
3759
+ }
3760
+ return {
3761
+ thread: newThread,
3762
+ clonedMessages,
3763
+ messageIdMap
3764
+ };
3765
+ } catch (error$1) {
3766
+ if (error$1 instanceof error.MastraError) {
3767
+ throw error$1;
3768
+ }
3769
+ throw new error.MastraError(
3770
+ {
3771
+ id: storage.createStorageErrorId("MONGODB", "CLONE_THREAD", "FAILED"),
3772
+ domain: error.ErrorDomain.STORAGE,
3773
+ category: error.ErrorCategory.THIRD_PARTY,
3774
+ details: { sourceThreadId, newThreadId }
3775
+ },
3776
+ error$1
3777
+ );
3778
+ }
3779
+ }
3645
3780
  // ============================================
3646
3781
  // Observational Memory Methods
3647
3782
  // ============================================
@@ -3791,6 +3926,55 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
3791
3926
  );
3792
3927
  }
3793
3928
  }
3929
+ async insertObservationalMemoryRecord(record) {
3930
+ try {
3931
+ const lookupKey = this.getOMKey(record.threadId, record.resourceId);
3932
+ const collection = await this.getCollection(OM_TABLE);
3933
+ await collection.insertOne({
3934
+ id: record.id,
3935
+ lookupKey,
3936
+ scope: record.scope,
3937
+ resourceId: record.resourceId,
3938
+ threadId: record.threadId || null,
3939
+ activeObservations: record.activeObservations || "",
3940
+ activeObservationsPendingUpdate: null,
3941
+ originType: record.originType || "initial",
3942
+ config: record.config || null,
3943
+ generationCount: record.generationCount || 0,
3944
+ lastObservedAt: record.lastObservedAt || null,
3945
+ lastReflectionAt: null,
3946
+ pendingMessageTokens: record.pendingMessageTokens || 0,
3947
+ totalTokensObserved: record.totalTokensObserved || 0,
3948
+ observationTokenCount: record.observationTokenCount || 0,
3949
+ observedMessageIds: record.observedMessageIds || null,
3950
+ bufferedObservationChunks: record.bufferedObservationChunks || null,
3951
+ bufferedReflection: record.bufferedReflection || null,
3952
+ bufferedReflectionTokens: record.bufferedReflectionTokens ?? null,
3953
+ bufferedReflectionInputTokens: record.bufferedReflectionInputTokens ?? null,
3954
+ reflectedObservationLineCount: record.reflectedObservationLineCount ?? null,
3955
+ isObserving: record.isObserving || false,
3956
+ isReflecting: record.isReflecting || false,
3957
+ isBufferingObservation: record.isBufferingObservation || false,
3958
+ isBufferingReflection: record.isBufferingReflection || false,
3959
+ lastBufferedAtTokens: record.lastBufferedAtTokens || 0,
3960
+ lastBufferedAtTime: record.lastBufferedAtTime || null,
3961
+ observedTimezone: record.observedTimezone || null,
3962
+ metadata: record.metadata || null,
3963
+ createdAt: record.createdAt,
3964
+ updatedAt: record.updatedAt
3965
+ });
3966
+ } catch (error$1) {
3967
+ throw new error.MastraError(
3968
+ {
3969
+ id: storage.createStorageErrorId("MONGODB", "INSERT_OBSERVATIONAL_MEMORY_RECORD", "FAILED"),
3970
+ domain: error.ErrorDomain.STORAGE,
3971
+ category: error.ErrorCategory.THIRD_PARTY,
3972
+ details: { id: record.id, threadId: record.threadId, resourceId: record.resourceId }
3973
+ },
3974
+ error$1
3975
+ );
3976
+ }
3977
+ }
3794
3978
  async updateActiveObservations(input) {
3795
3979
  try {
3796
3980
  const now = /* @__PURE__ */ new Date();
@@ -7194,6 +7378,9 @@ var WorkflowsStorageMongoDB = class _WorkflowsStorageMongoDB extends storage.Wor
7194
7378
  (idx) => _WorkflowsStorageMongoDB.MANAGED_COLLECTIONS.includes(idx.collection)
7195
7379
  );
7196
7380
  }
7381
+ supportsConcurrentUpdates() {
7382
+ return true;
7383
+ }
7197
7384
  async getCollection(name) {
7198
7385
  return this.#connector.getCollection(name);
7199
7386
  }
@@ -7250,21 +7437,128 @@ var WorkflowsStorageMongoDB = class _WorkflowsStorageMongoDB extends storage.Wor
7250
7437
  const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
7251
7438
  await collection.deleteMany({});
7252
7439
  }
7253
- updateWorkflowResults({
7254
- // workflowName,
7255
- // runId,
7256
- // stepId,
7257
- // result,
7258
- // requestContext,
7440
+ async updateWorkflowResults({
7441
+ workflowName,
7442
+ runId,
7443
+ stepId,
7444
+ result,
7445
+ requestContext
7259
7446
  }) {
7260
- throw new Error("Method not implemented.");
7447
+ try {
7448
+ const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
7449
+ const now = /* @__PURE__ */ new Date();
7450
+ const defaultSnapshot = {
7451
+ context: {},
7452
+ activePaths: [],
7453
+ timestamp: Date.now(),
7454
+ suspendedPaths: {},
7455
+ activeStepsPath: {},
7456
+ resumeLabels: {},
7457
+ serializedStepGraph: [],
7458
+ status: "pending",
7459
+ value: {},
7460
+ waitingPaths: {},
7461
+ runId,
7462
+ requestContext: {}
7463
+ };
7464
+ const updatedDoc = await collection.findOneAndUpdate(
7465
+ { workflow_name: workflowName, run_id: runId },
7466
+ [
7467
+ {
7468
+ $set: {
7469
+ workflow_name: workflowName,
7470
+ run_id: runId,
7471
+ // If snapshot doesn't exist, use default; otherwise merge
7472
+ snapshot: {
7473
+ $mergeObjects: [
7474
+ // Start with default snapshot if document is new
7475
+ { $ifNull: ["$snapshot", defaultSnapshot] },
7476
+ // Merge the new context entry
7477
+ {
7478
+ context: {
7479
+ $mergeObjects: [{ $ifNull: [{ $ifNull: ["$snapshot.context", {}] }, {}] }, { [stepId]: result }]
7480
+ }
7481
+ },
7482
+ // Merge the new request context
7483
+ {
7484
+ requestContext: {
7485
+ $mergeObjects: [{ $ifNull: [{ $ifNull: ["$snapshot.requestContext", {}] }, {}] }, requestContext]
7486
+ }
7487
+ }
7488
+ ]
7489
+ },
7490
+ updatedAt: now,
7491
+ // Only set createdAt if it doesn't exist
7492
+ createdAt: { $ifNull: ["$createdAt", now] }
7493
+ }
7494
+ }
7495
+ ],
7496
+ { upsert: true, returnDocument: "after" }
7497
+ );
7498
+ const snapshot = typeof updatedDoc?.snapshot === "string" ? JSON.parse(updatedDoc.snapshot) : updatedDoc?.snapshot;
7499
+ return snapshot?.context || {};
7500
+ } catch (error$1) {
7501
+ throw new error.MastraError(
7502
+ {
7503
+ id: storage.createStorageErrorId("MONGODB", "UPDATE_WORKFLOW_RESULTS", "FAILED"),
7504
+ domain: error.ErrorDomain.STORAGE,
7505
+ category: error.ErrorCategory.THIRD_PARTY,
7506
+ details: {
7507
+ workflowName,
7508
+ runId,
7509
+ stepId
7510
+ }
7511
+ },
7512
+ error$1
7513
+ );
7514
+ }
7261
7515
  }
7262
- updateWorkflowState({
7263
- // workflowName,
7264
- // runId,
7265
- // opts,
7516
+ async updateWorkflowState({
7517
+ workflowName,
7518
+ runId,
7519
+ opts
7266
7520
  }) {
7267
- throw new Error("Method not implemented.");
7521
+ try {
7522
+ const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
7523
+ const updatedDoc = await collection.findOneAndUpdate(
7524
+ {
7525
+ workflow_name: workflowName,
7526
+ run_id: runId,
7527
+ // Only update if snapshot exists and has context
7528
+ "snapshot.context": { $exists: true }
7529
+ },
7530
+ [
7531
+ {
7532
+ $set: {
7533
+ // Merge the new options into the existing snapshot
7534
+ snapshot: {
7535
+ $mergeObjects: ["$snapshot", opts]
7536
+ },
7537
+ updatedAt: /* @__PURE__ */ new Date()
7538
+ }
7539
+ }
7540
+ ],
7541
+ { returnDocument: "after" }
7542
+ );
7543
+ if (!updatedDoc) {
7544
+ return void 0;
7545
+ }
7546
+ const snapshot = typeof updatedDoc.snapshot === "string" ? JSON.parse(updatedDoc.snapshot) : updatedDoc.snapshot;
7547
+ return snapshot;
7548
+ } catch (error$1) {
7549
+ throw new error.MastraError(
7550
+ {
7551
+ id: storage.createStorageErrorId("MONGODB", "UPDATE_WORKFLOW_STATE", "FAILED"),
7552
+ domain: error.ErrorDomain.STORAGE,
7553
+ category: error.ErrorCategory.THIRD_PARTY,
7554
+ details: {
7555
+ workflowName,
7556
+ runId
7557
+ }
7558
+ },
7559
+ error$1
7560
+ );
7561
+ }
7268
7562
  }
7269
7563
  async persistWorkflowSnapshot({
7270
7564
  workflowName,