@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.es.js
CHANGED
|
@@ -5361,7 +5361,8 @@ function MastraRuntimeProvider({
|
|
|
5361
5361
|
threadId,
|
|
5362
5362
|
refreshThreadList,
|
|
5363
5363
|
settings,
|
|
5364
|
-
runtimeContext
|
|
5364
|
+
runtimeContext,
|
|
5365
|
+
modelVersion
|
|
5365
5366
|
}) {
|
|
5366
5367
|
const [isRunning, setIsRunning] = useState(false);
|
|
5367
5368
|
const [messages, setMessages] = useState([]);
|
|
@@ -5538,115 +5539,131 @@ function MastraRuntimeProvider({
|
|
|
5538
5539
|
}
|
|
5539
5540
|
}
|
|
5540
5541
|
};
|
|
5541
|
-
if (
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5542
|
+
if (modelVersion === "v2") {
|
|
5543
|
+
if (chatWithGenerateVNext) {
|
|
5544
|
+
const response = await agent.generateVNext({
|
|
5545
|
+
messages: [
|
|
5546
|
+
{
|
|
5547
|
+
role: "user",
|
|
5548
|
+
content: input
|
|
5549
|
+
},
|
|
5550
|
+
...attachments
|
|
5551
|
+
],
|
|
5552
|
+
runId: agentId,
|
|
5553
|
+
modelSettings: {
|
|
5554
|
+
frequencyPenalty,
|
|
5555
|
+
presencePenalty,
|
|
5556
|
+
maxRetries,
|
|
5557
|
+
temperature,
|
|
5558
|
+
topK,
|
|
5559
|
+
topP,
|
|
5560
|
+
maxOutputTokens: maxTokens
|
|
5547
5561
|
},
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
let updater = function() {
|
|
5571
|
-
setMessages((currentConversation) => {
|
|
5572
|
-
const message2 = {
|
|
5573
|
-
role: "assistant",
|
|
5574
|
-
content: [{ type: "text", text: content }]
|
|
5575
|
-
};
|
|
5576
|
-
if (!assistantMessageAdded) {
|
|
5577
|
-
assistantMessageAdded = true;
|
|
5562
|
+
providerOptions,
|
|
5563
|
+
instructions,
|
|
5564
|
+
runtimeContext: runtimeContextInstance,
|
|
5565
|
+
...memory ? { threadId, resourceId: agentId } : {}
|
|
5566
|
+
});
|
|
5567
|
+
handleGenerateResponse(response);
|
|
5568
|
+
setIsRunning(false);
|
|
5569
|
+
return;
|
|
5570
|
+
} else {
|
|
5571
|
+
let updater = function() {
|
|
5572
|
+
setMessages((currentConversation) => {
|
|
5573
|
+
const message2 = {
|
|
5574
|
+
role: "assistant",
|
|
5575
|
+
content: [{ type: "text", text: content }]
|
|
5576
|
+
};
|
|
5577
|
+
if (!assistantMessageAdded) {
|
|
5578
|
+
assistantMessageAdded = true;
|
|
5579
|
+
if (assistantToolCallAddedForUpdater) {
|
|
5580
|
+
assistantToolCallAddedForUpdater = false;
|
|
5581
|
+
}
|
|
5582
|
+
return [...currentConversation, message2];
|
|
5583
|
+
}
|
|
5578
5584
|
if (assistantToolCallAddedForUpdater) {
|
|
5579
5585
|
assistantToolCallAddedForUpdater = false;
|
|
5586
|
+
return [...currentConversation, message2];
|
|
5580
5587
|
}
|
|
5581
|
-
return [...currentConversation, message2];
|
|
5582
|
-
}
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5588
|
+
return [...currentConversation.slice(0, -1), message2];
|
|
5589
|
+
});
|
|
5590
|
+
};
|
|
5591
|
+
const response = await agent.streamVNext({
|
|
5592
|
+
messages: [
|
|
5593
|
+
{
|
|
5594
|
+
role: "user",
|
|
5595
|
+
content: input
|
|
5596
|
+
},
|
|
5597
|
+
...attachments
|
|
5598
|
+
],
|
|
5599
|
+
runId: agentId,
|
|
5600
|
+
modelSettings: {
|
|
5601
|
+
frequencyPenalty,
|
|
5602
|
+
presencePenalty,
|
|
5603
|
+
maxRetries,
|
|
5604
|
+
maxOutputTokens: maxTokens,
|
|
5605
|
+
temperature,
|
|
5606
|
+
topK,
|
|
5607
|
+
topP
|
|
5595
5608
|
},
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
onChunk: async (chunk) => {
|
|
5622
|
-
switch (chunk.type) {
|
|
5623
|
-
case "text-delta": {
|
|
5624
|
-
if (assistantToolCallAddedForContent) {
|
|
5625
|
-
assistantToolCallAddedForContent = false;
|
|
5626
|
-
content = chunk.payload.text;
|
|
5627
|
-
} else {
|
|
5628
|
-
content += chunk.payload.text;
|
|
5609
|
+
instructions,
|
|
5610
|
+
runtimeContext: runtimeContextInstance,
|
|
5611
|
+
...memory ? { threadId, resourceId: agentId } : {},
|
|
5612
|
+
providerOptions
|
|
5613
|
+
});
|
|
5614
|
+
if (!response.body) {
|
|
5615
|
+
throw new Error("No response body");
|
|
5616
|
+
}
|
|
5617
|
+
let content = "";
|
|
5618
|
+
let assistantMessageAdded = false;
|
|
5619
|
+
let assistantToolCallAddedForUpdater = false;
|
|
5620
|
+
let assistantToolCallAddedForContent = false;
|
|
5621
|
+
await response.processDataStream({
|
|
5622
|
+
onChunk: async (chunk) => {
|
|
5623
|
+
switch (chunk.type) {
|
|
5624
|
+
case "text-delta": {
|
|
5625
|
+
if (assistantToolCallAddedForContent) {
|
|
5626
|
+
assistantToolCallAddedForContent = false;
|
|
5627
|
+
content = chunk.payload.text;
|
|
5628
|
+
} else {
|
|
5629
|
+
content += chunk.payload.text;
|
|
5630
|
+
}
|
|
5631
|
+
console.log(chunk.payload.text, "VALUE");
|
|
5632
|
+
updater();
|
|
5633
|
+
break;
|
|
5629
5634
|
}
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5635
|
+
case "tool-call": {
|
|
5636
|
+
setMessages((currentConversation) => {
|
|
5637
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5638
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
5639
|
+
const updatedMessage = {
|
|
5640
|
+
...lastMessage,
|
|
5641
|
+
content: Array.isArray(lastMessage.content) ? [
|
|
5642
|
+
...lastMessage.content,
|
|
5643
|
+
{
|
|
5644
|
+
type: "tool-call",
|
|
5645
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5646
|
+
toolName: chunk.payload.toolName,
|
|
5647
|
+
args: chunk.payload.args
|
|
5648
|
+
}
|
|
5649
|
+
] : [
|
|
5650
|
+
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
5651
|
+
{
|
|
5652
|
+
type: "tool-call",
|
|
5653
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5654
|
+
toolName: chunk.payload.toolName,
|
|
5655
|
+
args: chunk.payload.args
|
|
5656
|
+
}
|
|
5657
|
+
]
|
|
5658
|
+
};
|
|
5659
|
+
assistantToolCallAddedForUpdater = true;
|
|
5660
|
+
assistantToolCallAddedForContent = true;
|
|
5661
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5662
|
+
}
|
|
5663
|
+
const newMessage = {
|
|
5664
|
+
role: "assistant",
|
|
5665
|
+
content: [
|
|
5666
|
+
{ type: "text", text: content },
|
|
5650
5667
|
{
|
|
5651
5668
|
type: "tool-call",
|
|
5652
5669
|
toolCallId: chunk.payload.toolCallId,
|
|
@@ -5657,277 +5674,278 @@ function MastraRuntimeProvider({
|
|
|
5657
5674
|
};
|
|
5658
5675
|
assistantToolCallAddedForUpdater = true;
|
|
5659
5676
|
assistantToolCallAddedForContent = true;
|
|
5660
|
-
return [...currentConversation
|
|
5677
|
+
return [...currentConversation, newMessage];
|
|
5678
|
+
});
|
|
5679
|
+
toolCallIdToName.current[chunk.payload.toolCallId] = chunk.payload.toolName;
|
|
5680
|
+
break;
|
|
5681
|
+
}
|
|
5682
|
+
case "tool-result": {
|
|
5683
|
+
setMessages((currentConversation) => {
|
|
5684
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5685
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5686
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
5687
|
+
if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === chunk.payload.toolCallId) {
|
|
5688
|
+
return {
|
|
5689
|
+
...part,
|
|
5690
|
+
result: chunk.payload.result
|
|
5691
|
+
};
|
|
5692
|
+
}
|
|
5693
|
+
return part;
|
|
5694
|
+
});
|
|
5695
|
+
const updatedMessage = {
|
|
5696
|
+
...lastMessage,
|
|
5697
|
+
content: updatedContent
|
|
5698
|
+
};
|
|
5699
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5700
|
+
}
|
|
5701
|
+
return currentConversation;
|
|
5702
|
+
});
|
|
5703
|
+
try {
|
|
5704
|
+
const toolName = toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5705
|
+
if (toolName === "updateWorkingMemory" && chunk.payload.result?.success) {
|
|
5706
|
+
await refreshWorkingMemory?.();
|
|
5707
|
+
}
|
|
5708
|
+
} finally {
|
|
5709
|
+
delete toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5661
5710
|
}
|
|
5662
|
-
|
|
5663
|
-
|
|
5711
|
+
break;
|
|
5712
|
+
}
|
|
5713
|
+
case "error": {
|
|
5714
|
+
if (typeof chunk.payload.error === "string") {
|
|
5715
|
+
throw new Error(chunk.payload.error);
|
|
5716
|
+
}
|
|
5717
|
+
break;
|
|
5718
|
+
}
|
|
5719
|
+
case "finish": {
|
|
5720
|
+
handleFinishReason(chunk.payload.finishReason);
|
|
5721
|
+
break;
|
|
5722
|
+
}
|
|
5723
|
+
case "reasoning-delta": {
|
|
5724
|
+
setMessages((currentConversation) => {
|
|
5725
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5726
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5727
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
5728
|
+
if (typeof part === "object" && part.type === "reasoning") {
|
|
5729
|
+
return {
|
|
5730
|
+
...part,
|
|
5731
|
+
text: part.text + chunk.payload.text
|
|
5732
|
+
};
|
|
5733
|
+
}
|
|
5734
|
+
return part;
|
|
5735
|
+
});
|
|
5736
|
+
const updatedMessage = {
|
|
5737
|
+
...lastMessage,
|
|
5738
|
+
content: updatedContent
|
|
5739
|
+
};
|
|
5740
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5741
|
+
}
|
|
5742
|
+
const newMessage = {
|
|
5743
|
+
role: "assistant",
|
|
5744
|
+
content: [
|
|
5745
|
+
{
|
|
5746
|
+
type: "reasoning",
|
|
5747
|
+
text: chunk.payload.text
|
|
5748
|
+
},
|
|
5749
|
+
{ type: "text", text: content }
|
|
5750
|
+
]
|
|
5751
|
+
};
|
|
5752
|
+
return [...currentConversation, newMessage];
|
|
5753
|
+
});
|
|
5754
|
+
break;
|
|
5755
|
+
}
|
|
5756
|
+
}
|
|
5757
|
+
}
|
|
5758
|
+
});
|
|
5759
|
+
setIsRunning(false);
|
|
5760
|
+
return;
|
|
5761
|
+
}
|
|
5762
|
+
} else {
|
|
5763
|
+
if (chatWithGenerate) {
|
|
5764
|
+
const generateResponse = await agent.generate({
|
|
5765
|
+
messages: [
|
|
5766
|
+
{
|
|
5767
|
+
role: "user",
|
|
5768
|
+
content: input
|
|
5769
|
+
},
|
|
5770
|
+
...attachments
|
|
5771
|
+
],
|
|
5772
|
+
runId: agentId,
|
|
5773
|
+
frequencyPenalty,
|
|
5774
|
+
presencePenalty,
|
|
5775
|
+
maxRetries,
|
|
5776
|
+
maxSteps,
|
|
5777
|
+
maxTokens,
|
|
5778
|
+
temperature,
|
|
5779
|
+
topK,
|
|
5780
|
+
topP,
|
|
5781
|
+
instructions,
|
|
5782
|
+
runtimeContext: runtimeContextInstance,
|
|
5783
|
+
...memory ? { threadId, resourceId: agentId } : {},
|
|
5784
|
+
providerOptions
|
|
5785
|
+
});
|
|
5786
|
+
if (generateResponse.response && "messages" in generateResponse.response) {
|
|
5787
|
+
const latestMessage = generateResponse.response.messages.reduce(
|
|
5788
|
+
(acc, message2) => {
|
|
5789
|
+
const _content = Array.isArray(acc.content) ? acc.content : [];
|
|
5790
|
+
if (typeof message2.content === "string") {
|
|
5791
|
+
return {
|
|
5792
|
+
...acc,
|
|
5664
5793
|
content: [
|
|
5665
|
-
|
|
5794
|
+
..._content,
|
|
5795
|
+
...generateResponse.reasoning ? [{ type: "reasoning", text: generateResponse.reasoning }] : [],
|
|
5666
5796
|
{
|
|
5667
|
-
type: "
|
|
5668
|
-
|
|
5669
|
-
toolName: chunk.payload.toolName,
|
|
5670
|
-
args: chunk.payload.args
|
|
5797
|
+
type: "text",
|
|
5798
|
+
text: message2.content
|
|
5671
5799
|
}
|
|
5672
5800
|
]
|
|
5673
5801
|
};
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
setMessages((currentConversation) => {
|
|
5683
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5684
|
-
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5685
|
-
const updatedContent = lastMessage.content.map((part) => {
|
|
5686
|
-
if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === chunk.payload.toolCallId) {
|
|
5687
|
-
return {
|
|
5688
|
-
...part,
|
|
5689
|
-
result: chunk.payload.result
|
|
5690
|
-
};
|
|
5802
|
+
}
|
|
5803
|
+
if (message2.role === "assistant") {
|
|
5804
|
+
const toolCallContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-call") : void 0;
|
|
5805
|
+
const reasoningContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "reasoning") : void 0;
|
|
5806
|
+
if (toolCallContent) {
|
|
5807
|
+
const newContent = _content.map((c) => {
|
|
5808
|
+
if (c.type === "tool-call" && c.toolCallId === toolCallContent?.toolCallId) {
|
|
5809
|
+
return { ...c, ...toolCallContent };
|
|
5691
5810
|
}
|
|
5692
|
-
return
|
|
5811
|
+
return c;
|
|
5693
5812
|
});
|
|
5694
|
-
const
|
|
5695
|
-
|
|
5696
|
-
|
|
5813
|
+
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5814
|
+
return {
|
|
5815
|
+
...acc,
|
|
5816
|
+
content: containsToolCall ? [...reasoningContent ? [reasoningContent] : [], ...newContent] : [..._content, ...reasoningContent ? [reasoningContent] : [], toolCallContent]
|
|
5697
5817
|
};
|
|
5698
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5699
5818
|
}
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5819
|
+
const textContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "text" && content.text) : void 0;
|
|
5820
|
+
if (textContent) {
|
|
5821
|
+
return {
|
|
5822
|
+
...acc,
|
|
5823
|
+
content: [..._content, ...reasoningContent ? [reasoningContent] : [], textContent]
|
|
5824
|
+
};
|
|
5706
5825
|
}
|
|
5707
|
-
} finally {
|
|
5708
|
-
delete toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5709
5826
|
}
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
break;
|
|
5717
|
-
}
|
|
5718
|
-
case "finish": {
|
|
5719
|
-
handleFinishReason(chunk.payload.finishReason);
|
|
5720
|
-
break;
|
|
5721
|
-
}
|
|
5722
|
-
case "reasoning-delta": {
|
|
5723
|
-
setMessages((currentConversation) => {
|
|
5724
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5725
|
-
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5726
|
-
const updatedContent = lastMessage.content.map((part) => {
|
|
5727
|
-
if (typeof part === "object" && part.type === "reasoning") {
|
|
5728
|
-
return {
|
|
5729
|
-
...part,
|
|
5730
|
-
text: part.text + chunk.payload.text
|
|
5731
|
-
};
|
|
5827
|
+
if (message2.role === "tool") {
|
|
5828
|
+
const toolResult = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-result") : void 0;
|
|
5829
|
+
if (toolResult) {
|
|
5830
|
+
const newContent = _content.map((c) => {
|
|
5831
|
+
if (c.type === "tool-call" && c.toolCallId === toolResult?.toolCallId) {
|
|
5832
|
+
return { ...c, result: toolResult.result };
|
|
5732
5833
|
}
|
|
5733
|
-
return
|
|
5834
|
+
return c;
|
|
5734
5835
|
});
|
|
5735
|
-
const
|
|
5736
|
-
|
|
5737
|
-
|
|
5836
|
+
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5837
|
+
return {
|
|
5838
|
+
...acc,
|
|
5839
|
+
content: containsToolCall ? newContent : [
|
|
5840
|
+
..._content,
|
|
5841
|
+
{ type: "tool-result", toolCallId: toolResult.toolCallId, result: toolResult.result }
|
|
5842
|
+
]
|
|
5738
5843
|
};
|
|
5739
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5740
5844
|
}
|
|
5741
|
-
const newMessage = {
|
|
5742
|
-
role: "assistant",
|
|
5743
|
-
content: [
|
|
5744
|
-
{
|
|
5745
|
-
type: "reasoning",
|
|
5746
|
-
text: chunk.payload.text
|
|
5747
|
-
},
|
|
5748
|
-
{ type: "text", text: content }
|
|
5749
|
-
]
|
|
5750
|
-
};
|
|
5751
|
-
return [...currentConversation, newMessage];
|
|
5752
|
-
});
|
|
5753
|
-
break;
|
|
5754
|
-
}
|
|
5755
|
-
}
|
|
5756
|
-
}
|
|
5757
|
-
});
|
|
5758
|
-
setIsRunning(false);
|
|
5759
|
-
return;
|
|
5760
|
-
}
|
|
5761
|
-
if (chatWithGenerate) {
|
|
5762
|
-
const generateResponse = await agent.generate({
|
|
5763
|
-
messages: [
|
|
5764
|
-
{
|
|
5765
|
-
role: "user",
|
|
5766
|
-
content: input
|
|
5767
|
-
},
|
|
5768
|
-
...attachments
|
|
5769
|
-
],
|
|
5770
|
-
runId: agentId,
|
|
5771
|
-
frequencyPenalty,
|
|
5772
|
-
presencePenalty,
|
|
5773
|
-
maxRetries,
|
|
5774
|
-
maxSteps,
|
|
5775
|
-
maxTokens,
|
|
5776
|
-
temperature,
|
|
5777
|
-
topK,
|
|
5778
|
-
topP,
|
|
5779
|
-
instructions,
|
|
5780
|
-
runtimeContext: runtimeContextInstance,
|
|
5781
|
-
...memory ? { threadId, resourceId: agentId } : {},
|
|
5782
|
-
providerOptions
|
|
5783
|
-
});
|
|
5784
|
-
if (generateResponse.response && "messages" in generateResponse.response) {
|
|
5785
|
-
const latestMessage = generateResponse.response.messages.reduce(
|
|
5786
|
-
(acc, message2) => {
|
|
5787
|
-
const _content = Array.isArray(acc.content) ? acc.content : [];
|
|
5788
|
-
if (typeof message2.content === "string") {
|
|
5789
|
-
return {
|
|
5790
|
-
...acc,
|
|
5791
|
-
content: [
|
|
5792
|
-
..._content,
|
|
5793
|
-
...generateResponse.reasoning ? [{ type: "reasoning", text: generateResponse.reasoning }] : [],
|
|
5794
|
-
{
|
|
5795
|
-
type: "text",
|
|
5796
|
-
text: message2.content
|
|
5797
|
-
}
|
|
5798
|
-
]
|
|
5799
|
-
};
|
|
5800
|
-
}
|
|
5801
|
-
if (message2.role === "assistant") {
|
|
5802
|
-
const toolCallContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-call") : void 0;
|
|
5803
|
-
const reasoningContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "reasoning") : void 0;
|
|
5804
|
-
if (toolCallContent) {
|
|
5805
|
-
const newContent = _content.map((c) => {
|
|
5806
|
-
if (c.type === "tool-call" && c.toolCallId === toolCallContent?.toolCallId) {
|
|
5807
|
-
return { ...c, ...toolCallContent };
|
|
5808
|
-
}
|
|
5809
|
-
return c;
|
|
5810
|
-
});
|
|
5811
|
-
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5812
|
-
return {
|
|
5813
|
-
...acc,
|
|
5814
|
-
content: containsToolCall ? [...reasoningContent ? [reasoningContent] : [], ...newContent] : [..._content, ...reasoningContent ? [reasoningContent] : [], toolCallContent]
|
|
5815
|
-
};
|
|
5816
|
-
}
|
|
5817
|
-
const textContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "text" && content.text) : void 0;
|
|
5818
|
-
if (textContent) {
|
|
5819
5845
|
return {
|
|
5820
5846
|
...acc,
|
|
5821
|
-
content: [..._content,
|
|
5847
|
+
content: [..._content, toolResult]
|
|
5822
5848
|
};
|
|
5823
5849
|
}
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5850
|
+
return acc;
|
|
5851
|
+
},
|
|
5852
|
+
{ role: "assistant", content: [] }
|
|
5853
|
+
);
|
|
5854
|
+
setMessages((currentConversation) => [...currentConversation, latestMessage]);
|
|
5855
|
+
handleFinishReason(generateResponse.finishReason);
|
|
5856
|
+
}
|
|
5857
|
+
} else {
|
|
5858
|
+
let updater = function() {
|
|
5859
|
+
setMessages((currentConversation) => {
|
|
5860
|
+
const message2 = {
|
|
5861
|
+
role: "assistant",
|
|
5862
|
+
content: [{ type: "text", text: content }]
|
|
5863
|
+
};
|
|
5864
|
+
if (!assistantMessageAdded) {
|
|
5865
|
+
assistantMessageAdded = true;
|
|
5866
|
+
if (assistantToolCallAddedForUpdater) {
|
|
5867
|
+
assistantToolCallAddedForUpdater = false;
|
|
5842
5868
|
}
|
|
5843
|
-
return
|
|
5844
|
-
...acc,
|
|
5845
|
-
content: [..._content, toolResult]
|
|
5846
|
-
};
|
|
5869
|
+
return [...currentConversation, message2];
|
|
5847
5870
|
}
|
|
5848
|
-
return acc;
|
|
5849
|
-
},
|
|
5850
|
-
{ role: "assistant", content: [] }
|
|
5851
|
-
);
|
|
5852
|
-
setMessages((currentConversation) => [...currentConversation, latestMessage]);
|
|
5853
|
-
handleFinishReason(generateResponse.finishReason);
|
|
5854
|
-
}
|
|
5855
|
-
} else {
|
|
5856
|
-
let updater = function() {
|
|
5857
|
-
setMessages((currentConversation) => {
|
|
5858
|
-
const message2 = {
|
|
5859
|
-
role: "assistant",
|
|
5860
|
-
content: [{ type: "text", text: content }]
|
|
5861
|
-
};
|
|
5862
|
-
if (!assistantMessageAdded) {
|
|
5863
|
-
assistantMessageAdded = true;
|
|
5864
5871
|
if (assistantToolCallAddedForUpdater) {
|
|
5865
5872
|
assistantToolCallAddedForUpdater = false;
|
|
5873
|
+
return [...currentConversation, message2];
|
|
5866
5874
|
}
|
|
5867
|
-
return [...currentConversation, message2];
|
|
5868
|
-
}
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5875
|
+
return [...currentConversation.slice(0, -1), message2];
|
|
5876
|
+
});
|
|
5877
|
+
};
|
|
5878
|
+
const response = await agent.stream({
|
|
5879
|
+
messages: [
|
|
5880
|
+
{
|
|
5881
|
+
role: "user",
|
|
5882
|
+
content: input
|
|
5883
|
+
},
|
|
5884
|
+
...attachments
|
|
5885
|
+
],
|
|
5886
|
+
runId: agentId,
|
|
5887
|
+
frequencyPenalty,
|
|
5888
|
+
presencePenalty,
|
|
5889
|
+
maxRetries,
|
|
5890
|
+
maxSteps,
|
|
5891
|
+
maxTokens,
|
|
5892
|
+
temperature,
|
|
5893
|
+
topK,
|
|
5894
|
+
topP,
|
|
5895
|
+
instructions,
|
|
5896
|
+
runtimeContext: runtimeContextInstance,
|
|
5897
|
+
...memory ? { threadId, resourceId: agentId } : {},
|
|
5898
|
+
providerOptions
|
|
5874
5899
|
});
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5900
|
+
if (!response.body) {
|
|
5901
|
+
throw new Error("No response body");
|
|
5902
|
+
}
|
|
5903
|
+
let content = "";
|
|
5904
|
+
let assistantMessageAdded = false;
|
|
5905
|
+
let assistantToolCallAddedForUpdater = false;
|
|
5906
|
+
let assistantToolCallAddedForContent = false;
|
|
5907
|
+
await response.processDataStream({
|
|
5908
|
+
onTextPart(value) {
|
|
5909
|
+
if (assistantToolCallAddedForContent) {
|
|
5910
|
+
assistantToolCallAddedForContent = false;
|
|
5911
|
+
content = value;
|
|
5912
|
+
} else {
|
|
5913
|
+
content += value;
|
|
5914
|
+
}
|
|
5915
|
+
updater();
|
|
5881
5916
|
},
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
},
|
|
5915
|
-
async onToolCallPart(value) {
|
|
5916
|
-
setMessages((currentConversation) => {
|
|
5917
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5918
|
-
if (lastMessage && lastMessage.role === "assistant") {
|
|
5919
|
-
const updatedMessage = {
|
|
5920
|
-
...lastMessage,
|
|
5921
|
-
content: Array.isArray(lastMessage.content) ? [
|
|
5922
|
-
...lastMessage.content,
|
|
5923
|
-
{
|
|
5924
|
-
type: "tool-call",
|
|
5925
|
-
toolCallId: value.toolCallId,
|
|
5926
|
-
toolName: value.toolName,
|
|
5927
|
-
args: value.args
|
|
5928
|
-
}
|
|
5929
|
-
] : [
|
|
5930
|
-
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
5917
|
+
async onToolCallPart(value) {
|
|
5918
|
+
setMessages((currentConversation) => {
|
|
5919
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5920
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
5921
|
+
const updatedMessage = {
|
|
5922
|
+
...lastMessage,
|
|
5923
|
+
content: Array.isArray(lastMessage.content) ? [
|
|
5924
|
+
...lastMessage.content,
|
|
5925
|
+
{
|
|
5926
|
+
type: "tool-call",
|
|
5927
|
+
toolCallId: value.toolCallId,
|
|
5928
|
+
toolName: value.toolName,
|
|
5929
|
+
args: value.args
|
|
5930
|
+
}
|
|
5931
|
+
] : [
|
|
5932
|
+
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
5933
|
+
{
|
|
5934
|
+
type: "tool-call",
|
|
5935
|
+
toolCallId: value.toolCallId,
|
|
5936
|
+
toolName: value.toolName,
|
|
5937
|
+
args: value.args
|
|
5938
|
+
}
|
|
5939
|
+
]
|
|
5940
|
+
};
|
|
5941
|
+
assistantToolCallAddedForUpdater = true;
|
|
5942
|
+
assistantToolCallAddedForContent = true;
|
|
5943
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5944
|
+
}
|
|
5945
|
+
const newMessage = {
|
|
5946
|
+
role: "assistant",
|
|
5947
|
+
content: [
|
|
5948
|
+
{ type: "text", text: content },
|
|
5931
5949
|
{
|
|
5932
5950
|
type: "tool-call",
|
|
5933
5951
|
toolCallId: value.toolCallId,
|
|
@@ -5938,95 +5956,80 @@ function MastraRuntimeProvider({
|
|
|
5938
5956
|
};
|
|
5939
5957
|
assistantToolCallAddedForUpdater = true;
|
|
5940
5958
|
assistantToolCallAddedForContent = true;
|
|
5941
|
-
return [...currentConversation
|
|
5959
|
+
return [...currentConversation, newMessage];
|
|
5960
|
+
});
|
|
5961
|
+
toolCallIdToName.current[value.toolCallId] = value.toolName;
|
|
5962
|
+
},
|
|
5963
|
+
async onToolResultPart(value) {
|
|
5964
|
+
setMessages((currentConversation) => {
|
|
5965
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5966
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5967
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
5968
|
+
if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === value.toolCallId) {
|
|
5969
|
+
return {
|
|
5970
|
+
...part,
|
|
5971
|
+
result: value.result
|
|
5972
|
+
};
|
|
5973
|
+
}
|
|
5974
|
+
return part;
|
|
5975
|
+
});
|
|
5976
|
+
const updatedMessage = {
|
|
5977
|
+
...lastMessage,
|
|
5978
|
+
content: updatedContent
|
|
5979
|
+
};
|
|
5980
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5981
|
+
}
|
|
5982
|
+
return currentConversation;
|
|
5983
|
+
});
|
|
5984
|
+
try {
|
|
5985
|
+
const toolName = toolCallIdToName.current[value.toolCallId];
|
|
5986
|
+
if (toolName === "updateWorkingMemory" && value.result?.success) {
|
|
5987
|
+
await refreshWorkingMemory?.();
|
|
5988
|
+
}
|
|
5989
|
+
} finally {
|
|
5990
|
+
delete toolCallIdToName.current[value.toolCallId];
|
|
5942
5991
|
}
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5992
|
+
},
|
|
5993
|
+
onErrorPart(error) {
|
|
5994
|
+
throw new Error(error);
|
|
5995
|
+
},
|
|
5996
|
+
onFinishMessagePart({ finishReason }) {
|
|
5997
|
+
handleFinishReason(finishReason);
|
|
5998
|
+
},
|
|
5999
|
+
onReasoningPart(value) {
|
|
6000
|
+
setMessages((currentConversation) => {
|
|
6001
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
6002
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
6003
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
6004
|
+
if (typeof part === "object" && part.type === "reasoning") {
|
|
6005
|
+
return {
|
|
6006
|
+
...part,
|
|
6007
|
+
text: part.text + value
|
|
6008
|
+
};
|
|
6009
|
+
}
|
|
6010
|
+
return part;
|
|
6011
|
+
});
|
|
6012
|
+
const updatedMessage = {
|
|
6013
|
+
...lastMessage,
|
|
6014
|
+
content: updatedContent
|
|
6015
|
+
};
|
|
6016
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
6017
|
+
}
|
|
6018
|
+
const newMessage = {
|
|
6019
|
+
role: "assistant",
|
|
6020
|
+
content: [
|
|
6021
|
+
{
|
|
6022
|
+
type: "reasoning",
|
|
6023
|
+
text: value
|
|
6024
|
+
},
|
|
6025
|
+
{ type: "text", text: content }
|
|
6026
|
+
]
|
|
5977
6027
|
};
|
|
5978
|
-
return [...currentConversation
|
|
5979
|
-
}
|
|
5980
|
-
return currentConversation;
|
|
5981
|
-
});
|
|
5982
|
-
try {
|
|
5983
|
-
const toolName = toolCallIdToName.current[value.toolCallId];
|
|
5984
|
-
if (toolName === "updateWorkingMemory" && value.result?.success) {
|
|
5985
|
-
await refreshWorkingMemory?.();
|
|
5986
|
-
}
|
|
5987
|
-
} finally {
|
|
5988
|
-
delete toolCallIdToName.current[value.toolCallId];
|
|
6028
|
+
return [...currentConversation, newMessage];
|
|
6029
|
+
});
|
|
5989
6030
|
}
|
|
5990
|
-
}
|
|
5991
|
-
|
|
5992
|
-
throw new Error(error);
|
|
5993
|
-
},
|
|
5994
|
-
onFinishMessagePart({ finishReason }) {
|
|
5995
|
-
handleFinishReason(finishReason);
|
|
5996
|
-
},
|
|
5997
|
-
onReasoningPart(value) {
|
|
5998
|
-
setMessages((currentConversation) => {
|
|
5999
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
6000
|
-
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
6001
|
-
const updatedContent = lastMessage.content.map((part) => {
|
|
6002
|
-
if (typeof part === "object" && part.type === "reasoning") {
|
|
6003
|
-
return {
|
|
6004
|
-
...part,
|
|
6005
|
-
text: part.text + value
|
|
6006
|
-
};
|
|
6007
|
-
}
|
|
6008
|
-
return part;
|
|
6009
|
-
});
|
|
6010
|
-
const updatedMessage = {
|
|
6011
|
-
...lastMessage,
|
|
6012
|
-
content: updatedContent
|
|
6013
|
-
};
|
|
6014
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
6015
|
-
}
|
|
6016
|
-
const newMessage = {
|
|
6017
|
-
role: "assistant",
|
|
6018
|
-
content: [
|
|
6019
|
-
{
|
|
6020
|
-
type: "reasoning",
|
|
6021
|
-
text: value
|
|
6022
|
-
},
|
|
6023
|
-
{ type: "text", text: content }
|
|
6024
|
-
]
|
|
6025
|
-
};
|
|
6026
|
-
return [...currentConversation, newMessage];
|
|
6027
|
-
});
|
|
6028
|
-
}
|
|
6029
|
-
});
|
|
6031
|
+
});
|
|
6032
|
+
}
|
|
6030
6033
|
}
|
|
6031
6034
|
setIsRunning(false);
|
|
6032
6035
|
setTimeout(() => {
|
|
@@ -6076,7 +6079,8 @@ const defaultSettings = {
|
|
|
6076
6079
|
maxSteps: 5,
|
|
6077
6080
|
temperature: 0.5,
|
|
6078
6081
|
topP: 1,
|
|
6079
|
-
chatWithGenerate: false
|
|
6082
|
+
chatWithGenerate: false,
|
|
6083
|
+
chatWithGenerateVNext: false
|
|
6080
6084
|
}
|
|
6081
6085
|
};
|
|
6082
6086
|
function useAgentSettingsState({ agentId }) {
|
|
@@ -6148,7 +6152,8 @@ const AgentChat = ({
|
|
|
6148
6152
|
initialMessages,
|
|
6149
6153
|
memory,
|
|
6150
6154
|
refreshThreadList,
|
|
6151
|
-
onInputChange
|
|
6155
|
+
onInputChange,
|
|
6156
|
+
modelVersion
|
|
6152
6157
|
}) => {
|
|
6153
6158
|
const { settings } = useAgentSettings();
|
|
6154
6159
|
const { runtimeContext } = usePlaygroundStore();
|
|
@@ -6157,6 +6162,7 @@ const AgentChat = ({
|
|
|
6157
6162
|
{
|
|
6158
6163
|
agentId,
|
|
6159
6164
|
agentName,
|
|
6165
|
+
modelVersion,
|
|
6160
6166
|
threadId,
|
|
6161
6167
|
initialMessages,
|
|
6162
6168
|
memory,
|