Change WebDriver args.
This commit is contained in:
parent
12408443d9
commit
83065b3186
|
|
@ -4,8 +4,8 @@ namespace BotSharp.Abstraction.Browsing;
|
|||
|
||||
public interface IWebBrowser
|
||||
{
|
||||
Task<BrowserActionResult> LaunchBrowser(string contextId, string? url);
|
||||
Task<BrowserActionResult> ScreenshotAsync(string contextId, string path);
|
||||
Task<BrowserActionResult> LaunchBrowser(MessageInfo message, string? url);
|
||||
Task<BrowserActionResult> ScreenshotAsync(MessageInfo message, string path);
|
||||
Task<BrowserActionResult> ScrollPageAsync(BrowserActionParams actionParams);
|
||||
|
||||
Task<BrowserActionResult> ActionOnElement(MessageInfo message, ElementLocatingArgs location, ElementActionArgs action);
|
||||
|
|
@ -19,7 +19,7 @@ public interface IWebBrowser
|
|||
Task<BrowserActionResult> ChangeListValue(BrowserActionParams actionParams);
|
||||
Task<BrowserActionResult> CheckRadioButton(BrowserActionParams actionParams);
|
||||
Task<BrowserActionResult> ChangeCheckbox(BrowserActionParams actionParams);
|
||||
Task<BrowserActionResult> GoToPage(string contextId, string url, bool openNewTab = false);
|
||||
Task<BrowserActionResult> GoToPage(MessageInfo message, string url, bool openNewTab = false);
|
||||
Task<string> ExtractData(BrowserActionParams actionParams);
|
||||
Task<T> EvaluateScript<T>(string contextId, string script);
|
||||
Task CloseBrowser(string contextId);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ namespace BotSharp.Abstraction.Browsing.Models;
|
|||
|
||||
public class MessageInfo
|
||||
{
|
||||
public string AgentId { get; set; }
|
||||
public string ContextId { get; set; }
|
||||
public string MessageId { get; set; }
|
||||
public string AgentId { get; set; } = null!;
|
||||
public string UserId { get; set; } = null!;
|
||||
public string ContextId { get; set; } = null!;
|
||||
public string? MessageId { get; set; }
|
||||
public string? TaskId { get; set; }
|
||||
public int StepNum { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,26 +2,29 @@ namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
|
|||
|
||||
public partial class PlaywrightWebDriver
|
||||
{
|
||||
public async Task<BrowserActionResult> GoToPage(string contextId, string url, bool openNewTab = false)
|
||||
public async Task<BrowserActionResult> GoToPage(MessageInfo message, string url, bool openNewTab = false)
|
||||
{
|
||||
var result = new BrowserActionResult();
|
||||
var context = await _instance.InitInstance(contextId);
|
||||
var context = await _instance.InitInstance(message.ContextId);
|
||||
try
|
||||
{
|
||||
// Check if the page is already open
|
||||
foreach (var p in context.Pages)
|
||||
if (!openNewTab && context.Pages.Count > 0)
|
||||
{
|
||||
if (p.Url == url)
|
||||
foreach (var p in context.Pages)
|
||||
{
|
||||
result.Body = await p.ContentAsync();
|
||||
result.IsSuccess = true;
|
||||
await p.BringToFrontAsync();
|
||||
return result;
|
||||
if (p.Url == url)
|
||||
{
|
||||
result.Body = await p.ContentAsync();
|
||||
result.IsSuccess = true;
|
||||
await p.BringToFrontAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var page = openNewTab ? await _instance.NewPage(contextId) :
|
||||
_instance.GetPage(contextId);
|
||||
var page = openNewTab ? await _instance.NewPage(message.ContextId) :
|
||||
_instance.GetPage(message.ContextId);
|
||||
var response = await page.GotoAsync(url);
|
||||
await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle, new PageWaitForLoadStateOptions
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
|
|||
|
||||
public partial class PlaywrightWebDriver
|
||||
{
|
||||
public async Task<BrowserActionResult> LaunchBrowser(string contextId, string? url)
|
||||
public async Task<BrowserActionResult> LaunchBrowser(MessageInfo message, string? url)
|
||||
{
|
||||
var result = new BrowserActionResult()
|
||||
{
|
||||
IsSuccess = true
|
||||
};
|
||||
var context = await _instance.InitInstance(contextId);
|
||||
var context = await _instance.InitInstance(message.ContextId);
|
||||
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
|
|
@ -22,7 +22,7 @@ public partial class PlaywrightWebDriver
|
|||
}
|
||||
}
|
||||
|
||||
var page = await _instance.NewPage(contextId);
|
||||
var page = await _instance.NewPage(message.ContextId);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
|
|||
|
||||
public partial class PlaywrightWebDriver
|
||||
{
|
||||
public async Task<BrowserActionResult> ScreenshotAsync(string contextId, string path)
|
||||
public async Task<BrowserActionResult> ScreenshotAsync(MessageInfo message, string path)
|
||||
{
|
||||
var result = new BrowserActionResult();
|
||||
|
||||
await _instance.Wait(contextId);
|
||||
var page = _instance.GetPage(contextId);
|
||||
await _instance.Wait(message.ContextId);
|
||||
var page = _instance.GetPage(message.ContextId);
|
||||
|
||||
await Task.Delay(500);
|
||||
var bytes = await page.ScreenshotAsync(new PageScreenshotOptions
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@ namespace BotSharp.Plugin.WebDriver.Drivers.SeleniumDriver;
|
|||
|
||||
public partial class SeleniumWebDriver
|
||||
{
|
||||
public async Task<BrowserActionResult> GoToPage(string contextId, string url, bool openNewTab = false)
|
||||
public async Task<BrowserActionResult> GoToPage(MessageInfo message, string url, bool openNewTab = false)
|
||||
{
|
||||
var result = new BrowserActionResult();
|
||||
try
|
||||
{
|
||||
var page = openNewTab ? await _instance.NewPage(contextId) :
|
||||
_instance.GetPage(contextId);
|
||||
var page = openNewTab ? await _instance.NewPage(message.ContextId) :
|
||||
_instance.GetPage(message.ContextId);
|
||||
page.GoToUrl(url);
|
||||
await _instance.Wait(contextId);
|
||||
await _instance.Wait(message.ContextId);
|
||||
|
||||
result.Body = _instance.GetPageContent(contextId);
|
||||
result.Body = _instance.GetPageContent(message.ContextId);
|
||||
result.IsSuccess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@ namespace BotSharp.Plugin.WebDriver.Drivers.SeleniumDriver;
|
|||
|
||||
public partial class SeleniumWebDriver
|
||||
{
|
||||
public async Task<BrowserActionResult> LaunchBrowser(string contextId, string? url)
|
||||
public async Task<BrowserActionResult> LaunchBrowser(MessageInfo message, string? url)
|
||||
{
|
||||
var result = new BrowserActionResult()
|
||||
{
|
||||
IsSuccess = true
|
||||
};
|
||||
var context = await _instance.InitInstance(contextId);
|
||||
var context = await _instance.InitInstance(message.ContextId);
|
||||
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
// Check if the page is already open
|
||||
var page = await _instance.NewPage(contextId);
|
||||
var page = await _instance.NewPage(message.ContextId);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public partial class SeleniumWebDriver : IWebBrowser
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<BrowserActionResult> ScreenshotAsync(string contextId, string path)
|
||||
public Task<BrowserActionResult> ScreenshotAsync(MessageInfo message, string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,12 @@ public class ChangeCheckboxFn : IFunctionCallback
|
|||
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,12 @@ public class ChangeListValueFn : IFunctionCallback
|
|||
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,12 @@ public class CheckRadioButtonFn : IFunctionCallback
|
|||
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,12 @@ public class ClickButtonFn : IFunctionCallback
|
|||
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,12 @@ public class ClickElementFn : IFunctionCallback
|
|||
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,12 @@ public class ExtractDataFn : IFunctionCallback
|
|||
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,22 @@ public class GoToPageFn : IFunctionCallback
|
|||
|
||||
url = url.Replace("https://https://", "https://");
|
||||
|
||||
var result = await _browser.GoToPage(convService.ConversationId, url);
|
||||
var result = await _browser.GoToPage(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, url);
|
||||
message.Content = result.IsSuccess ? $"Page {url} is open." : $"Page {url} open failed. {result.Message}";
|
||||
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return result.IsSuccess;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,12 @@ public class InputUserPasswordFn : IFunctionCallback
|
|||
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,12 @@ public class InputUserTextFn : IFunctionCallback
|
|||
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,12 @@ public class OpenBrowserFn : IFunctionCallback
|
|||
var url = webDriverService.ReplaceToken(args.Url);
|
||||
|
||||
url = url.Replace("https://https://", "https://");
|
||||
var result = await _browser.LaunchBrowser(convService.ConversationId, url);
|
||||
var result = await _browser.LaunchBrowser(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, url);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
|
|
@ -36,7 +41,12 @@ public class OpenBrowserFn : IFunctionCallback
|
|||
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return result.IsSuccess;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,12 @@ public class ScreenshotFn : IFunctionCallback
|
|||
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
message.Content = "Took screenshot completed. You can take another screenshot if needed.";
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,12 @@ public class ScrollPageFn : IFunctionCallback
|
|||
var webDriverService = _services.GetRequiredService<WebDriverService>();
|
||||
var path = webDriverService.GetScreenshotFilePath(message.MessageId);
|
||||
|
||||
message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path);
|
||||
message.Data = await _browser.ScreenshotAsync(new MessageInfo
|
||||
{
|
||||
AgentId = message.CurrentAgentId,
|
||||
ContextId = convService.ConversationId,
|
||||
MessageId = message.MessageId
|
||||
}, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue