Skip to content

Commit 60ecfea

Browse files
authored
Merge pull request #1118 from iceljc/master
sending json data
2 parents 54a90e0 + 4f42766 commit 60ecfea

File tree

8 files changed

+15
-22
lines changed

8 files changed

+15
-22
lines changed

src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ namespace BotSharp.Abstraction.Plugins;
33
public class PluginSettings
44
{
55
public string[] Assemblies { get; set; } = new string[0];
6-
7-
public string[] ExcludedFunctions { get; set; } = new string[0];
86
}

src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public static void RegisterPlugins(IServiceCollection services, IConfiguration c
125125
{
126126
var pluginSettings = new PluginSettings();
127127
config.Bind("PluginLoader", pluginSettings);
128-
var excludedFunctions = pluginSettings.ExcludedFunctions ?? [];
129128

130129
services.AddScoped(provider =>
131130
{
@@ -143,8 +142,7 @@ public static void RegisterPlugins(IServiceCollection services, IConfiguration c
143142
// Register function callback
144143
var functions = assembly.GetTypes()
145144
.Where(x => x.IsClass
146-
&& x.GetInterface(nameof(IFunctionCallback)) != null
147-
&& !excludedFunctions.Contains(x.Name))
145+
&& x.GetInterface(nameof(IFunctionCallback)) != null)
148146
.ToArray();
149147

150148
foreach (var function in functions)

src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public override async Task OnConversationInitialized(Conversation conversation)
4545
var user = await userService.GetUser(conv.User.Id);
4646
conv.User = UserDto.FromUser(user);
4747

48-
//await InitClientConversation(conv.Id, conv);
4948
await SendEvent(ChatEvent.OnConversationInitFromClient, conv.Id, conv);
5049
await base.OnConversationInitialized(conversation);
5150
}
@@ -172,7 +171,8 @@ private bool AllowSendingMessage()
172171
private async Task SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
173172
{
174173
var user = _services.GetRequiredService<IUserIdentity>();
175-
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(ChatHubConversationHook), callerName);
174+
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
175+
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(ChatHubConversationHook), callerName);
176176
}
177177
#endregion
178178
}

src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubCrontabHook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ private async Task SendEvent(CrontabItem item, ChatResponseDto data)
5454
{
5555
try
5656
{
57-
await _chatHub.Clients.User(item.UserId).SendAsync(ChatEvent.OnNotificationGenerated, data);
57+
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
58+
await _chatHub.Clients.User(item.UserId).SendAsync(ChatEvent.OnNotificationGenerated, json);
5859
}
5960
catch { }
6061
}

src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public override async Task OnMessageReceived(RoleDialogModel message)
6161
Source = ContentLogSource.UserInput,
6262
Log = log
6363
};
64-
//await SendContentLog(conversationId, input);
6564
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
6665
}
6766

@@ -80,7 +79,6 @@ public override async Task OnPostbackMessageReceived(RoleDialogModel message, Po
8079
Source = ContentLogSource.UserInput,
8180
Log = log
8281
};
83-
//await SendContentLog(conversationId, input);
8482
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
8583
}
8684

@@ -110,7 +108,6 @@ public async Task OnSessionUpdated(Agent agent, string instruction, FunctionDef[
110108
Source = ContentLogSource.Prompt,
111109
Log = log
112110
};
113-
//await SendContentLog(conversationId, input);
114111
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
115112
}
116113

@@ -133,7 +130,6 @@ public async Task OnRenderingTemplate(Agent agent, string name, string content)
133130
Source = ContentLogSource.HardRule,
134131
Log = log
135132
};
136-
//await SendContentLog(conversationId, input);
137133
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
138134
}
139135

@@ -162,7 +158,6 @@ public override async Task OnFunctionExecuting(RoleDialogModel message, InvokeFu
162158
Source = ContentLogSource.FunctionCall,
163159
Log = log
164160
};
165-
//await SendContentLog(conversationId, input);
166161
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
167162
}
168163

@@ -184,7 +179,6 @@ public override async Task OnFunctionExecuted(RoleDialogModel message, InvokeFun
184179
Source = ContentLogSource.FunctionCall,
185180
Log = log
186181
};
187-
//await SendContentLog(conversationId, input);
188182
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
189183
}
190184

@@ -212,7 +206,6 @@ public async Task AfterGenerated(RoleDialogModel message, TokenStatsModel tokenS
212206
Source = ContentLogSource.Prompt,
213207
Log = log
214208
};
215-
//await SendContentLog(conversationId, input);
216209
await SendEvent(ChatEvent.OnConversationContentLogGenerated, conversationId, BuildContentLog(input));
217210
}
218211

@@ -477,7 +470,8 @@ public async Task OnRoutingInstructionRevised(FunctionCallFromLlm instruct, Role
477470
private async Task SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
478471
{
479472
var user = _services.GetRequiredService<IUserIdentity>();
480-
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(StreamingLogHook), callerName);
473+
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
474+
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(StreamingLogHook), callerName);
481475
}
482476

483477
private ContentLogOutputModel BuildContentLog(ContentLogInputModel input)

src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public override async Task OnUserAgentConnectedInitially(Conversation conversati
8989
private async Task SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
9090
{
9191
var user = _services.GetRequiredService<IUserIdentity>();
92-
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(WelcomeHook), callerName);
92+
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
93+
await EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(WelcomeHook), callerName);
9394
}
9495
}

src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ namespace BotSharp.Plugin.ChatHub.Observers;
99

1010
public class ChatHubObserver : BotSharpObserverBase<HubObserveData<RoleDialogModel>>
1111
{
12-
private readonly ILogger _logger;
1312
private readonly IServiceProvider _services;
13+
private readonly BotSharpOptions _options;
14+
private readonly ILogger _logger;
1415

1516
public ChatHubObserver(
1617
IServiceProvider services,
18+
BotSharpOptions options,
1719
ILogger<ChatHubObserver> logger) : base()
1820
{
1921
_services = services;
22+
_options = options;
2023
_logger = logger;
2124
}
2225

@@ -133,7 +136,8 @@ private bool AllowSendingMessage()
133136
private void SendEvent<T>(string @event, string conversationId, T data, [CallerMemberName] string callerName = "")
134137
{
135138
var user = _services.GetRequiredService<IUserIdentity>();
136-
EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, data, nameof(ChatHubObserver), callerName)
139+
var json = JsonSerializer.Serialize(data, _options.JsonSerializerOptions);
140+
EventEmitter.SendChatEvent(_services, _logger, @event, conversationId, user?.Id, json, nameof(ChatHubObserver), callerName)
137141
.ConfigureAwait(false).GetAwaiter().GetResult();
138142
}
139143
#endregion

src/WebStarter/appsettings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,6 @@
541541
"BotSharp.Plugin.AudioHandler",
542542
"BotSharp.Plugin.ChartHandler",
543543
"BotSharp.Plugin.TencentCos"
544-
],
545-
"ExcludedFunctions": [
546-
"McpToolAdapter"
547544
]
548545
}
549546
}

0 commit comments

Comments
 (0)