@mastra/memory 1.17.5 → 1.17.6-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 (27) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{chunk-BPJLUC2F.js → chunk-QZGJY67D.js} +85 -6
  3. package/dist/chunk-QZGJY67D.js.map +1 -0
  4. package/dist/{chunk-UZDSNIGD.cjs → chunk-WNLFJKTX.cjs} +85 -6
  5. package/dist/chunk-WNLFJKTX.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +39 -39
  8. package/dist/docs/references/docs-agents-background-tasks.md +62 -2
  9. package/dist/docs/references/docs-memory-observational-memory.md +7 -2
  10. package/dist/docs/references/docs-memory-overview.md +2 -1
  11. package/dist/index.cjs +298 -172
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +289 -163
  15. package/dist/index.js.map +1 -1
  16. package/dist/{observational-memory-KWFKMLG6.cjs → observational-memory-BJF72NKJ.cjs} +26 -26
  17. package/dist/{observational-memory-KWFKMLG6.cjs.map → observational-memory-BJF72NKJ.cjs.map} +1 -1
  18. package/dist/{observational-memory-FBBKXNO5.js → observational-memory-HAJ3K5JJ.js} +3 -3
  19. package/dist/{observational-memory-FBBKXNO5.js.map → observational-memory-HAJ3K5JJ.js.map} +1 -1
  20. package/dist/processors/index.cjs +24 -24
  21. package/dist/processors/index.js +1 -1
  22. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
  23. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  25. package/package.json +8 -8
  26. package/dist/chunk-BPJLUC2F.js.map +0 -1
  27. package/dist/chunk-UZDSNIGD.cjs.map +0 -1
@@ -1696,8 +1696,9 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
1696
1696
  orderBy: { field: "createdAt", direction: "ASC" },
1697
1697
  filter: startDate ? { dateRange: { start: startDate } } : void 0
1698
1698
  });
1699
- if (result.messages.length > 0) {
1700
- this.messagesByThread.set(thread.id, result.messages);
1699
+ const messages = result.messages.filter((msg) => msg.role !== "system");
1700
+ if (messages.length > 0) {
1701
+ this.messagesByThread.set(thread.id, messages);
1701
1702
  }
1702
1703
  }
1703
1704
  if (currentThreadMessages.length > 0) {
@@ -3165,6 +3166,71 @@ function formatObserverAttachmentPlaceholder(part, counter) {
3165
3166
  const label = resolveObserverAttachmentLabel(part);
3166
3167
  return label ? `[${attachmentType} #${attachmentId}: ${label}]` : `[${attachmentType} #${attachmentId}]`;
3167
3168
  }
3169
+ function isRecord(value) {
3170
+ return !!value && typeof value === "object";
3171
+ }
3172
+ function mapToolResultBlockToAttachment(block) {
3173
+ if (!isRecord(block) || typeof block.type !== "string") {
3174
+ return void 0;
3175
+ }
3176
+ const mediaType = typeof block.mediaType === "string" ? block.mediaType : void 0;
3177
+ const filename = typeof block.filename === "string" ? block.filename : void 0;
3178
+ switch (block.type) {
3179
+ case "image-data": {
3180
+ const data = block.data;
3181
+ if (typeof data !== "string") return void 0;
3182
+ const image = mediaType ? `data:${mediaType};base64,${data}` : data;
3183
+ return { type: "image", image, mimeType: mediaType };
3184
+ }
3185
+ case "image-url": {
3186
+ const url = block.url;
3187
+ if (typeof url !== "string") return void 0;
3188
+ return { type: "image", image: url, mimeType: mediaType };
3189
+ }
3190
+ case "media": {
3191
+ const data = block.data;
3192
+ if (typeof data !== "string" || !mediaType) return void 0;
3193
+ const dataUri = `data:${mediaType};base64,${data}`;
3194
+ if (mediaType.toLowerCase().startsWith("image/")) {
3195
+ return { type: "image", image: dataUri, mimeType: mediaType };
3196
+ }
3197
+ return { type: "file", data: dataUri, mimeType: mediaType };
3198
+ }
3199
+ case "file-data": {
3200
+ const data = block.data;
3201
+ if (typeof data !== "string") return void 0;
3202
+ const dataUri = mediaType ? `data:${mediaType};base64,${data}` : data;
3203
+ return { type: "file", data: dataUri, mimeType: mediaType, filename };
3204
+ }
3205
+ case "file-url": {
3206
+ const url = block.url;
3207
+ if (typeof url !== "string") return void 0;
3208
+ return { type: "file", data: url, mimeType: mediaType, filename };
3209
+ }
3210
+ default:
3211
+ return void 0;
3212
+ }
3213
+ }
3214
+ function extractToolResultAttachments(result, counter) {
3215
+ if (!isRecord(result) || result.type !== "content" || !Array.isArray(result.value)) {
3216
+ return { resultWithoutAttachments: result, attachments: [] };
3217
+ }
3218
+ const record = result;
3219
+ const attachments = [];
3220
+ const newValue = record.value.map((block) => {
3221
+ const attachment = mapToolResultBlockToAttachment(block);
3222
+ if (!attachment) {
3223
+ return block;
3224
+ }
3225
+ attachments.push(toObserverInputAttachmentPart(attachment));
3226
+ const placeholder = formatObserverAttachmentPlaceholder(attachment, counter);
3227
+ return { type: isRecord(block) ? block.type : void 0, placeholder };
3228
+ });
3229
+ if (attachments.length === 0) {
3230
+ return { resultWithoutAttachments: result, attachments };
3231
+ }
3232
+ return { resultWithoutAttachments: { ...record, value: newValue }, attachments };
3233
+ }
3168
3234
  function formatObserverPartLine(title, body, time, previousTime) {
3169
3235
  const timeLabel = time && time !== previousTime ? `(${time})` : "";
3170
3236
  if (!title) {
@@ -3254,9 +3320,19 @@ function formatObserverMessage(msg, counter, options) {
3254
3320
  part,
3255
3321
  inv.result
3256
3322
  );
3323
+ const { resultWithoutAttachments, attachments: extractedAttachments } = extractToolResultAttachments(
3324
+ resultForObserver,
3325
+ counter
3326
+ );
3327
+ if (extractedAttachments.length > 0) {
3328
+ attachments.push(...extractedAttachments);
3329
+ }
3257
3330
  pushLine(
3258
3331
  `Tool Result ${inv.toolName}`,
3259
- maybeTruncate(formatToolResultForObserver(resultForObserver, { maxTokens: maxToolResultTokens }), maxLen),
3332
+ maybeTruncate(
3333
+ formatToolResultForObserver(resultWithoutAttachments, { maxTokens: maxToolResultTokens }),
3334
+ maxLen
3335
+ ),
3260
3336
  partCreatedAt
3261
3337
  );
3262
3338
  return;
@@ -7351,6 +7427,9 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
7351
7427
  }
7352
7428
  const result = [];
7353
7429
  for (const msg of allMessages) {
7430
+ if (msg.role === "system") {
7431
+ continue;
7432
+ }
7354
7433
  if (observedMessageIds?.has(msg.id)) {
7355
7434
  continue;
7356
7435
  }
@@ -7661,7 +7740,7 @@ ${suggestedResponse}
7661
7740
  } : void 0
7662
7741
  });
7663
7742
  }
7664
- return result.messages;
7743
+ return result.messages.filter((msg) => msg.role !== "system");
7665
7744
  }
7666
7745
  /**
7667
7746
  * Format unobserved messages from other threads as <unobserved-context> blocks.
@@ -9398,5 +9477,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
9398
9477
  exports.stripObservationGroups = stripObservationGroups;
9399
9478
  exports.truncateStringByTokens = truncateStringByTokens;
9400
9479
  exports.wrapInObservationGroup = wrapInObservationGroup;
9401
- //# sourceMappingURL=chunk-UZDSNIGD.cjs.map
9402
- //# sourceMappingURL=chunk-UZDSNIGD.cjs.map
9480
+ //# sourceMappingURL=chunk-WNLFJKTX.cjs.map
9481
+ //# sourceMappingURL=chunk-WNLFJKTX.cjs.map