@mastra/react 0.2.36-alpha.0 → 0.2.36-alpha.10
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 +83 -0
- package/dist/index.cjs +40 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -27
- package/dist/index.js.map +1 -1
- package/dist/lib/ai-sdk/types.d.ts +4 -2
- package/dist/lib/ai-sdk/types.d.ts.map +1 -1
- package/dist/lib/ai-sdk/utils/toUIMessage.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -383,23 +383,21 @@ var toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
383
383
|
return [...result, newMessage];
|
|
384
384
|
}
|
|
385
385
|
const parts = [...lastMessage.parts];
|
|
386
|
-
|
|
387
|
-
|
|
386
|
+
const lastPartIndex = parts.length - 1;
|
|
387
|
+
const lastPart = parts[lastPartIndex];
|
|
388
|
+
if (lastPart?.type === "reasoning") {
|
|
389
|
+
parts[lastPartIndex] = {
|
|
390
|
+
...lastPart,
|
|
391
|
+
text: lastPart.text + chunk.payload.text,
|
|
392
|
+
state: "streaming"
|
|
393
|
+
};
|
|
394
|
+
} else {
|
|
388
395
|
parts.push({
|
|
389
396
|
type: "reasoning",
|
|
390
397
|
text: chunk.payload.text,
|
|
391
398
|
state: "streaming",
|
|
392
399
|
providerMetadata: chunk.payload.providerMetadata
|
|
393
400
|
});
|
|
394
|
-
} else {
|
|
395
|
-
const reasoningPart = parts[reasoningPartIndex];
|
|
396
|
-
if (reasoningPart.type === "reasoning") {
|
|
397
|
-
parts[reasoningPartIndex] = {
|
|
398
|
-
...reasoningPart,
|
|
399
|
-
text: reasoningPart.text + chunk.payload.text,
|
|
400
|
-
state: "streaming"
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
401
|
}
|
|
404
402
|
return [
|
|
405
403
|
...result.slice(0, -1),
|
|
@@ -689,17 +687,29 @@ var toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
689
687
|
}
|
|
690
688
|
];
|
|
691
689
|
}
|
|
692
|
-
case "tool-call-suspended":
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
const
|
|
696
|
-
return
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
690
|
+
case "tool-call-suspended":
|
|
691
|
+
case "background-task-suspended": {
|
|
692
|
+
const isBgTaskEvent = chunk.type === "background-task-suspended";
|
|
693
|
+
const location = isBgTaskEvent ? locateToolPart(result, chunk.payload.toolCallId, isBgTaskEvent) : { messageIndex: result.length - 1 };
|
|
694
|
+
if (!location) return result;
|
|
695
|
+
const { messageIndex } = location;
|
|
696
|
+
const targetMessage = result[messageIndex];
|
|
697
|
+
if (!targetMessage || targetMessage.role !== "assistant") return result;
|
|
698
|
+
const lastSuspendedTools = targetMessage.metadata?.mode === "stream" ? targetMessage.metadata?.suspendedTools : {};
|
|
699
|
+
const nextMessage = {
|
|
700
|
+
...targetMessage,
|
|
701
|
+
metadata: mergeBgTaskMetadata(
|
|
702
|
+
targetMessage.metadata,
|
|
703
|
+
"stream",
|
|
704
|
+
{
|
|
705
|
+
resetRunningCount: isBgTaskEvent,
|
|
706
|
+
perTaskEntry: isBgTaskEvent ? {
|
|
707
|
+
toolCallId: chunk.payload.toolCallId,
|
|
708
|
+
suspendedAt: chunk.payload.suspendedAt,
|
|
709
|
+
taskId: chunk.payload.taskId
|
|
710
|
+
} : void 0
|
|
711
|
+
},
|
|
712
|
+
{
|
|
703
713
|
suspendedTools: {
|
|
704
714
|
...lastSuspendedTools,
|
|
705
715
|
[chunk.payload.toolName]: {
|
|
@@ -711,8 +721,9 @@ var toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
|
711
721
|
}
|
|
712
722
|
}
|
|
713
723
|
}
|
|
714
|
-
|
|
715
|
-
|
|
724
|
+
)
|
|
725
|
+
};
|
|
726
|
+
return [...result.slice(0, messageIndex), nextMessage, ...result.slice(messageIndex + 1)];
|
|
716
727
|
}
|
|
717
728
|
case "finish": {
|
|
718
729
|
const lastMessage = result[result.length - 1];
|
|
@@ -904,22 +915,24 @@ var locateToolPart = (messages, toolCallId, allowMetadataOnlyMatch) => {
|
|
|
904
915
|
}
|
|
905
916
|
return { messageIndex, toolPartIndex };
|
|
906
917
|
};
|
|
907
|
-
var mergeBgTaskMetadata = (existing, mode, args) => {
|
|
918
|
+
var mergeBgTaskMetadata = (existing, mode, args, otherMetadata) => {
|
|
908
919
|
const existingAny = existing ?? {};
|
|
909
920
|
const existingBgTasks = existingAny.backgroundTasks ?? {};
|
|
910
921
|
const nextBgTasks = { ...existingBgTasks };
|
|
911
922
|
if (args.perTaskEntry) {
|
|
912
|
-
const { toolCallId, startedAt, completedAt, taskId } = args.perTaskEntry;
|
|
923
|
+
const { toolCallId, startedAt, completedAt, taskId, suspendedAt } = args.perTaskEntry;
|
|
913
924
|
const prev = existingBgTasks[toolCallId] ?? { taskId };
|
|
914
925
|
nextBgTasks[toolCallId] = {
|
|
915
926
|
...prev,
|
|
916
927
|
taskId,
|
|
917
928
|
...startedAt !== void 0 ? { startedAt } : {},
|
|
918
|
-
...completedAt !== void 0 ? { completedAt } : {}
|
|
929
|
+
...completedAt !== void 0 ? { completedAt } : {},
|
|
930
|
+
...suspendedAt !== void 0 ? { suspendedAt } : {}
|
|
919
931
|
};
|
|
920
932
|
}
|
|
921
933
|
return {
|
|
922
934
|
...existingAny,
|
|
935
|
+
...otherMetadata ?? {},
|
|
923
936
|
mode,
|
|
924
937
|
...args.resetRunningCount ? { runningBackgroundTasksCount: void 0 } : {},
|
|
925
938
|
backgroundTasks: nextBgTasks
|