@mastra/playground-ui 5.1.21-alpha.3 → 5.1.21-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/dist/index.cjs.js +442 -436
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +442 -436
- package/dist/index.es.js.map +1 -1
- package/dist/src/domains/agents/components/agent-chat.d.ts +1 -1
- package/dist/src/services/mastra-runtime-provider.d.ts +1 -1
- package/dist/src/types.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -5394,7 +5394,8 @@ function MastraRuntimeProvider({
|
|
|
5394
5394
|
threadId,
|
|
5395
5395
|
refreshThreadList,
|
|
5396
5396
|
settings,
|
|
5397
|
-
runtimeContext
|
|
5397
|
+
runtimeContext,
|
|
5398
|
+
modelVersion
|
|
5398
5399
|
}) {
|
|
5399
5400
|
const [isRunning, setIsRunning] = React.useState(false);
|
|
5400
5401
|
const [messages, setMessages] = React.useState([]);
|
|
@@ -5571,115 +5572,131 @@ function MastraRuntimeProvider({
|
|
|
5571
5572
|
}
|
|
5572
5573
|
}
|
|
5573
5574
|
};
|
|
5574
|
-
if (
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5575
|
+
if (modelVersion === "v2") {
|
|
5576
|
+
if (chatWithGenerateVNext) {
|
|
5577
|
+
const response = await agent.generateVNext({
|
|
5578
|
+
messages: [
|
|
5579
|
+
{
|
|
5580
|
+
role: "user",
|
|
5581
|
+
content: input
|
|
5582
|
+
},
|
|
5583
|
+
...attachments
|
|
5584
|
+
],
|
|
5585
|
+
runId: agentId,
|
|
5586
|
+
modelSettings: {
|
|
5587
|
+
frequencyPenalty,
|
|
5588
|
+
presencePenalty,
|
|
5589
|
+
maxRetries,
|
|
5590
|
+
temperature,
|
|
5591
|
+
topK,
|
|
5592
|
+
topP,
|
|
5593
|
+
maxOutputTokens: maxTokens
|
|
5580
5594
|
},
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
let updater = function() {
|
|
5604
|
-
setMessages((currentConversation) => {
|
|
5605
|
-
const message2 = {
|
|
5606
|
-
role: "assistant",
|
|
5607
|
-
content: [{ type: "text", text: content }]
|
|
5608
|
-
};
|
|
5609
|
-
if (!assistantMessageAdded) {
|
|
5610
|
-
assistantMessageAdded = true;
|
|
5595
|
+
providerOptions,
|
|
5596
|
+
instructions,
|
|
5597
|
+
runtimeContext: runtimeContextInstance,
|
|
5598
|
+
...memory ? { threadId, resourceId: agentId } : {}
|
|
5599
|
+
});
|
|
5600
|
+
handleGenerateResponse(response);
|
|
5601
|
+
setIsRunning(false);
|
|
5602
|
+
return;
|
|
5603
|
+
} else {
|
|
5604
|
+
let updater = function() {
|
|
5605
|
+
setMessages((currentConversation) => {
|
|
5606
|
+
const message2 = {
|
|
5607
|
+
role: "assistant",
|
|
5608
|
+
content: [{ type: "text", text: content }]
|
|
5609
|
+
};
|
|
5610
|
+
if (!assistantMessageAdded) {
|
|
5611
|
+
assistantMessageAdded = true;
|
|
5612
|
+
if (assistantToolCallAddedForUpdater) {
|
|
5613
|
+
assistantToolCallAddedForUpdater = false;
|
|
5614
|
+
}
|
|
5615
|
+
return [...currentConversation, message2];
|
|
5616
|
+
}
|
|
5611
5617
|
if (assistantToolCallAddedForUpdater) {
|
|
5612
5618
|
assistantToolCallAddedForUpdater = false;
|
|
5619
|
+
return [...currentConversation, message2];
|
|
5613
5620
|
}
|
|
5614
|
-
return [...currentConversation, message2];
|
|
5615
|
-
}
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5621
|
+
return [...currentConversation.slice(0, -1), message2];
|
|
5622
|
+
});
|
|
5623
|
+
};
|
|
5624
|
+
const response = await agent.streamVNext({
|
|
5625
|
+
messages: [
|
|
5626
|
+
{
|
|
5627
|
+
role: "user",
|
|
5628
|
+
content: input
|
|
5629
|
+
},
|
|
5630
|
+
...attachments
|
|
5631
|
+
],
|
|
5632
|
+
runId: agentId,
|
|
5633
|
+
modelSettings: {
|
|
5634
|
+
frequencyPenalty,
|
|
5635
|
+
presencePenalty,
|
|
5636
|
+
maxRetries,
|
|
5637
|
+
maxOutputTokens: maxTokens,
|
|
5638
|
+
temperature,
|
|
5639
|
+
topK,
|
|
5640
|
+
topP
|
|
5628
5641
|
},
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
onChunk: async (chunk) => {
|
|
5655
|
-
switch (chunk.type) {
|
|
5656
|
-
case "text-delta": {
|
|
5657
|
-
if (assistantToolCallAddedForContent) {
|
|
5658
|
-
assistantToolCallAddedForContent = false;
|
|
5659
|
-
content = chunk.payload.text;
|
|
5660
|
-
} else {
|
|
5661
|
-
content += chunk.payload.text;
|
|
5642
|
+
instructions,
|
|
5643
|
+
runtimeContext: runtimeContextInstance,
|
|
5644
|
+
...memory ? { threadId, resourceId: agentId } : {},
|
|
5645
|
+
providerOptions
|
|
5646
|
+
});
|
|
5647
|
+
if (!response.body) {
|
|
5648
|
+
throw new Error("No response body");
|
|
5649
|
+
}
|
|
5650
|
+
let content = "";
|
|
5651
|
+
let assistantMessageAdded = false;
|
|
5652
|
+
let assistantToolCallAddedForUpdater = false;
|
|
5653
|
+
let assistantToolCallAddedForContent = false;
|
|
5654
|
+
await response.processDataStream({
|
|
5655
|
+
onChunk: async (chunk) => {
|
|
5656
|
+
switch (chunk.type) {
|
|
5657
|
+
case "text-delta": {
|
|
5658
|
+
if (assistantToolCallAddedForContent) {
|
|
5659
|
+
assistantToolCallAddedForContent = false;
|
|
5660
|
+
content = chunk.payload.text;
|
|
5661
|
+
} else {
|
|
5662
|
+
content += chunk.payload.text;
|
|
5663
|
+
}
|
|
5664
|
+
console.log(chunk.payload.text, "VALUE");
|
|
5665
|
+
updater();
|
|
5666
|
+
break;
|
|
5662
5667
|
}
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5668
|
+
case "tool-call": {
|
|
5669
|
+
setMessages((currentConversation) => {
|
|
5670
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5671
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
5672
|
+
const updatedMessage = {
|
|
5673
|
+
...lastMessage,
|
|
5674
|
+
content: Array.isArray(lastMessage.content) ? [
|
|
5675
|
+
...lastMessage.content,
|
|
5676
|
+
{
|
|
5677
|
+
type: "tool-call",
|
|
5678
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5679
|
+
toolName: chunk.payload.toolName,
|
|
5680
|
+
args: chunk.payload.args
|
|
5681
|
+
}
|
|
5682
|
+
] : [
|
|
5683
|
+
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
5684
|
+
{
|
|
5685
|
+
type: "tool-call",
|
|
5686
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5687
|
+
toolName: chunk.payload.toolName,
|
|
5688
|
+
args: chunk.payload.args
|
|
5689
|
+
}
|
|
5690
|
+
]
|
|
5691
|
+
};
|
|
5692
|
+
assistantToolCallAddedForUpdater = true;
|
|
5693
|
+
assistantToolCallAddedForContent = true;
|
|
5694
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5695
|
+
}
|
|
5696
|
+
const newMessage = {
|
|
5697
|
+
role: "assistant",
|
|
5698
|
+
content: [
|
|
5699
|
+
{ type: "text", text: content },
|
|
5683
5700
|
{
|
|
5684
5701
|
type: "tool-call",
|
|
5685
5702
|
toolCallId: chunk.payload.toolCallId,
|
|
@@ -5690,277 +5707,278 @@ function MastraRuntimeProvider({
|
|
|
5690
5707
|
};
|
|
5691
5708
|
assistantToolCallAddedForUpdater = true;
|
|
5692
5709
|
assistantToolCallAddedForContent = true;
|
|
5693
|
-
return [...currentConversation
|
|
5710
|
+
return [...currentConversation, newMessage];
|
|
5711
|
+
});
|
|
5712
|
+
toolCallIdToName.current[chunk.payload.toolCallId] = chunk.payload.toolName;
|
|
5713
|
+
break;
|
|
5714
|
+
}
|
|
5715
|
+
case "tool-result": {
|
|
5716
|
+
setMessages((currentConversation) => {
|
|
5717
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5718
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5719
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
5720
|
+
if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === chunk.payload.toolCallId) {
|
|
5721
|
+
return {
|
|
5722
|
+
...part,
|
|
5723
|
+
result: chunk.payload.result
|
|
5724
|
+
};
|
|
5725
|
+
}
|
|
5726
|
+
return part;
|
|
5727
|
+
});
|
|
5728
|
+
const updatedMessage = {
|
|
5729
|
+
...lastMessage,
|
|
5730
|
+
content: updatedContent
|
|
5731
|
+
};
|
|
5732
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5733
|
+
}
|
|
5734
|
+
return currentConversation;
|
|
5735
|
+
});
|
|
5736
|
+
try {
|
|
5737
|
+
const toolName = toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5738
|
+
if (toolName === "updateWorkingMemory" && chunk.payload.result?.success) {
|
|
5739
|
+
await refreshWorkingMemory?.();
|
|
5740
|
+
}
|
|
5741
|
+
} finally {
|
|
5742
|
+
delete toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5694
5743
|
}
|
|
5695
|
-
|
|
5696
|
-
|
|
5744
|
+
break;
|
|
5745
|
+
}
|
|
5746
|
+
case "error": {
|
|
5747
|
+
if (typeof chunk.payload.error === "string") {
|
|
5748
|
+
throw new Error(chunk.payload.error);
|
|
5749
|
+
}
|
|
5750
|
+
break;
|
|
5751
|
+
}
|
|
5752
|
+
case "finish": {
|
|
5753
|
+
handleFinishReason(chunk.payload.finishReason);
|
|
5754
|
+
break;
|
|
5755
|
+
}
|
|
5756
|
+
case "reasoning-delta": {
|
|
5757
|
+
setMessages((currentConversation) => {
|
|
5758
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5759
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5760
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
5761
|
+
if (typeof part === "object" && part.type === "reasoning") {
|
|
5762
|
+
return {
|
|
5763
|
+
...part,
|
|
5764
|
+
text: part.text + chunk.payload.text
|
|
5765
|
+
};
|
|
5766
|
+
}
|
|
5767
|
+
return part;
|
|
5768
|
+
});
|
|
5769
|
+
const updatedMessage = {
|
|
5770
|
+
...lastMessage,
|
|
5771
|
+
content: updatedContent
|
|
5772
|
+
};
|
|
5773
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5774
|
+
}
|
|
5775
|
+
const newMessage = {
|
|
5776
|
+
role: "assistant",
|
|
5777
|
+
content: [
|
|
5778
|
+
{
|
|
5779
|
+
type: "reasoning",
|
|
5780
|
+
text: chunk.payload.text
|
|
5781
|
+
},
|
|
5782
|
+
{ type: "text", text: content }
|
|
5783
|
+
]
|
|
5784
|
+
};
|
|
5785
|
+
return [...currentConversation, newMessage];
|
|
5786
|
+
});
|
|
5787
|
+
break;
|
|
5788
|
+
}
|
|
5789
|
+
}
|
|
5790
|
+
}
|
|
5791
|
+
});
|
|
5792
|
+
setIsRunning(false);
|
|
5793
|
+
return;
|
|
5794
|
+
}
|
|
5795
|
+
} else {
|
|
5796
|
+
if (chatWithGenerate) {
|
|
5797
|
+
const generateResponse = await agent.generate({
|
|
5798
|
+
messages: [
|
|
5799
|
+
{
|
|
5800
|
+
role: "user",
|
|
5801
|
+
content: input
|
|
5802
|
+
},
|
|
5803
|
+
...attachments
|
|
5804
|
+
],
|
|
5805
|
+
runId: agentId,
|
|
5806
|
+
frequencyPenalty,
|
|
5807
|
+
presencePenalty,
|
|
5808
|
+
maxRetries,
|
|
5809
|
+
maxSteps,
|
|
5810
|
+
maxTokens,
|
|
5811
|
+
temperature,
|
|
5812
|
+
topK,
|
|
5813
|
+
topP,
|
|
5814
|
+
instructions,
|
|
5815
|
+
runtimeContext: runtimeContextInstance,
|
|
5816
|
+
...memory ? { threadId, resourceId: agentId } : {},
|
|
5817
|
+
providerOptions
|
|
5818
|
+
});
|
|
5819
|
+
if (generateResponse.response && "messages" in generateResponse.response) {
|
|
5820
|
+
const latestMessage = generateResponse.response.messages.reduce(
|
|
5821
|
+
(acc, message2) => {
|
|
5822
|
+
const _content = Array.isArray(acc.content) ? acc.content : [];
|
|
5823
|
+
if (typeof message2.content === "string") {
|
|
5824
|
+
return {
|
|
5825
|
+
...acc,
|
|
5697
5826
|
content: [
|
|
5698
|
-
|
|
5827
|
+
..._content,
|
|
5828
|
+
...generateResponse.reasoning ? [{ type: "reasoning", text: generateResponse.reasoning }] : [],
|
|
5699
5829
|
{
|
|
5700
|
-
type: "
|
|
5701
|
-
|
|
5702
|
-
toolName: chunk.payload.toolName,
|
|
5703
|
-
args: chunk.payload.args
|
|
5830
|
+
type: "text",
|
|
5831
|
+
text: message2.content
|
|
5704
5832
|
}
|
|
5705
5833
|
]
|
|
5706
5834
|
};
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
setMessages((currentConversation) => {
|
|
5716
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5717
|
-
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5718
|
-
const updatedContent = lastMessage.content.map((part) => {
|
|
5719
|
-
if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === chunk.payload.toolCallId) {
|
|
5720
|
-
return {
|
|
5721
|
-
...part,
|
|
5722
|
-
result: chunk.payload.result
|
|
5723
|
-
};
|
|
5835
|
+
}
|
|
5836
|
+
if (message2.role === "assistant") {
|
|
5837
|
+
const toolCallContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-call") : void 0;
|
|
5838
|
+
const reasoningContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "reasoning") : void 0;
|
|
5839
|
+
if (toolCallContent) {
|
|
5840
|
+
const newContent = _content.map((c) => {
|
|
5841
|
+
if (c.type === "tool-call" && c.toolCallId === toolCallContent?.toolCallId) {
|
|
5842
|
+
return { ...c, ...toolCallContent };
|
|
5724
5843
|
}
|
|
5725
|
-
return
|
|
5844
|
+
return c;
|
|
5726
5845
|
});
|
|
5727
|
-
const
|
|
5728
|
-
|
|
5729
|
-
|
|
5846
|
+
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5847
|
+
return {
|
|
5848
|
+
...acc,
|
|
5849
|
+
content: containsToolCall ? [...reasoningContent ? [reasoningContent] : [], ...newContent] : [..._content, ...reasoningContent ? [reasoningContent] : [], toolCallContent]
|
|
5730
5850
|
};
|
|
5731
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5732
5851
|
}
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5852
|
+
const textContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "text" && content.text) : void 0;
|
|
5853
|
+
if (textContent) {
|
|
5854
|
+
return {
|
|
5855
|
+
...acc,
|
|
5856
|
+
content: [..._content, ...reasoningContent ? [reasoningContent] : [], textContent]
|
|
5857
|
+
};
|
|
5739
5858
|
}
|
|
5740
|
-
} finally {
|
|
5741
|
-
delete toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5742
5859
|
}
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
break;
|
|
5750
|
-
}
|
|
5751
|
-
case "finish": {
|
|
5752
|
-
handleFinishReason(chunk.payload.finishReason);
|
|
5753
|
-
break;
|
|
5754
|
-
}
|
|
5755
|
-
case "reasoning-delta": {
|
|
5756
|
-
setMessages((currentConversation) => {
|
|
5757
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5758
|
-
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5759
|
-
const updatedContent = lastMessage.content.map((part) => {
|
|
5760
|
-
if (typeof part === "object" && part.type === "reasoning") {
|
|
5761
|
-
return {
|
|
5762
|
-
...part,
|
|
5763
|
-
text: part.text + chunk.payload.text
|
|
5764
|
-
};
|
|
5860
|
+
if (message2.role === "tool") {
|
|
5861
|
+
const toolResult = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-result") : void 0;
|
|
5862
|
+
if (toolResult) {
|
|
5863
|
+
const newContent = _content.map((c) => {
|
|
5864
|
+
if (c.type === "tool-call" && c.toolCallId === toolResult?.toolCallId) {
|
|
5865
|
+
return { ...c, result: toolResult.result };
|
|
5765
5866
|
}
|
|
5766
|
-
return
|
|
5867
|
+
return c;
|
|
5767
5868
|
});
|
|
5768
|
-
const
|
|
5769
|
-
|
|
5770
|
-
|
|
5869
|
+
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5870
|
+
return {
|
|
5871
|
+
...acc,
|
|
5872
|
+
content: containsToolCall ? newContent : [
|
|
5873
|
+
..._content,
|
|
5874
|
+
{ type: "tool-result", toolCallId: toolResult.toolCallId, result: toolResult.result }
|
|
5875
|
+
]
|
|
5771
5876
|
};
|
|
5772
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5773
5877
|
}
|
|
5774
|
-
const newMessage = {
|
|
5775
|
-
role: "assistant",
|
|
5776
|
-
content: [
|
|
5777
|
-
{
|
|
5778
|
-
type: "reasoning",
|
|
5779
|
-
text: chunk.payload.text
|
|
5780
|
-
},
|
|
5781
|
-
{ type: "text", text: content }
|
|
5782
|
-
]
|
|
5783
|
-
};
|
|
5784
|
-
return [...currentConversation, newMessage];
|
|
5785
|
-
});
|
|
5786
|
-
break;
|
|
5787
|
-
}
|
|
5788
|
-
}
|
|
5789
|
-
}
|
|
5790
|
-
});
|
|
5791
|
-
setIsRunning(false);
|
|
5792
|
-
return;
|
|
5793
|
-
}
|
|
5794
|
-
if (chatWithGenerate) {
|
|
5795
|
-
const generateResponse = await agent.generate({
|
|
5796
|
-
messages: [
|
|
5797
|
-
{
|
|
5798
|
-
role: "user",
|
|
5799
|
-
content: input
|
|
5800
|
-
},
|
|
5801
|
-
...attachments
|
|
5802
|
-
],
|
|
5803
|
-
runId: agentId,
|
|
5804
|
-
frequencyPenalty,
|
|
5805
|
-
presencePenalty,
|
|
5806
|
-
maxRetries,
|
|
5807
|
-
maxSteps,
|
|
5808
|
-
maxTokens,
|
|
5809
|
-
temperature,
|
|
5810
|
-
topK,
|
|
5811
|
-
topP,
|
|
5812
|
-
instructions,
|
|
5813
|
-
runtimeContext: runtimeContextInstance,
|
|
5814
|
-
...memory ? { threadId, resourceId: agentId } : {},
|
|
5815
|
-
providerOptions
|
|
5816
|
-
});
|
|
5817
|
-
if (generateResponse.response && "messages" in generateResponse.response) {
|
|
5818
|
-
const latestMessage = generateResponse.response.messages.reduce(
|
|
5819
|
-
(acc, message2) => {
|
|
5820
|
-
const _content = Array.isArray(acc.content) ? acc.content : [];
|
|
5821
|
-
if (typeof message2.content === "string") {
|
|
5822
|
-
return {
|
|
5823
|
-
...acc,
|
|
5824
|
-
content: [
|
|
5825
|
-
..._content,
|
|
5826
|
-
...generateResponse.reasoning ? [{ type: "reasoning", text: generateResponse.reasoning }] : [],
|
|
5827
|
-
{
|
|
5828
|
-
type: "text",
|
|
5829
|
-
text: message2.content
|
|
5830
|
-
}
|
|
5831
|
-
]
|
|
5832
|
-
};
|
|
5833
|
-
}
|
|
5834
|
-
if (message2.role === "assistant") {
|
|
5835
|
-
const toolCallContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-call") : void 0;
|
|
5836
|
-
const reasoningContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "reasoning") : void 0;
|
|
5837
|
-
if (toolCallContent) {
|
|
5838
|
-
const newContent = _content.map((c) => {
|
|
5839
|
-
if (c.type === "tool-call" && c.toolCallId === toolCallContent?.toolCallId) {
|
|
5840
|
-
return { ...c, ...toolCallContent };
|
|
5841
|
-
}
|
|
5842
|
-
return c;
|
|
5843
|
-
});
|
|
5844
|
-
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5845
|
-
return {
|
|
5846
|
-
...acc,
|
|
5847
|
-
content: containsToolCall ? [...reasoningContent ? [reasoningContent] : [], ...newContent] : [..._content, ...reasoningContent ? [reasoningContent] : [], toolCallContent]
|
|
5848
|
-
};
|
|
5849
|
-
}
|
|
5850
|
-
const textContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "text" && content.text) : void 0;
|
|
5851
|
-
if (textContent) {
|
|
5852
5878
|
return {
|
|
5853
5879
|
...acc,
|
|
5854
|
-
content: [..._content,
|
|
5880
|
+
content: [..._content, toolResult]
|
|
5855
5881
|
};
|
|
5856
5882
|
}
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5883
|
+
return acc;
|
|
5884
|
+
},
|
|
5885
|
+
{ role: "assistant", content: [] }
|
|
5886
|
+
);
|
|
5887
|
+
setMessages((currentConversation) => [...currentConversation, latestMessage]);
|
|
5888
|
+
handleFinishReason(generateResponse.finishReason);
|
|
5889
|
+
}
|
|
5890
|
+
} else {
|
|
5891
|
+
let updater = function() {
|
|
5892
|
+
setMessages((currentConversation) => {
|
|
5893
|
+
const message2 = {
|
|
5894
|
+
role: "assistant",
|
|
5895
|
+
content: [{ type: "text", text: content }]
|
|
5896
|
+
};
|
|
5897
|
+
if (!assistantMessageAdded) {
|
|
5898
|
+
assistantMessageAdded = true;
|
|
5899
|
+
if (assistantToolCallAddedForUpdater) {
|
|
5900
|
+
assistantToolCallAddedForUpdater = false;
|
|
5875
5901
|
}
|
|
5876
|
-
return
|
|
5877
|
-
...acc,
|
|
5878
|
-
content: [..._content, toolResult]
|
|
5879
|
-
};
|
|
5902
|
+
return [...currentConversation, message2];
|
|
5880
5903
|
}
|
|
5881
|
-
return acc;
|
|
5882
|
-
},
|
|
5883
|
-
{ role: "assistant", content: [] }
|
|
5884
|
-
);
|
|
5885
|
-
setMessages((currentConversation) => [...currentConversation, latestMessage]);
|
|
5886
|
-
handleFinishReason(generateResponse.finishReason);
|
|
5887
|
-
}
|
|
5888
|
-
} else {
|
|
5889
|
-
let updater = function() {
|
|
5890
|
-
setMessages((currentConversation) => {
|
|
5891
|
-
const message2 = {
|
|
5892
|
-
role: "assistant",
|
|
5893
|
-
content: [{ type: "text", text: content }]
|
|
5894
|
-
};
|
|
5895
|
-
if (!assistantMessageAdded) {
|
|
5896
|
-
assistantMessageAdded = true;
|
|
5897
5904
|
if (assistantToolCallAddedForUpdater) {
|
|
5898
5905
|
assistantToolCallAddedForUpdater = false;
|
|
5906
|
+
return [...currentConversation, message2];
|
|
5899
5907
|
}
|
|
5900
|
-
return [...currentConversation, message2];
|
|
5901
|
-
}
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5908
|
+
return [...currentConversation.slice(0, -1), message2];
|
|
5909
|
+
});
|
|
5910
|
+
};
|
|
5911
|
+
const response = await agent.stream({
|
|
5912
|
+
messages: [
|
|
5913
|
+
{
|
|
5914
|
+
role: "user",
|
|
5915
|
+
content: input
|
|
5916
|
+
},
|
|
5917
|
+
...attachments
|
|
5918
|
+
],
|
|
5919
|
+
runId: agentId,
|
|
5920
|
+
frequencyPenalty,
|
|
5921
|
+
presencePenalty,
|
|
5922
|
+
maxRetries,
|
|
5923
|
+
maxSteps,
|
|
5924
|
+
maxTokens,
|
|
5925
|
+
temperature,
|
|
5926
|
+
topK,
|
|
5927
|
+
topP,
|
|
5928
|
+
instructions,
|
|
5929
|
+
runtimeContext: runtimeContextInstance,
|
|
5930
|
+
...memory ? { threadId, resourceId: agentId } : {},
|
|
5931
|
+
providerOptions
|
|
5907
5932
|
});
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5933
|
+
if (!response.body) {
|
|
5934
|
+
throw new Error("No response body");
|
|
5935
|
+
}
|
|
5936
|
+
let content = "";
|
|
5937
|
+
let assistantMessageAdded = false;
|
|
5938
|
+
let assistantToolCallAddedForUpdater = false;
|
|
5939
|
+
let assistantToolCallAddedForContent = false;
|
|
5940
|
+
await response.processDataStream({
|
|
5941
|
+
onTextPart(value) {
|
|
5942
|
+
if (assistantToolCallAddedForContent) {
|
|
5943
|
+
assistantToolCallAddedForContent = false;
|
|
5944
|
+
content = value;
|
|
5945
|
+
} else {
|
|
5946
|
+
content += value;
|
|
5947
|
+
}
|
|
5948
|
+
updater();
|
|
5914
5949
|
},
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
},
|
|
5948
|
-
async onToolCallPart(value) {
|
|
5949
|
-
setMessages((currentConversation) => {
|
|
5950
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5951
|
-
if (lastMessage && lastMessage.role === "assistant") {
|
|
5952
|
-
const updatedMessage = {
|
|
5953
|
-
...lastMessage,
|
|
5954
|
-
content: Array.isArray(lastMessage.content) ? [
|
|
5955
|
-
...lastMessage.content,
|
|
5956
|
-
{
|
|
5957
|
-
type: "tool-call",
|
|
5958
|
-
toolCallId: value.toolCallId,
|
|
5959
|
-
toolName: value.toolName,
|
|
5960
|
-
args: value.args
|
|
5961
|
-
}
|
|
5962
|
-
] : [
|
|
5963
|
-
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
5950
|
+
async onToolCallPart(value) {
|
|
5951
|
+
setMessages((currentConversation) => {
|
|
5952
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5953
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
5954
|
+
const updatedMessage = {
|
|
5955
|
+
...lastMessage,
|
|
5956
|
+
content: Array.isArray(lastMessage.content) ? [
|
|
5957
|
+
...lastMessage.content,
|
|
5958
|
+
{
|
|
5959
|
+
type: "tool-call",
|
|
5960
|
+
toolCallId: value.toolCallId,
|
|
5961
|
+
toolName: value.toolName,
|
|
5962
|
+
args: value.args
|
|
5963
|
+
}
|
|
5964
|
+
] : [
|
|
5965
|
+
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
5966
|
+
{
|
|
5967
|
+
type: "tool-call",
|
|
5968
|
+
toolCallId: value.toolCallId,
|
|
5969
|
+
toolName: value.toolName,
|
|
5970
|
+
args: value.args
|
|
5971
|
+
}
|
|
5972
|
+
]
|
|
5973
|
+
};
|
|
5974
|
+
assistantToolCallAddedForUpdater = true;
|
|
5975
|
+
assistantToolCallAddedForContent = true;
|
|
5976
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5977
|
+
}
|
|
5978
|
+
const newMessage = {
|
|
5979
|
+
role: "assistant",
|
|
5980
|
+
content: [
|
|
5981
|
+
{ type: "text", text: content },
|
|
5964
5982
|
{
|
|
5965
5983
|
type: "tool-call",
|
|
5966
5984
|
toolCallId: value.toolCallId,
|
|
@@ -5971,95 +5989,80 @@ function MastraRuntimeProvider({
|
|
|
5971
5989
|
};
|
|
5972
5990
|
assistantToolCallAddedForUpdater = true;
|
|
5973
5991
|
assistantToolCallAddedForContent = true;
|
|
5974
|
-
return [...currentConversation
|
|
5992
|
+
return [...currentConversation, newMessage];
|
|
5993
|
+
});
|
|
5994
|
+
toolCallIdToName.current[value.toolCallId] = value.toolName;
|
|
5995
|
+
},
|
|
5996
|
+
async onToolResultPart(value) {
|
|
5997
|
+
setMessages((currentConversation) => {
|
|
5998
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5999
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
6000
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
6001
|
+
if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === value.toolCallId) {
|
|
6002
|
+
return {
|
|
6003
|
+
...part,
|
|
6004
|
+
result: value.result
|
|
6005
|
+
};
|
|
6006
|
+
}
|
|
6007
|
+
return part;
|
|
6008
|
+
});
|
|
6009
|
+
const updatedMessage = {
|
|
6010
|
+
...lastMessage,
|
|
6011
|
+
content: updatedContent
|
|
6012
|
+
};
|
|
6013
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
6014
|
+
}
|
|
6015
|
+
return currentConversation;
|
|
6016
|
+
});
|
|
6017
|
+
try {
|
|
6018
|
+
const toolName = toolCallIdToName.current[value.toolCallId];
|
|
6019
|
+
if (toolName === "updateWorkingMemory" && value.result?.success) {
|
|
6020
|
+
await refreshWorkingMemory?.();
|
|
6021
|
+
}
|
|
6022
|
+
} finally {
|
|
6023
|
+
delete toolCallIdToName.current[value.toolCallId];
|
|
5975
6024
|
}
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6025
|
+
},
|
|
6026
|
+
onErrorPart(error) {
|
|
6027
|
+
throw new Error(error);
|
|
6028
|
+
},
|
|
6029
|
+
onFinishMessagePart({ finishReason }) {
|
|
6030
|
+
handleFinishReason(finishReason);
|
|
6031
|
+
},
|
|
6032
|
+
onReasoningPart(value) {
|
|
6033
|
+
setMessages((currentConversation) => {
|
|
6034
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
6035
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
6036
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
6037
|
+
if (typeof part === "object" && part.type === "reasoning") {
|
|
6038
|
+
return {
|
|
6039
|
+
...part,
|
|
6040
|
+
text: part.text + value
|
|
6041
|
+
};
|
|
6042
|
+
}
|
|
6043
|
+
return part;
|
|
6044
|
+
});
|
|
6045
|
+
const updatedMessage = {
|
|
6046
|
+
...lastMessage,
|
|
6047
|
+
content: updatedContent
|
|
6048
|
+
};
|
|
6049
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
6050
|
+
}
|
|
6051
|
+
const newMessage = {
|
|
6052
|
+
role: "assistant",
|
|
6053
|
+
content: [
|
|
6054
|
+
{
|
|
6055
|
+
type: "reasoning",
|
|
6056
|
+
text: value
|
|
6057
|
+
},
|
|
6058
|
+
{ type: "text", text: content }
|
|
6059
|
+
]
|
|
6010
6060
|
};
|
|
6011
|
-
return [...currentConversation
|
|
6012
|
-
}
|
|
6013
|
-
return currentConversation;
|
|
6014
|
-
});
|
|
6015
|
-
try {
|
|
6016
|
-
const toolName = toolCallIdToName.current[value.toolCallId];
|
|
6017
|
-
if (toolName === "updateWorkingMemory" && value.result?.success) {
|
|
6018
|
-
await refreshWorkingMemory?.();
|
|
6019
|
-
}
|
|
6020
|
-
} finally {
|
|
6021
|
-
delete toolCallIdToName.current[value.toolCallId];
|
|
6061
|
+
return [...currentConversation, newMessage];
|
|
6062
|
+
});
|
|
6022
6063
|
}
|
|
6023
|
-
}
|
|
6024
|
-
|
|
6025
|
-
throw new Error(error);
|
|
6026
|
-
},
|
|
6027
|
-
onFinishMessagePart({ finishReason }) {
|
|
6028
|
-
handleFinishReason(finishReason);
|
|
6029
|
-
},
|
|
6030
|
-
onReasoningPart(value) {
|
|
6031
|
-
setMessages((currentConversation) => {
|
|
6032
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
6033
|
-
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
6034
|
-
const updatedContent = lastMessage.content.map((part) => {
|
|
6035
|
-
if (typeof part === "object" && part.type === "reasoning") {
|
|
6036
|
-
return {
|
|
6037
|
-
...part,
|
|
6038
|
-
text: part.text + value
|
|
6039
|
-
};
|
|
6040
|
-
}
|
|
6041
|
-
return part;
|
|
6042
|
-
});
|
|
6043
|
-
const updatedMessage = {
|
|
6044
|
-
...lastMessage,
|
|
6045
|
-
content: updatedContent
|
|
6046
|
-
};
|
|
6047
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
6048
|
-
}
|
|
6049
|
-
const newMessage = {
|
|
6050
|
-
role: "assistant",
|
|
6051
|
-
content: [
|
|
6052
|
-
{
|
|
6053
|
-
type: "reasoning",
|
|
6054
|
-
text: value
|
|
6055
|
-
},
|
|
6056
|
-
{ type: "text", text: content }
|
|
6057
|
-
]
|
|
6058
|
-
};
|
|
6059
|
-
return [...currentConversation, newMessage];
|
|
6060
|
-
});
|
|
6061
|
-
}
|
|
6062
|
-
});
|
|
6064
|
+
});
|
|
6065
|
+
}
|
|
6063
6066
|
}
|
|
6064
6067
|
setIsRunning(false);
|
|
6065
6068
|
setTimeout(() => {
|
|
@@ -6109,7 +6112,8 @@ const defaultSettings = {
|
|
|
6109
6112
|
maxSteps: 5,
|
|
6110
6113
|
temperature: 0.5,
|
|
6111
6114
|
topP: 1,
|
|
6112
|
-
chatWithGenerate: false
|
|
6115
|
+
chatWithGenerate: false,
|
|
6116
|
+
chatWithGenerateVNext: false
|
|
6113
6117
|
}
|
|
6114
6118
|
};
|
|
6115
6119
|
function useAgentSettingsState({ agentId }) {
|
|
@@ -6181,7 +6185,8 @@ const AgentChat = ({
|
|
|
6181
6185
|
initialMessages,
|
|
6182
6186
|
memory,
|
|
6183
6187
|
refreshThreadList,
|
|
6184
|
-
onInputChange
|
|
6188
|
+
onInputChange,
|
|
6189
|
+
modelVersion
|
|
6185
6190
|
}) => {
|
|
6186
6191
|
const { settings } = useAgentSettings();
|
|
6187
6192
|
const { runtimeContext } = usePlaygroundStore();
|
|
@@ -6190,6 +6195,7 @@ const AgentChat = ({
|
|
|
6190
6195
|
{
|
|
6191
6196
|
agentId,
|
|
6192
6197
|
agentName,
|
|
6198
|
+
modelVersion,
|
|
6193
6199
|
threadId,
|
|
6194
6200
|
initialMessages,
|
|
6195
6201
|
memory,
|