@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 CHANGED
@@ -5394,7 +5394,8 @@ function MastraRuntimeProvider({
5394
5394
  threadId,
5395
5395
  refreshThreadList,
5396
5396
  settings,
5397
- runtimeContext
5397
+ runtimeContext,
5398
+ modelVersion
5398
5399
  }) {
5399
5400
  const [isRunning, setIsRunning] = React.useState(false);
5400
5401
  const [messages, setMessages] = React.useState([]);
@@ -5412,6 +5413,8 @@ function MastraRuntimeProvider({
5412
5413
  topP,
5413
5414
  instructions,
5414
5415
  chatWithGenerate,
5416
+ chatWithGenerateVNext,
5417
+ chatWithStreamVNext,
5415
5418
  providerOptions
5416
5419
  } = settings?.modelSettings ?? {};
5417
5420
  const toolCallIdToName = React.useRef({});
@@ -5489,31 +5492,9 @@ function MastraRuntimeProvider({
5489
5492
  });
5490
5493
  const agent = clientWithAbort.getAgent(agentId);
5491
5494
  try {
5492
- if (chatWithGenerate) {
5493
- const generateResponse = await agent.generate({
5494
- messages: [
5495
- {
5496
- role: "user",
5497
- content: input
5498
- },
5499
- ...attachments
5500
- ],
5501
- runId: agentId,
5502
- frequencyPenalty,
5503
- presencePenalty,
5504
- maxRetries,
5505
- maxSteps,
5506
- maxTokens,
5507
- temperature,
5508
- topK,
5509
- topP,
5510
- instructions,
5511
- runtimeContext: runtimeContextInstance,
5512
- ...memory ? { threadId, resourceId: agentId } : {},
5513
- providerOptions
5514
- });
5515
- if (generateResponse.response && "messages" in generateResponse.response) {
5516
- const latestMessage = generateResponse.response.messages.reduce(
5495
+ let handleGenerateResponse = function(generatedResponse) {
5496
+ if (generatedResponse.response && "messages" in generatedResponse.response) {
5497
+ const latestMessage = generatedResponse.response.messages.reduce(
5517
5498
  (acc, message2) => {
5518
5499
  const _content = Array.isArray(acc.content) ? acc.content : [];
5519
5500
  if (typeof message2.content === "string") {
@@ -5521,7 +5502,7 @@ function MastraRuntimeProvider({
5521
5502
  ...acc,
5522
5503
  content: [
5523
5504
  ..._content,
5524
- ...generateResponse.reasoning ? [{ type: "reasoning", text: generateResponse.reasoning }] : [],
5505
+ ...generatedResponse.reasoning ? [{ type: "reasoning", text: generatedResponse.reasoning }] : [],
5525
5506
  {
5526
5507
  type: "text",
5527
5508
  text: message2.content
@@ -5533,9 +5514,14 @@ function MastraRuntimeProvider({
5533
5514
  const toolCallContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-call") : void 0;
5534
5515
  const reasoningContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "reasoning") : void 0;
5535
5516
  if (toolCallContent) {
5536
- const newContent = _content.map((c) => {
5517
+ const newContent = message2.content.map((c) => {
5537
5518
  if (c.type === "tool-call" && c.toolCallId === toolCallContent?.toolCallId) {
5538
- return { ...c, ...toolCallContent };
5519
+ return {
5520
+ ...c,
5521
+ toolCallId: toolCallContent.toolCallId,
5522
+ toolName: toolCallContent.toolName,
5523
+ args: toolCallContent.input
5524
+ };
5539
5525
  }
5540
5526
  return c;
5541
5527
  });
@@ -5558,7 +5544,7 @@ function MastraRuntimeProvider({
5558
5544
  if (toolResult) {
5559
5545
  const newContent = _content.map((c) => {
5560
5546
  if (c.type === "tool-call" && c.toolCallId === toolResult?.toolCallId) {
5561
- return { ...c, result: toolResult.result };
5547
+ return { ...c, result: toolResult.output?.value };
5562
5548
  }
5563
5549
  return c;
5564
5550
  });
@@ -5567,7 +5553,7 @@ function MastraRuntimeProvider({
5567
5553
  ...acc,
5568
5554
  content: containsToolCall ? newContent : [
5569
5555
  ..._content,
5570
- { type: "tool-result", toolCallId: toolResult.toolCallId, result: toolResult.result }
5556
+ { type: "tool-result", toolCallId: toolResult.toolCallId, result: toolResult.output?.value }
5571
5557
  ]
5572
5558
  };
5573
5559
  }
@@ -5581,84 +5567,418 @@ function MastraRuntimeProvider({
5581
5567
  { role: "assistant", content: [] }
5582
5568
  );
5583
5569
  setMessages((currentConversation) => [...currentConversation, latestMessage]);
5584
- handleFinishReason(generateResponse.finishReason);
5570
+ if (generatedResponse.finishReason) {
5571
+ handleFinishReason(generatedResponse.finishReason);
5572
+ }
5585
5573
  }
5586
- } else {
5587
- let updater = function() {
5588
- setMessages((currentConversation) => {
5589
- const message2 = {
5590
- role: "assistant",
5591
- content: [{ type: "text", text: content }]
5592
- };
5593
- if (!assistantMessageAdded) {
5594
- assistantMessageAdded = true;
5574
+ };
5575
+ if (modelVersion === "v2") {
5576
+ if (chatWithGenerateVNext) {
5577
+ const response = await agent.generateVNext({
5578
+ messages: [
5579
+ {
5580
+ role: "user",
5581
+ content: input
5582
+ },
5583
+ ...attachments
5584
+ ],
5585
+ runId: agentId,
5586
+ modelSettings: {
5587
+ frequencyPenalty,
5588
+ presencePenalty,
5589
+ maxRetries,
5590
+ temperature,
5591
+ topK,
5592
+ topP,
5593
+ maxOutputTokens: maxTokens
5594
+ },
5595
+ providerOptions,
5596
+ instructions,
5597
+ runtimeContext: runtimeContextInstance,
5598
+ ...memory ? { threadId, resourceId: agentId } : {}
5599
+ });
5600
+ handleGenerateResponse(response);
5601
+ setIsRunning(false);
5602
+ return;
5603
+ } else {
5604
+ let updater = function() {
5605
+ setMessages((currentConversation) => {
5606
+ const message2 = {
5607
+ role: "assistant",
5608
+ content: [{ type: "text", text: content }]
5609
+ };
5610
+ if (!assistantMessageAdded) {
5611
+ assistantMessageAdded = true;
5612
+ if (assistantToolCallAddedForUpdater) {
5613
+ assistantToolCallAddedForUpdater = false;
5614
+ }
5615
+ return [...currentConversation, message2];
5616
+ }
5595
5617
  if (assistantToolCallAddedForUpdater) {
5596
5618
  assistantToolCallAddedForUpdater = false;
5619
+ return [...currentConversation, message2];
5620
+ }
5621
+ return [...currentConversation.slice(0, -1), message2];
5622
+ });
5623
+ };
5624
+ const response = await agent.streamVNext({
5625
+ messages: [
5626
+ {
5627
+ role: "user",
5628
+ content: input
5629
+ },
5630
+ ...attachments
5631
+ ],
5632
+ runId: agentId,
5633
+ modelSettings: {
5634
+ frequencyPenalty,
5635
+ presencePenalty,
5636
+ maxRetries,
5637
+ maxOutputTokens: maxTokens,
5638
+ temperature,
5639
+ topK,
5640
+ topP
5641
+ },
5642
+ instructions,
5643
+ runtimeContext: runtimeContextInstance,
5644
+ ...memory ? { threadId, resourceId: agentId } : {},
5645
+ providerOptions
5646
+ });
5647
+ if (!response.body) {
5648
+ throw new Error("No response body");
5649
+ }
5650
+ let content = "";
5651
+ let assistantMessageAdded = false;
5652
+ let assistantToolCallAddedForUpdater = false;
5653
+ let assistantToolCallAddedForContent = false;
5654
+ await response.processDataStream({
5655
+ onChunk: async (chunk) => {
5656
+ switch (chunk.type) {
5657
+ case "text-delta": {
5658
+ if (assistantToolCallAddedForContent) {
5659
+ assistantToolCallAddedForContent = false;
5660
+ content = chunk.payload.text;
5661
+ } else {
5662
+ content += chunk.payload.text;
5663
+ }
5664
+ console.log(chunk.payload.text, "VALUE");
5665
+ updater();
5666
+ break;
5667
+ }
5668
+ case "tool-call": {
5669
+ setMessages((currentConversation) => {
5670
+ const lastMessage = currentConversation[currentConversation.length - 1];
5671
+ if (lastMessage && lastMessage.role === "assistant") {
5672
+ const updatedMessage = {
5673
+ ...lastMessage,
5674
+ content: Array.isArray(lastMessage.content) ? [
5675
+ ...lastMessage.content,
5676
+ {
5677
+ type: "tool-call",
5678
+ toolCallId: chunk.payload.toolCallId,
5679
+ toolName: chunk.payload.toolName,
5680
+ args: chunk.payload.args
5681
+ }
5682
+ ] : [
5683
+ ...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
5684
+ {
5685
+ type: "tool-call",
5686
+ toolCallId: chunk.payload.toolCallId,
5687
+ toolName: chunk.payload.toolName,
5688
+ args: chunk.payload.args
5689
+ }
5690
+ ]
5691
+ };
5692
+ assistantToolCallAddedForUpdater = true;
5693
+ assistantToolCallAddedForContent = true;
5694
+ return [...currentConversation.slice(0, -1), updatedMessage];
5695
+ }
5696
+ const newMessage = {
5697
+ role: "assistant",
5698
+ content: [
5699
+ { type: "text", text: content },
5700
+ {
5701
+ type: "tool-call",
5702
+ toolCallId: chunk.payload.toolCallId,
5703
+ toolName: chunk.payload.toolName,
5704
+ args: chunk.payload.args
5705
+ }
5706
+ ]
5707
+ };
5708
+ assistantToolCallAddedForUpdater = true;
5709
+ assistantToolCallAddedForContent = true;
5710
+ return [...currentConversation, newMessage];
5711
+ });
5712
+ toolCallIdToName.current[chunk.payload.toolCallId] = chunk.payload.toolName;
5713
+ break;
5714
+ }
5715
+ case "tool-result": {
5716
+ setMessages((currentConversation) => {
5717
+ const lastMessage = currentConversation[currentConversation.length - 1];
5718
+ if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
5719
+ const updatedContent = lastMessage.content.map((part) => {
5720
+ if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === chunk.payload.toolCallId) {
5721
+ return {
5722
+ ...part,
5723
+ result: chunk.payload.result
5724
+ };
5725
+ }
5726
+ return part;
5727
+ });
5728
+ const updatedMessage = {
5729
+ ...lastMessage,
5730
+ content: updatedContent
5731
+ };
5732
+ return [...currentConversation.slice(0, -1), updatedMessage];
5733
+ }
5734
+ return currentConversation;
5735
+ });
5736
+ try {
5737
+ const toolName = toolCallIdToName.current[chunk.payload.toolCallId];
5738
+ if (toolName === "updateWorkingMemory" && chunk.payload.result?.success) {
5739
+ await refreshWorkingMemory?.();
5740
+ }
5741
+ } finally {
5742
+ delete toolCallIdToName.current[chunk.payload.toolCallId];
5743
+ }
5744
+ break;
5745
+ }
5746
+ case "error": {
5747
+ if (typeof chunk.payload.error === "string") {
5748
+ throw new Error(chunk.payload.error);
5749
+ }
5750
+ break;
5751
+ }
5752
+ case "finish": {
5753
+ handleFinishReason(chunk.payload.finishReason);
5754
+ break;
5755
+ }
5756
+ case "reasoning-delta": {
5757
+ setMessages((currentConversation) => {
5758
+ const lastMessage = currentConversation[currentConversation.length - 1];
5759
+ if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
5760
+ const updatedContent = lastMessage.content.map((part) => {
5761
+ if (typeof part === "object" && part.type === "reasoning") {
5762
+ return {
5763
+ ...part,
5764
+ text: part.text + chunk.payload.text
5765
+ };
5766
+ }
5767
+ return part;
5768
+ });
5769
+ const updatedMessage = {
5770
+ ...lastMessage,
5771
+ content: updatedContent
5772
+ };
5773
+ return [...currentConversation.slice(0, -1), updatedMessage];
5774
+ }
5775
+ const newMessage = {
5776
+ role: "assistant",
5777
+ content: [
5778
+ {
5779
+ type: "reasoning",
5780
+ text: chunk.payload.text
5781
+ },
5782
+ { type: "text", text: content }
5783
+ ]
5784
+ };
5785
+ return [...currentConversation, newMessage];
5786
+ });
5787
+ break;
5788
+ }
5597
5789
  }
5598
- return [...currentConversation, message2];
5599
- }
5600
- if (assistantToolCallAddedForUpdater) {
5601
- assistantToolCallAddedForUpdater = false;
5602
- return [...currentConversation, message2];
5603
5790
  }
5604
- return [...currentConversation.slice(0, -1), message2];
5605
5791
  });
5606
- };
5607
- const response = await agent.stream({
5608
- messages: [
5609
- {
5610
- role: "user",
5611
- content: input
5612
- },
5613
- ...attachments
5614
- ],
5615
- runId: agentId,
5616
- frequencyPenalty,
5617
- presencePenalty,
5618
- maxRetries,
5619
- maxSteps,
5620
- maxTokens,
5621
- temperature,
5622
- topK,
5623
- topP,
5624
- instructions,
5625
- runtimeContext: runtimeContextInstance,
5626
- ...memory ? { threadId, resourceId: agentId } : {},
5627
- providerOptions
5628
- });
5629
- if (!response.body) {
5630
- throw new Error("No response body");
5792
+ setIsRunning(false);
5793
+ return;
5631
5794
  }
5632
- let content = "";
5633
- let assistantMessageAdded = false;
5634
- let assistantToolCallAddedForUpdater = false;
5635
- let assistantToolCallAddedForContent = false;
5636
- await response.processDataStream({
5637
- onTextPart(value) {
5638
- if (assistantToolCallAddedForContent) {
5639
- assistantToolCallAddedForContent = false;
5640
- content = value;
5641
- } else {
5642
- content += value;
5643
- }
5644
- updater();
5645
- },
5646
- async onToolCallPart(value) {
5795
+ } else {
5796
+ if (chatWithGenerate) {
5797
+ const generateResponse = await agent.generate({
5798
+ messages: [
5799
+ {
5800
+ role: "user",
5801
+ content: input
5802
+ },
5803
+ ...attachments
5804
+ ],
5805
+ runId: agentId,
5806
+ frequencyPenalty,
5807
+ presencePenalty,
5808
+ maxRetries,
5809
+ maxSteps,
5810
+ maxTokens,
5811
+ temperature,
5812
+ topK,
5813
+ topP,
5814
+ instructions,
5815
+ runtimeContext: runtimeContextInstance,
5816
+ ...memory ? { threadId, resourceId: agentId } : {},
5817
+ providerOptions
5818
+ });
5819
+ if (generateResponse.response && "messages" in generateResponse.response) {
5820
+ const latestMessage = generateResponse.response.messages.reduce(
5821
+ (acc, message2) => {
5822
+ const _content = Array.isArray(acc.content) ? acc.content : [];
5823
+ if (typeof message2.content === "string") {
5824
+ return {
5825
+ ...acc,
5826
+ content: [
5827
+ ..._content,
5828
+ ...generateResponse.reasoning ? [{ type: "reasoning", text: generateResponse.reasoning }] : [],
5829
+ {
5830
+ type: "text",
5831
+ text: message2.content
5832
+ }
5833
+ ]
5834
+ };
5835
+ }
5836
+ if (message2.role === "assistant") {
5837
+ const toolCallContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-call") : void 0;
5838
+ const reasoningContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "reasoning") : void 0;
5839
+ if (toolCallContent) {
5840
+ const newContent = _content.map((c) => {
5841
+ if (c.type === "tool-call" && c.toolCallId === toolCallContent?.toolCallId) {
5842
+ return { ...c, ...toolCallContent };
5843
+ }
5844
+ return c;
5845
+ });
5846
+ const containsToolCall = newContent.some((c) => c.type === "tool-call");
5847
+ return {
5848
+ ...acc,
5849
+ content: containsToolCall ? [...reasoningContent ? [reasoningContent] : [], ...newContent] : [..._content, ...reasoningContent ? [reasoningContent] : [], toolCallContent]
5850
+ };
5851
+ }
5852
+ const textContent = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "text" && content.text) : void 0;
5853
+ if (textContent) {
5854
+ return {
5855
+ ...acc,
5856
+ content: [..._content, ...reasoningContent ? [reasoningContent] : [], textContent]
5857
+ };
5858
+ }
5859
+ }
5860
+ if (message2.role === "tool") {
5861
+ const toolResult = Array.isArray(message2.content) ? message2.content.find((content) => content.type === "tool-result") : void 0;
5862
+ if (toolResult) {
5863
+ const newContent = _content.map((c) => {
5864
+ if (c.type === "tool-call" && c.toolCallId === toolResult?.toolCallId) {
5865
+ return { ...c, result: toolResult.result };
5866
+ }
5867
+ return c;
5868
+ });
5869
+ const containsToolCall = newContent.some((c) => c.type === "tool-call");
5870
+ return {
5871
+ ...acc,
5872
+ content: containsToolCall ? newContent : [
5873
+ ..._content,
5874
+ { type: "tool-result", toolCallId: toolResult.toolCallId, result: toolResult.result }
5875
+ ]
5876
+ };
5877
+ }
5878
+ return {
5879
+ ...acc,
5880
+ content: [..._content, toolResult]
5881
+ };
5882
+ }
5883
+ return acc;
5884
+ },
5885
+ { role: "assistant", content: [] }
5886
+ );
5887
+ setMessages((currentConversation) => [...currentConversation, latestMessage]);
5888
+ handleFinishReason(generateResponse.finishReason);
5889
+ }
5890
+ } else {
5891
+ let updater = function() {
5647
5892
  setMessages((currentConversation) => {
5648
- const lastMessage = currentConversation[currentConversation.length - 1];
5649
- if (lastMessage && lastMessage.role === "assistant") {
5650
- const updatedMessage = {
5651
- ...lastMessage,
5652
- content: Array.isArray(lastMessage.content) ? [
5653
- ...lastMessage.content,
5654
- {
5655
- type: "tool-call",
5656
- toolCallId: value.toolCallId,
5657
- toolName: value.toolName,
5658
- args: value.args
5659
- }
5660
- ] : [
5661
- ...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
5893
+ const message2 = {
5894
+ role: "assistant",
5895
+ content: [{ type: "text", text: content }]
5896
+ };
5897
+ if (!assistantMessageAdded) {
5898
+ assistantMessageAdded = true;
5899
+ if (assistantToolCallAddedForUpdater) {
5900
+ assistantToolCallAddedForUpdater = false;
5901
+ }
5902
+ return [...currentConversation, message2];
5903
+ }
5904
+ if (assistantToolCallAddedForUpdater) {
5905
+ assistantToolCallAddedForUpdater = false;
5906
+ return [...currentConversation, message2];
5907
+ }
5908
+ return [...currentConversation.slice(0, -1), message2];
5909
+ });
5910
+ };
5911
+ const response = await agent.stream({
5912
+ messages: [
5913
+ {
5914
+ role: "user",
5915
+ content: input
5916
+ },
5917
+ ...attachments
5918
+ ],
5919
+ runId: agentId,
5920
+ frequencyPenalty,
5921
+ presencePenalty,
5922
+ maxRetries,
5923
+ maxSteps,
5924
+ maxTokens,
5925
+ temperature,
5926
+ topK,
5927
+ topP,
5928
+ instructions,
5929
+ runtimeContext: runtimeContextInstance,
5930
+ ...memory ? { threadId, resourceId: agentId } : {},
5931
+ providerOptions
5932
+ });
5933
+ if (!response.body) {
5934
+ throw new Error("No response body");
5935
+ }
5936
+ let content = "";
5937
+ let assistantMessageAdded = false;
5938
+ let assistantToolCallAddedForUpdater = false;
5939
+ let assistantToolCallAddedForContent = false;
5940
+ await response.processDataStream({
5941
+ onTextPart(value) {
5942
+ if (assistantToolCallAddedForContent) {
5943
+ assistantToolCallAddedForContent = false;
5944
+ content = value;
5945
+ } else {
5946
+ content += value;
5947
+ }
5948
+ updater();
5949
+ },
5950
+ async onToolCallPart(value) {
5951
+ setMessages((currentConversation) => {
5952
+ const lastMessage = currentConversation[currentConversation.length - 1];
5953
+ if (lastMessage && lastMessage.role === "assistant") {
5954
+ const updatedMessage = {
5955
+ ...lastMessage,
5956
+ content: Array.isArray(lastMessage.content) ? [
5957
+ ...lastMessage.content,
5958
+ {
5959
+ type: "tool-call",
5960
+ toolCallId: value.toolCallId,
5961
+ toolName: value.toolName,
5962
+ args: value.args
5963
+ }
5964
+ ] : [
5965
+ ...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
5966
+ {
5967
+ type: "tool-call",
5968
+ toolCallId: value.toolCallId,
5969
+ toolName: value.toolName,
5970
+ args: value.args
5971
+ }
5972
+ ]
5973
+ };
5974
+ assistantToolCallAddedForUpdater = true;
5975
+ assistantToolCallAddedForContent = true;
5976
+ return [...currentConversation.slice(0, -1), updatedMessage];
5977
+ }
5978
+ const newMessage = {
5979
+ role: "assistant",
5980
+ content: [
5981
+ { type: "text", text: content },
5662
5982
  {
5663
5983
  type: "tool-call",
5664
5984
  toolCallId: value.toolCallId,
@@ -5669,95 +5989,80 @@ function MastraRuntimeProvider({
5669
5989
  };
5670
5990
  assistantToolCallAddedForUpdater = true;
5671
5991
  assistantToolCallAddedForContent = true;
5672
- return [...currentConversation.slice(0, -1), updatedMessage];
5992
+ return [...currentConversation, newMessage];
5993
+ });
5994
+ toolCallIdToName.current[value.toolCallId] = value.toolName;
5995
+ },
5996
+ async onToolResultPart(value) {
5997
+ setMessages((currentConversation) => {
5998
+ const lastMessage = currentConversation[currentConversation.length - 1];
5999
+ if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
6000
+ const updatedContent = lastMessage.content.map((part) => {
6001
+ if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === value.toolCallId) {
6002
+ return {
6003
+ ...part,
6004
+ result: value.result
6005
+ };
6006
+ }
6007
+ return part;
6008
+ });
6009
+ const updatedMessage = {
6010
+ ...lastMessage,
6011
+ content: updatedContent
6012
+ };
6013
+ return [...currentConversation.slice(0, -1), updatedMessage];
6014
+ }
6015
+ return currentConversation;
6016
+ });
6017
+ try {
6018
+ const toolName = toolCallIdToName.current[value.toolCallId];
6019
+ if (toolName === "updateWorkingMemory" && value.result?.success) {
6020
+ await refreshWorkingMemory?.();
6021
+ }
6022
+ } finally {
6023
+ delete toolCallIdToName.current[value.toolCallId];
5673
6024
  }
5674
- const newMessage = {
5675
- role: "assistant",
5676
- content: [
5677
- { type: "text", text: content },
5678
- {
5679
- type: "tool-call",
5680
- toolCallId: value.toolCallId,
5681
- toolName: value.toolName,
5682
- args: value.args
5683
- }
5684
- ]
5685
- };
5686
- assistantToolCallAddedForUpdater = true;
5687
- assistantToolCallAddedForContent = true;
5688
- return [...currentConversation, newMessage];
5689
- });
5690
- toolCallIdToName.current[value.toolCallId] = value.toolName;
5691
- },
5692
- async onToolResultPart(value) {
5693
- setMessages((currentConversation) => {
5694
- const lastMessage = currentConversation[currentConversation.length - 1];
5695
- if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
5696
- const updatedContent = lastMessage.content.map((part) => {
5697
- if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === value.toolCallId) {
5698
- return {
5699
- ...part,
5700
- result: value.result
5701
- };
5702
- }
5703
- return part;
5704
- });
5705
- const updatedMessage = {
5706
- ...lastMessage,
5707
- content: updatedContent
6025
+ },
6026
+ onErrorPart(error) {
6027
+ throw new Error(error);
6028
+ },
6029
+ onFinishMessagePart({ finishReason }) {
6030
+ handleFinishReason(finishReason);
6031
+ },
6032
+ onReasoningPart(value) {
6033
+ setMessages((currentConversation) => {
6034
+ const lastMessage = currentConversation[currentConversation.length - 1];
6035
+ if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
6036
+ const updatedContent = lastMessage.content.map((part) => {
6037
+ if (typeof part === "object" && part.type === "reasoning") {
6038
+ return {
6039
+ ...part,
6040
+ text: part.text + value
6041
+ };
6042
+ }
6043
+ return part;
6044
+ });
6045
+ const updatedMessage = {
6046
+ ...lastMessage,
6047
+ content: updatedContent
6048
+ };
6049
+ return [...currentConversation.slice(0, -1), updatedMessage];
6050
+ }
6051
+ const newMessage = {
6052
+ role: "assistant",
6053
+ content: [
6054
+ {
6055
+ type: "reasoning",
6056
+ text: value
6057
+ },
6058
+ { type: "text", text: content }
6059
+ ]
5708
6060
  };
5709
- return [...currentConversation.slice(0, -1), updatedMessage];
5710
- }
5711
- return currentConversation;
5712
- });
5713
- try {
5714
- const toolName = toolCallIdToName.current[value.toolCallId];
5715
- if (toolName === "updateWorkingMemory" && value.result?.success) {
5716
- await refreshWorkingMemory?.();
5717
- }
5718
- } finally {
5719
- delete toolCallIdToName.current[value.toolCallId];
6061
+ return [...currentConversation, newMessage];
6062
+ });
5720
6063
  }
5721
- },
5722
- onErrorPart(error) {
5723
- throw new Error(error);
5724
- },
5725
- onFinishMessagePart({ finishReason }) {
5726
- handleFinishReason(finishReason);
5727
- },
5728
- onReasoningPart(value) {
5729
- setMessages((currentConversation) => {
5730
- const lastMessage = currentConversation[currentConversation.length - 1];
5731
- if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
5732
- const updatedContent = lastMessage.content.map((part) => {
5733
- if (typeof part === "object" && part.type === "reasoning") {
5734
- return {
5735
- ...part,
5736
- text: part.text + value
5737
- };
5738
- }
5739
- return part;
5740
- });
5741
- const updatedMessage = {
5742
- ...lastMessage,
5743
- content: updatedContent
5744
- };
5745
- return [...currentConversation.slice(0, -1), updatedMessage];
5746
- }
5747
- const newMessage = {
5748
- role: "assistant",
5749
- content: [
5750
- {
5751
- type: "reasoning",
5752
- text: value
5753
- },
5754
- { type: "text", text: content }
5755
- ]
5756
- };
5757
- return [...currentConversation, newMessage];
5758
- });
5759
- }
5760
- });
6064
+ });
6065
+ }
5761
6066
  }
5762
6067
  setIsRunning(false);
5763
6068
  setTimeout(() => {
@@ -5807,7 +6112,8 @@ const defaultSettings = {
5807
6112
  maxSteps: 5,
5808
6113
  temperature: 0.5,
5809
6114
  topP: 1,
5810
- chatWithGenerate: false
6115
+ chatWithGenerate: false,
6116
+ chatWithGenerateVNext: false
5811
6117
  }
5812
6118
  };
5813
6119
  function useAgentSettingsState({ agentId }) {
@@ -5879,7 +6185,8 @@ const AgentChat = ({
5879
6185
  initialMessages,
5880
6186
  memory,
5881
6187
  refreshThreadList,
5882
- onInputChange
6188
+ onInputChange,
6189
+ modelVersion
5883
6190
  }) => {
5884
6191
  const { settings } = useAgentSettings();
5885
6192
  const { runtimeContext } = usePlaygroundStore();
@@ -5888,6 +6195,7 @@ const AgentChat = ({
5888
6195
  {
5889
6196
  agentId,
5890
6197
  agentName,
6198
+ modelVersion,
5891
6199
  threadId,
5892
6200
  initialMessages,
5893
6201
  memory,
@@ -6655,28 +6963,47 @@ const AgentAdvancedSettings = () => {
6655
6963
  ] }) });
6656
6964
  };
6657
6965
 
6658
- const AgentSettings = () => {
6966
+ const AgentSettings = ({ modelVersion }) => {
6659
6967
  const { settings, setSettings, resetAll } = useAgentSettings();
6968
+ let radioValue;
6969
+ if (modelVersion === "v2") {
6970
+ radioValue = settings?.modelSettings?.chatWithGenerateVNext ? "generateVNext" : "streamVNext";
6971
+ } else {
6972
+ radioValue = settings?.modelSettings?.chatWithGenerate ? "generate" : "stream";
6973
+ }
6660
6974
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-5 text-xs py-2 pb-4", children: [
6661
6975
  /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "space-y-7", children: [
6662
6976
  /* @__PURE__ */ jsxRuntime.jsx(Entry, { label: "Chat Method", children: /* @__PURE__ */ jsxRuntime.jsxs(
6663
6977
  RadioGroup,
6664
6978
  {
6665
6979
  orientation: "horizontal",
6666
- value: settings?.modelSettings?.chatWithGenerate ? "generate" : "stream",
6980
+ value: radioValue,
6667
6981
  onValueChange: (value) => setSettings({
6668
6982
  ...settings,
6669
- modelSettings: { ...settings?.modelSettings, chatWithGenerate: value === "generate" }
6983
+ modelSettings: {
6984
+ ...settings?.modelSettings,
6985
+ chatWithGenerate: value === "generate",
6986
+ chatWithGenerateVNext: value === "generateVNext",
6987
+ chatWithStreamVNext: value === "streamVNext"
6988
+ }
6670
6989
  }),
6671
6990
  className: "flex flex-row gap-4",
6672
6991
  children: [
6673
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
6992
+ modelVersion !== "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
6674
6993
  /* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "generate", id: "generate", className: "text-icon6" }),
6675
6994
  /* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "generate", children: "Generate" })
6676
6995
  ] }),
6677
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
6996
+ modelVersion === "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
6997
+ /* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "generateVNext", id: "generateVNext", className: "text-icon6" }),
6998
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "generateVNext", children: "Generate vNext" })
6999
+ ] }),
7000
+ modelVersion !== "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
6678
7001
  /* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "stream", id: "stream", className: "text-icon6" }),
6679
7002
  /* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "stream", children: "Stream" })
7003
+ ] }),
7004
+ modelVersion === "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
7005
+ /* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "streamVNext", id: "streamVNext", className: "text-icon6" }),
7006
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "streamVNext", children: "Stream vNext" })
6680
7007
  ] })
6681
7008
  ]
6682
7009
  }