@mastra/core 1.2.0-alpha.0 → 1.2.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.
Files changed (263) hide show
  1. package/CHANGELOG.md +314 -0
  2. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +1 -1
  3. package/dist/agent/agent.d.ts +17 -2
  4. package/dist/agent/agent.d.ts.map +1 -1
  5. package/dist/agent/index.cjs +13 -13
  6. package/dist/agent/index.js +2 -2
  7. package/dist/agent/message-list/index.cjs +18 -18
  8. package/dist/agent/message-list/index.js +1 -1
  9. package/dist/agent/message-list/merge/MessageMerger.d.ts +5 -0
  10. package/dist/agent/message-list/merge/MessageMerger.d.ts.map +1 -1
  11. package/dist/agent/message-list/message-list.d.ts +15 -0
  12. package/dist/agent/message-list/message-list.d.ts.map +1 -1
  13. package/dist/agent/workflows/prepare-stream/index.d.ts +9 -8
  14. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  15. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +4 -0
  16. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
  17. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +9 -7
  18. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
  19. package/dist/agent/workflows/prepare-stream/schema.d.ts +24 -14
  20. package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -1
  21. package/dist/{chunk-XVHK5IAO.cjs → chunk-3LRUJTH3.cjs} +50 -333
  22. package/dist/chunk-3LRUJTH3.cjs.map +1 -0
  23. package/dist/{chunk-2CVY7S66.js → chunk-4XLGMCCQ.js} +18 -21
  24. package/dist/chunk-4XLGMCCQ.js.map +1 -0
  25. package/dist/{chunk-HIP5W3LZ.js → chunk-57O4TPB3.js} +60 -4
  26. package/dist/chunk-57O4TPB3.js.map +1 -0
  27. package/dist/{chunk-FAJYC6PA.js → chunk-5HDIPOLV.js} +363 -104
  28. package/dist/chunk-5HDIPOLV.js.map +1 -0
  29. package/dist/{chunk-OAOMKZXU.cjs → chunk-AP3Z4EAP.cjs} +60 -56
  30. package/dist/chunk-AP3Z4EAP.cjs.map +1 -0
  31. package/dist/{chunk-I6PWV32C.cjs → chunk-AQHO4OC2.cjs} +517 -61
  32. package/dist/chunk-AQHO4OC2.cjs.map +1 -0
  33. package/dist/{chunk-W57QS6F6.cjs → chunk-ARQG4ZSD.cjs} +430 -168
  34. package/dist/chunk-ARQG4ZSD.cjs.map +1 -0
  35. package/dist/{chunk-AC63Y6KP.js → chunk-BP2TSCBW.js} +3 -3
  36. package/dist/chunk-BP2TSCBW.js.map +1 -0
  37. package/dist/{chunk-NS33UC72.js → chunk-ENCTSDWC.js} +104 -11
  38. package/dist/chunk-ENCTSDWC.js.map +1 -0
  39. package/dist/{chunk-66BWIF4S.js → chunk-EY3WXGUD.js} +43 -326
  40. package/dist/chunk-EY3WXGUD.js.map +1 -0
  41. package/dist/{chunk-IUODLQMU.cjs → chunk-G5NRZOPO.cjs} +60 -4
  42. package/dist/chunk-G5NRZOPO.cjs.map +1 -0
  43. package/dist/{chunk-22EV7GMK.cjs → chunk-HMCXNOF6.cjs} +105 -10
  44. package/dist/chunk-HMCXNOF6.cjs.map +1 -0
  45. package/dist/{chunk-EYUXOOSQ.cjs → chunk-HN2MSTR6.cjs} +130 -9
  46. package/dist/chunk-HN2MSTR6.cjs.map +1 -0
  47. package/dist/{chunk-7ALOYTDY.cjs → chunk-I66TMZJ3.cjs} +15 -6
  48. package/dist/chunk-I66TMZJ3.cjs.map +1 -0
  49. package/dist/{chunk-Y2SVKUOQ.cjs → chunk-JRJJ5VQE.cjs} +44 -3
  50. package/dist/chunk-JRJJ5VQE.cjs.map +1 -0
  51. package/dist/{chunk-CILDTRXD.js → chunk-MNWW2R3U.js} +42 -4
  52. package/dist/chunk-MNWW2R3U.js.map +1 -0
  53. package/dist/{chunk-FYMM4PKR.js → chunk-NRMSZFAU.js} +12 -8
  54. package/dist/chunk-NRMSZFAU.js.map +1 -0
  55. package/dist/{chunk-SPVI7HCP.js → chunk-NYC6PYZF.js} +6 -6
  56. package/dist/{chunk-SPVI7HCP.js.map → chunk-NYC6PYZF.js.map} +1 -1
  57. package/dist/{chunk-XS2MED4Y.js → chunk-P62OJXQ4.js} +129 -8
  58. package/dist/chunk-P62OJXQ4.js.map +1 -0
  59. package/dist/{chunk-USHB3SPM.js → chunk-PPAJGWVW.js} +5 -5
  60. package/dist/chunk-PPAJGWVW.js.map +1 -0
  61. package/dist/{chunk-DWD5DB6W.js → chunk-RUMXBL6P.js} +4 -4
  62. package/dist/{chunk-DWD5DB6W.js.map → chunk-RUMXBL6P.js.map} +1 -1
  63. package/dist/{chunk-KNPIRLQQ.cjs → chunk-SS4AZHZW.cjs} +21 -24
  64. package/dist/chunk-SS4AZHZW.cjs.map +1 -0
  65. package/dist/{chunk-4DDIPGB6.js → chunk-T6PRRKMW.js} +15 -6
  66. package/dist/chunk-T6PRRKMW.js.map +1 -0
  67. package/dist/{chunk-ODNSWEMV.cjs → chunk-VBOO4F4D.cjs} +8 -8
  68. package/dist/chunk-VBOO4F4D.cjs.map +1 -0
  69. package/dist/{chunk-MCI7M6AT.cjs → chunk-YL6ETQ5I.cjs} +7 -7
  70. package/dist/{chunk-MCI7M6AT.cjs.map → chunk-YL6ETQ5I.cjs.map} +1 -1
  71. package/dist/{chunk-STNSGW7W.cjs → chunk-YLODOPYM.cjs} +3 -3
  72. package/dist/chunk-YLODOPYM.cjs.map +1 -0
  73. package/dist/{chunk-BLXWTBLL.cjs → chunk-Z2OKCLGV.cjs} +18 -18
  74. package/dist/{chunk-BLXWTBLL.cjs.map → chunk-Z2OKCLGV.cjs.map} +1 -1
  75. package/dist/{chunk-OQPAOUDS.js → chunk-ZODRDMZ7.js} +508 -52
  76. package/dist/chunk-ZODRDMZ7.js.map +1 -0
  77. package/dist/docs/README.md +1 -1
  78. package/dist/docs/SKILL.md +1 -1
  79. package/dist/docs/SOURCE_MAP.json +357 -330
  80. package/dist/docs/agents/01-overview.md +2 -2
  81. package/dist/docs/configuration.mdx/01-reference.md +20 -0
  82. package/dist/docs/evals/01-overview.md +5 -5
  83. package/dist/docs/evals/04-reference.md +84 -10
  84. package/dist/docs/mcp/01-overview.md +2 -2
  85. package/dist/docs/memory/02-storage.md +10 -0
  86. package/dist/docs/observability/01-overview.md +1 -1
  87. package/dist/docs/observability/03-overview.md +3 -3
  88. package/dist/docs/rag/01-overview.md +1 -1
  89. package/dist/docs/tools-mcp/01-mcp-overview.md +2 -2
  90. package/dist/docs/voice/01-overview.md +1 -1
  91. package/dist/docs/workflows/01-overview.md +5 -5
  92. package/dist/docs/workspace/01-overview.md +2 -3
  93. package/dist/editor/index.cjs +4 -0
  94. package/dist/editor/index.cjs.map +1 -0
  95. package/dist/editor/index.d.ts +2 -0
  96. package/dist/editor/index.d.ts.map +1 -0
  97. package/dist/editor/index.js +3 -0
  98. package/dist/editor/index.js.map +1 -0
  99. package/dist/editor/types.d.ts +64 -0
  100. package/dist/editor/types.d.ts.map +1 -0
  101. package/dist/evals/index.cjs +20 -20
  102. package/dist/evals/index.js +3 -3
  103. package/dist/evals/scoreTraces/index.cjs +5 -5
  104. package/dist/evals/scoreTraces/index.js +2 -2
  105. package/dist/features/index.cjs +1 -1
  106. package/dist/features/index.cjs.map +1 -1
  107. package/dist/features/index.d.ts.map +1 -1
  108. package/dist/features/index.js +1 -1
  109. package/dist/features/index.js.map +1 -1
  110. package/dist/index.cjs +7 -2
  111. package/dist/index.d.ts +9 -0
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +2 -1
  114. package/dist/llm/index.cjs +18 -18
  115. package/dist/llm/index.js +3 -3
  116. package/dist/llm/model/embedding-router.d.ts +3 -1
  117. package/dist/llm/model/embedding-router.d.ts.map +1 -1
  118. package/dist/llm/model/model.d.ts +2 -2
  119. package/dist/llm/model/model.d.ts.map +1 -1
  120. package/dist/llm/model/model.loop.d.ts +1 -1
  121. package/dist/llm/model/model.loop.d.ts.map +1 -1
  122. package/dist/llm/model/provider-types.generated.d.ts +54 -2
  123. package/dist/loop/index.cjs +12 -12
  124. package/dist/loop/index.js +1 -1
  125. package/dist/loop/loop.d.ts.map +1 -1
  126. package/dist/loop/network/index.d.ts +4 -4
  127. package/dist/loop/types.d.ts +6 -1
  128. package/dist/loop/types.d.ts.map +1 -1
  129. package/dist/loop/workflows/agentic-execution/index.d.ts +22 -22
  130. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +15 -15
  131. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  132. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +7 -7
  133. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  134. package/dist/loop/workflows/agentic-loop/index.d.ts +22 -22
  135. package/dist/loop/workflows/schema.d.ts +30 -30
  136. package/dist/mastra/index.cjs +2 -2
  137. package/dist/mastra/index.d.ts +30 -132
  138. package/dist/mastra/index.d.ts.map +1 -1
  139. package/dist/mastra/index.js +1 -1
  140. package/dist/memory/index.cjs +23 -11
  141. package/dist/memory/index.js +1 -1
  142. package/dist/memory/memory.d.ts +6 -1
  143. package/dist/memory/memory.d.ts.map +1 -1
  144. package/dist/memory/mock.d.ts.map +1 -1
  145. package/dist/memory/types.d.ts +282 -0
  146. package/dist/memory/types.d.ts.map +1 -1
  147. package/dist/models-dev-OQKVMEIT.cjs +12 -0
  148. package/dist/{models-dev-SOIECXXQ.cjs.map → models-dev-OQKVMEIT.cjs.map} +1 -1
  149. package/dist/models-dev-Z45JSLWD.js +3 -0
  150. package/dist/{models-dev-2HBSVUOS.js.map → models-dev-Z45JSLWD.js.map} +1 -1
  151. package/dist/processors/index.cjs +41 -41
  152. package/dist/processors/index.d.ts +38 -1
  153. package/dist/processors/index.d.ts.map +1 -1
  154. package/dist/processors/index.js +1 -1
  155. package/dist/processors/memory/message-history.d.ts +16 -0
  156. package/dist/processors/memory/message-history.d.ts.map +1 -1
  157. package/dist/processors/processors/skills.d.ts.map +1 -1
  158. package/dist/processors/runner.d.ts +17 -3
  159. package/dist/processors/runner.d.ts.map +1 -1
  160. package/dist/processors/step-schema.d.ts +34 -34
  161. package/dist/provider-registry-NR7FXV2Q.cjs +40 -0
  162. package/dist/{provider-registry-ML2VWWLB.cjs.map → provider-registry-NR7FXV2Q.cjs.map} +1 -1
  163. package/dist/provider-registry-RPOTQNHI.js +3 -0
  164. package/dist/{provider-registry-K5L4DHRK.js.map → provider-registry-RPOTQNHI.js.map} +1 -1
  165. package/dist/provider-registry.json +126 -5
  166. package/dist/relevance/index.cjs +3 -3
  167. package/dist/relevance/index.js +1 -1
  168. package/dist/storage/constants.cjs +28 -16
  169. package/dist/storage/constants.d.ts +13 -1
  170. package/dist/storage/constants.d.ts.map +1 -1
  171. package/dist/storage/constants.js +1 -1
  172. package/dist/storage/domains/agents/base.d.ts.map +1 -1
  173. package/dist/storage/domains/agents/inmemory.d.ts.map +1 -1
  174. package/dist/storage/domains/inmemory-db.d.ts +3 -1
  175. package/dist/storage/domains/inmemory-db.d.ts.map +1 -1
  176. package/dist/storage/domains/memory/base.d.ts +62 -1
  177. package/dist/storage/domains/memory/base.d.ts.map +1 -1
  178. package/dist/storage/domains/memory/inmemory.d.ts +24 -2
  179. package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
  180. package/dist/storage/domains/observability/types.d.ts +50 -50
  181. package/dist/storage/domains/operations/inmemory.d.ts +5 -3
  182. package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
  183. package/dist/storage/index.cjs +113 -101
  184. package/dist/storage/index.js +2 -2
  185. package/dist/storage/types.d.ts +203 -16
  186. package/dist/storage/types.d.ts.map +1 -1
  187. package/dist/stream/base/output.d.ts.map +1 -1
  188. package/dist/stream/index.cjs +11 -11
  189. package/dist/stream/index.js +2 -2
  190. package/dist/test-utils/llm-mock.cjs +4 -4
  191. package/dist/test-utils/llm-mock.js +1 -1
  192. package/dist/tool-loop-agent/index.cjs +4 -4
  193. package/dist/tool-loop-agent/index.js +1 -1
  194. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  195. package/dist/utils.cjs +23 -23
  196. package/dist/utils.d.ts +1 -1
  197. package/dist/utils.d.ts.map +1 -1
  198. package/dist/utils.js +1 -1
  199. package/dist/vector/index.cjs +7 -7
  200. package/dist/vector/index.cjs.map +1 -1
  201. package/dist/vector/index.js +1 -1
  202. package/dist/vector/index.js.map +1 -1
  203. package/dist/vector/vector.d.ts +3 -1
  204. package/dist/vector/vector.d.ts.map +1 -1
  205. package/dist/workflows/evented/index.cjs +10 -10
  206. package/dist/workflows/evented/index.js +1 -1
  207. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  208. package/dist/workflows/index.cjs +25 -25
  209. package/dist/workflows/index.js +1 -1
  210. package/dist/workflows/step.d.ts +2 -1
  211. package/dist/workflows/step.d.ts.map +1 -1
  212. package/dist/workflows/workflow.d.ts +2 -2
  213. package/dist/workflows/workflow.d.ts.map +1 -1
  214. package/dist/workspace/filesystem/index.d.ts +1 -0
  215. package/dist/workspace/filesystem/index.d.ts.map +1 -1
  216. package/dist/workspace/filesystem/local-filesystem.d.ts +3 -2
  217. package/dist/workspace/filesystem/local-filesystem.d.ts.map +1 -1
  218. package/dist/workspace/filesystem/mastra-filesystem.d.ts +65 -0
  219. package/dist/workspace/filesystem/mastra-filesystem.d.ts.map +1 -0
  220. package/dist/workspace/index.cjs +40 -32
  221. package/dist/workspace/index.d.ts +2 -0
  222. package/dist/workspace/index.d.ts.map +1 -1
  223. package/dist/workspace/index.js +1 -1
  224. package/dist/workspace/sandbox/index.d.ts +1 -0
  225. package/dist/workspace/sandbox/index.d.ts.map +1 -1
  226. package/dist/workspace/sandbox/local-sandbox.d.ts +3 -2
  227. package/dist/workspace/sandbox/local-sandbox.d.ts.map +1 -1
  228. package/dist/workspace/sandbox/mastra-sandbox.d.ts +52 -0
  229. package/dist/workspace/sandbox/mastra-sandbox.d.ts.map +1 -0
  230. package/dist/workspace/tools/tools.d.ts.map +1 -1
  231. package/dist/workspace/workspace.d.ts +21 -0
  232. package/dist/workspace/workspace.d.ts.map +1 -1
  233. package/editor.d.ts +1 -0
  234. package/package.json +8 -8
  235. package/src/llm/model/provider-types.generated.d.ts +54 -2
  236. package/dist/chunk-22EV7GMK.cjs.map +0 -1
  237. package/dist/chunk-2CVY7S66.js.map +0 -1
  238. package/dist/chunk-4DDIPGB6.js.map +0 -1
  239. package/dist/chunk-66BWIF4S.js.map +0 -1
  240. package/dist/chunk-7ALOYTDY.cjs.map +0 -1
  241. package/dist/chunk-AC63Y6KP.js.map +0 -1
  242. package/dist/chunk-CILDTRXD.js.map +0 -1
  243. package/dist/chunk-EYUXOOSQ.cjs.map +0 -1
  244. package/dist/chunk-FAJYC6PA.js.map +0 -1
  245. package/dist/chunk-FYMM4PKR.js.map +0 -1
  246. package/dist/chunk-HIP5W3LZ.js.map +0 -1
  247. package/dist/chunk-I6PWV32C.cjs.map +0 -1
  248. package/dist/chunk-IUODLQMU.cjs.map +0 -1
  249. package/dist/chunk-KNPIRLQQ.cjs.map +0 -1
  250. package/dist/chunk-NS33UC72.js.map +0 -1
  251. package/dist/chunk-OAOMKZXU.cjs.map +0 -1
  252. package/dist/chunk-ODNSWEMV.cjs.map +0 -1
  253. package/dist/chunk-OQPAOUDS.js.map +0 -1
  254. package/dist/chunk-STNSGW7W.cjs.map +0 -1
  255. package/dist/chunk-USHB3SPM.js.map +0 -1
  256. package/dist/chunk-W57QS6F6.cjs.map +0 -1
  257. package/dist/chunk-XS2MED4Y.js.map +0 -1
  258. package/dist/chunk-XVHK5IAO.cjs.map +0 -1
  259. package/dist/chunk-Y2SVKUOQ.cjs.map +0 -1
  260. package/dist/models-dev-2HBSVUOS.js +0 -3
  261. package/dist/models-dev-SOIECXXQ.cjs +0 -12
  262. package/dist/provider-registry-K5L4DHRK.js +0 -3
  263. package/dist/provider-registry-ML2VWWLB.cjs +0 -40
@@ -1,6 +1,6 @@
1
- import { MessageList } from './chunk-HIP5W3LZ.js';
2
- import { TABLE_SCHEMAS, TABLE_SCORERS, listTracesArgsSchema, toTraceSpans, TABLE_WORKFLOW_SNAPSHOT } from './chunk-CILDTRXD.js';
3
- import { deepEqual } from './chunk-4DDIPGB6.js';
1
+ import { MessageList } from './chunk-57O4TPB3.js';
2
+ import { TABLE_SCHEMAS, TABLE_SCORERS, listTracesArgsSchema, toTraceSpans, TABLE_WORKFLOW_SNAPSHOT } from './chunk-MNWW2R3U.js';
3
+ import { deepEqual } from './chunk-T6PRRKMW.js';
4
4
  import { MastraError } from './chunk-FJEVLHJT.js';
5
5
  import { MastraBase } from './chunk-JIT2OY3X.js';
6
6
 
@@ -154,24 +154,33 @@ var AgentsStorage = class extends StorageDomain {
154
154
  if (!agent) {
155
155
  return null;
156
156
  }
157
+ let version = null;
157
158
  if (agent.activeVersionId) {
158
- const activeVersion = await this.getVersion(agent.activeVersionId);
159
- if (activeVersion) {
160
- const {
161
- id: _versionId,
162
- agentId: _agentId,
163
- versionNumber: _versionNumber,
164
- changedFields: _changedFields,
165
- changeMessage: _changeMessage,
166
- createdAt: _createdAt,
167
- ...snapshotConfig
168
- } = activeVersion;
169
- return {
170
- ...agent,
171
- ...snapshotConfig
172
- };
159
+ version = await this.getVersion(agent.activeVersionId);
160
+ if (!version) {
161
+ console.warn(
162
+ `[AgentsStorage] Agent ${agent.id} has activeVersionId ${agent.activeVersionId} but version not found. Falling back to latest version.`
163
+ );
173
164
  }
174
165
  }
166
+ if (!version) {
167
+ version = await this.getLatestVersion(agent.id);
168
+ }
169
+ if (version) {
170
+ const {
171
+ id: _versionId,
172
+ agentId: _agentId,
173
+ versionNumber: _versionNumber,
174
+ changedFields: _changedFields,
175
+ changeMessage: _changeMessage,
176
+ createdAt: _createdAt,
177
+ ...snapshotConfig
178
+ } = version;
179
+ return {
180
+ ...agent,
181
+ ...snapshotConfig
182
+ };
183
+ }
175
184
  return agent;
176
185
  }
177
186
  /**
@@ -185,23 +194,27 @@ var AgentsStorage = class extends StorageDomain {
185
194
  const result = await this.listAgents(args);
186
195
  const resolvedAgents = await Promise.all(
187
196
  result.agents.map(async (agent) => {
197
+ let version = null;
188
198
  if (agent.activeVersionId) {
189
- const activeVersion = await this.getVersion(agent.activeVersionId);
190
- if (activeVersion) {
191
- const {
192
- id: _versionId,
193
- agentId: _agentId,
194
- versionNumber: _versionNumber,
195
- changedFields: _changedFields,
196
- changeMessage: _changeMessage,
197
- createdAt: _createdAt,
198
- ...snapshotConfig
199
- } = activeVersion;
200
- return {
201
- ...agent,
202
- ...snapshotConfig
203
- };
204
- }
199
+ version = await this.getVersion(agent.activeVersionId);
200
+ }
201
+ if (!version) {
202
+ version = await this.getLatestVersion(agent.id);
203
+ }
204
+ if (version) {
205
+ const {
206
+ id: _versionId,
207
+ agentId: _agentId,
208
+ versionNumber: _versionNumber,
209
+ changedFields: _changedFields,
210
+ changeMessage: _changeMessage,
211
+ createdAt: _createdAt,
212
+ ...snapshotConfig
213
+ } = version;
214
+ return {
215
+ ...agent,
216
+ ...snapshotConfig
217
+ };
205
218
  }
206
219
  return agent;
207
220
  })
@@ -279,10 +292,7 @@ var InMemoryAgentsStorage = class extends AgentsStorage {
279
292
  changedFields: Object.keys(snapshotConfig),
280
293
  changeMessage: "Initial version"
281
294
  });
282
- newAgent.activeVersionId = versionId;
283
- newAgent.status = "published";
284
- this.db.agents.set(agent.id, newAgent);
285
- return { ...newAgent };
295
+ return this.deepCopyAgent(newAgent);
286
296
  }
287
297
  async updateAgent({ id, ...updates }) {
288
298
  this.logger.debug(`InMemoryAgentsStorage: updateAgent called for ${id}`);
@@ -290,20 +300,69 @@ var InMemoryAgentsStorage = class extends AgentsStorage {
290
300
  if (!existingAgent) {
291
301
  throw new Error(`Agent with id ${id} not found`);
292
302
  }
303
+ const { authorId, activeVersionId, metadata, ...configFields } = updates;
304
+ const configFieldNames = [
305
+ "name",
306
+ "description",
307
+ "instructions",
308
+ "model",
309
+ "tools",
310
+ "defaultOptions",
311
+ "workflows",
312
+ "agents",
313
+ "integrationTools",
314
+ "inputProcessors",
315
+ "outputProcessors",
316
+ "memory",
317
+ "scorers"
318
+ ];
319
+ const hasConfigUpdate = configFieldNames.some((field) => field in configFields);
293
320
  const updatedAgent = {
294
321
  ...existingAgent,
295
- ...updates.authorId !== void 0 && { authorId: updates.authorId },
296
- ...updates.activeVersionId !== void 0 && { activeVersionId: updates.activeVersionId },
297
- ...updates.metadata !== void 0 && {
298
- metadata: { ...existingAgent.metadata, ...updates.metadata }
322
+ ...authorId !== void 0 && { authorId },
323
+ ...activeVersionId !== void 0 && { activeVersionId },
324
+ ...metadata !== void 0 && {
325
+ metadata: { ...existingAgent.metadata, ...metadata }
299
326
  },
300
327
  updatedAt: /* @__PURE__ */ new Date()
301
328
  };
302
- if (updates.activeVersionId !== void 0) {
329
+ if (activeVersionId !== void 0) {
303
330
  updatedAgent.status = "published";
304
331
  }
332
+ if (hasConfigUpdate) {
333
+ const latestVersion = await this.getLatestVersion(id);
334
+ if (!latestVersion) {
335
+ throw new Error(`No versions found for agent ${id}`);
336
+ }
337
+ const {
338
+ id: _versionId,
339
+ agentId: _agentId,
340
+ versionNumber: _versionNumber,
341
+ changedFields: _changedFields,
342
+ changeMessage: _changeMessage,
343
+ createdAt: _createdAt,
344
+ ...latestConfig
345
+ } = latestVersion;
346
+ const newConfig = {
347
+ ...latestConfig,
348
+ ...configFields
349
+ };
350
+ const changedFields = configFieldNames.filter(
351
+ (field) => field in configFields && configFields[field] !== latestConfig[field]
352
+ );
353
+ const newVersionId = crypto.randomUUID();
354
+ const newVersionNumber = latestVersion.versionNumber + 1;
355
+ await this.createVersion({
356
+ id: newVersionId,
357
+ agentId: id,
358
+ versionNumber: newVersionNumber,
359
+ ...newConfig,
360
+ changedFields,
361
+ changeMessage: `Updated ${changedFields.join(", ")}`
362
+ });
363
+ }
305
364
  this.db.agents.set(id, updatedAgent);
306
- return { ...updatedAgent };
365
+ return this.deepCopyAgent(updatedAgent);
307
366
  }
308
367
  async deleteAgent({ id }) {
309
368
  this.logger.debug(`InMemoryAgentsStorage: deleteAgent called for ${id}`);
@@ -465,8 +524,8 @@ var InMemoryAgentsStorage = class extends AgentsStorage {
465
524
  workflows: version.workflows ? [...version.workflows] : version.workflows,
466
525
  agents: version.agents ? [...version.agents] : version.agents,
467
526
  integrationTools: version.integrationTools ? [...version.integrationTools] : version.integrationTools,
468
- inputProcessors: version.inputProcessors ? version.inputProcessors.map((p) => ({ ...p })) : version.inputProcessors,
469
- outputProcessors: version.outputProcessors ? version.outputProcessors.map((p) => ({ ...p })) : version.outputProcessors,
527
+ inputProcessors: version.inputProcessors ? [...version.inputProcessors] : version.inputProcessors,
528
+ outputProcessors: version.outputProcessors ? [...version.outputProcessors] : version.outputProcessors,
470
529
  memory: version.memory ? { ...version.memory } : version.memory,
471
530
  scorers: version.scorers ? { ...version.scorers } : version.scorers,
472
531
  changedFields: version.changedFields ? [...version.changedFields] : version.changedFields
@@ -505,6 +564,8 @@ var InMemoryDB = class {
505
564
  traces = /* @__PURE__ */ new Map();
506
565
  agents = /* @__PURE__ */ new Map();
507
566
  agentVersions = /* @__PURE__ */ new Map();
567
+ /** Observational memory records, keyed by resourceId, each holding array of records (generations) */
568
+ observationalMemory = /* @__PURE__ */ new Map();
508
569
  /**
509
570
  * Clears all data from all collections.
510
571
  * Useful for testing.
@@ -518,6 +579,7 @@ var InMemoryDB = class {
518
579
  this.traces.clear();
519
580
  this.agents.clear();
520
581
  this.agentVersions.clear();
582
+ this.observationalMemory.clear();
521
583
  }
522
584
  };
523
585
 
@@ -691,12 +753,30 @@ var SAFE_METADATA_KEY_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
691
753
  var MAX_METADATA_KEY_LENGTH = 128;
692
754
  var DISALLOWED_METADATA_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
693
755
  var MemoryStorage = class extends StorageDomain {
756
+ /**
757
+ * Whether this storage adapter supports Observational Memory.
758
+ * Adapters that implement OM methods should set this to true.
759
+ * Defaults to false for backwards compatibility with custom adapters.
760
+ */
761
+ supportsObservationalMemory = false;
694
762
  constructor() {
695
763
  super({
696
764
  component: "STORAGE",
697
765
  name: "MEMORY"
698
766
  });
699
767
  }
768
+ /**
769
+ * List messages by resource ID only (across all threads).
770
+ * Used by Observational Memory and LongMemEval for resource-scoped queries.
771
+ *
772
+ * @param args - Resource ID and pagination/filtering options
773
+ * @returns Paginated list of messages for the resource
774
+ */
775
+ async listMessagesByResourceId(_args) {
776
+ throw new Error(
777
+ `Resource-scoped message listing is not implemented by this storage adapter (${this.constructor.name}). Use an adapter that supports Observational Memory (pg, libsql, mongodb) or disable observational memory.`
778
+ );
779
+ }
700
780
  async deleteMessages(_messageIds) {
701
781
  throw new Error(
702
782
  `Message deletion is not supported by this storage adapter (${this.constructor.name}). The deleteMessages method needs to be implemented in the storage adapter.`
@@ -735,6 +815,122 @@ var MemoryStorage = class extends StorageDomain {
735
815
  direction: orderBy?.direction && orderBy.direction in THREAD_THREAD_SORT_DIRECTION_SET ? orderBy.direction : defaultDirection
736
816
  };
737
817
  }
818
+ // ============================================
819
+ // Observational Memory Methods
820
+ // ============================================
821
+ /**
822
+ * Get the current observational memory record for a thread/resource.
823
+ * Returns the most recent active record.
824
+ */
825
+ async getObservationalMemory(_threadId, _resourceId) {
826
+ throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
827
+ }
828
+ /**
829
+ * Get observational memory history (previous generations).
830
+ * Returns records in reverse chronological order (newest first).
831
+ */
832
+ async getObservationalMemoryHistory(_threadId, _resourceId, _limit) {
833
+ throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
834
+ }
835
+ /**
836
+ * Create a new observational memory record.
837
+ * Called when starting observations for a new thread/resource.
838
+ */
839
+ async initializeObservationalMemory(_input) {
840
+ throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
841
+ }
842
+ /**
843
+ * Update active observations.
844
+ * Called when observations are created and immediately activated (no buffering).
845
+ */
846
+ async updateActiveObservations(_input) {
847
+ throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
848
+ }
849
+ // ============================================
850
+ // Buffering Methods (DISABLED - not currently used)
851
+ // These methods were designed for async observation buffering
852
+ // which has been disabled. Keeping commented for future reference.
853
+ // ============================================
854
+ // /**
855
+ // * Update buffered observations.
856
+ // * Called when observations are created asynchronously.
857
+ // */
858
+ // async updateBufferedObservations(_input: UpdateBufferedObservationsInput): Promise<void> {
859
+ // throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
860
+ // }
861
+ // /**
862
+ // * Swap buffered observations to active.
863
+ // * Atomic operation that:
864
+ // * 1. Moves bufferedObservations → activeObservations
865
+ // * 2. Moves bufferedMessageIds → observedMessageIds
866
+ // * 3. Clears buffered state
867
+ // */
868
+ // async swapBufferedToActive(_id: string): Promise<void> {
869
+ // throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
870
+ // }
871
+ // /**
872
+ // * Mark messages as currently being observed (in-flight).
873
+ // */
874
+ // async markMessagesAsBuffering(_id: string, _messageIds: string[]): Promise<void> {
875
+ // throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
876
+ // }
877
+ // /**
878
+ // * Mark messages as buffered (observation complete but not active).
879
+ // * Moves messageIds from bufferingMessageIds → bufferedMessageIds.
880
+ // */
881
+ // async markMessagesAsBuffered(_id: string, _messageIds: string[]): Promise<void> {
882
+ // throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
883
+ // }
884
+ /**
885
+ * Create a new generation from a reflection.
886
+ * Creates a new record with:
887
+ * - originType: 'reflection'
888
+ * - activeObservations containing the reflection
889
+ * - generationCount incremented from the current record
890
+ */
891
+ async createReflectionGeneration(_input) {
892
+ throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
893
+ }
894
+ // /**
895
+ // * Update buffered reflection (async reflection in progress).
896
+ // */
897
+ // async updateBufferedReflection(_id: string, _reflection: string): Promise<void> {
898
+ // throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
899
+ // }
900
+ // /**
901
+ // * Swap buffered reflection to active observations.
902
+ // * Creates a new generation and makes it the active one.
903
+ // */
904
+ // async swapReflectionToActive(_id: string): Promise<ObservationalMemoryRecord> {
905
+ // throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
906
+ // }
907
+ /**
908
+ * Set the isReflecting flag.
909
+ */
910
+ async setReflectingFlag(_id, _isReflecting) {
911
+ throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
912
+ }
913
+ /**
914
+ * Set the isObserving flag.
915
+ */
916
+ async setObservingFlag(_id, _isObserving) {
917
+ throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
918
+ }
919
+ /**
920
+ * Clear all observational memory for a thread/resource.
921
+ * Removes all records and history.
922
+ */
923
+ async clearObservationalMemory(_threadId, _resourceId) {
924
+ throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
925
+ }
926
+ /**
927
+ * Add to the pending message token count.
928
+ * Called when messages are processed but observation hasn't triggered yet.
929
+ * This allows accumulating tokens across multiple sessions.
930
+ */
931
+ async addPendingMessageTokens(_id, _tokenCount) {
932
+ throw new Error(`Observational memory is not implemented by this storage adapter (${this.constructor.name}).`);
933
+ }
738
934
  /**
739
935
  * Validates metadata keys to prevent SQL injection attacks and prototype pollution.
740
936
  * Keys must start with a letter or underscore, followed by alphanumeric characters or underscores.
@@ -823,6 +1019,7 @@ var THREAD_THREAD_SORT_DIRECTION_SET = {
823
1019
 
824
1020
  // src/storage/domains/memory/inmemory.ts
825
1021
  var InMemoryMemory = class extends MemoryStorage {
1022
+ supportsObservationalMemory = true;
826
1023
  db;
827
1024
  constructor({ db }) {
828
1025
  super();
@@ -832,6 +1029,7 @@ var InMemoryMemory = class extends MemoryStorage {
832
1029
  this.db.threads.clear();
833
1030
  this.db.messages.clear();
834
1031
  this.db.resources.clear();
1032
+ this.db.observationalMemory.clear();
835
1033
  }
836
1034
  async getThreadById({ threadId }) {
837
1035
  this.logger.debug(`InMemoryMemory: getThreadById called for ${threadId}`);
@@ -872,7 +1070,7 @@ var InMemoryMemory = class extends MemoryStorage {
872
1070
  }
873
1071
  async listMessages({
874
1072
  threadId,
875
- resourceId,
1073
+ resourceId: optionalResourceId,
876
1074
  include,
877
1075
  filter,
878
1076
  perPage: perPageInput,
@@ -896,8 +1094,8 @@ var InMemoryMemory = class extends MemoryStorage {
896
1094
  }
897
1095
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
898
1096
  let threadMessages = Array.from(this.db.messages.values()).filter((msg) => {
899
- if (!threadIdSet.has(msg.thread_id)) return false;
900
- if (resourceId && msg.resourceId !== resourceId) return false;
1097
+ if (threadIdSet && !threadIdSet.has(msg.thread_id)) return false;
1098
+ if (optionalResourceId && msg.resourceId !== optionalResourceId) return false;
901
1099
  return true;
902
1100
  });
903
1101
  threadMessages = filterByDateRange(threadMessages, (msg) => new Date(msg.createdAt), filter?.dateRange);
@@ -1014,6 +1212,50 @@ var InMemoryMemory = class extends MemoryStorage {
1014
1212
  hasMore
1015
1213
  };
1016
1214
  }
1215
+ async listMessagesByResourceId({
1216
+ resourceId,
1217
+ filter,
1218
+ perPage: perPageInput,
1219
+ page = 0,
1220
+ orderBy
1221
+ }) {
1222
+ this.logger.debug(`InMemoryMemory: listMessagesByResourceId called for resource ${resourceId}`);
1223
+ const { field, direction } = this.parseOrderBy(orderBy, "ASC");
1224
+ const perPage = normalizePerPage(perPageInput, 40);
1225
+ if (page < 0) {
1226
+ throw new Error("page must be >= 0");
1227
+ }
1228
+ const maxOffset = Number.MAX_SAFE_INTEGER / 2;
1229
+ if (page * perPage > maxOffset) {
1230
+ throw new Error("page value too large");
1231
+ }
1232
+ const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1233
+ let messages = Array.from(this.db.messages.values()).filter((msg) => msg.resourceId === resourceId);
1234
+ messages = filterByDateRange(messages, (msg) => new Date(msg.createdAt), filter?.dateRange);
1235
+ messages.sort((a, b) => {
1236
+ const isDateField = field === "createdAt" || field === "updatedAt";
1237
+ const aValue = isDateField ? new Date(a[field]).getTime() : a[field];
1238
+ const bValue = isDateField ? new Date(b[field]).getTime() : b[field];
1239
+ if (typeof aValue === "number" && typeof bValue === "number") {
1240
+ return direction === "ASC" ? aValue - bValue : bValue - aValue;
1241
+ }
1242
+ return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
1243
+ });
1244
+ const total = messages.length;
1245
+ const paginatedMessages = messages.slice(offset, offset + perPage);
1246
+ const list = new MessageList().add(
1247
+ paginatedMessages.map((m) => this.parseStoredMessage(m)),
1248
+ "memory"
1249
+ );
1250
+ const hasMore = offset + paginatedMessages.length < total;
1251
+ return {
1252
+ messages: list.get.all.db(),
1253
+ total,
1254
+ page,
1255
+ perPage: perPageForResponse,
1256
+ hasMore
1257
+ };
1258
+ }
1017
1259
  parseStoredMessage(message) {
1018
1260
  const { resourceId, content, role, thread_id, ...rest } = message;
1019
1261
  let parsedContent = safelyParseJSON(content);
@@ -1322,6 +1564,219 @@ var InMemoryMemory = class extends MemoryStorage {
1322
1564
  return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
1323
1565
  });
1324
1566
  }
1567
+ // ============================================
1568
+ // Observational Memory Implementation
1569
+ // ============================================
1570
+ getObservationalMemoryKey(threadId, resourceId) {
1571
+ if (threadId) {
1572
+ return `thread:${threadId}`;
1573
+ }
1574
+ return `resource:${resourceId}`;
1575
+ }
1576
+ async getObservationalMemory(threadId, resourceId) {
1577
+ const key = this.getObservationalMemoryKey(threadId, resourceId);
1578
+ const records = this.db.observationalMemory.get(key);
1579
+ return records?.[0] ?? null;
1580
+ }
1581
+ async getObservationalMemoryHistory(threadId, resourceId, limit) {
1582
+ const key = this.getObservationalMemoryKey(threadId, resourceId);
1583
+ const records = this.db.observationalMemory.get(key) ?? [];
1584
+ return limit != null ? records.slice(0, limit) : records;
1585
+ }
1586
+ async initializeObservationalMemory(input) {
1587
+ const { threadId, resourceId, scope, config, observedTimezone } = input;
1588
+ const key = this.getObservationalMemoryKey(threadId, resourceId);
1589
+ const now = /* @__PURE__ */ new Date();
1590
+ const record = {
1591
+ id: crypto.randomUUID(),
1592
+ scope,
1593
+ threadId,
1594
+ resourceId,
1595
+ // Timestamps at top level
1596
+ createdAt: now,
1597
+ updatedAt: now,
1598
+ // lastObservedAt starts undefined - all messages are "unobserved" initially
1599
+ // This ensures historical data (like LongMemEval fixtures) works correctly
1600
+ lastObservedAt: void 0,
1601
+ originType: "initial",
1602
+ generationCount: 0,
1603
+ activeObservations: "",
1604
+ // Buffering (for async observation/reflection)
1605
+ bufferedObservations: void 0,
1606
+ bufferedReflection: void 0,
1607
+ // Message tracking
1608
+ // Note: Message ID tracking removed in favor of cursor-based lastObservedAt
1609
+ // Token tracking
1610
+ totalTokensObserved: 0,
1611
+ observationTokenCount: 0,
1612
+ pendingMessageTokens: 0,
1613
+ // State flags
1614
+ isReflecting: false,
1615
+ isObserving: false,
1616
+ // Configuration
1617
+ config,
1618
+ // Timezone used for observation date formatting
1619
+ observedTimezone,
1620
+ // Extensible metadata (optional)
1621
+ metadata: {}
1622
+ };
1623
+ const existing = this.db.observationalMemory.get(key) ?? [];
1624
+ this.db.observationalMemory.set(key, [record, ...existing]);
1625
+ return record;
1626
+ }
1627
+ async updateActiveObservations(input) {
1628
+ const { id, observations, tokenCount, lastObservedAt, observedMessageIds } = input;
1629
+ const record = this.findObservationalMemoryRecordById(id);
1630
+ if (!record) {
1631
+ throw new Error(`Observational memory record not found: ${id}`);
1632
+ }
1633
+ record.activeObservations = observations;
1634
+ record.observationTokenCount = tokenCount;
1635
+ record.totalTokensObserved += tokenCount;
1636
+ record.pendingMessageTokens = 0;
1637
+ record.lastObservedAt = lastObservedAt;
1638
+ record.updatedAt = /* @__PURE__ */ new Date();
1639
+ if (observedMessageIds) {
1640
+ record.observedMessageIds = observedMessageIds;
1641
+ }
1642
+ }
1643
+ async updateBufferedObservations(input) {
1644
+ const { id, observations } = input;
1645
+ const record = this.findObservationalMemoryRecordById(id);
1646
+ if (!record) {
1647
+ throw new Error(`Observational memory record not found: ${id}`);
1648
+ }
1649
+ record.bufferedObservations = observations;
1650
+ record.updatedAt = /* @__PURE__ */ new Date();
1651
+ }
1652
+ async swapBufferedToActive(id) {
1653
+ const record = this.findObservationalMemoryRecordById(id);
1654
+ if (!record) {
1655
+ throw new Error(`Observational memory record not found: ${id}`);
1656
+ }
1657
+ if (!record.bufferedObservations) {
1658
+ return;
1659
+ }
1660
+ if (record.activeObservations) {
1661
+ record.activeObservations = `${record.activeObservations}
1662
+
1663
+ ${record.bufferedObservations}`;
1664
+ } else {
1665
+ record.activeObservations = record.bufferedObservations;
1666
+ }
1667
+ record.bufferedObservations = void 0;
1668
+ record.lastObservedAt = /* @__PURE__ */ new Date();
1669
+ record.updatedAt = /* @__PURE__ */ new Date();
1670
+ }
1671
+ async markMessagesAsBuffering(id, _messageIds) {
1672
+ const record = this.findObservationalMemoryRecordById(id);
1673
+ if (!record) {
1674
+ throw new Error(`Observational memory record not found: ${id}`);
1675
+ }
1676
+ record.updatedAt = /* @__PURE__ */ new Date();
1677
+ }
1678
+ async markMessagesAsBuffered(id, _messageIds) {
1679
+ const record = this.findObservationalMemoryRecordById(id);
1680
+ if (!record) {
1681
+ throw new Error(`Observational memory record not found: ${id}`);
1682
+ }
1683
+ record.updatedAt = /* @__PURE__ */ new Date();
1684
+ }
1685
+ async createReflectionGeneration(input) {
1686
+ const { currentRecord, reflection, tokenCount } = input;
1687
+ const key = this.getObservationalMemoryKey(currentRecord.threadId, currentRecord.resourceId);
1688
+ const now = /* @__PURE__ */ new Date();
1689
+ const newRecord = {
1690
+ id: crypto.randomUUID(),
1691
+ scope: currentRecord.scope,
1692
+ threadId: currentRecord.threadId,
1693
+ resourceId: currentRecord.resourceId,
1694
+ // Timestamps at top level
1695
+ createdAt: now,
1696
+ updatedAt: now,
1697
+ lastObservedAt: currentRecord.lastObservedAt ?? now,
1698
+ // Carry over from observation (which always runs before reflection)
1699
+ originType: "reflection",
1700
+ generationCount: currentRecord.generationCount + 1,
1701
+ activeObservations: reflection,
1702
+ config: currentRecord.config,
1703
+ totalTokensObserved: currentRecord.totalTokensObserved,
1704
+ observationTokenCount: tokenCount,
1705
+ pendingMessageTokens: 0,
1706
+ isReflecting: false,
1707
+ isObserving: false,
1708
+ // Timezone used for observation date formatting
1709
+ observedTimezone: currentRecord.observedTimezone,
1710
+ // Extensible metadata (optional)
1711
+ metadata: {}
1712
+ };
1713
+ const existing = this.db.observationalMemory.get(key) ?? [];
1714
+ this.db.observationalMemory.set(key, [newRecord, ...existing]);
1715
+ return newRecord;
1716
+ }
1717
+ async updateBufferedReflection(id, reflection) {
1718
+ const record = this.findObservationalMemoryRecordById(id);
1719
+ if (!record) {
1720
+ throw new Error(`Observational memory record not found: ${id}`);
1721
+ }
1722
+ record.bufferedReflection = reflection;
1723
+ record.updatedAt = /* @__PURE__ */ new Date();
1724
+ }
1725
+ async swapReflectionToActive(id) {
1726
+ const record = this.findObservationalMemoryRecordById(id);
1727
+ if (!record) {
1728
+ throw new Error(`Observational memory record not found: ${id}`);
1729
+ }
1730
+ if (!record.bufferedReflection) {
1731
+ throw new Error("No buffered reflection to swap");
1732
+ }
1733
+ const newRecord = await this.createReflectionGeneration({
1734
+ currentRecord: record,
1735
+ reflection: record.bufferedReflection,
1736
+ tokenCount: 0
1737
+ // Will be calculated by caller
1738
+ });
1739
+ record.bufferedReflection = void 0;
1740
+ return newRecord;
1741
+ }
1742
+ async setReflectingFlag(id, isReflecting) {
1743
+ const record = this.findObservationalMemoryRecordById(id);
1744
+ if (!record) {
1745
+ throw new Error(`Observational memory record not found: ${id}`);
1746
+ }
1747
+ record.isReflecting = isReflecting;
1748
+ record.updatedAt = /* @__PURE__ */ new Date();
1749
+ }
1750
+ async setObservingFlag(id, isObserving) {
1751
+ const record = this.findObservationalMemoryRecordById(id);
1752
+ if (!record) {
1753
+ throw new Error(`Observational memory record not found: ${id}`);
1754
+ }
1755
+ record.isObserving = isObserving;
1756
+ record.updatedAt = /* @__PURE__ */ new Date();
1757
+ }
1758
+ async clearObservationalMemory(threadId, resourceId) {
1759
+ const key = this.getObservationalMemoryKey(threadId, resourceId);
1760
+ this.db.observationalMemory.delete(key);
1761
+ }
1762
+ async addPendingMessageTokens(id, tokenCount) {
1763
+ const record = this.findObservationalMemoryRecordById(id);
1764
+ if (!record) {
1765
+ throw new Error(`Observational memory record not found: ${id}`);
1766
+ }
1767
+ record.pendingMessageTokens = (record.pendingMessageTokens ?? 0) + tokenCount;
1768
+ record.updatedAt = /* @__PURE__ */ new Date();
1769
+ }
1770
+ /**
1771
+ * Helper to find an observational memory record by ID across all keys
1772
+ */
1773
+ findObservationalMemoryRecordById(id) {
1774
+ for (const records of this.db.observationalMemory.values()) {
1775
+ const record = records.find((r) => r.id === id);
1776
+ if (record) return record;
1777
+ }
1778
+ return null;
1779
+ }
1325
1780
  };
1326
1781
 
1327
1782
  // src/storage/domains/observability/base.ts
@@ -2317,7 +2772,8 @@ var StoreOperationsInMemory = class extends StoreOperations {
2317
2772
  mastra_scorers: /* @__PURE__ */ new Map(),
2318
2773
  mastra_ai_spans: /* @__PURE__ */ new Map(),
2319
2774
  mastra_agents: /* @__PURE__ */ new Map(),
2320
- mastra_agent_versions: /* @__PURE__ */ new Map()
2775
+ mastra_agent_versions: /* @__PURE__ */ new Map(),
2776
+ mastra_observational_memory: /* @__PURE__ */ new Map()
2321
2777
  };
2322
2778
  }
2323
2779
  getDatabase() {
@@ -2383,5 +2839,5 @@ var StoreOperationsInMemory = class extends StoreOperations {
2383
2839
  };
2384
2840
 
2385
2841
  export { AgentsStorage, InMemoryAgentsStorage, InMemoryDB, InMemoryMemory, InMemoryStore, MastraCompositeStore, MastraStorage, MemoryStorage, MockStore, ObservabilityInMemory, ObservabilityStorage, ScoresInMemory, ScoresStorage, StorageDomain, StoreOperations, StoreOperationsInMemory, WorkflowsInMemory, WorkflowsStorage, calculatePagination, createPendingMarker, createStorageErrorId, createStoreErrorId, createVectorErrorId, ensureDate, filterByDateRange, getDefaultValue, getSqlType, jsonValueEquals, normalizePerPage, safelyParseJSON, serializeDate, transformRow, transformScoreRow };
2386
- //# sourceMappingURL=chunk-OQPAOUDS.js.map
2387
- //# sourceMappingURL=chunk-OQPAOUDS.js.map
2842
+ //# sourceMappingURL=chunk-ZODRDMZ7.js.map
2843
+ //# sourceMappingURL=chunk-ZODRDMZ7.js.map