diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 5e180f22b..a5a96a123 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -143,55 +143,29 @@ public async Task> GetDialogs([FromRoute] string { var service = _services.GetRequiredService(); var userService = _services.GetRequiredService(); + var settings = _services.GetRequiredService(); + var (isAdmin, user) = await userService.IsAdminUser(_user.Id); - if (user == null) - { - return null; - } var filter = new ConversationFilter { Id = conversationId, - UserId = !isAdmin ? user.Id : null, + UserId = !isAdmin ? user?.Id : null, IsLoadLatestStates = isLoadStates }; - var conversations = await service.GetConversations(filter); - if (conversations.Items.IsNullOrEmpty()) - { - return null; - } - var result = ConversationViewModel.FromSession(conversations.Items.First()); - var state = _services.GetRequiredService(); - user = await userService.GetUser(result.User.Id); - result.User = UserViewModel.FromUser(user); - - return result; - } - - [HttpPost("/conversation/summary")] - public async Task GetConversationSummary([FromBody] ConversationSummaryModel input) - { - var service = _services.GetRequiredService(); - return await service.GetConversationSummary(input.ConversationIds); - } + var conversations = await service.GetConversations(filter); + var conv = !conversations.Items.IsNullOrEmpty() + ? ConversationViewModel.FromSession(conversations.Items.First()) + : new(); - [HttpGet("/conversation/{conversationId}/user")] - public async Task GetConversationUser([FromRoute] string conversationId) - { - var service = _services.GetRequiredService(); - var conversations = await service.GetConversations(new ConversationFilter - { - Id = conversationId - }); + user = !string.IsNullOrEmpty(conv?.User?.Id) + ? await userService.GetUser(conv.User.Id) + : null; - var userService = _services.GetRequiredService(); - var conversation = conversations?.Items?.FirstOrDefault(); - var userId = conversation == null ? _user.Id : conversation.UserId; - var user = await userService.GetUser(userId); if (user == null) { - return new UserViewModel + user = new User { Id = _user.Id, UserName = _user.UserName, @@ -202,7 +176,16 @@ public async Task GetConversationUser([FromRoute] string conversa }; } - return UserViewModel.FromUser(user); + conv.User = UserViewModel.FromUser(user); + conv.IsRealtimeEnabled = settings?.Assemblies?.Contains("BotSharp.Core.Realtime") ?? false; + return conv; + } + + [HttpPost("/conversation/summary")] + public async Task GetConversationSummary([FromBody] ConversationSummaryModel input) + { + var service = _services.GetRequiredService(); + return await service.GetConversationSummary(input.ConversationIds); } [HttpPut("/conversation/{conversationId}/update-title")] diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/View/ConversationViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/View/ConversationViewModel.cs index 6300f6612..e7110f44d 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/View/ConversationViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/View/ConversationViewModel.cs @@ -1,9 +1,13 @@ using BotSharp.Abstraction.Conversations.Dtos; +using System.Text.Json.Serialization; namespace BotSharp.OpenAPI.ViewModels.Conversations; public class ConversationViewModel : ConversationDto { + [JsonPropertyName("is_realtime_enabled")] + public bool IsRealtimeEnabled { get; set; } + public static ConversationViewModel FromSession(Conversation sess) { return new ConversationViewModel diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Models/Realtime/RealtimeSessionBody.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Models/Realtime/RealtimeSessionBody.cs index a5ed764e0..f767a6f16 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Models/Realtime/RealtimeSessionBody.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Models/Realtime/RealtimeSessionBody.cs @@ -76,7 +76,7 @@ public class RealtimeSessionTurnDetection public string Type { get; set; } = "semantic_vad"; [JsonPropertyName("eagerness")] - public string eagerness { get;set; } = "auto"; + public string Eagerness { get;set; } = "auto"; } public class InputAudioTranscription