@mastra/observability 1.15.1 → 1.15.2-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.
package/dist/index.js CHANGED
@@ -1666,6 +1666,14 @@ function supportsModelInference() {
1666
1666
  function formatPreviewLabel(label, fallback) {
1667
1667
  return typeof label === "string" && label.length > 0 ? label : fallback;
1668
1668
  }
1669
+ function formatToolResultPreviewValue(value) {
1670
+ if (typeof value === "string") return value;
1671
+ if (value && typeof value === "object" && "type" in value && value.type === "text") {
1672
+ const textValue = value.value;
1673
+ if (typeof textValue === "string") return textValue;
1674
+ }
1675
+ return JSON.stringify(value);
1676
+ }
1669
1677
  function summarizePart(part) {
1670
1678
  if (typeof part === "string") {
1671
1679
  return part;
@@ -1694,7 +1702,7 @@ function summarizePart(part) {
1694
1702
  if ("function" in part && part.function && typeof part.function === "object") {
1695
1703
  return `[tool: ${formatPreviewLabel(part.function.name, "unknown")}]`;
1696
1704
  }
1697
- if ("toolName" in part) {
1705
+ if ("toolName" in part && !("type" in part && part.type === "tool-result")) {
1698
1706
  return `[tool: ${formatPreviewLabel(part.toolName, "unknown")}]`;
1699
1707
  }
1700
1708
  if ("type" in part && typeof part.type === "string") {
@@ -1707,8 +1715,15 @@ function summarizePart(part) {
1707
1715
  return "[reasoning]";
1708
1716
  case "tool-call":
1709
1717
  return `[tool: ${formatPreviewLabel(part.toolName, "unknown")}]`;
1710
- case "tool-result":
1711
- return "[tool-result]";
1718
+ case "tool-result": {
1719
+ const toolResult = part;
1720
+ const mastraMeta = toolResult.providerMetadata?.mastra ?? toolResult.providerOptions?.mastra;
1721
+ const toolName = formatPreviewLabel(part.toolName, "unknown");
1722
+ if (mastraMeta?.modelOutput !== void 0) {
1723
+ return formatToolResultPreviewValue(mastraMeta.modelOutput);
1724
+ }
1725
+ return `[tool-result: ${toolName}]`;
1726
+ }
1712
1727
  default:
1713
1728
  return `[${part.type}]`;
1714
1729
  }
@@ -2402,7 +2417,9 @@ var ModelSpanTracker = class {
2402
2417
  if (dynamic !== void 0) metadata.dynamic = dynamic;
2403
2418
  if (providerExecuted !== void 0) metadata.providerExecuted = providerExecuted;
2404
2419
  if (providerMetadata !== void 0) metadata.providerMetadata = providerMetadata;
2405
- this.#createEventSpan(chunk.type, providerExecuted ? result : void 0, { metadata });
2420
+ const mastraMeta = providerMetadata?.mastra;
2421
+ const spanOutput = providerExecuted ? result : mastraMeta?.modelOutput !== void 0 ? mastraMeta.modelOutput : void 0;
2422
+ this.#createEventSpan(chunk.type, spanOutput, { metadata });
2406
2423
  break;
2407
2424
  }
2408
2425
  }