From d2bba95f47b6ad6f936d2d3818d47eb49ff5c9ae Mon Sep 17 00:00:00 2001 From: Wenbo Cao <104199@smsassist.com> Date: Tue, 1 Apr 2025 10:27:31 -0500 Subject: [PATCH] Revert all changes --- .../BotSharp.Plugin.WebDriver.csproj | 9 ---- .../PlaywrightWebDriver.ExtractData.cs | 7 +-- .../Hooks/WebUtilityHook.cs | 4 +- .../UtilFunctions/UtilWebActionOnElementFn.cs | 2 +- .../UtilFunctions/UtilWebExtractDataFn.cs | 45 ------------------- .../util-web-extract_data_from_page.json | 14 ------ 6 files changed, 4 insertions(+), 77 deletions(-) delete mode 100644 src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebExtractDataFn.cs delete mode 100644 src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-extract_data_from_page.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj index 07c3ff7d..03f1a9b9 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj +++ b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj @@ -31,9 +31,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -106,10 +103,4 @@ - - - PreserveNewest - - - diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.ExtractData.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.ExtractData.cs index a191d92c..b716b7ba 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.ExtractData.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.ExtractData.cs @@ -9,11 +9,8 @@ public partial class PlaywrightWebDriver await Task.Delay(3000); // Retrieve the page raw html and infer the element path - var pageContent = _instance.GetPage(actionParams.ContextId); - var body = await pageContent.QuerySelectorAsync("body"); - var pageUrl = pageContent.Url; - var pageBody = await body.InnerTextAsync(); - string content = $"Page URL: `{pageUrl}`
PageBody: {pageBody}"; + var body = await _instance.GetPage(actionParams.ContextId).QuerySelectorAsync("body"); + var content = await body.InnerTextAsync(); var driverService = _services.GetRequiredService(); var answer = await driverService.ExtraData(actionParams.Agent, content, actionParams.Context.Question, actionParams.MessageId); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Hooks/WebUtilityHook.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Hooks/WebUtilityHook.cs index a46547ac..63637119 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Hooks/WebUtilityHook.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Hooks/WebUtilityHook.cs @@ -7,7 +7,6 @@ public class WebUtilityHook : IAgentUtilityHook private const string GO_TO_PAGE_FN = $"{PREFIX}go_to_page"; private const string LOCATE_ELEMENT_FN = $"{PREFIX}locate_element"; private const string ACTION_ON_ELEMENT_FN = $"{PREFIX}action_on_element"; - private const string EXTRACT_DATA_FN = $"{PREFIX}extract_data_from_page"; public void AddUtilities(List utilities) { @@ -21,8 +20,7 @@ public class WebUtilityHook : IAgentUtilityHook new(CLOSE_BROWSER_FN), new(GO_TO_PAGE_FN), new(LOCATE_ELEMENT_FN), - new(ACTION_ON_ELEMENT_FN), - new(EXTRACT_DATA_FN) + new(ACTION_ON_ELEMENT_FN) ], Templates = [ diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebActionOnElementFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebActionOnElementFn.cs index 2f616ef4..0788acb8 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebActionOnElementFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebActionOnElementFn.cs @@ -45,7 +45,7 @@ public class UtilWebActionOnElementFn : IFunctionCallback }; var result = await browser.ActionOnElement(msg, locatorArgs, actionArgs); - message.Content = $"{actionArgs.Action} executed {(result.IsSuccess ? "success" : "failed")}"; + message.Content = $"{actionArgs.Action} executed {(result.IsSuccess ? "success" : "failed")}. Current page url: '{result.UrlAfterAction}'."; var path = webDriverService.GetScreenshotFilePath(message.MessageId); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebExtractDataFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebExtractDataFn.cs deleted file mode 100644 index b5268281..00000000 --- a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebExtractDataFn.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Playwright; - -namespace BotSharp.Plugin.WebDriver.UtilFunctions -{ - public class UtilWebExtractDataFn : IFunctionCallback - { - public string Name => "util-web-extract_data_from_page"; - public string Indication => "Util Web Extract Data from web page"; - private readonly IServiceProvider _services; - public UtilWebExtractDataFn( - IServiceProvider services) - { - _services = services; - } - public async Task Execute(RoleDialogModel message) - { - var convService = _services.GetRequiredService(); - var args = JsonSerializer.Deserialize(message.FunctionArgs); - var agentService = _services.GetRequiredService(); - var agent = await agentService.LoadAgent(message.CurrentAgentId); - var _browser = _services.GetRequiredService(); - var webDriverService = _services.GetRequiredService(); - - var contextId = webDriverService.GetMessageContext(message); - var browerActionParams = new BrowserActionParams(agent, args, contextId, message.MessageId); - message.Content = await _browser.ExtractData(browerActionParams); - - var path = webDriverService.GetScreenshotFilePath(message.MessageId); - - message.Data = await _browser.ScreenshotAsync(new MessageInfo - { - AgentId = message.CurrentAgentId, - ContextId = contextId, - MessageId = message.MessageId - }, path); - - return true; - } - } -} diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-extract_data_from_page.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-extract_data_from_page.json deleted file mode 100644 index a354c37b..00000000 --- a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-extract_data_from_page.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "util-web-extract_data_from_page", - "description": "Extract data from current web page.", - "parameters": { - "type": "object", - "properties": { - "question": { - "type": "string", - "description": "the information user wants to know" - } - }, - "required": [ "question" ] - } -} \ No newline at end of file