From 4af97e9035f2ceb160f292f35caa71d8f3914da8 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Sat, 6 Sep 2025 12:16:32 -0500 Subject: [PATCH] allow sending indication --- .../Functions/PlotChartFn.cs | 1 + .../Hooks/ChatHubConversationHook.cs | 34 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs b/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs index b51da11c7..572deb08f 100644 --- a/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs +++ b/src/Plugins/BotSharp.Plugin.ChartHandler/Functions/PlotChartFn.cs @@ -82,6 +82,7 @@ public async Task Execute(RoleDialogModel message) MessageId = message.MessageId, CurrentAgentId = message.CurrentAgentId, Content = obj.ReportSummary, + Indication = "Summarizing", FunctionName = message.FunctionName, FunctionArgs = message.FunctionArgs, CreatedAt = DateTime.UtcNow diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs index b8188d0f7..6ffa49648 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs @@ -95,6 +95,14 @@ public override async Task OnResponseGenerated(RoleDialogModel message) var conv = _services.GetRequiredService(); var state = _services.GetRequiredService(); + + var sender = new UserDto + { + FirstName = "AI", + LastName = "Assistant", + Role = AgentRole.Assistant + }; + var data = new ChatResponseDto() { ConversationId = conv.ConversationId, @@ -105,12 +113,7 @@ public override async Task OnResponseGenerated(RoleDialogModel message) Data = message.Data, States = state.GetStates(), IsStreaming = message.IsStreaming, - Sender = new() - { - FirstName = "AI", - LastName = "Assistant", - Role = AgentRole.Assistant - } + Sender = sender }; // Send type-off to client @@ -130,6 +133,18 @@ public override async Task OnResponseGenerated(RoleDialogModel message) foreach (var item in wrapper.Messages) { + if (!string.IsNullOrWhiteSpace(item.Indication)) + { + data = new ChatResponseDto + { + ConversationId = conv.ConversationId, + MessageId = item.MessageId, + Indication = item.Indication, + Sender = sender + }; + await SendEvent(ChatEvent.OnIndicationReceived, conv.ConversationId, data); + } + await Task.Delay(wrapper.SendingInterval); data = new ChatResponseDto @@ -142,12 +157,7 @@ public override async Task OnResponseGenerated(RoleDialogModel message) Data = item.Data, States = state.GetStates(), IsAppend = true, - Sender = new() - { - FirstName = "AI", - LastName = "Assistant", - Role = AgentRole.Assistant - } + Sender = sender }; await SendEvent(ChatEvent.OnMessageReceivedFromAssistant, conv.ConversationId, data); }