BotSharp/src/Plugins/BotSharp.Plugin.WebDriver/Functions/InputUserTextFn.cs

33 lines
954 B
C#
Raw Normal View History

2024-01-03 19:40:41 +00:00
using BotSharp.Abstraction.Agents;
using BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
namespace BotSharp.Plugin.WebDriver.Functions;
public class InputUserTextFn : IFunctionCallback
{
public string Name => "input_user_text";
private readonly IServiceProvider _services;
private readonly PlaywrightWebDriver _driver;
public InputUserTextFn(IServiceProvider services,
PlaywrightWebDriver driver)
{
_services = services;
_driver = driver;
}
public async Task<bool> Execute(RoleDialogModel message)
{
var args = JsonSerializer.Deserialize<BrowsingContextIn>(message.FunctionArgs);
var agentService = _services.GetRequiredService<IAgentService>();
var agent = await agentService.LoadAgent(message.CurrentAgentId);
await _driver.InputUserText(agent, args, message.MessageId);
message.Content = "Executed successfully.";
return true;
}
}