@mastra/react 0.0.0-netlify-no-bundle-20251127120354 → 0.0.0-new-button-export-20251219130424

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
@@ -47,7 +47,7 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
47
47
  return {
48
48
  ...prev,
49
49
  status: chunk.payload.workflowStatus,
50
- ...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : {}
50
+ ...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : finalStatus === "tripwire" && chunk.payload.tripwire ? { tripwire: chunk.payload.tripwire } : {}
51
51
  };
52
52
  }
53
53
  const { stepCallId, stepName, ...newPayload } = chunk.payload ?? {};
@@ -99,6 +99,34 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
99
99
  };
100
100
  const toUIMessage = ({ chunk, conversation, metadata }) => {
101
101
  const result = [...conversation];
102
+ if (chunk.type.startsWith("data-")) {
103
+ const lastMessage = result[result.length - 1];
104
+ if (!lastMessage || lastMessage.role !== "assistant") {
105
+ const newMessage = {
106
+ id: `data-${chunk.runId}-${Date.now()}`,
107
+ role: "assistant",
108
+ parts: [
109
+ {
110
+ type: chunk.type,
111
+ data: "data" in chunk ? chunk.data : void 0
112
+ }
113
+ ],
114
+ metadata
115
+ };
116
+ return [...result, newMessage];
117
+ }
118
+ const updatedMessage = {
119
+ ...lastMessage,
120
+ parts: [
121
+ ...lastMessage.parts,
122
+ {
123
+ type: chunk.type,
124
+ data: "data" in chunk ? chunk.data : void 0
125
+ }
126
+ ]
127
+ };
128
+ return [...result.slice(0, -1), updatedMessage];
129
+ }
102
130
  switch (chunk.type) {
103
131
  case "tripwire": {
104
132
  const newMessage = {
@@ -107,19 +135,24 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
107
135
  parts: [
108
136
  {
109
137
  type: "text",
110
- text: chunk.payload.tripwireReason
138
+ text: chunk.payload.reason
111
139
  }
112
140
  ],
113
141
  metadata: {
114
142
  ...metadata,
115
- status: "warning"
143
+ status: "tripwire",
144
+ tripwire: {
145
+ retry: chunk.payload.retry,
146
+ tripwirePayload: chunk.payload.metadata,
147
+ processorId: chunk.payload.processorId
148
+ }
116
149
  }
117
150
  };
118
151
  return [...result, newMessage];
119
152
  }
120
153
  case "start": {
121
154
  const newMessage = {
122
- id: `start-${chunk.runId + Date.now()}`,
155
+ id: typeof chunk.payload.messageId === "string" ? chunk.payload.messageId : `start-${chunk.runId + Date.now()}`,
123
156
  role: "assistant",
124
157
  parts: [],
125
158
  metadata
@@ -424,7 +457,7 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
424
457
  mode: "stream",
425
458
  requireApprovalMetadata: {
426
459
  ...lastRequireApprovalMetadata,
427
- [chunk.payload.toolCallId]: {
460
+ [chunk.payload.toolName]: {
428
461
  toolCallId: chunk.payload.toolCallId,
429
462
  toolName: chunk.payload.toolName,
430
463
  args: chunk.payload.args
@@ -434,6 +467,30 @@ const toUIMessage = ({ chunk, conversation, metadata }) => {
434
467
  }
435
468
  ];
436
469
  }
470
+ case "tool-call-suspended": {
471
+ const lastMessage = result[result.length - 1];
472
+ if (!lastMessage || lastMessage.role !== "assistant") return result;
473
+ const lastSuspendedTools = lastMessage.metadata?.mode === "stream" ? lastMessage.metadata?.suspendedTools : {};
474
+ return [
475
+ ...result.slice(0, -1),
476
+ {
477
+ ...lastMessage,
478
+ metadata: {
479
+ ...lastMessage.metadata,
480
+ mode: "stream",
481
+ suspendedTools: {
482
+ ...lastSuspendedTools,
483
+ [chunk.payload.toolName]: {
484
+ toolCallId: chunk.payload.toolCallId,
485
+ toolName: chunk.payload.toolName,
486
+ args: chunk.payload.args,
487
+ suspendPayload: chunk.payload.suspendPayload
488
+ }
489
+ }
490
+ }
491
+ }
492
+ ];
493
+ }
437
494
  case "finish": {
438
495
  const lastMessage = result[result.length - 1];
439
496
  if (!lastMessage || lastMessage.role !== "assistant") return result;
@@ -649,13 +706,14 @@ const toAssistantUIMessage = (message) => {
649
706
  return baseToolCall;
650
707
  }
651
708
  if (part.type.startsWith("tool-") && part.state !== "input-available") {
652
- const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.substring(5);
709
+ const toolName2 = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.substring(5);
710
+ const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
653
711
  const baseToolCall = {
654
712
  type: "tool-call",
655
713
  toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
656
- toolName,
657
- argsText: "input" in part ? JSON.stringify(part.input) : "{}",
658
- args: "input" in part ? part.input : {},
714
+ toolName: toolName2,
715
+ argsText: JSON.stringify(cleanInput ?? {}),
716
+ args: cleanInput ?? {},
659
717
  metadata: message.metadata
660
718
  };
661
719
  if ("output" in part) {
@@ -665,20 +723,31 @@ const toAssistantUIMessage = (message) => {
665
723
  }
666
724
  return baseToolCall;
667
725
  }
726
+ const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
668
727
  const requireApprovalMetadata = extendedMessage.metadata?.requireApprovalMetadata;
728
+ const suspendedTools = extendedMessage.metadata?.suspendedTools;
669
729
  const partToolCallId = "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : void 0;
670
- const suspensionData = partToolCallId ? requireApprovalMetadata?.[partToolCallId] : void 0;
730
+ const suspensionData = toolName ? requireApprovalMetadata?.[toolName] ?? suspendedTools?.[toolName] : void 0;
671
731
  if (suspensionData) {
672
- const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.startsWith("tool-") ? part.type.substring(5) : "";
732
+ const { suspendedToolRunId, ...cleanInput } = "input" in part ? part.input : {};
673
733
  return {
674
734
  type: "tool-call",
675
735
  toolCallId: partToolCallId,
676
736
  toolName,
677
- argsText: "input" in part ? JSON.stringify(part.input) : "{}",
678
- args: "input" in part ? part.input : {},
737
+ argsText: JSON.stringify(cleanInput ?? {}),
738
+ args: cleanInput,
679
739
  metadata: extendedMessage.metadata
680
740
  };
681
741
  }
742
+ if (part.type.startsWith("data-")) {
743
+ return {
744
+ type: "data",
745
+ name: part.type.substring(5),
746
+ // Extract name from 'data-{name}'
747
+ data: part.data,
748
+ metadata: message.metadata
749
+ };
750
+ }
682
751
  return {
683
752
  type: "text",
684
753
  text: "",
@@ -731,28 +800,34 @@ const resolveInitialMessages = (messages) => {
731
800
  const primitiveType = json.primitiveType || "";
732
801
  const primitiveId = json.primitiveId || "";
733
802
  const finalResult = json.finalResult;
734
- const toolCalls = finalResult?.toolCalls || [];
803
+ const messages2 = finalResult?.messages || [];
735
804
  const childMessages = [];
736
- for (const toolCall of toolCalls) {
737
- if (toolCall.type === "tool-call" && toolCall.payload) {
738
- const toolCallId = toolCall.payload.toolCallId;
739
- let toolResult;
740
- for (const message2 of finalResult?.messages || []) {
741
- for (const part of message2.content || []) {
742
- if (typeof part === "object" && part.type === "tool-result" && part.toolCallId === toolCallId) {
743
- toolResult = part;
744
- break;
745
- }
805
+ const toolResultMap = /* @__PURE__ */ new Map();
806
+ for (const msg of messages2) {
807
+ if (Array.isArray(msg.content)) {
808
+ for (const part of msg.content) {
809
+ if (typeof part === "object" && part.type === "tool-result") {
810
+ toolResultMap.set(part.toolCallId, part);
811
+ }
812
+ }
813
+ }
814
+ }
815
+ for (const msg of messages2) {
816
+ if (msg.type === "tool-call" && Array.isArray(msg.content)) {
817
+ for (const part of msg.content) {
818
+ if (typeof part === "object" && part.type === "tool-call") {
819
+ const toolCallContent = part;
820
+ const toolResult = toolResultMap.get(toolCallContent.toolCallId);
821
+ const isWorkflow = Boolean(toolResult?.result?.result?.steps);
822
+ childMessages.push({
823
+ type: "tool",
824
+ toolCallId: toolCallContent.toolCallId,
825
+ toolName: toolCallContent.toolName,
826
+ args: toolCallContent.args,
827
+ toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
828
+ });
746
829
  }
747
830
  }
748
- const isWorkflow = Boolean(toolResult?.result?.result?.steps);
749
- childMessages.push({
750
- type: "tool",
751
- toolCallId: toolCall.payload.toolCallId,
752
- toolName: toolCall.payload.toolName,
753
- args: toolCall.payload.args,
754
- toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
755
- });
756
831
  }
757
832
  }
758
833
  if (finalResult && finalResult.text) {
@@ -804,6 +879,17 @@ const resolveInitialMessages = (messages) => {
804
879
  }
805
880
  };
806
881
  }
882
+ const suspendedTools = extendedMessage.metadata?.suspendedTools;
883
+ if (suspendedTools && typeof suspendedTools === "object") {
884
+ return {
885
+ ...message,
886
+ metadata: {
887
+ ...message.metadata,
888
+ mode: "stream",
889
+ suspendedTools
890
+ }
891
+ };
892
+ }
807
893
  return message;
808
894
  });
809
895
  };
@@ -1279,7 +1365,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
1279
1365
  threadId,
1280
1366
  modelSettings,
1281
1367
  signal,
1282
- onFinish
1368
+ onFinish,
1369
+ tracingOptions
1283
1370
  }) => {
1284
1371
  const {
1285
1372
  frequencyPenalty,
@@ -1315,7 +1402,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
1315
1402
  instructions,
1316
1403
  requestContext,
1317
1404
  ...threadId ? { threadId, resourceId: resourceId || agentId } : {},
1318
- providerOptions
1405
+ providerOptions,
1406
+ tracingOptions
1319
1407
  });
1320
1408
  setIsRunning(false);
1321
1409
  if (response && "uiMessages" in response.response && response.response.uiMessages) {
@@ -1329,7 +1417,15 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
1329
1417
  setMessages((prev) => [...prev, ...mastraUIMessages]);
1330
1418
  }
1331
1419
  };
1332
- const stream = async ({ coreUserMessages, requestContext, threadId, onChunk, modelSettings, signal }) => {
1420
+ const stream = async ({
1421
+ coreUserMessages,
1422
+ requestContext,
1423
+ threadId,
1424
+ onChunk,
1425
+ modelSettings,
1426
+ signal,
1427
+ tracingOptions
1428
+ }) => {
1333
1429
  const {
1334
1430
  frequencyPenalty,
1335
1431
  presencePenalty,
@@ -1367,7 +1463,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
1367
1463
  requestContext,
1368
1464
  ...threadId ? { threadId, resourceId: resourceId || agentId } : {},
1369
1465
  providerOptions,
1370
- requireToolApproval
1466
+ requireToolApproval,
1467
+ tracingOptions
1371
1468
  });
1372
1469
  _onChunk.current = onChunk;
1373
1470
  _currentRunId.current = runId;
@@ -1385,7 +1482,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
1385
1482
  threadId,
1386
1483
  onNetworkChunk,
1387
1484
  modelSettings,
1388
- signal
1485
+ signal,
1486
+ tracingOptions
1389
1487
  }) => {
1390
1488
  const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
1391
1489
  setIsRunning(true);
@@ -1409,7 +1507,8 @@ const useChat = ({ agentId, resourceId, initializeMessages }) => {
1409
1507
  },
1410
1508
  runId,
1411
1509
  requestContext,
1412
- ...threadId ? { thread: threadId, resourceId: resourceId || agentId } : {}
1510
+ ...threadId ? { thread: threadId, resourceId: resourceId || agentId } : {},
1511
+ tracingOptions
1413
1512
  });
1414
1513
  const transformer = new AISdkNetworkTransformer();
1415
1514
  await response.processDataStream({