Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
4 changes: 1 addition & 3 deletions src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -172,7 +171,8 @@ private bool AllowSendingMessage()
private async Task SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
{
var user = _services.GetRequiredService<IUserIdentity>();
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
}
Expand Down
10 changes: 2 additions & 8 deletions src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -477,7 +470,8 @@ public async Task OnRoutingInstructionRevised(FunctionCallFromLlm instruct, Role
private async Task SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
{
var user = _services.GetRequiredService<IUserIdentity>();
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)
Expand Down
3 changes: 2 additions & 1 deletion src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public override async Task OnUserAgentConnectedInitially(Conversation conversati
private async Task SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
{
var user = _services.GetRequiredService<IUserIdentity>();
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ namespace BotSharp.Plugin.ChatHub.Observers;

public class ChatHubObserver : BotSharpObserverBase<HubObserveData<RoleDialogModel>>
{
private readonly ILogger _logger;
private readonly IServiceProvider _services;
private readonly BotSharpOptions _options;
private readonly ILogger _logger;

public ChatHubObserver(
IServiceProvider services,
BotSharpOptions options,
ILogger<ChatHubObserver> logger) : base()
{
_services = services;
_options = options;
_logger = logger;
}

Expand Down Expand Up @@ -133,7 +136,8 @@ private bool AllowSendingMessage()
private void SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
{
var user = _services.GetRequiredService<IUserIdentity>();
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
Expand Down
3 changes: 0 additions & 3 deletions src/WebStarter/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,6 @@
"BotSharp.Plugin.AudioHandler",
"BotSharp.Plugin.ChartHandler",
"BotSharp.Plugin.TencentCos"
],
"ExcludedFunctions": [
"McpToolAdapter"
]
}
}
Loading