@mastra/server 1.33.0-alpha.0 → 1.33.0-alpha.2

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.
@@ -1040,7 +1040,7 @@ function imageSize(input) {
1040
1040
  throw new TypeError(`unsupported file type: ${type}`);
1041
1041
  }
1042
1042
 
1043
- // ../memory/dist/chunk-BPJLUC2F.js
1043
+ // ../memory/dist/chunk-NUYSX3DD.js
1044
1044
  var OM_DEBUG_LOG = process.env.OM_DEBUG ? join(process.cwd(), "om-debug.log") : null;
1045
1045
  function omDebug(msg) {
1046
1046
  if (!OM_DEBUG_LOG) return;
@@ -4157,6 +4157,71 @@ function formatObserverAttachmentPlaceholder(part, counter) {
4157
4157
  const label = resolveObserverAttachmentLabel(part);
4158
4158
  return label ? `[${attachmentType} #${attachmentId}: ${label}]` : `[${attachmentType} #${attachmentId}]`;
4159
4159
  }
4160
+ function isRecord(value) {
4161
+ return !!value && typeof value === "object";
4162
+ }
4163
+ function mapToolResultBlockToAttachment(block) {
4164
+ if (!isRecord(block) || typeof block.type !== "string") {
4165
+ return void 0;
4166
+ }
4167
+ const mediaType = typeof block.mediaType === "string" ? block.mediaType : void 0;
4168
+ const filename = typeof block.filename === "string" ? block.filename : void 0;
4169
+ switch (block.type) {
4170
+ case "image-data": {
4171
+ const data = block.data;
4172
+ if (typeof data !== "string") return void 0;
4173
+ const image = mediaType ? `data:${mediaType};base64,${data}` : data;
4174
+ return { type: "image", image, mimeType: mediaType };
4175
+ }
4176
+ case "image-url": {
4177
+ const url = block.url;
4178
+ if (typeof url !== "string") return void 0;
4179
+ return { type: "image", image: url, mimeType: mediaType };
4180
+ }
4181
+ case "media": {
4182
+ const data = block.data;
4183
+ if (typeof data !== "string" || !mediaType) return void 0;
4184
+ const dataUri = `data:${mediaType};base64,${data}`;
4185
+ if (mediaType.toLowerCase().startsWith("image/")) {
4186
+ return { type: "image", image: dataUri, mimeType: mediaType };
4187
+ }
4188
+ return { type: "file", data: dataUri, mimeType: mediaType };
4189
+ }
4190
+ case "file-data": {
4191
+ const data = block.data;
4192
+ if (typeof data !== "string") return void 0;
4193
+ const dataUri = mediaType ? `data:${mediaType};base64,${data}` : data;
4194
+ return { type: "file", data: dataUri, mimeType: mediaType, filename };
4195
+ }
4196
+ case "file-url": {
4197
+ const url = block.url;
4198
+ if (typeof url !== "string") return void 0;
4199
+ return { type: "file", data: url, mimeType: mediaType, filename };
4200
+ }
4201
+ default:
4202
+ return void 0;
4203
+ }
4204
+ }
4205
+ function extractToolResultAttachments(result, counter) {
4206
+ if (!isRecord(result) || result.type !== "content" || !Array.isArray(result.value)) {
4207
+ return { resultWithoutAttachments: result, attachments: [] };
4208
+ }
4209
+ const record = result;
4210
+ const attachments = [];
4211
+ const newValue = record.value.map((block) => {
4212
+ const attachment = mapToolResultBlockToAttachment(block);
4213
+ if (!attachment) {
4214
+ return block;
4215
+ }
4216
+ attachments.push(toObserverInputAttachmentPart(attachment));
4217
+ const placeholder = formatObserverAttachmentPlaceholder(attachment, counter);
4218
+ return { type: isRecord(block) ? block.type : void 0, placeholder };
4219
+ });
4220
+ if (attachments.length === 0) {
4221
+ return { resultWithoutAttachments: result, attachments };
4222
+ }
4223
+ return { resultWithoutAttachments: { ...record, value: newValue }, attachments };
4224
+ }
4160
4225
  function formatObserverPartLine(title, body, time, previousTime) {
4161
4226
  const timeLabel = time && time !== previousTime ? `(${time})` : "";
4162
4227
  if (!title) {
@@ -4246,9 +4311,19 @@ function formatObserverMessage(msg, counter, options) {
4246
4311
  part,
4247
4312
  inv.result
4248
4313
  );
4314
+ const { resultWithoutAttachments, attachments: extractedAttachments } = extractToolResultAttachments(
4315
+ resultForObserver,
4316
+ counter
4317
+ );
4318
+ if (extractedAttachments.length > 0) {
4319
+ attachments.push(...extractedAttachments);
4320
+ }
4249
4321
  pushLine(
4250
4322
  `Tool Result ${inv.toolName}`,
4251
- maybeTruncate(formatToolResultForObserver(resultForObserver, { maxTokens: maxToolResultTokens }), maxLen),
4323
+ maybeTruncate(
4324
+ formatToolResultForObserver(resultWithoutAttachments, { maxTokens: maxToolResultTokens }),
4325
+ maxLen
4326
+ ),
4252
4327
  partCreatedAt
4253
4328
  );
4254
4329
  return;
@@ -10351,5 +10426,5 @@ function getObservationsAsOf(activeObservations, asOf) {
10351
10426
  }
10352
10427
 
10353
10428
  export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, e, estimateTokenCount, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
10354
- //# sourceMappingURL=chunk-4HRTLLE6.js.map
10355
- //# sourceMappingURL=chunk-4HRTLLE6.js.map
10429
+ //# sourceMappingURL=chunk-S65AMBAF.js.map
10430
+ //# sourceMappingURL=chunk-S65AMBAF.js.map