@mastra/server 1.33.0-alpha.0 → 1.33.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.
@@ -1042,7 +1042,7 @@ function imageSize(input) {
1042
1042
  throw new TypeError(`unsupported file type: ${type}`);
1043
1043
  }
1044
1044
 
1045
- // ../memory/dist/chunk-BPJLUC2F.js
1045
+ // ../memory/dist/chunk-NUYSX3DD.js
1046
1046
  var OM_DEBUG_LOG = process.env.OM_DEBUG ? path.join(process.cwd(), "om-debug.log") : null;
1047
1047
  function omDebug(msg) {
1048
1048
  if (!OM_DEBUG_LOG) return;
@@ -4159,6 +4159,71 @@ function formatObserverAttachmentPlaceholder(part, counter) {
4159
4159
  const label = resolveObserverAttachmentLabel(part);
4160
4160
  return label ? `[${attachmentType} #${attachmentId}: ${label}]` : `[${attachmentType} #${attachmentId}]`;
4161
4161
  }
4162
+ function isRecord(value) {
4163
+ return !!value && typeof value === "object";
4164
+ }
4165
+ function mapToolResultBlockToAttachment(block) {
4166
+ if (!isRecord(block) || typeof block.type !== "string") {
4167
+ return void 0;
4168
+ }
4169
+ const mediaType = typeof block.mediaType === "string" ? block.mediaType : void 0;
4170
+ const filename = typeof block.filename === "string" ? block.filename : void 0;
4171
+ switch (block.type) {
4172
+ case "image-data": {
4173
+ const data = block.data;
4174
+ if (typeof data !== "string") return void 0;
4175
+ const image = mediaType ? `data:${mediaType};base64,${data}` : data;
4176
+ return { type: "image", image, mimeType: mediaType };
4177
+ }
4178
+ case "image-url": {
4179
+ const url = block.url;
4180
+ if (typeof url !== "string") return void 0;
4181
+ return { type: "image", image: url, mimeType: mediaType };
4182
+ }
4183
+ case "media": {
4184
+ const data = block.data;
4185
+ if (typeof data !== "string" || !mediaType) return void 0;
4186
+ const dataUri = `data:${mediaType};base64,${data}`;
4187
+ if (mediaType.toLowerCase().startsWith("image/")) {
4188
+ return { type: "image", image: dataUri, mimeType: mediaType };
4189
+ }
4190
+ return { type: "file", data: dataUri, mimeType: mediaType };
4191
+ }
4192
+ case "file-data": {
4193
+ const data = block.data;
4194
+ if (typeof data !== "string") return void 0;
4195
+ const dataUri = mediaType ? `data:${mediaType};base64,${data}` : data;
4196
+ return { type: "file", data: dataUri, mimeType: mediaType, filename };
4197
+ }
4198
+ case "file-url": {
4199
+ const url = block.url;
4200
+ if (typeof url !== "string") return void 0;
4201
+ return { type: "file", data: url, mimeType: mediaType, filename };
4202
+ }
4203
+ default:
4204
+ return void 0;
4205
+ }
4206
+ }
4207
+ function extractToolResultAttachments(result, counter) {
4208
+ if (!isRecord(result) || result.type !== "content" || !Array.isArray(result.value)) {
4209
+ return { resultWithoutAttachments: result, attachments: [] };
4210
+ }
4211
+ const record = result;
4212
+ const attachments = [];
4213
+ const newValue = record.value.map((block) => {
4214
+ const attachment = mapToolResultBlockToAttachment(block);
4215
+ if (!attachment) {
4216
+ return block;
4217
+ }
4218
+ attachments.push(toObserverInputAttachmentPart(attachment));
4219
+ const placeholder = formatObserverAttachmentPlaceholder(attachment, counter);
4220
+ return { type: isRecord(block) ? block.type : void 0, placeholder };
4221
+ });
4222
+ if (attachments.length === 0) {
4223
+ return { resultWithoutAttachments: result, attachments };
4224
+ }
4225
+ return { resultWithoutAttachments: { ...record, value: newValue }, attachments };
4226
+ }
4162
4227
  function formatObserverPartLine(title, body, time, previousTime) {
4163
4228
  const timeLabel = time && time !== previousTime ? `(${time})` : "";
4164
4229
  if (!title) {
@@ -4248,9 +4313,19 @@ function formatObserverMessage(msg, counter, options) {
4248
4313
  part,
4249
4314
  inv.result
4250
4315
  );
4316
+ const { resultWithoutAttachments, attachments: extractedAttachments } = extractToolResultAttachments(
4317
+ resultForObserver,
4318
+ counter
4319
+ );
4320
+ if (extractedAttachments.length > 0) {
4321
+ attachments.push(...extractedAttachments);
4322
+ }
4251
4323
  pushLine(
4252
4324
  `Tool Result ${inv.toolName}`,
4253
- maybeTruncate(formatToolResultForObserver(resultForObserver, { maxTokens: maxToolResultTokens }), maxLen),
4325
+ maybeTruncate(
4326
+ formatToolResultForObserver(resultWithoutAttachments, { maxTokens: maxToolResultTokens }),
4327
+ maxLen
4328
+ ),
4254
4329
  partCreatedAt
4255
4330
  );
4256
4331
  return;
@@ -10380,5 +10455,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
10380
10455
  exports.stripObservationGroups = stripObservationGroups;
10381
10456
  exports.truncateStringByTokens = truncateStringByTokens;
10382
10457
  exports.wrapInObservationGroup = wrapInObservationGroup;
10383
- //# sourceMappingURL=chunk-ZW7DMFEG.cjs.map
10384
- //# sourceMappingURL=chunk-ZW7DMFEG.cjs.map
10458
+ //# sourceMappingURL=chunk-BBX7Q7UG.cjs.map
10459
+ //# sourceMappingURL=chunk-BBX7Q7UG.cjs.map