@mastra/react 0.2.36-alpha.3 → 0.2.36-alpha.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @mastra/react
2
2
 
3
+ ## 0.2.36-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Handle `background-task-suspended` chunks in `toUIMessage` so suspend metadata is restored after resume. ([#16260](https://github.com/mastra-ai/mastra/pull/16260))
8
+
9
+ - Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a)]:
10
+ - @mastra/core@1.33.0-alpha.4
11
+ - @mastra/client-js@1.18.0-alpha.4
12
+
3
13
  ## 0.2.36-alpha.3
4
14
 
5
15
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -691,17 +691,29 @@ var toUIMessage = ({ chunk, conversation, metadata }) => {
691
691
  }
692
692
  ];
693
693
  }
694
- case "tool-call-suspended": {
695
- const lastMessage = result[result.length - 1];
696
- if (!lastMessage || lastMessage.role !== "assistant") return result;
697
- const lastSuspendedTools = lastMessage.metadata?.mode === "stream" ? lastMessage.metadata?.suspendedTools : {};
698
- return [
699
- ...result.slice(0, -1),
700
- {
701
- ...lastMessage,
702
- metadata: {
703
- ...lastMessage.metadata,
704
- mode: "stream",
694
+ case "tool-call-suspended":
695
+ case "background-task-suspended": {
696
+ const isBgTaskEvent = chunk.type === "background-task-suspended";
697
+ const location = isBgTaskEvent ? locateToolPart(result, chunk.payload.toolCallId, isBgTaskEvent) : { messageIndex: result.length - 1 };
698
+ if (!location) return result;
699
+ const { messageIndex } = location;
700
+ const targetMessage = result[messageIndex];
701
+ if (!targetMessage || targetMessage.role !== "assistant") return result;
702
+ const lastSuspendedTools = targetMessage.metadata?.mode === "stream" ? targetMessage.metadata?.suspendedTools : {};
703
+ const nextMessage = {
704
+ ...targetMessage,
705
+ metadata: mergeBgTaskMetadata(
706
+ targetMessage.metadata,
707
+ "stream",
708
+ {
709
+ resetRunningCount: isBgTaskEvent,
710
+ perTaskEntry: isBgTaskEvent ? {
711
+ toolCallId: chunk.payload.toolCallId,
712
+ suspendedAt: chunk.payload.suspendedAt,
713
+ taskId: chunk.payload.taskId
714
+ } : void 0
715
+ },
716
+ {
705
717
  suspendedTools: {
706
718
  ...lastSuspendedTools,
707
719
  [chunk.payload.toolName]: {
@@ -713,8 +725,9 @@ var toUIMessage = ({ chunk, conversation, metadata }) => {
713
725
  }
714
726
  }
715
727
  }
716
- }
717
- ];
728
+ )
729
+ };
730
+ return [...result.slice(0, messageIndex), nextMessage, ...result.slice(messageIndex + 1)];
718
731
  }
719
732
  case "finish": {
720
733
  const lastMessage = result[result.length - 1];
@@ -906,22 +919,24 @@ var locateToolPart = (messages, toolCallId, allowMetadataOnlyMatch) => {
906
919
  }
907
920
  return { messageIndex, toolPartIndex };
908
921
  };
909
- var mergeBgTaskMetadata = (existing, mode, args) => {
922
+ var mergeBgTaskMetadata = (existing, mode, args, otherMetadata) => {
910
923
  const existingAny = existing ?? {};
911
924
  const existingBgTasks = existingAny.backgroundTasks ?? {};
912
925
  const nextBgTasks = { ...existingBgTasks };
913
926
  if (args.perTaskEntry) {
914
- const { toolCallId, startedAt, completedAt, taskId } = args.perTaskEntry;
927
+ const { toolCallId, startedAt, completedAt, taskId, suspendedAt } = args.perTaskEntry;
915
928
  const prev = existingBgTasks[toolCallId] ?? { taskId };
916
929
  nextBgTasks[toolCallId] = {
917
930
  ...prev,
918
931
  taskId,
919
932
  ...startedAt !== void 0 ? { startedAt } : {},
920
- ...completedAt !== void 0 ? { completedAt } : {}
933
+ ...completedAt !== void 0 ? { completedAt } : {},
934
+ ...suspendedAt !== void 0 ? { suspendedAt } : {}
921
935
  };
922
936
  }
923
937
  return {
924
938
  ...existingAny,
939
+ ...otherMetadata ?? {},
925
940
  mode,
926
941
  ...args.resetRunningCount ? { runningBackgroundTasksCount: void 0 } : {},
927
942
  backgroundTasks: nextBgTasks