diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs index 1a08fc5ba..70564846f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs @@ -3,6 +3,4 @@ namespace BotSharp.Abstraction.Plugins; public class PluginSettings { public string[] Assemblies { get; set; } = new string[0]; - - public string[] ExcludedFunctions { get; set; } = new string[0]; } diff --git a/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs b/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs index 5c00de0d2..bfae45bac 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs +++ b/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs @@ -125,7 +125,6 @@ public static void RegisterPlugins(IServiceCollection services, IConfiguration c { var pluginSettings = new PluginSettings(); config.Bind("PluginLoader", pluginSettings); - var excludedFunctions = pluginSettings.ExcludedFunctions ?? []; services.AddScoped(provider => { @@ -143,8 +142,7 @@ public static void RegisterPlugins(IServiceCollection services, IConfiguration c // Register function callback var functions = assembly.GetTypes() .Where(x => x.IsClass - && x.GetInterface(nameof(IFunctionCallback)) != null - && !excludedFunctions.Contains(x.Name)) + && x.GetInterface(nameof(IFunctionCallback)) != null) .ToArray(); foreach (var function in functions) diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs index e07f94d47..3831ecd78 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs @@ -45,7 +45,6 @@ public override async Task OnConversationInitialized(Conversation conversation) var user = await userService.GetUser(conv.User.Id); conv.User = UserDto.FromUser(user); - //await InitClientConversation(conv.Id, conv); await SendEvent(ChatEvent.OnConversationInitFromClient, conv.Id, conv); await base.OnConversationInitialized(conversation); } @@ -172,7 +171,8 @@ private bool AllowSendingMessage() private async Task SendEvent(string @event, string conversationId, T data, [CallerMemberName] string callerName = "") { var user = _services.GetRequiredService(); - await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(ChatHubConversationHook), callerName); + var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions); + await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(ChatHubConversationHook), callerName); } #endregion } diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubCrontabHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubCrontabHook.cs index f965d28ef..dd584f172 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubCrontabHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubCrontabHook.cs @@ -54,7 +54,8 @@ private async Task SendEvent(CrontabItem item, ChatResponseDto data) { try { - await _chatHub.Clients.User(item.UserId).SendAsync(ChatEvent.OnNotificationGenerated, data); + var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions); + await _chatHub.Clients.User(item.UserId).SendAsync(ChatEvent.OnNotificationGenerated, json); } catch { } } diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs index 86adaf2c5..7156f29f9 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs @@ -61,7 +61,6 @@ public override async Task OnMessageReceived(RoleDialogModel message) Source = ContentLogSource.UserInput, Log = log }; - //await SendContentLog(conversationId, input); await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input)); } @@ -80,7 +79,6 @@ public override async Task OnPostbackMessageReceived(RoleDialogModel message, Po Source = ContentLogSource.UserInput, Log = log }; - //await SendContentLog(conversationId, input); await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input)); } @@ -110,7 +108,6 @@ public async Task OnSessionUpdated(Agent agent, string instruction, FunctionDef[ Source = ContentLogSource.Prompt, Log = log }; - //await SendContentLog(conversationId, input); await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input)); } @@ -133,7 +130,6 @@ public async Task OnRenderingTemplate(Agent agent, string name, string content) Source = ContentLogSource.HardRule, Log = log }; - //await SendContentLog(conversationId, input); await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input)); } @@ -162,7 +158,6 @@ public override async Task OnFunctionExecuting(RoleDialogModel message, InvokeFu Source = ContentLogSource.FunctionCall, Log = log }; - //await SendContentLog(conversationId, input); await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input)); } @@ -184,7 +179,6 @@ public override async Task OnFunctionExecuted(RoleDialogModel message, InvokeFun Source = ContentLogSource.FunctionCall, Log = log }; - //await SendContentLog(conversationId, input); await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input)); } @@ -212,7 +206,6 @@ public async Task AfterGenerated(RoleDialogModel message, TokenStatsModel tokenS Source = ContentLogSource.Prompt, Log = log }; - //await SendContentLog(conversationId, input); await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input)); } @@ -477,7 +470,8 @@ public async Task OnRoutingInstructionRevised(FunctionCallFromLlm instruct, Role private async Task SendEvent(string @event, string conversationId, T data, [CallerMemberName] string callerName = "") { var user = _services.GetRequiredService(); - await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(StreamingLogHook), callerName); + var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions); + await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(StreamingLogHook), callerName); } private ContentLogOutputModel BuildContentLog(ContentLogInputModel input) diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs index 8a1845687..3fbd852e1 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs @@ -89,6 +89,7 @@ public override async Task OnUserAgentConnectedInitially(Conversation conversati private async Task SendEvent(string @event, string conversationId, T data, [CallerMemberName] string callerName = "") { var user = _services.GetRequiredService(); - await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(WelcomeHook), callerName); + var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions); + await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(WelcomeHook), callerName); } } diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs index 9b5a97e54..03a56d47b 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs @@ -9,14 +9,17 @@ namespace BotSharp.Plugin.ChatHub.Observers; public class ChatHubObserver : BotSharpObserverBase> { - private readonly ILogger _logger; private readonly IServiceProvider _services; + private readonly BotSharpOptions _options; + private readonly ILogger _logger; public ChatHubObserver( IServiceProvider services, + BotSharpOptions options, ILogger logger) : base() { _services = services; + _options = options; _logger = logger; } @@ -133,7 +136,8 @@ private bool AllowSendingMessage() private void SendEvent(string @event, string conversationId, T data, [CallerMemberName] string callerName = "") { var user = _services.GetRequiredService(); - EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(ChatHubObserver), callerName) + var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions); + EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(ChatHubObserver), callerName) .ConfigureAwait(false).GetAwaiter().GetResult(); } #endregion diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index 4e7a42633..1e0365ee5 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -541,9 +541,6 @@ "BotSharp.Plugin.AudioHandler", "BotSharp.Plugin.ChartHandler", "BotSharp.Plugin.TencentCos" - ], - "ExcludedFunctions": [ - "McpToolAdapter" ] } }