@mastra/client-js 1.40.1-alpha.7 → 1.41.0-alpha.11

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
@@ -860,6 +860,15 @@ var Agent = class extends BaseResource {
860
860
  return this.request(`/agents/${this.agentId}${this.getQueryString(requestContext)}`);
861
861
  }
862
862
  /**
863
+ * Reads a markdown plan submitted by this agent through the core submit_plan tool.
864
+ * The server only serves paths under `.mastracode/plans/` and only when the
865
+ * agent exposes that capability.
866
+ */
867
+ readPlan(path, requestContext) {
868
+ const contextQuery = this.getQueryString(requestContext, "&");
869
+ return this.request(`/agents/${this.agentId}/plans/file?path=${encodeURIComponent(path)}${contextQuery}`);
870
+ }
871
+ /**
863
872
  * Probe the agent's browser session state before opening a screencast WebSocket.
864
873
  *
865
874
  * Returns `{ hasSession, screencastAvailable }`. Use this to avoid opening a WS
@@ -1380,13 +1389,22 @@ var Agent = class extends BaseResource {
1380
1389
  let currentTextPart = void 0;
1381
1390
  let currentReasoningPart = void 0;
1382
1391
  let currentReasoningTextDetail = void 0;
1383
- function updateToolInvocationPart(toolCallId, invocation) {
1392
+ function updateToolInvocationPart(toolCallId, invocation, partProviderMetadata) {
1384
1393
  const part = message.parts.find((part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId);
1385
- if (part != null) part.toolInvocation = invocation;
1386
- else message.parts.push({
1387
- type: "tool-invocation",
1388
- toolInvocation: invocation
1389
- });
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
+ }
1390
1408
  }
1391
1409
  const data = [];
1392
1410
  let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
@@ -1524,7 +1542,7 @@ var Agent = class extends BaseResource {
1524
1542
  if (message.toolInvocations == null) message.toolInvocations = [];
1525
1543
  message.toolInvocations.push(invocation);
1526
1544
  }
1527
- updateToolInvocationPart(value.toolCallId, invocation);
1545
+ updateToolInvocationPart(value.toolCallId, invocation, value.providerMetadata);
1528
1546
  execUpdate();
1529
1547
  if (onToolCall) {
1530
1548
  const result = await onToolCall({ toolCall: value });
@@ -1536,7 +1554,7 @@ var Agent = class extends BaseResource {
1536
1554
  result
1537
1555
  };
1538
1556
  message.toolInvocations[message.toolInvocations.length - 1] = invocation;
1539
- updateToolInvocationPart(value.toolCallId, invocation);
1557
+ updateToolInvocationPart(value.toolCallId, invocation, value.providerMetadata);
1540
1558
  execUpdate();
1541
1559
  }
1542
1560
  }
@@ -1552,7 +1570,7 @@ var Agent = class extends BaseResource {
1552
1570
  ...value
1553
1571
  };
1554
1572
  toolInvocations[toolInvocationIndex] = invocation;
1555
- updateToolInvocationPart(value.toolCallId, invocation);
1573
+ updateToolInvocationPart(value.toolCallId, invocation, value.providerMetadata);
1556
1574
  execUpdate();
1557
1575
  },
1558
1576
  onDataPart(value) {
@@ -1632,13 +1650,22 @@ var Agent = class extends BaseResource {
1632
1650
  let currentTextPart = void 0;
1633
1651
  let currentReasoningPart = void 0;
1634
1652
  let currentReasoningTextDetail = void 0;
1635
- function updateToolInvocationPart(toolCallId, invocation) {
1653
+ function updateToolInvocationPart(toolCallId, invocation, partProviderMetadata) {
1636
1654
  const part = message.parts.find((part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId);
1637
- if (part != null) part.toolInvocation = invocation;
1638
- else message.parts.push({
1639
- type: "tool-invocation",
1640
- toolInvocation: invocation
1641
- });
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
+ }
1642
1669
  }
1643
1670
  const data = [];
1644
1671
  let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
@@ -1734,7 +1761,7 @@ var Agent = class extends BaseResource {
1734
1761
  if (message.toolInvocations == null) message.toolInvocations = [];
1735
1762
  message.toolInvocations.push(invocation);
1736
1763
  }
1737
- updateToolInvocationPart(chunk.payload.toolCallId, invocation);
1764
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation, chunk.payload.providerMetadata);
1738
1765
  execUpdate();
1739
1766
  if (onToolCall) {
1740
1767
  const result = await onToolCall({ toolCall: chunk.payload });
@@ -1746,7 +1773,7 @@ var Agent = class extends BaseResource {
1746
1773
  result
1747
1774
  };
1748
1775
  message.toolInvocations[message.toolInvocations.length - 1] = invocation;
1749
- updateToolInvocationPart(chunk.payload.toolCallId, invocation);
1776
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation, chunk.payload.providerMetadata);
1750
1777
  execUpdate();
1751
1778
  }
1752
1779
  }
@@ -1803,7 +1830,7 @@ var Agent = class extends BaseResource {
1803
1830
  ...chunk.payload
1804
1831
  };
1805
1832
  toolInvocations[toolInvocationIndex] = invocation;
1806
- updateToolInvocationPart(chunk.payload.toolCallId, invocation);
1833
+ updateToolInvocationPart(chunk.payload.toolCallId, invocation, chunk.payload.providerMetadata);
1807
1834
  execUpdate();
1808
1835
  break;
1809
1836
  }
@@ -5621,22 +5648,29 @@ const KNOWN_AGENT_CONTROLLER_EVENT_TYPES = new Set(Object.keys({
5621
5648
  message_start: true,
5622
5649
  message_update: true,
5623
5650
  message_end: true,
5651
+ state_changed: true,
5624
5652
  tool_input_start: true,
5625
5653
  tool_input_delta: true,
5626
5654
  tool_input_end: true,
5627
5655
  tool_start: true,
5628
5656
  tool_update: true,
5629
5657
  shell_output: true,
5658
+ command_exit: true,
5630
5659
  tool_end: true,
5631
5660
  tool_approval_required: true,
5632
5661
  tool_suspended: true,
5662
+ tool_suspension_cancelled: true,
5633
5663
  mode_changed: true,
5634
5664
  model_changed: true,
5635
5665
  thread_changed: true,
5636
5666
  thread_created: true,
5637
5667
  thread_deleted: true,
5638
5668
  subagent_start: true,
5669
+ subagent_text_delta: true,
5670
+ subagent_tool_start: true,
5671
+ subagent_tool_end: true,
5639
5672
  subagent_end: true,
5673
+ subagent_model_changed: true,
5640
5674
  task_updated: true,
5641
5675
  notification: true,
5642
5676
  notification_summary: true,
@@ -5667,19 +5701,37 @@ const KNOWN_AGENT_CONTROLLER_EVENT_TYPES = new Set(Object.keys({
5667
5701
  function isKnownAgentControllerEvent(event) {
5668
5702
  return KNOWN_AGENT_CONTROLLER_EVENT_TYPES.has(event.type);
5669
5703
  }
5704
+ const toDate = (value) => value instanceof Date ? value : new Date(value);
5670
5705
  function hydrateMessage(message) {
5671
5706
  return {
5672
5707
  ...message,
5673
- createdAt: message.createdAt instanceof Date ? message.createdAt : new Date(message.createdAt)
5708
+ createdAt: toDate(message.createdAt)
5674
5709
  };
5675
5710
  }
5676
- function hydrateEventMessage(event) {
5677
- if (event.type !== "message_start" && event.type !== "message_update" && event.type !== "message_end") return event;
5711
+ function hydrateThread(thread) {
5678
5712
  return {
5679
- ...event,
5680
- message: hydrateMessage(event.message)
5713
+ ...thread,
5714
+ createdAt: toDate(thread.createdAt),
5715
+ updatedAt: toDate(thread.updatedAt)
5681
5716
  };
5682
5717
  }
5718
+ /** The stream carries every timestamp as an ISO string; give consumers back the `Date`s the type promises. */
5719
+ function hydrateEventTimestamps(event) {
5720
+ if (!isKnownAgentControllerEvent(event)) return event;
5721
+ switch (event.type) {
5722
+ case "message_start":
5723
+ case "message_update":
5724
+ case "message_end": return {
5725
+ ...event,
5726
+ message: hydrateMessage(event.message)
5727
+ };
5728
+ case "thread_created": return {
5729
+ ...event,
5730
+ thread: hydrateThread(event.thread)
5731
+ };
5732
+ default: return event;
5733
+ }
5734
+ }
5683
5735
  /**
5684
5736
  * A session bound to a `resourceId` within one agent controller. Sessions are
5685
5737
  * get-or-create on the server, so re-creating the same resourceId (and scope)
@@ -5811,7 +5863,7 @@ var AgentControllerSession = class extends BaseResource {
5811
5863
  if (!data) continue;
5812
5864
  let event;
5813
5865
  try {
5814
- event = hydrateEventMessage(JSON.parse(data));
5866
+ event = hydrateEventTimestamps(JSON.parse(data));
5815
5867
  } catch {
5816
5868
  continue;
5817
5869
  }
@@ -5965,8 +6017,9 @@ var AgentControllerSession = class extends BaseResource {
5965
6017
  });
5966
6018
  }
5967
6019
  /** Get the current mode, model, and thread (for initial UI hydration). */
5968
- state() {
5969
- return this.request(this.url(this.base()));
6020
+ state(options) {
6021
+ const path = options?.threadId ? `${this.base()}?threadId=${encodeURIComponent(options.threadId)}` : this.base();
6022
+ return this.request(this.url(path));
5970
6023
  }
5971
6024
  /** Merge key-value pairs into the session state. Existing keys not in the payload are preserved. */
5972
6025
  async setState(updates) {