@mastra/react 0.0.0-monorepo-binary-20251013210052 → 0.0.0-usechat-duplicate-20251016110554

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
@@ -550,6 +550,9 @@ const toAssistantUIMessage = (message) => {
550
550
  class AISdkNetworkTransformer {
551
551
  transform({ chunk, conversation, metadata }) {
552
552
  const newConversation = [...conversation];
553
+ if (chunk.type === "routing-agent-text-delta") {
554
+ return this.handleRoutingAgentConversation(chunk, newConversation);
555
+ }
553
556
  if (chunk.type.startsWith("agent-execution-")) {
554
557
  return this.handleAgentConversation(chunk, newConversation, metadata);
555
558
  }
@@ -560,22 +563,80 @@ class AISdkNetworkTransformer {
560
563
  return this.handleToolConversation(chunk, newConversation, metadata);
561
564
  }
562
565
  if (chunk.type === "network-execution-event-step-finish") {
563
- const newMessage = {
564
- id: `network-execution-event-step-finish-${chunk.runId}-${Date.now()}`,
565
- role: "assistant",
566
- parts: [
566
+ const lastMessage = newConversation[newConversation.length - 1];
567
+ if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
568
+ const agentChunk = chunk.payload;
569
+ const parts = [...lastMessage.parts];
570
+ const textPartIndex = parts.findIndex((part) => part.type === "text");
571
+ if (textPartIndex === -1) {
572
+ parts.push({
573
+ type: "text",
574
+ text: agentChunk.result,
575
+ state: "done"
576
+ });
577
+ return [
578
+ ...newConversation.slice(0, -1),
567
579
  {
568
- type: "text",
569
- text: chunk.payload?.result || "",
570
- state: "done"
580
+ ...lastMessage,
581
+ parts
571
582
  }
572
- ],
573
- metadata
574
- };
575
- return [...newConversation, newMessage];
583
+ ];
584
+ }
585
+ const textPart = parts[textPartIndex];
586
+ if (textPart.type === "text") {
587
+ parts[textPartIndex] = {
588
+ ...textPart,
589
+ state: "done"
590
+ };
591
+ return [
592
+ ...newConversation.slice(0, -1),
593
+ {
594
+ ...lastMessage,
595
+ parts
596
+ }
597
+ ];
598
+ }
599
+ return newConversation;
576
600
  }
577
601
  return newConversation;
578
602
  }
603
+ handleRoutingAgentConversation = (chunk, newConversation) => {
604
+ const lastMessage = newConversation[newConversation.length - 1];
605
+ if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
606
+ const agentChunk = chunk.payload;
607
+ const parts = [...lastMessage.parts];
608
+ const textPartIndex = parts.findIndex((part) => part.type === "text");
609
+ if (textPartIndex === -1) {
610
+ parts.push({
611
+ type: "text",
612
+ text: agentChunk.text,
613
+ state: "streaming"
614
+ });
615
+ return [
616
+ ...newConversation.slice(0, -1),
617
+ {
618
+ ...lastMessage,
619
+ parts
620
+ }
621
+ ];
622
+ }
623
+ const textPart = parts[textPartIndex];
624
+ if (textPart.type === "text") {
625
+ parts[textPartIndex] = {
626
+ ...textPart,
627
+ text: textPart.text + agentChunk.text,
628
+ state: "streaming"
629
+ };
630
+ return [
631
+ ...newConversation.slice(0, -1),
632
+ {
633
+ ...lastMessage,
634
+ parts
635
+ }
636
+ ];
637
+ }
638
+ return newConversation;
639
+ };
579
640
  handleAgentConversation = (chunk, newConversation, metadata) => {
580
641
  if (chunk.type === "agent-execution-start") {
581
642
  const primitiveId = chunk.payload?.args?.primitiveId;