@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.cjs.js
CHANGED
|
@@ -5412,6 +5412,8 @@ function MastraRuntimeProvider({
|
|
|
5412
5412
|
topP,
|
|
5413
5413
|
instructions,
|
|
5414
5414
|
chatWithGenerate,
|
|
5415
|
+
chatWithGenerateVNext,
|
|
5416
|
+
chatWithStreamVNext,
|
|
5415
5417
|
providerOptions
|
|
5416
5418
|
} = settings?.modelSettings ?? {};
|
|
5417
5419
|
const toolCallIdToName = React.useRef({});
|
|
@@ -5489,6 +5491,306 @@ function MastraRuntimeProvider({
|
|
|
5489
5491
|
});
|
|
5490
5492
|
const agent = clientWithAbort.getAgent(agentId);
|
|
5491
5493
|
try {
|
|
5494
|
+
let handleGenerateResponse = function(generatedResponse) {
|
|
5495
|
+
if (generatedResponse.response && "messages" in generatedResponse.response) {
|
|
5496
|
+
const latestMessage = generatedResponse.response.messages.reduce(
|
|
5497
|
+
(acc, message2) => {
|
|
5498
|
+
const _content = Array.isArray(acc.content) ? acc.content : [];
|
|
5499
|
+
if (typeof message2.content === "string") {
|
|
5500
|
+
return {
|
|
5501
|
+
...acc,
|
|
5502
|
+
content: [
|
|
5503
|
+
..._content,
|
|
5504
|
+
...generatedResponse.reasoning ? [{ type: "reasoning", text: generatedResponse.reasoning }] : [],
|
|
5505
|
+
{
|
|
5506
|
+
type: "text",
|
|
5507
|
+
text: message2.content
|
|
5508
|
+
}
|
|
5509
|
+
]
|
|
5510
|
+
};
|
|
5511
|
+
}
|
|
5512
|
+
if (message2.role === "assistant") {
|
|
5513
|
+
const toolCallContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-call") : void 0;
|
|
5514
|
+
const reasoningContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "reasoning") : void 0;
|
|
5515
|
+
if (toolCallContent) {
|
|
5516
|
+
const newContent = message2.content.map((c) => {
|
|
5517
|
+
if (c.type === "tool-call" && c.toolCallId === toolCallContent?.toolCallId) {
|
|
5518
|
+
return {
|
|
5519
|
+
...c,
|
|
5520
|
+
toolCallId: toolCallContent.toolCallId,
|
|
5521
|
+
toolName: toolCallContent.toolName,
|
|
5522
|
+
args: toolCallContent.input
|
|
5523
|
+
};
|
|
5524
|
+
}
|
|
5525
|
+
return c;
|
|
5526
|
+
});
|
|
5527
|
+
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5528
|
+
return {
|
|
5529
|
+
...acc,
|
|
5530
|
+
content: containsToolCall ? [...reasoningContent ? [reasoningContent] : [], ...newContent] : [..._content, ...reasoningContent ? [reasoningContent] : [], toolCallContent]
|
|
5531
|
+
};
|
|
5532
|
+
}
|
|
5533
|
+
const textContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "text" && content.text) : void 0;
|
|
5534
|
+
if (textContent) {
|
|
5535
|
+
return {
|
|
5536
|
+
...acc,
|
|
5537
|
+
content: [..._content, ...reasoningContent ? [reasoningContent] : [], textContent]
|
|
5538
|
+
};
|
|
5539
|
+
}
|
|
5540
|
+
}
|
|
5541
|
+
if (message2.role === "tool") {
|
|
5542
|
+
const toolResult = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-result") : void 0;
|
|
5543
|
+
if (toolResult) {
|
|
5544
|
+
const newContent = _content.map((c) => {
|
|
5545
|
+
if (c.type === "tool-call" && c.toolCallId === toolResult?.toolCallId) {
|
|
5546
|
+
return { ...c, result: toolResult.output?.value };
|
|
5547
|
+
}
|
|
5548
|
+
return c;
|
|
5549
|
+
});
|
|
5550
|
+
const containsToolCall = newContent.some((c) => c.type === "tool-call");
|
|
5551
|
+
return {
|
|
5552
|
+
...acc,
|
|
5553
|
+
content: containsToolCall ? newContent : [
|
|
5554
|
+
..._content,
|
|
5555
|
+
{ type: "tool-result", toolCallId: toolResult.toolCallId, result: toolResult.output?.value }
|
|
5556
|
+
]
|
|
5557
|
+
};
|
|
5558
|
+
}
|
|
5559
|
+
return {
|
|
5560
|
+
...acc,
|
|
5561
|
+
content: [..._content, toolResult]
|
|
5562
|
+
};
|
|
5563
|
+
}
|
|
5564
|
+
return acc;
|
|
5565
|
+
},
|
|
5566
|
+
{ role: "assistant", content: [] }
|
|
5567
|
+
);
|
|
5568
|
+
setMessages((currentConversation) => [...currentConversation, latestMessage]);
|
|
5569
|
+
if (generatedResponse.finishReason) {
|
|
5570
|
+
handleFinishReason(generatedResponse.finishReason);
|
|
5571
|
+
}
|
|
5572
|
+
}
|
|
5573
|
+
};
|
|
5574
|
+
if (chatWithGenerateVNext) {
|
|
5575
|
+
const response = await agent.generateVNext({
|
|
5576
|
+
messages: [
|
|
5577
|
+
{
|
|
5578
|
+
role: "user",
|
|
5579
|
+
content: input
|
|
5580
|
+
},
|
|
5581
|
+
...attachments
|
|
5582
|
+
],
|
|
5583
|
+
runId: agentId,
|
|
5584
|
+
modelSettings: {
|
|
5585
|
+
frequencyPenalty,
|
|
5586
|
+
presencePenalty,
|
|
5587
|
+
maxRetries,
|
|
5588
|
+
temperature,
|
|
5589
|
+
topK,
|
|
5590
|
+
topP,
|
|
5591
|
+
maxOutputTokens: maxTokens
|
|
5592
|
+
},
|
|
5593
|
+
providerOptions,
|
|
5594
|
+
instructions,
|
|
5595
|
+
runtimeContext: runtimeContextInstance,
|
|
5596
|
+
...memory ? { threadId, resourceId: agentId } : {}
|
|
5597
|
+
});
|
|
5598
|
+
handleGenerateResponse(response);
|
|
5599
|
+
setIsRunning(false);
|
|
5600
|
+
return;
|
|
5601
|
+
}
|
|
5602
|
+
if (chatWithStreamVNext) {
|
|
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;
|
|
5611
|
+
if (assistantToolCallAddedForUpdater) {
|
|
5612
|
+
assistantToolCallAddedForUpdater = false;
|
|
5613
|
+
}
|
|
5614
|
+
return [...currentConversation, message2];
|
|
5615
|
+
}
|
|
5616
|
+
if (assistantToolCallAddedForUpdater) {
|
|
5617
|
+
assistantToolCallAddedForUpdater = false;
|
|
5618
|
+
return [...currentConversation, message2];
|
|
5619
|
+
}
|
|
5620
|
+
return [...currentConversation.slice(0, -1), message2];
|
|
5621
|
+
});
|
|
5622
|
+
};
|
|
5623
|
+
const response = await agent.streamVNext({
|
|
5624
|
+
messages: [
|
|
5625
|
+
{
|
|
5626
|
+
role: "user",
|
|
5627
|
+
content: input
|
|
5628
|
+
},
|
|
5629
|
+
...attachments
|
|
5630
|
+
],
|
|
5631
|
+
runId: agentId,
|
|
5632
|
+
modelSettings: {
|
|
5633
|
+
frequencyPenalty,
|
|
5634
|
+
presencePenalty,
|
|
5635
|
+
maxRetries,
|
|
5636
|
+
maxOutputTokens: maxTokens,
|
|
5637
|
+
temperature,
|
|
5638
|
+
topK,
|
|
5639
|
+
topP
|
|
5640
|
+
},
|
|
5641
|
+
instructions,
|
|
5642
|
+
runtimeContext: runtimeContextInstance,
|
|
5643
|
+
...memory ? { threadId, resourceId: agentId } : {},
|
|
5644
|
+
providerOptions
|
|
5645
|
+
});
|
|
5646
|
+
if (!response.body) {
|
|
5647
|
+
throw new Error("No response body");
|
|
5648
|
+
}
|
|
5649
|
+
let content = "";
|
|
5650
|
+
let assistantMessageAdded = false;
|
|
5651
|
+
let assistantToolCallAddedForUpdater = false;
|
|
5652
|
+
let assistantToolCallAddedForContent = false;
|
|
5653
|
+
await response.processDataStream({
|
|
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;
|
|
5662
|
+
}
|
|
5663
|
+
console.log(chunk.payload.text, "VALUE");
|
|
5664
|
+
updater();
|
|
5665
|
+
break;
|
|
5666
|
+
}
|
|
5667
|
+
case "tool-call": {
|
|
5668
|
+
setMessages((currentConversation) => {
|
|
5669
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
5670
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
5671
|
+
const updatedMessage = {
|
|
5672
|
+
...lastMessage,
|
|
5673
|
+
content: Array.isArray(lastMessage.content) ? [
|
|
5674
|
+
...lastMessage.content,
|
|
5675
|
+
{
|
|
5676
|
+
type: "tool-call",
|
|
5677
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5678
|
+
toolName: chunk.payload.toolName,
|
|
5679
|
+
args: chunk.payload.args
|
|
5680
|
+
}
|
|
5681
|
+
] : [
|
|
5682
|
+
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
5683
|
+
{
|
|
5684
|
+
type: "tool-call",
|
|
5685
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5686
|
+
toolName: chunk.payload.toolName,
|
|
5687
|
+
args: chunk.payload.args
|
|
5688
|
+
}
|
|
5689
|
+
]
|
|
5690
|
+
};
|
|
5691
|
+
assistantToolCallAddedForUpdater = true;
|
|
5692
|
+
assistantToolCallAddedForContent = true;
|
|
5693
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5694
|
+
}
|
|
5695
|
+
const newMessage = {
|
|
5696
|
+
role: "assistant",
|
|
5697
|
+
content: [
|
|
5698
|
+
{ type: "text", text: content },
|
|
5699
|
+
{
|
|
5700
|
+
type: "tool-call",
|
|
5701
|
+
toolCallId: chunk.payload.toolCallId,
|
|
5702
|
+
toolName: chunk.payload.toolName,
|
|
5703
|
+
args: chunk.payload.args
|
|
5704
|
+
}
|
|
5705
|
+
]
|
|
5706
|
+
};
|
|
5707
|
+
assistantToolCallAddedForUpdater = true;
|
|
5708
|
+
assistantToolCallAddedForContent = true;
|
|
5709
|
+
return [...currentConversation, newMessage];
|
|
5710
|
+
});
|
|
5711
|
+
toolCallIdToName.current[chunk.payload.toolCallId] = chunk.payload.toolName;
|
|
5712
|
+
break;
|
|
5713
|
+
}
|
|
5714
|
+
case "tool-result": {
|
|
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
|
+
};
|
|
5724
|
+
}
|
|
5725
|
+
return part;
|
|
5726
|
+
});
|
|
5727
|
+
const updatedMessage = {
|
|
5728
|
+
...lastMessage,
|
|
5729
|
+
content: updatedContent
|
|
5730
|
+
};
|
|
5731
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5732
|
+
}
|
|
5733
|
+
return currentConversation;
|
|
5734
|
+
});
|
|
5735
|
+
try {
|
|
5736
|
+
const toolName = toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5737
|
+
if (toolName === "updateWorkingMemory" && chunk.payload.result?.success) {
|
|
5738
|
+
await refreshWorkingMemory?.();
|
|
5739
|
+
}
|
|
5740
|
+
} finally {
|
|
5741
|
+
delete toolCallIdToName.current[chunk.payload.toolCallId];
|
|
5742
|
+
}
|
|
5743
|
+
break;
|
|
5744
|
+
}
|
|
5745
|
+
case "error": {
|
|
5746
|
+
if (typeof chunk.payload.error === "string") {
|
|
5747
|
+
throw new Error(chunk.payload.error);
|
|
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
|
+
};
|
|
5765
|
+
}
|
|
5766
|
+
return part;
|
|
5767
|
+
});
|
|
5768
|
+
const updatedMessage = {
|
|
5769
|
+
...lastMessage,
|
|
5770
|
+
content: updatedContent
|
|
5771
|
+
};
|
|
5772
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
5773
|
+
}
|
|
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
|
+
}
|
|
5492
5794
|
if (chatWithGenerate) {
|
|
5493
5795
|
const generateResponse = await agent.generate({
|
|
5494
5796
|
messages: [
|
|
@@ -6655,28 +6957,47 @@ const AgentAdvancedSettings = () => {
|
|
|
6655
6957
|
] }) });
|
|
6656
6958
|
};
|
|
6657
6959
|
|
|
6658
|
-
const AgentSettings = () => {
|
|
6960
|
+
const AgentSettings = ({ modelVersion }) => {
|
|
6659
6961
|
const { settings, setSettings, resetAll } = useAgentSettings();
|
|
6962
|
+
let radioValue;
|
|
6963
|
+
if (modelVersion === "v2") {
|
|
6964
|
+
radioValue = settings?.modelSettings?.chatWithGenerateVNext ? "generateVNext" : "streamVNext";
|
|
6965
|
+
} else {
|
|
6966
|
+
radioValue = settings?.modelSettings?.chatWithGenerate ? "generate" : "stream";
|
|
6967
|
+
}
|
|
6660
6968
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-5 text-xs py-2 pb-4", children: [
|
|
6661
6969
|
/* @__PURE__ */ jsxRuntime.jsxs("section", { className: "space-y-7", children: [
|
|
6662
6970
|
/* @__PURE__ */ jsxRuntime.jsx(Entry, { label: "Chat Method", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6663
6971
|
RadioGroup,
|
|
6664
6972
|
{
|
|
6665
6973
|
orientation: "horizontal",
|
|
6666
|
-
value:
|
|
6974
|
+
value: radioValue,
|
|
6667
6975
|
onValueChange: (value) => setSettings({
|
|
6668
6976
|
...settings,
|
|
6669
|
-
modelSettings: {
|
|
6977
|
+
modelSettings: {
|
|
6978
|
+
...settings?.modelSettings,
|
|
6979
|
+
chatWithGenerate: value === "generate",
|
|
6980
|
+
chatWithGenerateVNext: value === "generateVNext",
|
|
6981
|
+
chatWithStreamVNext: value === "streamVNext"
|
|
6982
|
+
}
|
|
6670
6983
|
}),
|
|
6671
6984
|
className: "flex flex-row gap-4",
|
|
6672
6985
|
children: [
|
|
6673
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6986
|
+
modelVersion !== "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6674
6987
|
/* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "generate", id: "generate", className: "text-icon6" }),
|
|
6675
6988
|
/* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "generate", children: "Generate" })
|
|
6676
6989
|
] }),
|
|
6677
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6990
|
+
modelVersion === "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6991
|
+
/* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "generateVNext", id: "generateVNext", className: "text-icon6" }),
|
|
6992
|
+
/* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "generateVNext", children: "Generate vNext" })
|
|
6993
|
+
] }),
|
|
6994
|
+
modelVersion !== "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6678
6995
|
/* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "stream", id: "stream", className: "text-icon6" }),
|
|
6679
6996
|
/* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "stream", children: "Stream" })
|
|
6997
|
+
] }),
|
|
6998
|
+
modelVersion === "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
6999
|
+
/* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "streamVNext", id: "streamVNext", className: "text-icon6" }),
|
|
7000
|
+
/* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "streamVNext", children: "Stream vNext" })
|
|
6680
7001
|
] })
|
|
6681
7002
|
]
|
|
6682
7003
|
}
|