@mastra/client-js 1.41.0-alpha.8 → 1.41.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
@@ -1389,13 +1389,22 @@ var Agent = class extends BaseResource {
1389
1389
  let currentTextPart = void 0;
1390
1390
  let currentReasoningPart = void 0;
1391
1391
  let currentReasoningTextDetail = void 0;
1392
- function updateToolInvocationPart(toolCallId, invocation) {
1392
+ function updateToolInvocationPart(toolCallId, invocation, partProviderMetadata) {
1393
1393
  const part = message.parts.find((part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId);
1394
- if (part != null) part.toolInvocation = invocation;
1395
- else message.parts.push({
1396
- type: "tool-invocation",
1397
- toolInvocation: invocation
1398
- });
1394
+ if (part != null) {
1395
+ part.toolInvocation = invocation;
1396
+ if (partProviderMetadata !== void 0) part.providerMetadata = {
1397
+ ...part.providerMetadata ?? {},
1398
+ ...partProviderMetadata
1399
+ };
1400
+ } else {
1401
+ const newPart = {
1402
+ type: "tool-invocation",
1403
+ toolInvocation: invocation
1404
+ };
1405
+ if (partProviderMetadata !== void 0) newPart.providerMetadata = partProviderMetadata;
1406
+ message.parts.push(newPart);
1407
+ }
1399
1408
  }
1400
1409
  const data = [];
1401
1410
  let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
@@ -1533,7 +1542,7 @@ var Agent = class extends BaseResource {
1533
1542
  if (message.toolInvocations == null) message.toolInvocations = [];
1534
1543
  message.toolInvocations.push(invocation);
1535
1544
  }
1536
- updateToolInvocationPart(value.toolCallId, invocation);
1545
+ updateToolInvocationPart(value.toolCallId, invocation, value.providerMetadata);
1537
1546
  execUpdate();
1538
1547
  if (onToolCall) {
1539
1548
  const result = await onToolCall({ toolCall: value });
@@ -1545,7 +1554,7 @@ var Agent = class extends BaseResource {
1545
1554
  result
1546
1555
  };
1547
1556
  message.toolInvocations[message.toolInvocations.length - 1] = invocation;
1548
- updateToolInvocationPart(value.toolCallId, invocation);
1557
+ updateToolInvocationPart(value.toolCallId, invocation, value.providerMetadata);
1549
1558
  execUpdate();
1550
1559
  }
1551
1560
  }
@@ -1561,7 +1570,7 @@ var Agent = class extends BaseResource {
1561
1570
  ...value
1562
1571
  };
1563
1572
  toolInvocations[toolInvocationIndex] = invocation;
1564
- updateToolInvocationPart(value.toolCallId, invocation);
1573
+ updateToolInvocationPart(value.toolCallId, invocation, value.providerMetadata);
1565
1574
  execUpdate();
1566
1575
  },
1567
1576
  onDataPart(value) {
@@ -1641,13 +1650,22 @@ var Agent = class extends BaseResource {
1641
1650
  let currentTextPart = void 0;
1642
1651
  let currentReasoningPart = void 0;
1643
1652
  let currentReasoningTextDetail = void 0;
1644
- function updateToolInvocationPart(toolCallId, invocation) {
1653
+ function updateToolInvocationPart(toolCallId, invocation, partProviderMetadata) {
1645
1654
  const part = message.parts.find((part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId);
1646
- if (part != null) part.toolInvocation = invocation;
1647
- else message.parts.push({
1648
- type: "tool-invocation",
1649
- toolInvocation: invocation
1650
- });
1655
+ if (part != null) {
1656
+ part.toolInvocation = invocation;
1657
+ if (partProviderMetadata !== void 0) part.providerMetadata = {
1658
+ ...part.providerMetadata ?? {},
1659
+ ...partProviderMetadata
1660
+ };
1661
+ } else {
1662
+ const newPart = {
1663
+ type: "tool-invocation",
1664
+ toolInvocation: invocation
1665
+ };
1666
+ if (partProviderMetadata !== void 0) newPart.providerMetadata = partProviderMetadata;
1667
+ message.parts.push(newPart);
1668
+ }
1651
1669
  }
1652
1670
  const data = [];
1653
1671
  let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
@@ -1743,7 +1761,7 @@ var Agent = class extends BaseResource {
1743
1761
  if (message.toolInvocations == null) message.toolInvocations = [];
1744
1762
  message.toolInvocations.push(invocation);
1745
1763
  }
1746
- updateToolInvocationPart(chunk.payload.toolCallId, invocation);
1764
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation, chunk.payload.providerMetadata);
1747
1765
  execUpdate();
1748
1766
  if (onToolCall) {
1749
1767
  const result = await onToolCall({ toolCall: chunk.payload });
@@ -1755,7 +1773,7 @@ var Agent = class extends BaseResource {
1755
1773
  result
1756
1774
  };
1757
1775
  message.toolInvocations[message.toolInvocations.length - 1] = invocation;
1758
- updateToolInvocationPart(chunk.payload.toolCallId, invocation);
1776
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation, chunk.payload.providerMetadata);
1759
1777
  execUpdate();
1760
1778
  }
1761
1779
  }
@@ -1812,7 +1830,7 @@ var Agent = class extends BaseResource {
1812
1830
  ...chunk.payload
1813
1831
  };
1814
1832
  toolInvocations[toolInvocationIndex] = invocation;
1815
- updateToolInvocationPart(chunk.payload.toolCallId, invocation);
1833
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation, chunk.payload.providerMetadata);
1816
1834
  execUpdate();
1817
1835
  break;
1818
1836
  }
@@ -5630,22 +5648,29 @@ const KNOWN_AGENT_CONTROLLER_EVENT_TYPES = new Set(Object.keys({
5630
5648
  message_start: true,
5631
5649
  message_update: true,
5632
5650
  message_end: true,
5651
+ state_changed: true,
5633
5652
  tool_input_start: true,
5634
5653
  tool_input_delta: true,
5635
5654
  tool_input_end: true,
5636
5655
  tool_start: true,
5637
5656
  tool_update: true,
5638
5657
  shell_output: true,
5658
+ command_exit: true,
5639
5659
  tool_end: true,
5640
5660
  tool_approval_required: true,
5641
5661
  tool_suspended: true,
5662
+ tool_suspension_cancelled: true,
5642
5663
  mode_changed: true,
5643
5664
  model_changed: true,
5644
5665
  thread_changed: true,
5645
5666
  thread_created: true,
5646
5667
  thread_deleted: true,
5647
5668
  subagent_start: true,
5669
+ subagent_text_delta: true,
5670
+ subagent_tool_start: true,
5671
+ subagent_tool_end: true,
5648
5672
  subagent_end: true,
5673
+ subagent_model_changed: true,
5649
5674
  task_updated: true,
5650
5675
  notification: true,
5651
5676
  notification_summary: true,
@@ -5676,19 +5701,42 @@ const KNOWN_AGENT_CONTROLLER_EVENT_TYPES = new Set(Object.keys({
5676
5701
  function isKnownAgentControllerEvent(event) {
5677
5702
  return KNOWN_AGENT_CONTROLLER_EVENT_TYPES.has(event.type);
5678
5703
  }
5704
+ const toDate = (value) => value instanceof Date ? value : new Date(value);
5679
5705
  function hydrateMessage(message) {
5680
5706
  return {
5681
5707
  ...message,
5682
- createdAt: message.createdAt instanceof Date ? message.createdAt : new Date(message.createdAt)
5708
+ createdAt: toDate(message.createdAt)
5683
5709
  };
5684
5710
  }
5685
- function hydrateEventMessage(event) {
5686
- if (event.type !== "message_start" && event.type !== "message_update" && event.type !== "message_end") return event;
5711
+ function hydrateThread(thread) {
5687
5712
  return {
5688
- ...event,
5689
- message: hydrateMessage(event.message)
5713
+ ...thread,
5714
+ createdAt: toDate(thread.createdAt),
5715
+ updatedAt: toDate(thread.updatedAt)
5690
5716
  };
5691
5717
  }
5718
+ function isKnownParsedEvent(event) {
5719
+ return KNOWN_AGENT_CONTROLLER_EVENT_TYPES.has(event.type);
5720
+ }
5721
+ /** The stream carries every timestamp as an ISO string; give consumers back the `Date`s {@link Hydrated} promises. */
5722
+ function hydrateKnownEvent(event) {
5723
+ switch (event.type) {
5724
+ case "message_start":
5725
+ case "message_update":
5726
+ case "message_end": return {
5727
+ ...event,
5728
+ message: hydrateMessage(event.message)
5729
+ };
5730
+ case "thread_created": return {
5731
+ ...event,
5732
+ thread: hydrateThread(event.thread)
5733
+ };
5734
+ default: return event;
5735
+ }
5736
+ }
5737
+ function hydrateEventTimestamps(event) {
5738
+ return isKnownParsedEvent(event) ? hydrateKnownEvent(event) : event;
5739
+ }
5692
5740
  /**
5693
5741
  * A session bound to a `resourceId` within one agent controller. Sessions are
5694
5742
  * get-or-create on the server, so re-creating the same resourceId (and scope)
@@ -5820,7 +5868,7 @@ var AgentControllerSession = class extends BaseResource {
5820
5868
  if (!data) continue;
5821
5869
  let event;
5822
5870
  try {
5823
- event = hydrateEventMessage(JSON.parse(data));
5871
+ event = hydrateEventTimestamps(JSON.parse(data));
5824
5872
  } catch {
5825
5873
  continue;
5826
5874
  }