Merge pull request #1118 from iceljc/master

sending json data
This commit is contained in:
iceljc 2025-08-06 11:28:31 -05:00 committed by GitHub
commit 60ecfea2e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 15 additions and 22 deletions

View file

@ -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];
}

View file

@ -125,7 +125,6 @@ public static class BotSharpCoreExtensions
{
var pluginSettings = new PluginSettings();
config.Bind("PluginLoader", pluginSettings);
var excludedFunctions = pluginSettings.ExcludedFunctions ?? [];
services.AddScoped(provider =>
{
@ -143,8 +142,7 @@ public static class BotSharpCoreExtensions
// 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)

View file

@ -45,7 +45,6 @@ public class ChatHubConversationHook : ConversationHookBase
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 @@ public class ChatHubConversationHook : ConversationHookBase
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
}

View file

@ -54,7 +54,8 @@ public class ChatHubCrontabHook : ICrontabHook
{
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 { }
}

View file

@ -61,7 +61,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
Source = ContentLogSource.UserInput,
Log = log
};
//await SendContentLog(conversationId, input);
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
}
@ -80,7 +79,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
Source = ContentLogSource.UserInput,
Log = log
};
//await SendContentLog(conversationId, input);
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
}
@ -110,7 +108,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
Source = ContentLogSource.Prompt,
Log = log
};
//await SendContentLog(conversationId, input);
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
}
@ -133,7 +130,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
Source = ContentLogSource.HardRule,
Log = log
};
//await SendContentLog(conversationId, input);
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
}
@ -162,7 +158,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
Source = ContentLogSource.FunctionCall,
Log = log
};
//await SendContentLog(conversationId, input);
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
}
@ -184,7 +179,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
Source = ContentLogSource.FunctionCall,
Log = log
};
//await SendContentLog(conversationId, input);
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
}
@ -212,7 +206,6 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
Source = ContentLogSource.Prompt,
Log = log
};
//await SendContentLog(conversationId, input);
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
}
@ -477,7 +470,8 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
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)

View file

@ -89,6 +89,7 @@ public class WelcomeHook : ConversationHookBase
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);
}
}

View file

@ -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;
}
@ -133,7 +136,8 @@ public class ChatHubObserver : BotSharpObserverBase<HubObserveData<RoleDialogMod
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

View file

@ -541,9 +541,6 @@
"BotSharp.Plugin.AudioHandler",
"BotSharp.Plugin.ChartHandler",
"BotSharp.Plugin.TencentCos"
],
"ExcludedFunctions": [
"McpToolAdapter"
]
}
}