@mastra/memory 1.17.5 → 1.17.6-alpha.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.
@@ -3165,6 +3165,71 @@ function formatObserverAttachmentPlaceholder(part, counter) {
3165
3165
  const label = resolveObserverAttachmentLabel(part);
3166
3166
  return label ? `[${attachmentType} #${attachmentId}: ${label}]` : `[${attachmentType} #${attachmentId}]`;
3167
3167
  }
3168
+ function isRecord(value) {
3169
+ return !!value && typeof value === "object";
3170
+ }
3171
+ function mapToolResultBlockToAttachment(block) {
3172
+ if (!isRecord(block) || typeof block.type !== "string") {
3173
+ return void 0;
3174
+ }
3175
+ const mediaType = typeof block.mediaType === "string" ? block.mediaType : void 0;
3176
+ const filename = typeof block.filename === "string" ? block.filename : void 0;
3177
+ switch (block.type) {
3178
+ case "image-data": {
3179
+ const data = block.data;
3180
+ if (typeof data !== "string") return void 0;
3181
+ const image = mediaType ? `data:${mediaType};base64,${data}` : data;
3182
+ return { type: "image", image, mimeType: mediaType };
3183
+ }
3184
+ case "image-url": {
3185
+ const url = block.url;
3186
+ if (typeof url !== "string") return void 0;
3187
+ return { type: "image", image: url, mimeType: mediaType };
3188
+ }
3189
+ case "media": {
3190
+ const data = block.data;
3191
+ if (typeof data !== "string" || !mediaType) return void 0;
3192
+ const dataUri = `data:${mediaType};base64,${data}`;
3193
+ if (mediaType.toLowerCase().startsWith("image/")) {
3194
+ return { type: "image", image: dataUri, mimeType: mediaType };
3195
+ }
3196
+ return { type: "file", data: dataUri, mimeType: mediaType };
3197
+ }
3198
+ case "file-data": {
3199
+ const data = block.data;
3200
+ if (typeof data !== "string") return void 0;
3201
+ const dataUri = mediaType ? `data:${mediaType};base64,${data}` : data;
3202
+ return { type: "file", data: dataUri, mimeType: mediaType, filename };
3203
+ }
3204
+ case "file-url": {
3205
+ const url = block.url;
3206
+ if (typeof url !== "string") return void 0;
3207
+ return { type: "file", data: url, mimeType: mediaType, filename };
3208
+ }
3209
+ default:
3210
+ return void 0;
3211
+ }
3212
+ }
3213
+ function extractToolResultAttachments(result, counter) {
3214
+ if (!isRecord(result) || result.type !== "content" || !Array.isArray(result.value)) {
3215
+ return { resultWithoutAttachments: result, attachments: [] };
3216
+ }
3217
+ const record = result;
3218
+ const attachments = [];
3219
+ const newValue = record.value.map((block) => {
3220
+ const attachment = mapToolResultBlockToAttachment(block);
3221
+ if (!attachment) {
3222
+ return block;
3223
+ }
3224
+ attachments.push(toObserverInputAttachmentPart(attachment));
3225
+ const placeholder = formatObserverAttachmentPlaceholder(attachment, counter);
3226
+ return { type: isRecord(block) ? block.type : void 0, placeholder };
3227
+ });
3228
+ if (attachments.length === 0) {
3229
+ return { resultWithoutAttachments: result, attachments };
3230
+ }
3231
+ return { resultWithoutAttachments: { ...record, value: newValue }, attachments };
3232
+ }
3168
3233
  function formatObserverPartLine(title, body, time, previousTime) {
3169
3234
  const timeLabel = time && time !== previousTime ? `(${time})` : "";
3170
3235
  if (!title) {
@@ -3254,9 +3319,19 @@ function formatObserverMessage(msg, counter, options) {
3254
3319
  part,
3255
3320
  inv.result
3256
3321
  );
3322
+ const { resultWithoutAttachments, attachments: extractedAttachments } = extractToolResultAttachments(
3323
+ resultForObserver,
3324
+ counter
3325
+ );
3326
+ if (extractedAttachments.length > 0) {
3327
+ attachments.push(...extractedAttachments);
3328
+ }
3257
3329
  pushLine(
3258
3330
  `Tool Result ${inv.toolName}`,
3259
- maybeTruncate(formatToolResultForObserver(resultForObserver, { maxTokens: maxToolResultTokens }), maxLen),
3331
+ maybeTruncate(
3332
+ formatToolResultForObserver(resultWithoutAttachments, { maxTokens: maxToolResultTokens }),
3333
+ maxLen
3334
+ ),
3260
3335
  partCreatedAt
3261
3336
  );
3262
3337
  return;
@@ -9398,5 +9473,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
9398
9473
  exports.stripObservationGroups = stripObservationGroups;
9399
9474
  exports.truncateStringByTokens = truncateStringByTokens;
9400
9475
  exports.wrapInObservationGroup = wrapInObservationGroup;
9401
- //# sourceMappingURL=chunk-UZDSNIGD.cjs.map
9402
- //# sourceMappingURL=chunk-UZDSNIGD.cjs.map
9476
+ //# sourceMappingURL=chunk-ZUUSLGY6.cjs.map
9477
+ //# sourceMappingURL=chunk-ZUUSLGY6.cjs.map