diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 13fb51990..7f12eec20 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -371,9 +371,11 @@ await conv.SendMessage(agentId, inputMsg, { response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content; response.Function = msg.FunctionName; + response.MessageLabel = msg.MessageLabel; response.RichContent = msg.SecondaryRichContent ?? msg.RichContent; response.Instruction = msg.Instruction; response.Data = msg.Data; + response.AdditionalMessageWrapper = ChatResponseWrapper.From(msg.AdditionalMessageWrapper, conversationId, inputMsg.MessageId); }); var state = _services.GetRequiredService(); @@ -426,11 +428,13 @@ await conv.SendMessage(agentId, inputMsg, async msg => { response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content; + response.MessageLabel = msg.MessageLabel; response.Function = msg.FunctionName; response.RichContent = msg.SecondaryRichContent ?? msg.RichContent; response.Instruction = msg.Instruction; response.Data = msg.Data; response.States = state.GetStates(); + response.AdditionalMessageWrapper = ChatResponseWrapper.From(msg.AdditionalMessageWrapper, conversationId, inputMsg.MessageId); await OnChunkReceived(Response, response); }); diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/Response/ChatResponseModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/Response/ChatResponseModel.cs index 4d1492007..37db30841 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/Response/ChatResponseModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/Response/ChatResponseModel.cs @@ -1,7 +1,46 @@ using BotSharp.Abstraction.Conversations.Dtos; +using System.Text.Json.Serialization; namespace BotSharp.OpenAPI.ViewModels.Conversations; public class ChatResponseModel : ChatResponseDto { + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("additional_message_wrapper")] + public ChatResponseWrapper? AdditionalMessageWrapper { get; set; } } + +public class ChatResponseWrapper +{ + [JsonPropertyName("sending_interval")] + public int SendingInterval { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("messages")] + public List? Messages { get; set; } + + public static ChatResponseWrapper? From(ChatMessageWrapper? wrapper, string conversationId, string? messageId = null) + { + if (wrapper == null) + { + return null; + } + + return new ChatResponseWrapper + { + SendingInterval = wrapper.SendingInterval, + Messages = wrapper?.Messages?.Select(x => new ChatResponseModel + { + ConversationId = conversationId, + MessageId = messageId ?? x.MessageId, + Text = !string.IsNullOrEmpty(x.SecondaryContent) ? x.SecondaryContent : x.Content, + MessageLabel = x.MessageLabel, + Function = x.FunctionName, + RichContent = x.SecondaryRichContent ?? x.RichContent, + Instruction = x.Instruction, + Data = x.Data, + IsAppend = true + })?.ToList() + }; + } +} \ No newline at end of file