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 @@ -5,7 +5,7 @@ namespace BotSharp.Abstraction.Agents;

public abstract class AgentHookBase : IAgentHook
{
public virtual string SelfId => throw new NotImplementedException("Please set SelfId as agent id!");
public abstract string SelfId { get; }

protected Agent _agent;
public Agent Agent => _agent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace BotSharp.Abstraction.Conversations;

public abstract class ConversationHookBase : IConversationHook
{
public abstract string SelfId { get; }

public virtual bool IsMatch(string agentId)
=> string.IsNullOrEmpty(SelfId) || SelfId == agentId;

public Agent Agent { get; private set; }

public Conversation Conversation { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace BotSharp.Abstraction.Instructs;

public class InstructHookBase : IInstructHook
public abstract class InstructHookBase : IInstructHook
{
public virtual string SelfId => throw new NotImplementedException("Please set SelfId as agent id!");
public abstract string SelfId { get; }

public virtual async Task BeforeCompletion(Agent agent, RoleDialogModel message)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ namespace BotSharp.Core.Realtime.Hooks;
public class RealtimeConversationHook : ConversationHookBase, IConversationHook
{
private readonly IServiceProvider _services;

public override string SelfId => string.Empty;

public RealtimeConversationHook(IServiceProvider services)
{
_services = services;
}

public async Task OnFunctionExecuting(RoleDialogModel message, InvokeFunctionOptions? options = null)
public override async Task OnFunctionExecuting(RoleDialogModel message, InvokeFunctionOptions? options = null)
{
var hub = _services.GetRequiredService<IRealtimeHub>();
if (hub.HubConn == null)
Expand All @@ -34,7 +37,7 @@ public async Task OnFunctionExecuting(RoleDialogModel message, InvokeFunctionOpt
await Task.CompletedTask;
}

public async Task OnFunctionExecuted(RoleDialogModel message, InvokeFunctionOptions? options = null)
public override async Task OnFunctionExecuted(RoleDialogModel message, InvokeFunctionOptions? options = null)
{
var hub = _services.GetRequiredService<IRealtimeHub>();
if (options?.From != InvokeSource.Llm || hub.HubConn == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class EvaluationConversationHook : ConversationHookBase
private readonly IExecutionLogger _logger;
private readonly ConversationSetting _convSettings;

public override string SelfId => string.Empty;

public EvaluationConversationHook(IExecutionLogger logger, ConversationSetting convSettings)
{
_logger = logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class TranslationResponseHook : ConversationHookBase
private readonly IConversationStateService _states;
private const string AIAssistant = BuiltInAgentId.AIAssistant;

public override string SelfId => string.Empty;

public TranslationResponseHook(IServiceProvider services,
IConversationStateService states)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class RateLimitConversationHook : ConversationHookBase
{
private readonly IServiceProvider _services;
private readonly ILogger _logger;

public override string SelfId => string.Empty;

public RateLimitConversationHook(IServiceProvider services, ILogger<RateLimitConversationHook> logger)
{
_services = services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ChatHubConversationHook : ConversationHookBase
private readonly BotSharpOptions _options;
private readonly ChatHubSettings _settings;

public override string SelfId => string.Empty;

public ChatHubConversationHook(
IServiceProvider services,
IHubContext<SignalRHub> chatHub,
Expand Down
2 changes: 2 additions & 0 deletions src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
private readonly IAgentService _agentService;
private readonly IRoutingContext _routingCtx;

public override string SelfId => string.Empty;

public StreamingLogHook(
ConversationSetting convSettings,
BotSharpOptions options,
Expand Down
2 changes: 2 additions & 0 deletions src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class WelcomeHook : ConversationHookBase
private readonly BotSharpOptions _options;
private readonly ChatHubSettings _settings;

public override string SelfId => string.Empty;

public WelcomeHook(
IServiceProvider services,
IHubContext<SignalRHub> chatHub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Hooks\" />
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions src/Plugins/BotSharp.Plugin.Dashboard/DashboardPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Plugins;
using BotSharp.Abstraction.Plugins.Models;
using BotSharp.Abstraction.Settings;
using BotSharp.Abstraction.Statistics.Settings;
using BotSharp.Plugin.Dashboard.Hooks;

namespace BotSharp.Plugin.Dashboard;

Expand All @@ -15,7 +12,7 @@ public class DashboardPlugin : IBotSharpPlugin
public string IconUrl => "https://cdn0.iconfinder.com/data/icons/octicons/1024/dashboard-512.png";
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
services.AddScoped<IConversationHook, StatsConversationHook>();

}

public bool AttachMenu(List<PluginMenuDef> menu)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
using BotSharp.Abstraction.Agents;
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Routing.Settings;
using BotSharp.Abstraction.Templating;
using BotSharp.Plugin.RoutingSpeeder.Providers;
using BotSharp.Plugin.RoutingSpeeder.Settings;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using BotSharp.Plugin.RoutingSpeeder.Settings;
using BotSharp.Abstraction.Templating;
using BotSharp.Plugin.RoutingSpeeder.Providers;
using BotSharp.Abstraction.Agents;
using System.IO;
using BotSharp.Abstraction.Routing.Settings;
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Abstraction.Routing;

namespace BotSharp.Plugin.RoutingSpeeder;

public class RoutingConversationHook: ConversationHookBase
{
private readonly IServiceProvider _services;
private RouterSpeederSettings _settings;

public override string SelfId => string.Empty;

public RoutingConversationHook(IServiceProvider service, RouterSpeederSettings settings)
{
_services = service;
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/Plugins/BotSharp.Plugin.SqlDriver/SqlDriverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
services.AddScoped<DbKnowledgeService>();
services.AddScoped<IPlanningHook, SqlDriverPlanningHook>();
services.AddScoped<IKnowledgeHook, SqlDriverKnowledgeHook>();
services.AddScoped<IConversationHook, SqlDriverConversationHook>();
services.AddScoped<IAgentUtilityHook, SqlUtilityHook>();
services.AddScoped<ICrontabHook, SqlDriverCrontabHook>();
services.AddScoped<IChartProcessor, SqlChartProcessor>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BotSharp.Abstraction.Hooks;
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Routing.Enums;
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Plugin.Twilio.Interfaces;
using BotSharp.Plugin.Twilio.Models;
Expand All @@ -15,6 +14,8 @@ public class TwilioConversationHook : ConversationHookBase, IConversationHook
private readonly TwilioSetting _setting;
private readonly ILogger _logger;

public override string SelfId => string.Empty;

public TwilioConversationHook(IServiceProvider services,
TwilioSetting setting,
ILogger<TwilioConversationHook> logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace BotSharp.Plugin.WebDriver.Hooks;
public class WebDriverConversationHook : ConversationHookBase
{
private readonly IServiceProvider _services;

public override string SelfId => string.Empty;

public WebDriverConversationHook(IServiceProvider services)
{
_services = services;
Expand Down
Loading