@mastra/playground-ui 5.1.21-alpha.2 → 5.1.21-alpha.3
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.es.js
CHANGED
|
@@ -5379,6 +5379,8 @@ function MastraRuntimeProvider({
|
|
|
5379
5379
|
topP,
|
|
5380
5380
|
instructions,
|
|
5381
5381
|
chatWithGenerate,
|
|
5382
|
+
chatWithGenerateVNext,
|
|
5383
|
+
chatWithStreamVNext,
|
|
5382
5384
|
providerOptions
|
|
5383
5385
|
} = settings?.modelSettings ?? {};
|
|
5384
5386
|
const toolCallIdToName = useRef({});
|
|
@@ -5456,6 +5458,306 @@ function MastraRuntimeProvider({
|
|
|
5456
5458
|
});
|
|
5457
5459
|
const agent = clientWithAbort.getAgent(agentId);
|
|
5458
5460
|
try {
|
|
5461
|
+
let handleGenerateResponse = function(generatedResponse) {
|
|
5462
|
+
if (generatedResponse.response && "messages" in generatedResponse.response) {
|
|
5463
|
+
const latestMessage = generatedResponse.response.messages.reduce(
|
|
5464
|
+
(acc, message2) => {
|
|
5465
|
+
const _content = Array.isArray(acc.content) ? acc.content : [];
|
|
5466
|
+
if (typeof message2.content === "string") {
|
|
5467
|
+
return {
|
|
5468
|
+
...acc,
|
|
5469
|
+
content: [
|
|
5470
|
+
..._content,
|
|
5471
|
+
...generatedResponse.reasoning ? [{ type: "reasoning", text: generatedResponse.reasoning }] : [],
|
|
5472
|
+
{
|
|
5473
|
+
type: "text",
|
|
5474
|
+
text: message2.content
|
|
5475
|
+
}
|
|
5476
|
+
]
|
|
5477
|
+
};
|
|
5478
|
+
}
|
|
5479
|
+
if (message2.role === "assistant") {
|
|
5480
|
+
const toolCallContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-call") : void 0;
|
|
5481
|
+
const reasoningContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "reasoning") : void 0;
|
|
5482
|
+
if (toolCallContent) {
|
|
5483
|
+
const newContent = message2.content.map((c) => {
|
|
5484
|
+
if (c.type === "tool-call" && c.toolCallId === toolCallContent?.toolCallId) {
|
|
5485
|
+
return {
|
|
5486
|
+
...c,
|
|
5487
|
+
toolCallId: toolCallContent.toolCallId,
|
|
5488
|
+
toolName: toolCallContent.toolName,
|
|
5489
|
+
args: toolCallContent.input
|
|
5490
|
+
};
|
|
5491
|
+
}
|
|
5492
|
+
return c;
|
|
5493
|
+
});
|
|
5494
|
+
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5495
|
+
return {
|
|
5496
|
+
...acc,
|
|
5497
|
+
content: containsToolCall ? [...reasoningContent ? [reasoningContent] : [], ...newContent] : [..._content, ...reasoningContent ? [reasoningContent] : [], toolCallContent]
|
|
5498
|
+
};
|
|
5499
|
+
}
|
|
5500
|
+
const textContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "text" && content.text) : void 0;
|
|
5501
|
+
if (textContent) {
|
|
5502
|
+
return {
|
|
5503
|
+
...acc,
|
|
5504
|
+
content: [..._content, ...reasoningContent ? [reasoningContent] : [], textContent]
|
|
5505
|
+
};
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
if (message2.role === "tool") {
|
|
5509
|
+
const toolResult = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-result") : void 0;
|
|
5510
|
+
if (toolResult) {
|
|
5511
|
+
const newContent = _content.map((c) => {
|
|
5512
|
+
if (c.type === "tool-call" && c.toolCallId === toolResult?.toolCallId) {
|
|
5513
|
+
return { ...c, result: toolResult.output?.value };
|
|
5514
|
+
}
|
|
5515
|
+
return c;
|
|
5516
|
+
});
|
|
5517
|
+
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5518
|
+
return {
|
|
5519
|
+
...acc,
|
|
5520
|
+
content: containsToolCall ? newContent : [
|
|
5521
|
+
..._content,
|
|
5522
|
+
{ type: "tool-result", toolCallId: toolResult.toolCallId, result: toolResult.output?.value }
|
|
5523
|
+
]
|
|
5524
|
+
};
|
|
5525
|
+
}
|
|
5526
|
+
return {
|
|
5527
|
+
...acc,
|
|
5528
|
+
content: [..._content, toolResult]
|
|
5529
|
+
};
|
|
5530
|
+
}
|
|
5531
|
+
return acc;
|
|
5532
|
+
},
|
|
5533
|
+
{ role: "assistant", content: [] }
|
|
5534
|
+
);
|
|
5535
|
+
setMessages((currentConversation) => [...currentConversation, latestMessage]);
|
|
5536
|
+
if (generatedResponse.finishReason) {
|
|
5537
|
+
handleFinishReason(generatedResponse.finishReason);
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
5540
|
+
};
|
|
5541
|
+
if (chatWithGenerateVNext) {
|
|
5542
|
+
const response = await agent.generateVNext({
|
|
5543
|
+
messages: [
|
|
5544
|
+
{
|
|
5545
|
+
role: "user",
|
|
5546
|
+
content: input
|
|
5547
|
+
},
|
|
5548
|
+
...attachments
|
|
5549
|
+
],
|
|
5550
|
+
runId: agentId,
|
|
5551
|
+
modelSettings: {
|
|
5552
|
+
frequencyPenalty,
|
|
5553
|
+
presencePenalty,
|
|
5554
|
+
maxRetries,
|
|
5555
|
+
temperature,
|
|
5556
|
+
topK,
|
|
5557
|
+
topP,
|
|
5558
|
+
maxOutputTokens: maxTokens
|
|
5559
|
+
},
|
|
5560
|
+
providerOptions,
|
|
5561
|
+
instructions,
|
|
5562
|
+
runtimeContext: runtimeContextInstance,
|
|
5563
|
+
...memory ? { threadId, resourceId: agentId } : {}
|
|
5564
|
+
});
|
|
5565
|
+
handleGenerateResponse(response);
|
|
5566
|
+
setIsRunning(false);
|
|
5567
|
+
return;
|
|
5568
|
+
}
|
|
5569
|
+
if (chatWithStreamVNext) {
|
|
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;
|
|
5578
|
+
if (assistantToolCallAddedForUpdater) {
|
|
5579
|
+
assistantToolCallAddedForUpdater = false;
|
|
5580
|
+
}
|
|
5581
|
+
return [...currentConversation, message2];
|
|
5582
|
+
}
|
|
5583
|
+
if (assistantToolCallAddedForUpdater) {
|
|
5584
|
+
assistantToolCallAddedForUpdater = false;
|
|
5585
|
+
return [...currentConversation, message2];
|
|
5586
|
+
}
|
|
5587
|
+
return [...currentConversation.slice(0, -1), message2];
|
|
5588
|
+
});
|
|
5589
|
+
};
|
|
5590
|
+
const response = await agent.streamVNext({
|
|
5591
|
+
messages: [
|
|
5592
|
+
{
|
|
5593
|
+
role: "user",
|
|
5594
|
+
content: input
|
|
5595
|
+
},
|
|
5596
|
+
...attachments
|
|
5597
|
+
],
|
|
5598
|
+
runId: agentId,
|
|
5599
|
+
modelSettings: {
|
|
5600
|
+
frequencyPenalty,
|
|
5601
|
+
presencePenalty,
|
|
5602
|
+
maxRetries,
|
|
5603
|
+
maxOutputTokens: maxTokens,
|
|
5604
|
+
temperature,
|
|
5605
|
+
topK,
|
|
5606
|
+
topP
|
|
5607
|
+
},
|
|
5608
|
+
instructions,
|
|
5609
|
+
runtimeContext: runtimeContextInstance,
|
|
5610
|
+
...memory ? { threadId, resourceId: agentId } : {},
|
|
5611
|
+
providerOptions
|
|
5612
|
+
});
|
|
5613
|
+
if (!response.body) {
|
|
5614
|
+
throw new Error("No response body");
|
|
5615
|
+
}
|
|
5616
|
+
let content = "";
|
|
5617
|
+
let assistantMessageAdded = false;
|
|
5618
|
+
let assistantToolCallAddedForUpdater = false;
|
|
5619
|
+
let assistantToolCallAddedForContent = false;
|
|
5620
|
+
await response.processDataStream({
|
|
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;
|
|
5629
|
+
}
|
|
5630
|
+
console.log(chunk.payload.text, "VALUE");
|
|
5631
|
+
updater();
|
|
5632
|
+
break;
|
|
5633
|
+
}
|
|
5634
|
+
case "tool-call": {
|
|
5635
|
+
setMessages((currentConversation) => {
|
|
5636
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5637
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
5638
|
+
const updatedMessage = {
|
|
5639
|
+
...lastMessage,
|
|
5640
|
+
content: Array.isArray(lastMessage.content) ? [
|
|
5641
|
+
...lastMessage.content,
|
|
5642
|
+
{
|
|
5643
|
+
type: "tool-call",
|
|
5644
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5645
|
+
toolName: chunk.payload.toolName,
|
|
5646
|
+
args: chunk.payload.args
|
|
5647
|
+
}
|
|
5648
|
+
] : [
|
|
5649
|
+
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
5650
|
+
{
|
|
5651
|
+
type: "tool-call",
|
|
5652
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5653
|
+
toolName: chunk.payload.toolName,
|
|
5654
|
+
args: chunk.payload.args
|
|
5655
|
+
}
|
|
5656
|
+
]
|
|
5657
|
+
};
|
|
5658
|
+
assistantToolCallAddedForUpdater = true;
|
|
5659
|
+
assistantToolCallAddedForContent = true;
|
|
5660
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5661
|
+
}
|
|
5662
|
+
const newMessage = {
|
|
5663
|
+
role: "assistant",
|
|
5664
|
+
content: [
|
|
5665
|
+
{ type: "text", text: content },
|
|
5666
|
+
{
|
|
5667
|
+
type: "tool-call",
|
|
5668
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5669
|
+
toolName: chunk.payload.toolName,
|
|
5670
|
+
args: chunk.payload.args
|
|
5671
|
+
}
|
|
5672
|
+
]
|
|
5673
|
+
};
|
|
5674
|
+
assistantToolCallAddedForUpdater = true;
|
|
5675
|
+
assistantToolCallAddedForContent = true;
|
|
5676
|
+
return [...currentConversation, newMessage];
|
|
5677
|
+
});
|
|
5678
|
+
toolCallIdToName.current[chunk.payload.toolCallId] = chunk.payload.toolName;
|
|
5679
|
+
break;
|
|
5680
|
+
}
|
|
5681
|
+
case "tool-result": {
|
|
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
|
+
};
|
|
5691
|
+
}
|
|
5692
|
+
return part;
|
|
5693
|
+
});
|
|
5694
|
+
const updatedMessage = {
|
|
5695
|
+
...lastMessage,
|
|
5696
|
+
content: updatedContent
|
|
5697
|
+
};
|
|
5698
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5699
|
+
}
|
|
5700
|
+
return currentConversation;
|
|
5701
|
+
});
|
|
5702
|
+
try {
|
|
5703
|
+
const toolName = toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5704
|
+
if (toolName === "updateWorkingMemory" && chunk.payload.result?.success) {
|
|
5705
|
+
await refreshWorkingMemory?.();
|
|
5706
|
+
}
|
|
5707
|
+
} finally {
|
|
5708
|
+
delete toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5709
|
+
}
|
|
5710
|
+
break;
|
|
5711
|
+
}
|
|
5712
|
+
case "error": {
|
|
5713
|
+
if (typeof chunk.payload.error === "string") {
|
|
5714
|
+
throw new Error(chunk.payload.error);
|
|
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
|
+
};
|
|
5732
|
+
}
|
|
5733
|
+
return part;
|
|
5734
|
+
});
|
|
5735
|
+
const updatedMessage = {
|
|
5736
|
+
...lastMessage,
|
|
5737
|
+
content: updatedContent
|
|
5738
|
+
};
|
|
5739
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5740
|
+
}
|
|
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
|
+
}
|
|
5459
5761
|
if (chatWithGenerate) {
|
|
5460
5762
|
const generateResponse = await agent.generate({
|
|
5461
5763
|
messages: [
|
|
@@ -6622,28 +6924,47 @@ const AgentAdvancedSettings = () => {
|
|
|
6622
6924
|
] }) });
|
|
6623
6925
|
};
|
|
6624
6926
|
|
|
6625
|
-
const AgentSettings = () => {
|
|
6927
|
+
const AgentSettings = ({ modelVersion }) => {
|
|
6626
6928
|
const { settings, setSettings, resetAll } = useAgentSettings();
|
|
6929
|
+
let radioValue;
|
|
6930
|
+
if (modelVersion === "v2") {
|
|
6931
|
+
radioValue = settings?.modelSettings?.chatWithGenerateVNext ? "generateVNext" : "streamVNext";
|
|
6932
|
+
} else {
|
|
6933
|
+
radioValue = settings?.modelSettings?.chatWithGenerate ? "generate" : "stream";
|
|
6934
|
+
}
|
|
6627
6935
|
return /* @__PURE__ */ jsxs("div", { className: "px-5 text-xs py-2 pb-4", children: [
|
|
6628
6936
|
/* @__PURE__ */ jsxs("section", { className: "space-y-7", children: [
|
|
6629
6937
|
/* @__PURE__ */ jsx(Entry, { label: "Chat Method", children: /* @__PURE__ */ jsxs(
|
|
6630
6938
|
RadioGroup,
|
|
6631
6939
|
{
|
|
6632
6940
|
orientation: "horizontal",
|
|
6633
|
-
value:
|
|
6941
|
+
value: radioValue,
|
|
6634
6942
|
onValueChange: (value) => setSettings({
|
|
6635
6943
|
...settings,
|
|
6636
|
-
modelSettings: {
|
|
6944
|
+
modelSettings: {
|
|
6945
|
+
...settings?.modelSettings,
|
|
6946
|
+
chatWithGenerate: value === "generate",
|
|
6947
|
+
chatWithGenerateVNext: value === "generateVNext",
|
|
6948
|
+
chatWithStreamVNext: value === "streamVNext"
|
|
6949
|
+
}
|
|
6637
6950
|
}),
|
|
6638
6951
|
className: "flex flex-row gap-4",
|
|
6639
6952
|
children: [
|
|
6640
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6953
|
+
modelVersion !== "v2" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6641
6954
|
/* @__PURE__ */ jsx(RadioGroupItem, { value: "generate", id: "generate", className: "text-icon6" }),
|
|
6642
6955
|
/* @__PURE__ */ jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "generate", children: "Generate" })
|
|
6643
6956
|
] }),
|
|
6644
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6957
|
+
modelVersion === "v2" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6958
|
+
/* @__PURE__ */ jsx(RadioGroupItem, { value: "generateVNext", id: "generateVNext", className: "text-icon6" }),
|
|
6959
|
+
/* @__PURE__ */ jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "generateVNext", children: "Generate vNext" })
|
|
6960
|
+
] }),
|
|
6961
|
+
modelVersion !== "v2" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6645
6962
|
/* @__PURE__ */ jsx(RadioGroupItem, { value: "stream", id: "stream", className: "text-icon6" }),
|
|
6646
6963
|
/* @__PURE__ */ jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "stream", children: "Stream" })
|
|
6964
|
+
] }),
|
|
6965
|
+
modelVersion === "v2" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6966
|
+
/* @__PURE__ */ jsx(RadioGroupItem, { value: "streamVNext", id: "streamVNext", className: "text-icon6" }),
|
|
6967
|
+
/* @__PURE__ */ jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "streamVNext", children: "Stream vNext" })
|
|
6647
6968
|
] })
|
|
6648
6969
|
]
|
|
6649
6970
|
}
|