@mastra/playground-ui 5.1.21-alpha.2 → 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 +521 -194
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +521 -194
- package/dist/index.es.js.map +1 -1
- package/dist/src/domains/agents/components/agent-chat.d.ts +1 -1
- package/dist/src/domains/agents/components/agent-settings.d.ts +3 -1
- package/dist/src/services/mastra-runtime-provider.d.ts +1 -1
- package/dist/src/types.d.ts +3 -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([]);
|
|
@@ -5379,6 +5380,8 @@ function MastraRuntimeProvider({
|
|
|
5379
5380
|
topP,
|
|
5380
5381
|
instructions,
|
|
5381
5382
|
chatWithGenerate,
|
|
5383
|
+
chatWithGenerateVNext,
|
|
5384
|
+
chatWithStreamVNext,
|
|
5382
5385
|
providerOptions
|
|
5383
5386
|
} = settings?.modelSettings ?? {};
|
|
5384
5387
|
const toolCallIdToName = useRef({});
|
|
@@ -5456,31 +5459,9 @@ function MastraRuntimeProvider({
|
|
|
5456
5459
|
});
|
|
5457
5460
|
const agent = clientWithAbort.getAgent(agentId);
|
|
5458
5461
|
try {
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
messages
|
|
5462
|
-
{
|
|
5463
|
-
role: "user",
|
|
5464
|
-
content: input
|
|
5465
|
-
},
|
|
5466
|
-
...attachments
|
|
5467
|
-
],
|
|
5468
|
-
runId: agentId,
|
|
5469
|
-
frequencyPenalty,
|
|
5470
|
-
presencePenalty,
|
|
5471
|
-
maxRetries,
|
|
5472
|
-
maxSteps,
|
|
5473
|
-
maxTokens,
|
|
5474
|
-
temperature,
|
|
5475
|
-
topK,
|
|
5476
|
-
topP,
|
|
5477
|
-
instructions,
|
|
5478
|
-
runtimeContext: runtimeContextInstance,
|
|
5479
|
-
...memory ? { threadId, resourceId: agentId } : {},
|
|
5480
|
-
providerOptions
|
|
5481
|
-
});
|
|
5482
|
-
if (generateResponse.response && "messages" in generateResponse.response) {
|
|
5483
|
-
const latestMessage = generateResponse.response.messages.reduce(
|
|
5462
|
+
let handleGenerateResponse = function(generatedResponse) {
|
|
5463
|
+
if (generatedResponse.response && "messages" in generatedResponse.response) {
|
|
5464
|
+
const latestMessage = generatedResponse.response.messages.reduce(
|
|
5484
5465
|
(acc, message2) => {
|
|
5485
5466
|
const _content = Array.isArray(acc.content) ? acc.content : [];
|
|
5486
5467
|
if (typeof message2.content === "string") {
|
|
@@ -5488,7 +5469,7 @@ function MastraRuntimeProvider({
|
|
|
5488
5469
|
...acc,
|
|
5489
5470
|
content: [
|
|
5490
5471
|
..._content,
|
|
5491
|
-
...
|
|
5472
|
+
...generatedResponse.reasoning ? [{ type: "reasoning", text: generatedResponse.reasoning }] : [],
|
|
5492
5473
|
{
|
|
5493
5474
|
type: "text",
|
|
5494
5475
|
text: message2.content
|
|
@@ -5500,9 +5481,14 @@ function MastraRuntimeProvider({
|
|
|
5500
5481
|
const toolCallContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-call") : void 0;
|
|
5501
5482
|
const reasoningContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "reasoning") : void 0;
|
|
5502
5483
|
if (toolCallContent) {
|
|
5503
|
-
const newContent =
|
|
5484
|
+
const newContent = message2.content.map((c) => {
|
|
5504
5485
|
if (c.type === "tool-call" && c.toolCallId === toolCallContent?.toolCallId) {
|
|
5505
|
-
return {
|
|
5486
|
+
return {
|
|
5487
|
+
...c,
|
|
5488
|
+
toolCallId: toolCallContent.toolCallId,
|
|
5489
|
+
toolName: toolCallContent.toolName,
|
|
5490
|
+
args: toolCallContent.input
|
|
5491
|
+
};
|
|
5506
5492
|
}
|
|
5507
5493
|
return c;
|
|
5508
5494
|
});
|
|
@@ -5525,7 +5511,7 @@ function MastraRuntimeProvider({
|
|
|
5525
5511
|
if (toolResult) {
|
|
5526
5512
|
const newContent = _content.map((c) => {
|
|
5527
5513
|
if (c.type === "tool-call" && c.toolCallId === toolResult?.toolCallId) {
|
|
5528
|
-
return { ...c, result: toolResult.
|
|
5514
|
+
return { ...c, result: toolResult.output?.value };
|
|
5529
5515
|
}
|
|
5530
5516
|
return c;
|
|
5531
5517
|
});
|
|
@@ -5534,7 +5520,7 @@ function MastraRuntimeProvider({
|
|
|
5534
5520
|
...acc,
|
|
5535
5521
|
content: containsToolCall ? newContent : [
|
|
5536
5522
|
..._content,
|
|
5537
|
-
{ type: "tool-result", toolCallId: toolResult.toolCallId, result: toolResult.
|
|
5523
|
+
{ type: "tool-result", toolCallId: toolResult.toolCallId, result: toolResult.output?.value }
|
|
5538
5524
|
]
|
|
5539
5525
|
};
|
|
5540
5526
|
}
|
|
@@ -5548,84 +5534,418 @@ function MastraRuntimeProvider({
|
|
|
5548
5534
|
{ role: "assistant", content: [] }
|
|
5549
5535
|
);
|
|
5550
5536
|
setMessages((currentConversation) => [...currentConversation, latestMessage]);
|
|
5551
|
-
|
|
5537
|
+
if (generatedResponse.finishReason) {
|
|
5538
|
+
handleFinishReason(generatedResponse.finishReason);
|
|
5539
|
+
}
|
|
5552
5540
|
}
|
|
5553
|
-
}
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5541
|
+
};
|
|
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
|
|
5561
|
+
},
|
|
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
|
+
}
|
|
5562
5584
|
if (assistantToolCallAddedForUpdater) {
|
|
5563
5585
|
assistantToolCallAddedForUpdater = false;
|
|
5586
|
+
return [...currentConversation, message2];
|
|
5587
|
+
}
|
|
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
|
|
5608
|
+
},
|
|
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;
|
|
5634
|
+
}
|
|
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 },
|
|
5667
|
+
{
|
|
5668
|
+
type: "tool-call",
|
|
5669
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5670
|
+
toolName: chunk.payload.toolName,
|
|
5671
|
+
args: chunk.payload.args
|
|
5672
|
+
}
|
|
5673
|
+
]
|
|
5674
|
+
};
|
|
5675
|
+
assistantToolCallAddedForUpdater = true;
|
|
5676
|
+
assistantToolCallAddedForContent = true;
|
|
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];
|
|
5710
|
+
}
|
|
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
|
+
}
|
|
5564
5756
|
}
|
|
5565
|
-
return [...currentConversation, message2];
|
|
5566
|
-
}
|
|
5567
|
-
if (assistantToolCallAddedForUpdater) {
|
|
5568
|
-
assistantToolCallAddedForUpdater = false;
|
|
5569
|
-
return [...currentConversation, message2];
|
|
5570
5757
|
}
|
|
5571
|
-
return [...currentConversation.slice(0, -1), message2];
|
|
5572
5758
|
});
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
messages: [
|
|
5576
|
-
{
|
|
5577
|
-
role: "user",
|
|
5578
|
-
content: input
|
|
5579
|
-
},
|
|
5580
|
-
...attachments
|
|
5581
|
-
],
|
|
5582
|
-
runId: agentId,
|
|
5583
|
-
frequencyPenalty,
|
|
5584
|
-
presencePenalty,
|
|
5585
|
-
maxRetries,
|
|
5586
|
-
maxSteps,
|
|
5587
|
-
maxTokens,
|
|
5588
|
-
temperature,
|
|
5589
|
-
topK,
|
|
5590
|
-
topP,
|
|
5591
|
-
instructions,
|
|
5592
|
-
runtimeContext: runtimeContextInstance,
|
|
5593
|
-
...memory ? { threadId, resourceId: agentId } : {},
|
|
5594
|
-
providerOptions
|
|
5595
|
-
});
|
|
5596
|
-
if (!response.body) {
|
|
5597
|
-
throw new Error("No response body");
|
|
5759
|
+
setIsRunning(false);
|
|
5760
|
+
return;
|
|
5598
5761
|
}
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
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,
|
|
5793
|
+
content: [
|
|
5794
|
+
..._content,
|
|
5795
|
+
...generateResponse.reasoning ? [{ type: "reasoning", text: generateResponse.reasoning }] : [],
|
|
5796
|
+
{
|
|
5797
|
+
type: "text",
|
|
5798
|
+
text: message2.content
|
|
5799
|
+
}
|
|
5800
|
+
]
|
|
5801
|
+
};
|
|
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 };
|
|
5810
|
+
}
|
|
5811
|
+
return c;
|
|
5812
|
+
});
|
|
5813
|
+
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5814
|
+
return {
|
|
5815
|
+
...acc,
|
|
5816
|
+
content: containsToolCall ? [...reasoningContent ? [reasoningContent] : [], ...newContent] : [..._content, ...reasoningContent ? [reasoningContent] : [], toolCallContent]
|
|
5817
|
+
};
|
|
5818
|
+
}
|
|
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
|
+
};
|
|
5825
|
+
}
|
|
5826
|
+
}
|
|
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 };
|
|
5833
|
+
}
|
|
5834
|
+
return c;
|
|
5835
|
+
});
|
|
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
|
+
]
|
|
5843
|
+
};
|
|
5844
|
+
}
|
|
5845
|
+
return {
|
|
5846
|
+
...acc,
|
|
5847
|
+
content: [..._content, toolResult]
|
|
5848
|
+
};
|
|
5849
|
+
}
|
|
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() {
|
|
5614
5859
|
setMessages((currentConversation) => {
|
|
5615
|
-
const
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
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;
|
|
5868
|
+
}
|
|
5869
|
+
return [...currentConversation, message2];
|
|
5870
|
+
}
|
|
5871
|
+
if (assistantToolCallAddedForUpdater) {
|
|
5872
|
+
assistantToolCallAddedForUpdater = false;
|
|
5873
|
+
return [...currentConversation, message2];
|
|
5874
|
+
}
|
|
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
|
|
5899
|
+
});
|
|
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();
|
|
5916
|
+
},
|
|
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 },
|
|
5629
5949
|
{
|
|
5630
5950
|
type: "tool-call",
|
|
5631
5951
|
toolCallId: value.toolCallId,
|
|
@@ -5636,95 +5956,80 @@ function MastraRuntimeProvider({
|
|
|
5636
5956
|
};
|
|
5637
5957
|
assistantToolCallAddedForUpdater = true;
|
|
5638
5958
|
assistantToolCallAddedForContent = true;
|
|
5639
|
-
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];
|
|
5640
5991
|
}
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
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
|
+
]
|
|
5675
6027
|
};
|
|
5676
|
-
return [...currentConversation
|
|
5677
|
-
}
|
|
5678
|
-
return currentConversation;
|
|
5679
|
-
});
|
|
5680
|
-
try {
|
|
5681
|
-
const toolName = toolCallIdToName.current[value.toolCallId];
|
|
5682
|
-
if (toolName === "updateWorkingMemory" && value.result?.success) {
|
|
5683
|
-
await refreshWorkingMemory?.();
|
|
5684
|
-
}
|
|
5685
|
-
} finally {
|
|
5686
|
-
delete toolCallIdToName.current[value.toolCallId];
|
|
6028
|
+
return [...currentConversation, newMessage];
|
|
6029
|
+
});
|
|
5687
6030
|
}
|
|
5688
|
-
}
|
|
5689
|
-
|
|
5690
|
-
throw new Error(error);
|
|
5691
|
-
},
|
|
5692
|
-
onFinishMessagePart({ finishReason }) {
|
|
5693
|
-
handleFinishReason(finishReason);
|
|
5694
|
-
},
|
|
5695
|
-
onReasoningPart(value) {
|
|
5696
|
-
setMessages((currentConversation) => {
|
|
5697
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5698
|
-
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
5699
|
-
const updatedContent = lastMessage.content.map((part) => {
|
|
5700
|
-
if (typeof part === "object" && part.type === "reasoning") {
|
|
5701
|
-
return {
|
|
5702
|
-
...part,
|
|
5703
|
-
text: part.text + value
|
|
5704
|
-
};
|
|
5705
|
-
}
|
|
5706
|
-
return part;
|
|
5707
|
-
});
|
|
5708
|
-
const updatedMessage = {
|
|
5709
|
-
...lastMessage,
|
|
5710
|
-
content: updatedContent
|
|
5711
|
-
};
|
|
5712
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5713
|
-
}
|
|
5714
|
-
const newMessage = {
|
|
5715
|
-
role: "assistant",
|
|
5716
|
-
content: [
|
|
5717
|
-
{
|
|
5718
|
-
type: "reasoning",
|
|
5719
|
-
text: value
|
|
5720
|
-
},
|
|
5721
|
-
{ type: "text", text: content }
|
|
5722
|
-
]
|
|
5723
|
-
};
|
|
5724
|
-
return [...currentConversation, newMessage];
|
|
5725
|
-
});
|
|
5726
|
-
}
|
|
5727
|
-
});
|
|
6031
|
+
});
|
|
6032
|
+
}
|
|
5728
6033
|
}
|
|
5729
6034
|
setIsRunning(false);
|
|
5730
6035
|
setTimeout(() => {
|
|
@@ -5774,7 +6079,8 @@ const defaultSettings = {
|
|
|
5774
6079
|
maxSteps: 5,
|
|
5775
6080
|
temperature: 0.5,
|
|
5776
6081
|
topP: 1,
|
|
5777
|
-
chatWithGenerate: false
|
|
6082
|
+
chatWithGenerate: false,
|
|
6083
|
+
chatWithGenerateVNext: false
|
|
5778
6084
|
}
|
|
5779
6085
|
};
|
|
5780
6086
|
function useAgentSettingsState({ agentId }) {
|
|
@@ -5846,7 +6152,8 @@ const AgentChat = ({
|
|
|
5846
6152
|
initialMessages,
|
|
5847
6153
|
memory,
|
|
5848
6154
|
refreshThreadList,
|
|
5849
|
-
onInputChange
|
|
6155
|
+
onInputChange,
|
|
6156
|
+
modelVersion
|
|
5850
6157
|
}) => {
|
|
5851
6158
|
const { settings } = useAgentSettings();
|
|
5852
6159
|
const { runtimeContext } = usePlaygroundStore();
|
|
@@ -5855,6 +6162,7 @@ const AgentChat = ({
|
|
|
5855
6162
|
{
|
|
5856
6163
|
agentId,
|
|
5857
6164
|
agentName,
|
|
6165
|
+
modelVersion,
|
|
5858
6166
|
threadId,
|
|
5859
6167
|
initialMessages,
|
|
5860
6168
|
memory,
|
|
@@ -6622,28 +6930,47 @@ const AgentAdvancedSettings = () => {
|
|
|
6622
6930
|
] }) });
|
|
6623
6931
|
};
|
|
6624
6932
|
|
|
6625
|
-
const AgentSettings = () => {
|
|
6933
|
+
const AgentSettings = ({ modelVersion }) => {
|
|
6626
6934
|
const { settings, setSettings, resetAll } = useAgentSettings();
|
|
6935
|
+
let radioValue;
|
|
6936
|
+
if (modelVersion === "v2") {
|
|
6937
|
+
radioValue = settings?.modelSettings?.chatWithGenerateVNext ? "generateVNext" : "streamVNext";
|
|
6938
|
+
} else {
|
|
6939
|
+
radioValue = settings?.modelSettings?.chatWithGenerate ? "generate" : "stream";
|
|
6940
|
+
}
|
|
6627
6941
|
return /* @__PURE__ */ jsxs("div", { className: "px-5 text-xs py-2 pb-4", children: [
|
|
6628
6942
|
/* @__PURE__ */ jsxs("section", { className: "space-y-7", children: [
|
|
6629
6943
|
/* @__PURE__ */ jsx(Entry, { label: "Chat Method", children: /* @__PURE__ */ jsxs(
|
|
6630
6944
|
RadioGroup,
|
|
6631
6945
|
{
|
|
6632
6946
|
orientation: "horizontal",
|
|
6633
|
-
value:
|
|
6947
|
+
value: radioValue,
|
|
6634
6948
|
onValueChange: (value) => setSettings({
|
|
6635
6949
|
...settings,
|
|
6636
|
-
modelSettings: {
|
|
6950
|
+
modelSettings: {
|
|
6951
|
+
...settings?.modelSettings,
|
|
6952
|
+
chatWithGenerate: value === "generate",
|
|
6953
|
+
chatWithGenerateVNext: value === "generateVNext",
|
|
6954
|
+
chatWithStreamVNext: value === "streamVNext"
|
|
6955
|
+
}
|
|
6637
6956
|
}),
|
|
6638
6957
|
className: "flex flex-row gap-4",
|
|
6639
6958
|
children: [
|
|
6640
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6959
|
+
modelVersion !== "v2" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6641
6960
|
/* @__PURE__ */ jsx(RadioGroupItem, { value: "generate", id: "generate", className: "text-icon6" }),
|
|
6642
6961
|
/* @__PURE__ */ jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "generate", children: "Generate" })
|
|
6643
6962
|
] }),
|
|
6644
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6963
|
+
modelVersion === "v2" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6964
|
+
/* @__PURE__ */ jsx(RadioGroupItem, { value: "generateVNext", id: "generateVNext", className: "text-icon6" }),
|
|
6965
|
+
/* @__PURE__ */ jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "generateVNext", children: "Generate vNext" })
|
|
6966
|
+
] }),
|
|
6967
|
+
modelVersion !== "v2" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6645
6968
|
/* @__PURE__ */ jsx(RadioGroupItem, { value: "stream", id: "stream", className: "text-icon6" }),
|
|
6646
6969
|
/* @__PURE__ */ jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "stream", children: "Stream" })
|
|
6970
|
+
] }),
|
|
6971
|
+
modelVersion === "v2" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6972
|
+
/* @__PURE__ */ jsx(RadioGroupItem, { value: "streamVNext", id: "streamVNext", className: "text-icon6" }),
|
|
6973
|
+
/* @__PURE__ */ jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "streamVNext", children: "Stream vNext" })
|
|
6647
6974
|
] })
|
|
6648
6975
|
]
|
|
6649
6976
|
}
|