BotSharp/src/Plugins/BotSharp.Plugin.WebDriver/WebDriverPlugin.cs

40 lines
1.6 KiB
C#
Raw Normal View History

2024-04-29 14:13:17 +00:00
using BotSharp.Abstraction.Browsing.Settings;
using BotSharp.Abstraction.Settings;
2024-01-03 19:40:41 +00:00
using BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
2024-02-06 20:42:35 +00:00
using BotSharp.Plugin.WebDriver.Hooks;
2023-11-15 13:33:46 +00:00
2024-01-03 04:43:37 +00:00
namespace BotSharp.Plugin.Playwrights;
2023-11-15 13:33:46 +00:00
public class WebDriverPlugin : IBotSharpPlugin
{
2024-01-12 22:20:22 +00:00
public string Id => "f0e26bc3-cfde-4b63-845c-c9c542abea44";
2023-11-15 13:33:46 +00:00
public string Name => "Web Driver";
2024-01-06 22:24:22 +00:00
public string Description => "Empower agent to manipulate web browser in automation tools.";
public string IconUrl => "https://cdn-icons-png.flaticon.com/512/8576/8576378.png";
2024-08-04 22:48:52 +00:00
public string[] AgentIds => ["f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b"];
2024-01-03 04:43:37 +00:00
2023-11-15 13:33:46 +00:00
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
2024-04-29 14:13:17 +00:00
var settings = new WebBrowsingSettings();
config.Bind("WebBrowsing", settings);
services.AddSingleton(x => settings);
2024-04-29 14:13:17 +00:00
services.AddScoped<PlaywrightWebDriver>();
services.AddSingleton<PlaywrightInstance>();
2024-08-04 22:48:52 +00:00
// services.AddScoped<SeleniumWebDriver>();
// services.AddSingleton<SeleniumInstance>();
2024-04-19 18:40:30 +00:00
2024-04-29 14:13:17 +00:00
services.AddScoped<IWebBrowser>(provider => settings.Driver switch
{
"Playwright" => provider.GetRequiredService<PlaywrightWebDriver>(),
2024-08-04 22:48:52 +00:00
// "Selenium" => provider.GetRequiredService<SeleniumWebDriver>(),
2024-04-29 14:13:17 +00:00
_ => provider.GetRequiredService<PlaywrightWebDriver>(),
});
2024-01-03 04:43:37 +00:00
services.AddScoped<WebDriverService>();
2024-02-06 20:42:35 +00:00
services.AddScoped<IConversationHook, WebDriverConversationHook>();
2025-02-03 23:43:04 +00:00
services.AddScoped<IAgentUtilityHook, WebUtilityHook>();
2023-11-15 13:33:46 +00:00
}
}