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-04-19 18:40:30 +00:00
|
|
|
using BotSharp.Plugin.WebDriver.Drivers.SeleniumDriver;
|
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-01-13 00:31:25 +00:00
|
|
|
public string[] AgentIds => new[] { "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);
|
2024-04-19 18:40:30 +00:00
|
|
|
|
2024-04-29 14:13:17 +00:00
|
|
|
services.AddScoped(provider =>
|
|
|
|
|
{
|
|
|
|
|
var settingService = provider.GetRequiredService<ISettingService>();
|
|
|
|
|
return settings;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
services.AddScoped<PlaywrightWebDriver>();
|
|
|
|
|
services.AddSingleton<PlaywrightInstance>();
|
|
|
|
|
|
|
|
|
|
services.AddScoped<SeleniumWebDriver>();
|
2024-04-19 18:40:30 +00:00
|
|
|
services.AddSingleton<SeleniumInstance>();
|
|
|
|
|
|
2024-04-29 14:13:17 +00:00
|
|
|
services.AddScoped<IWebBrowser>(provider => settings.Driver switch
|
|
|
|
|
{
|
|
|
|
|
"Playwright" => provider.GetRequiredService<PlaywrightWebDriver>(),
|
|
|
|
|
"Selenium" => provider.GetRequiredService<SeleniumWebDriver>(),
|
|
|
|
|
_ => 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>();
|
2023-11-15 13:33:46 +00:00
|
|
|
}
|
|
|
|
|
}
|