@mastra/memory 1.19.1-alpha.0 → 1.20.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{chunk-BCYGTJF2.js → chunk-G72RLVRT.js} +50 -8
  3. package/dist/chunk-G72RLVRT.js.map +1 -0
  4. package/dist/{chunk-IRMLP4QH.cjs → chunk-PNKMNTE6.cjs} +49 -7
  5. package/dist/chunk-PNKMNTE6.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +47 -47
  8. package/dist/docs/references/docs-memory-multi-user-threads.md +1 -1
  9. package/dist/docs/references/docs-memory-observational-memory.md +2 -2
  10. package/dist/docs/references/docs-memory-storage.md +1 -1
  11. package/dist/docs/references/reference-memory-observational-memory.md +1 -1
  12. package/dist/docs/references/reference-storage-dsql.md +1 -1
  13. package/dist/docs/references/reference-storage-redis.md +1 -1
  14. package/dist/index.cjs +15 -14
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +6 -5
  18. package/dist/index.js.map +1 -1
  19. package/dist/{observational-memory-RWXMKXJP.cjs → observational-memory-25PDEXBJ.cjs} +26 -26
  20. package/dist/{observational-memory-RWXMKXJP.cjs.map → observational-memory-25PDEXBJ.cjs.map} +1 -1
  21. package/dist/{observational-memory-CSI3OZXQ.js → observational-memory-FBSRD6QN.js} +3 -3
  22. package/dist/{observational-memory-CSI3OZXQ.js.map → observational-memory-FBSRD6QN.js.map} +1 -1
  23. package/dist/processors/index.cjs +24 -24
  24. package/dist/processors/index.js +1 -1
  25. package/dist/processors/observational-memory/message-utils.d.ts +1 -0
  26. package/dist/processors/observational-memory/message-utils.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  28. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
  29. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
  30. package/dist/processors/observational-memory/observer-runner.d.ts +11 -0
  31. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
  32. package/dist/processors/observational-memory/types.d.ts +7 -3
  33. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  34. package/package.json +3 -3
  35. package/dist/chunk-BCYGTJF2.js.map +0 -1
  36. package/dist/chunk-IRMLP4QH.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.20.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - Add per-provider capability files and `auto` mode for `observeAttachments` ([#16922](https://github.com/mastra-ai/mastra/pull/16922))
8
+ - Generate per-provider capability files (e.g. `capabilities/openai.json`) alongside the model router registry, sourced from models.dev API
9
+ - Export `modelSupportsAttachments(modelRouterId)` from `@mastra/core/llm` to check whether a model supports image/file attachments
10
+ - Extend `observeAttachments` config to accept `'auto'` in addition to `boolean | string[]`
11
+ - When set to `'auto'`, the observer resolves the model (including function-based models) and checks the capability registry before deciding to forward or drop attachment parts
12
+
13
+ ### Patch Changes
14
+
15
+ - Fixed observational memory so in-progress messages are not removed during observation cleanup. ([#16913](https://github.com/mastra-ai/mastra/pull/16913))
16
+
17
+ - Updated dependencies [[`ac442a4`](https://github.com/mastra-ai/mastra/commit/ac442a42fda0354ac2bcea772bf6691cb3e9dbb3), [`1e5c067`](https://github.com/mastra-ai/mastra/commit/1e5c067d2e20a781af670578180d1ee249806d41), [`008baaf`](https://github.com/mastra-ai/mastra/commit/008baafd8d851f831407045aebead5a2e3342eff), [`8116436`](https://github.com/mastra-ai/mastra/commit/81164363eb225d774e41ff27da6a5ea611406688), [`c27c4b9`](https://github.com/mastra-ai/mastra/commit/c27c4b9f137df5414fca4e45896aceccff6b0ed5), [`08b3b59`](https://github.com/mastra-ai/mastra/commit/08b3b590dd960dee6c9a6e39272f8927d803db6e)]:
18
+ - @mastra/core@1.37.0-alpha.3
19
+
3
20
  ## 1.19.1-alpha.0
4
21
 
5
22
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_RETRIEVAL_INSTRUCTIONS, OBSERVATION_CONTINUATION_HINT } from './chunk-LSJJAJAF.js';
2
2
  import { coreFeatures } from '@mastra/core/features';
3
- import { resolveModelConfig } from '@mastra/core/llm';
3
+ import { resolveModelConfig, modelSupportsAttachments } from '@mastra/core/llm';
4
4
  import { getThreadOMMetadata, setThreadOMMetadata, parseMemoryRequestContext } from '@mastra/core/memory';
5
5
  import { MessageHistory } from '@mastra/core/processors';
6
6
  import xxhash from 'xxhash-wasm';
@@ -669,6 +669,7 @@ function filterObservedMessages(opts) {
669
669
  const { messageList, record } = opts;
670
670
  const allMessages = messageList.get.all.db();
671
671
  const useMarkerBoundaryPruning = opts.useMarkerBoundaryPruning ?? true;
672
+ const preserveMessageIds = opts.preserveMessageIds ?? /* @__PURE__ */ new Set();
672
673
  let markerMessageIndex = -1;
673
674
  let markerMessage = null;
674
675
  for (let i = allMessages.length - 1; i >= 0; i--) {
@@ -684,7 +685,7 @@ function filterObservedMessages(opts) {
684
685
  const messagesToRemove = [];
685
686
  for (let i = 0; i < markerMessageIndex; i++) {
686
687
  const msg = allMessages[i];
687
- if (msg?.id && msg.id !== "om-continuation") {
688
+ if (msg?.id && msg.id !== "om-continuation" && !preserveMessageIds.has(msg.id)) {
688
689
  messagesToRemove.push(msg.id);
689
690
  }
690
691
  }
@@ -703,7 +704,7 @@ function filterObservedMessages(opts) {
703
704
  const lastObservedAt = record.lastObservedAt;
704
705
  const messagesToRemove = [];
705
706
  for (const msg of allMessages) {
706
- if (!msg?.id || msg.id === "om-continuation") continue;
707
+ if (!msg?.id || msg.id === "om-continuation" || preserveMessageIds.has(msg.id)) continue;
707
708
  if (observedIds.has(msg.id)) {
708
709
  messagesToRemove.push(msg.id);
709
710
  continue;
@@ -2269,11 +2270,15 @@ var ObservationStep = class {
2269
2270
  });
2270
2271
  if (!didThresholdCleanup) {
2271
2272
  const fallbackCursor = this.turn.record.threadId ? getThreadOMMetadata((await om.getStorage().getThreadById({ threadId: this.turn.record.threadId }))?.metadata)?.lastObservedMessageCursor : void 0;
2273
+ const pendingMessageIds = new Set(
2274
+ [...messageList.get.input.db(), ...messageList.get.response.db()].map((msg) => msg.id).filter(Boolean)
2275
+ );
2272
2276
  filterObservedMessages({
2273
2277
  messageList,
2274
2278
  record: this.turn.record,
2275
2279
  useMarkerBoundaryPruning: this.stepNumber === 0,
2276
- fallbackCursor
2280
+ fallbackCursor,
2281
+ preserveMessageIds: pendingMessageIds
2277
2282
  });
2278
2283
  }
2279
2284
  this._context = {
@@ -4101,6 +4106,41 @@ var ObserverRunner = class {
4101
4106
  }
4102
4107
  return agent;
4103
4108
  }
4109
+ /**
4110
+ * Extract a router-style model ID (`provider/model`) from a model config.
4111
+ * Handles strings, LanguageModel objects, and function-based models.
4112
+ */
4113
+ extractModelRouterId(model, requestContext) {
4114
+ if (typeof model === "string") return model;
4115
+ if (typeof model === "function") {
4116
+ if (!requestContext) return void 0;
4117
+ try {
4118
+ const resolved = model({ requestContext });
4119
+ if (resolved instanceof Promise) return void 0;
4120
+ return this.extractModelRouterId(resolved);
4121
+ } catch {
4122
+ return void 0;
4123
+ }
4124
+ }
4125
+ const obj = model;
4126
+ if (typeof obj.provider === "string" && typeof obj.modelId === "string") {
4127
+ return `${obj.provider}/${obj.modelId}`;
4128
+ }
4129
+ return void 0;
4130
+ }
4131
+ /**
4132
+ * Resolve the attachment filter for a given model. When set to `'auto'`,
4133
+ * the provider capabilities registry is consulted to decide whether the
4134
+ * model accepts multimodal input.
4135
+ */
4136
+ resolveAttachmentFilter(model, requestContext) {
4137
+ const raw = this.observationConfig.observeAttachments;
4138
+ if (raw !== "auto") return raw;
4139
+ const routerId = this.extractModelRouterId(model, requestContext);
4140
+ if (!routerId) return true;
4141
+ const supports = modelSupportsAttachments(routerId);
4142
+ return supports ?? true;
4143
+ }
4104
4144
  async withAbortCheck(fn, abortSignal) {
4105
4145
  if (abortSignal?.aborted) {
4106
4146
  throw new Error("The operation was aborted.");
@@ -4118,6 +4158,7 @@ var ObserverRunner = class {
4118
4158
  const inputTokens = this.tokenCounter.countMessages(messagesToObserve);
4119
4159
  const resolvedModel = options?.model ? { model: options.model } : this.resolveModel(inputTokens);
4120
4160
  const agent = this.createAgent(resolvedModel.model);
4161
+ const attachmentFilter = this.resolveAttachmentFilter(resolvedModel.model, options?.requestContext);
4121
4162
  const observerMessages = [
4122
4163
  {
4123
4164
  role: "user",
@@ -4127,7 +4168,7 @@ var ObserverRunner = class {
4127
4168
  })
4128
4169
  },
4129
4170
  buildObserverHistoryMessage(messagesToObserve, {
4130
- attachmentFilter: this.observationConfig.observeAttachments
4171
+ attachmentFilter
4131
4172
  })
4132
4173
  ];
4133
4174
  const doGenerate = async () => {
@@ -4214,6 +4255,7 @@ var ObserverRunner = class {
4214
4255
  );
4215
4256
  const resolvedModel = model ? { model } : this.resolveModel(inputTokens);
4216
4257
  const agent = this.createAgent(resolvedModel.model, true);
4258
+ const multiThreadAttachmentFilter = this.resolveAttachmentFilter(resolvedModel.model, requestContext);
4217
4259
  const observerMessages = [
4218
4260
  {
4219
4261
  role: "user",
@@ -4226,7 +4268,7 @@ var ObserverRunner = class {
4226
4268
  )
4227
4269
  },
4228
4270
  buildMultiThreadObserverHistoryMessage(messagesByThread, threadOrder, {
4229
- attachmentFilter: this.observationConfig.observeAttachments
4271
+ attachmentFilter: multiThreadAttachmentFilter
4230
4272
  })
4231
4273
  ];
4232
4274
  for (const msgs of messagesByThread.values()) {
@@ -9809,5 +9851,5 @@ function getObservationsAsOf(activeObservations, asOf) {
9809
9851
  }
9810
9852
 
9811
9853
  export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
9812
- //# sourceMappingURL=chunk-BCYGTJF2.js.map
9813
- //# sourceMappingURL=chunk-BCYGTJF2.js.map
9854
+ //# sourceMappingURL=chunk-G72RLVRT.js.map
9855
+ //# sourceMappingURL=chunk-G72RLVRT.js.map