@mastra/mongodb 1.28.0-alpha.0 → 1.28.0-alpha.2

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.
Files changed (44) hide show
  1. package/dist/_types/@internal_core@0.1.4/dist/memory/index.d.ts +25 -0
  2. package/dist/docs/SKILL.md +1 -1
  3. package/dist/docs/assets/SOURCE_MAP.json +14 -14
  4. package/dist/index.cjs +37 -5
  5. package/dist/index.js +37 -5
  6. package/package.json +8 -7
  7. package/dist/index.cjs.map +0 -1
  8. package/dist/index.d.ts.map +0 -1
  9. package/dist/index.js.map +0 -1
  10. package/dist/storage/connectors/MongoDBConnector.d.ts.map +0 -1
  11. package/dist/storage/connectors/base.d.ts.map +0 -1
  12. package/dist/storage/db/index.d.ts.map +0 -1
  13. package/dist/storage/domains/agents/index.d.ts.map +0 -1
  14. package/dist/storage/domains/background-tasks/index.d.ts.map +0 -1
  15. package/dist/storage/domains/blobs/index.d.ts.map +0 -1
  16. package/dist/storage/domains/datasets/index.d.ts.map +0 -1
  17. package/dist/storage/domains/experiments/index.d.ts.map +0 -1
  18. package/dist/storage/domains/knowledge/index.d.ts.map +0 -1
  19. package/dist/storage/domains/knowledge/pages.d.ts.map +0 -1
  20. package/dist/storage/domains/mcp-clients/index.d.ts.map +0 -1
  21. package/dist/storage/domains/mcp-servers/index.d.ts.map +0 -1
  22. package/dist/storage/domains/memory/index.d.ts.map +0 -1
  23. package/dist/storage/domains/notifications/index.d.ts.map +0 -1
  24. package/dist/storage/domains/observability/index.d.ts.map +0 -1
  25. package/dist/storage/domains/prompt-blocks/index.d.ts.map +0 -1
  26. package/dist/storage/domains/run-fencing.d.ts.map +0 -1
  27. package/dist/storage/domains/schedules/index.d.ts.map +0 -1
  28. package/dist/storage/domains/scorer-definitions/index.d.ts.map +0 -1
  29. package/dist/storage/domains/scores/index.d.ts.map +0 -1
  30. package/dist/storage/domains/skills/index.d.ts.map +0 -1
  31. package/dist/storage/domains/utils.d.ts.map +0 -1
  32. package/dist/storage/domains/workflow-definitions/index.d.ts.map +0 -1
  33. package/dist/storage/domains/workflows/index.d.ts.map +0 -1
  34. package/dist/storage/domains/workspaces/index.d.ts.map +0 -1
  35. package/dist/storage/index.d.ts.map +0 -1
  36. package/dist/storage/retention.d.ts.map +0 -1
  37. package/dist/storage/types.d.ts.map +0 -1
  38. package/dist/vector/__fixtures__/atlas-local.d.ts.map +0 -1
  39. package/dist/vector/filter.d.ts.map +0 -1
  40. package/dist/vector/index.d.ts.map +0 -1
  41. package/dist/vector/ownership.d.ts.map +0 -1
  42. package/dist/vector/prompt.d.ts.map +0 -1
  43. package/dist/vector/provisioning.d.ts.map +0 -1
  44. package/dist/vector/search-definition.d.ts.map +0 -1
@@ -96,4 +96,29 @@ export declare function assertActiveObservationsApplied(result: UpdateActiveObse
96
96
  * (equal, or only appended to since).
97
97
  */
98
98
  export declare function isAppendOnlySince(storedObservations: string, snapshotObservations: string): boolean;
99
+ /** The buffered-reflection fields a `swapBufferedReflectionToActive` caller read, and the stored ones. */
100
+ export interface BufferedReflectionState {
101
+ bufferedReflection?: string | null;
102
+ reflectedObservationLineCount?: number | null;
103
+ }
104
+ /**
105
+ * Whether the stored buffered reflection and reflected line count are still the ones in
106
+ * `snapshot`, so a buffered-reflection swap activates exactly the buffer the caller read.
107
+ *
108
+ * Another writer can extend the buffer (`updateBufferedReflection` appends and moves the line
109
+ * count) after the caller's read. The activated text alone cannot tell the two apart: an
110
+ * extension that repeats the unreflected tail and moves the cut past it produces the same text.
111
+ * A snapshot without a buffered reflection (callers that never read one) is not checked.
112
+ */
113
+ export declare function isBufferedReflectionUnchangedSince(stored: BufferedReflectionState, snapshot: BufferedReflectionState): boolean;
114
+ /**
115
+ * The generation a buffered-reflection swap just created, marked with
116
+ * `bufferedReflectionVerified: true` when the swap checked the caller's buffered reflection with
117
+ * `isBufferedReflectionUnchangedSince` in the same atomic step. A snapshot without a buffered
118
+ * reflection was not checked, so its successor is returned unmarked. Always returns a new object,
119
+ * so a store's own record is never handed out or mutated.
120
+ */
121
+ export declare function withBufferedReflectionVerified<T extends object>(successor: T, snapshot: BufferedReflectionState): T & {
122
+ bufferedReflectionVerified?: true;
123
+ };
99
124
  //# sourceMappingURL=index.d.ts.map
@@ -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.28.0-alpha.0"
6
+ version: "1.28.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.28.0-alpha.0",
2
+ "version": "1.28.0-alpha.2",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {
5
5
  "BackgroundTasksStorageMongoDB": {
@@ -15,12 +15,12 @@
15
15
  "MONGODB_PROMPT": {
16
16
  "types": "dist/vector/prompt.d.ts",
17
17
  "implementation": "dist/index.js",
18
- "line": 16729
18
+ "line": 16763
19
19
  },
20
20
  "MemoryStorageMongoDB": {
21
21
  "types": "dist/storage/domains/memory/index.d.ts",
22
22
  "implementation": "dist/index.js",
23
- "line": 10312
23
+ "line": 10341
24
24
  },
25
25
  "MongoDBAgentsStorage": {
26
26
  "types": "dist/storage/domains/agents/index.d.ts",
@@ -55,22 +55,22 @@
55
55
  "MongoDBPromptBlocksStorage": {
56
56
  "types": "dist/storage/domains/prompt-blocks/index.d.ts",
57
57
  "implementation": "dist/index.js",
58
- "line": 13399
58
+ "line": 13433
59
59
  },
60
60
  "MongoDBScorerDefinitionsStorage": {
61
61
  "types": "dist/storage/domains/scorer-definitions/index.d.ts",
62
62
  "implementation": "dist/index.js",
63
- "line": 14109
63
+ "line": 14143
64
64
  },
65
65
  "MongoDBSkillsStorage": {
66
66
  "types": "dist/storage/domains/skills/index.d.ts",
67
67
  "implementation": "dist/index.js",
68
- "line": 14939
68
+ "line": 14973
69
69
  },
70
70
  "MongoDBStore": {
71
71
  "types": "dist/storage/index.d.ts",
72
72
  "implementation": "dist/index.js",
73
- "line": 16650
73
+ "line": 16684
74
74
  },
75
75
  "MongoDBVector": {
76
76
  "types": "dist/vector/index.d.ts",
@@ -80,37 +80,37 @@
80
80
  "MongoDBWorkflowDefinitionsStore": {
81
81
  "types": "dist/storage/domains/workflow-definitions/index.d.ts",
82
82
  "implementation": "dist/index.js",
83
- "line": 15440
83
+ "line": 15474
84
84
  },
85
85
  "MongoDBWorkspacesStorage": {
86
86
  "types": "dist/storage/domains/workspaces/index.d.ts",
87
87
  "implementation": "dist/index.js",
88
- "line": 16148
88
+ "line": 16182
89
89
  },
90
90
  "NotificationsMongoDB": {
91
91
  "types": "dist/storage/domains/notifications/index.d.ts",
92
92
  "implementation": "dist/index.js",
93
- "line": 12427
93
+ "line": 12461
94
94
  },
95
95
  "ObservabilityMongoDB": {
96
96
  "types": "dist/storage/domains/observability/index.d.ts",
97
97
  "implementation": "dist/index.js",
98
- "line": 12717
98
+ "line": 12751
99
99
  },
100
100
  "SchedulesMongoDB": {
101
101
  "types": "dist/storage/domains/schedules/index.d.ts",
102
102
  "implementation": "dist/index.js",
103
- "line": 13906
103
+ "line": 13940
104
104
  },
105
105
  "ScoresStorageMongoDB": {
106
106
  "types": "dist/storage/domains/scores/index.d.ts",
107
107
  "implementation": "dist/index.js",
108
- "line": 14558
108
+ "line": 14592
109
109
  },
110
110
  "WorkflowsStorageMongoDB": {
111
111
  "types": "dist/storage/domains/workflows/index.d.ts",
112
112
  "implementation": "dist/index.js",
113
- "line": 15610
113
+ "line": 15644
114
114
  }
115
115
  },
116
116
  "modules": {}
package/dist/index.cjs CHANGED
@@ -11,7 +11,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
11
11
  let _mastra_core_evals = require("@mastra/core/evals");
12
12
  let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
13
13
  // package.json
14
- var version = "1.28.0-alpha.0";
14
+ var version = "1.28.0-alpha.2";
15
15
  // src/vector/filter.ts
16
16
  /**
17
17
  * Translator for MongoDB filter queries.
@@ -10181,6 +10181,35 @@ function isAppendOnlySince(storedObservations, snapshotObservations) {
10181
10181
  const snapshot = snapshotObservations ?? "";
10182
10182
  return stored === snapshot || stored.startsWith(snapshot);
10183
10183
  }
10184
+ /**
10185
+ * Whether the stored buffered reflection and reflected line count are still the ones in
10186
+ * `snapshot`, so a buffered-reflection swap activates exactly the buffer the caller read.
10187
+ *
10188
+ * Another writer can extend the buffer (`updateBufferedReflection` appends and moves the line
10189
+ * count) after the caller's read. The activated text alone cannot tell the two apart: an
10190
+ * extension that repeats the unreflected tail and moves the cut past it produces the same text.
10191
+ * A snapshot without a buffered reflection (callers that never read one) is not checked.
10192
+ */
10193
+ function isBufferedReflectionUnchangedSince(stored, snapshot) {
10194
+ if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return true;
10195
+ if ((stored.bufferedReflection ?? "") !== snapshot.bufferedReflection) return false;
10196
+ if (snapshot.reflectedObservationLineCount === void 0 || snapshot.reflectedObservationLineCount === null) return true;
10197
+ return (stored.reflectedObservationLineCount ?? 0) === snapshot.reflectedObservationLineCount;
10198
+ }
10199
+ /**
10200
+ * The generation a buffered-reflection swap just created, marked with
10201
+ * `bufferedReflectionVerified: true` when the swap checked the caller's buffered reflection with
10202
+ * `isBufferedReflectionUnchangedSince` in the same atomic step. A snapshot without a buffered
10203
+ * reflection was not checked, so its successor is returned unmarked. Always returns a new object,
10204
+ * so a store's own record is never handed out or mutated.
10205
+ */
10206
+ function withBufferedReflectionVerified(successor, snapshot) {
10207
+ if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return { ...successor };
10208
+ return {
10209
+ ...successor,
10210
+ bufferedReflectionVerified: true
10211
+ };
10212
+ }
10184
10213
  // src/storage/domains/run-fencing.ts
10185
10214
  async function getRunClaims(connector, name) {
10186
10215
  return await connector.getCollection(name);
@@ -12134,7 +12163,9 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
12134
12163
  async swapBufferedReflectionToActive(input) {
12135
12164
  try {
12136
12165
  const { currentRecord } = input;
12137
- return await this.#rollOver(currentRecord, "swapBufferedReflectionToActive", (doc) => {
12166
+ const planned = {};
12167
+ const result = await this.#rollOver(currentRecord, "swapBufferedReflectionToActive", (doc) => {
12168
+ planned.id = void 0;
12138
12169
  const stored = this.parseOMDocument(doc);
12139
12170
  const bufferedReflection = stored.bufferedReflection || "";
12140
12171
  if (!bufferedReflection) throw new _mastra_core_error.MastraError({
@@ -12145,12 +12176,14 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
12145
12176
  details: { id: currentRecord.id }
12146
12177
  });
12147
12178
  if (!isAppendOnlySince(stored.activeObservations, currentRecord.activeObservations)) return null;
12179
+ if (!isBufferedReflectionUnchangedSince(stored, currentRecord)) return null;
12148
12180
  const reflectedLineCount = stored.reflectedObservationLineCount ?? 0;
12149
12181
  const unreflectedContent = (stored.activeObservations || "").split("\n").slice(reflectedLineCount).join("\n").trim();
12150
12182
  const newObservations = unreflectedContent ? `${bufferedReflection}\n\n${unreflectedContent}` : bufferedReflection;
12151
12183
  const tokenCount = input.tokenCount + Math.max(0, (stored.observationTokenCount ?? 0) - (currentRecord.observationTokenCount ?? 0));
12184
+ planned.id = input.newRecordId ?? globalThis.crypto.randomUUID();
12152
12185
  return {
12153
- newId: input.newRecordId ?? globalThis.crypto.randomUUID(),
12186
+ newId: planned.id,
12154
12187
  mode: "equal",
12155
12188
  reflection: newObservations,
12156
12189
  tokenCount,
@@ -12160,6 +12193,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
12160
12193
  createdAt: /* @__PURE__ */ new Date()
12161
12194
  };
12162
12195
  });
12196
+ return result.id === planned.id ? withBufferedReflectionVerified(result, currentRecord) : result;
12163
12197
  } catch (error) {
12164
12198
  if (error instanceof _mastra_core_error.MastraError) throw error;
12165
12199
  throw new _mastra_core_error.MastraError({
@@ -16842,5 +16876,3 @@ exports.ObservabilityMongoDB = ObservabilityMongoDB;
16842
16876
  exports.SchedulesMongoDB = SchedulesMongoDB;
16843
16877
  exports.ScoresStorageMongoDB = ScoresStorageMongoDB;
16844
16878
  exports.WorkflowsStorageMongoDB = WorkflowsStorageMongoDB;
16845
-
16846
- //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { MessageList } from "@mastra/core/agent";
10
10
  import { saveScorePayloadSchema } from "@mastra/core/evals";
11
11
  import { skillSnapshotFieldValuesEqual } from "@mastra/core/storage/domains/skills";
12
12
  // package.json
13
- var version = "1.28.0-alpha.0";
13
+ var version = "1.28.0-alpha.2";
14
14
  // src/vector/filter.ts
15
15
  /**
16
16
  * Translator for MongoDB filter queries.
@@ -10180,6 +10180,35 @@ function isAppendOnlySince(storedObservations, snapshotObservations) {
10180
10180
  const snapshot = snapshotObservations ?? "";
10181
10181
  return stored === snapshot || stored.startsWith(snapshot);
10182
10182
  }
10183
+ /**
10184
+ * Whether the stored buffered reflection and reflected line count are still the ones in
10185
+ * `snapshot`, so a buffered-reflection swap activates exactly the buffer the caller read.
10186
+ *
10187
+ * Another writer can extend the buffer (`updateBufferedReflection` appends and moves the line
10188
+ * count) after the caller's read. The activated text alone cannot tell the two apart: an
10189
+ * extension that repeats the unreflected tail and moves the cut past it produces the same text.
10190
+ * A snapshot without a buffered reflection (callers that never read one) is not checked.
10191
+ */
10192
+ function isBufferedReflectionUnchangedSince(stored, snapshot) {
10193
+ if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return true;
10194
+ if ((stored.bufferedReflection ?? "") !== snapshot.bufferedReflection) return false;
10195
+ if (snapshot.reflectedObservationLineCount === void 0 || snapshot.reflectedObservationLineCount === null) return true;
10196
+ return (stored.reflectedObservationLineCount ?? 0) === snapshot.reflectedObservationLineCount;
10197
+ }
10198
+ /**
10199
+ * The generation a buffered-reflection swap just created, marked with
10200
+ * `bufferedReflectionVerified: true` when the swap checked the caller's buffered reflection with
10201
+ * `isBufferedReflectionUnchangedSince` in the same atomic step. A snapshot without a buffered
10202
+ * reflection was not checked, so its successor is returned unmarked. Always returns a new object,
10203
+ * so a store's own record is never handed out or mutated.
10204
+ */
10205
+ function withBufferedReflectionVerified(successor, snapshot) {
10206
+ if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return { ...successor };
10207
+ return {
10208
+ ...successor,
10209
+ bufferedReflectionVerified: true
10210
+ };
10211
+ }
10183
10212
  // src/storage/domains/run-fencing.ts
10184
10213
  async function getRunClaims(connector, name) {
10185
10214
  return await connector.getCollection(name);
@@ -12133,7 +12162,9 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
12133
12162
  async swapBufferedReflectionToActive(input) {
12134
12163
  try {
12135
12164
  const { currentRecord } = input;
12136
- return await this.#rollOver(currentRecord, "swapBufferedReflectionToActive", (doc) => {
12165
+ const planned = {};
12166
+ const result = await this.#rollOver(currentRecord, "swapBufferedReflectionToActive", (doc) => {
12167
+ planned.id = void 0;
12137
12168
  const stored = this.parseOMDocument(doc);
12138
12169
  const bufferedReflection = stored.bufferedReflection || "";
12139
12170
  if (!bufferedReflection) throw new MastraError({
@@ -12144,12 +12175,14 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
12144
12175
  details: { id: currentRecord.id }
12145
12176
  });
12146
12177
  if (!isAppendOnlySince(stored.activeObservations, currentRecord.activeObservations)) return null;
12178
+ if (!isBufferedReflectionUnchangedSince(stored, currentRecord)) return null;
12147
12179
  const reflectedLineCount = stored.reflectedObservationLineCount ?? 0;
12148
12180
  const unreflectedContent = (stored.activeObservations || "").split("\n").slice(reflectedLineCount).join("\n").trim();
12149
12181
  const newObservations = unreflectedContent ? `${bufferedReflection}\n\n${unreflectedContent}` : bufferedReflection;
12150
12182
  const tokenCount = input.tokenCount + Math.max(0, (stored.observationTokenCount ?? 0) - (currentRecord.observationTokenCount ?? 0));
12183
+ planned.id = input.newRecordId ?? globalThis.crypto.randomUUID();
12151
12184
  return {
12152
- newId: input.newRecordId ?? globalThis.crypto.randomUUID(),
12185
+ newId: planned.id,
12153
12186
  mode: "equal",
12154
12187
  reflection: newObservations,
12155
12188
  tokenCount,
@@ -12159,6 +12192,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
12159
12192
  createdAt: /* @__PURE__ */ new Date()
12160
12193
  };
12161
12194
  });
12195
+ return result.id === planned.id ? withBufferedReflectionVerified(result, currentRecord) : result;
12162
12196
  } catch (error) {
12163
12197
  if (error instanceof MastraError) throw error;
12164
12198
  throw new MastraError({
@@ -16820,5 +16854,3 @@ Example Complex Query:
16820
16854
  ]
16821
16855
  }`;
16822
16856
  export { BackgroundTasksStorageMongoDB, KnowledgeMongoDB, MONGODB_PROMPT, MemoryStorageMongoDB, MongoDBAgentsStorage, MongoDBBlobStore, MongoDBDatasetsStorage, MongoDBExperimentsStorage, MongoDBMCPClientsStorage, MongoDBMCPServersStorage, MongoDBPromptBlocksStorage, MongoDBScorerDefinitionsStorage, MongoDBSkillsStorage, MongoDBStore, MongoDBVector, MongoDBWorkflowDefinitionsStore, MongoDBWorkspacesStorage, NotificationsMongoDB, ObservabilityMongoDB, SchedulesMongoDB, ScoresStorageMongoDB, WorkflowsStorageMongoDB };
16823
-
16824
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mongodb",
3
- "version": "1.28.0-alpha.0",
3
+ "version": "1.28.0-alpha.2",
4
4
  "description": "MongoDB provider for Mastra - includes vector store capabilities",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@lukeed/uuid": "^2.0.1",
24
- "mongodb": "^7.7.0"
24
+ "mongodb": "^7.9.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "22.19.15",
@@ -32,18 +32,19 @@
32
32
  "tsx": "^4.23.15",
33
33
  "typescript": "^7.0.2",
34
34
  "vitest": "5.1.0",
35
- "@internal/core": "0.1.4",
36
35
  "@internal/lint": "0.0.151",
37
- "@internal/storage-test-utils": "0.0.147",
38
36
  "@internal/types-builder": "0.0.126",
39
- "@mastra/core": "1.85.1-alpha.0",
40
- "@mastra/memory": "1.41.3-alpha.0"
37
+ "@internal/core": "0.1.4",
38
+ "@mastra/core": "1.86.0-alpha.7",
39
+ "@mastra/memory": "1.41.3-alpha.3",
40
+ "@internal/storage-test-utils": "0.0.147"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@mastra/core": ">=1.76.0-0 <2.0.0-0"
44
44
  },
45
45
  "files": [
46
- "dist"
46
+ "dist",
47
+ "!dist/**/*.d.*ts.map"
47
48
  ],
48
49
  "homepage": "https://mastra.ai",
49
50
  "repository": {