From e45713fea946b9277fa52c961d5d9915ce9e615b Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Fri, 14 Feb 2025 00:51:43 +0800 Subject: [PATCH 01/13] Change default app data folder --- .../Drivers/PlaywrightDriver/PlaywrightInstance.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs index efe8e7eb..4c65aa32 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs @@ -57,7 +57,8 @@ public class PlaywrightInstance : IDisposable } else { - string userDataDir = args.UserDataDir ?? $"{Path.GetTempPath()}\\playwright\\{ctxId}"; + string localAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + string userDataDir = args.UserDataDir ?? $"{localAppDataFolder}\\playwright\\{ctxId}"; _contexts[ctxId] = await _playwright.Chromium.LaunchPersistentContextAsync(userDataDir, new BrowserTypeLaunchPersistentContextOptions { Headless = args.Headless, From 9a6d22eeeb691940cea0bfdfcf8c59d991bd281b Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Fri, 14 Feb 2025 16:07:45 +0000 Subject: [PATCH 02/13] Set UrlAfterAction --- .../BotSharp.Plugin.WebDriver.csproj | 10 ++++++++-- .../PlaywrightWebDriver.GoToPage.cs | 17 +++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj index ace808b0..572b2917 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj +++ b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj @@ -9,10 +9,16 @@ $(GenerateDocumentationFile) $(SolutionDir)packages + + + + + + - - + + diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GoToPage.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GoToPage.cs index 371a8c06..7327bb40 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GoToPage.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GoToPage.cs @@ -15,9 +15,12 @@ public partial class PlaywrightWebDriver if (page != null) { - await page.EvaluateAsync(@"() => { - window.open('', '_blank'); - }"); + if (page.Url != "about:blank") + { + await page.EvaluateAsync(@"() => { + window.open('', '_blank'); + }"); + } if (args.EnableResponseCallback) { @@ -36,13 +39,6 @@ public partial class PlaywrightWebDriver else { page = await _instance.NewPage(message, args); - - Serilog.Log.Information($"goto page: {args.Url}"); - - if (args.OpenNewTab && page != null && page.Url == "about:blank") - { - page = await _instance.NewPage(message, args); - } } if (page == null) @@ -95,6 +91,7 @@ public partial class PlaywrightWebDriver } result.ResponseStatusCode = response.Status; + result.UrlAfterAction = page.Url; if (response.Status == 200) { result.IsSuccess = true; From 4e8a307f3d1cc97e0dd56db86b7fabb68911f75a Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Fri, 14 Feb 2025 16:10:20 +0000 Subject: [PATCH 03/13] move data to WebStarter --- .../BotSharp.Plugin.WebDriver.csproj | 101 +----------------- .../functions/util-web-action_on_element.json | 0 .../functions/util-web-close_browser.json | 0 .../functions/util-web-go_to_page.json | 0 .../functions/util-web-locate_element.json | 0 .../util-web-action_on_element.fn.liquid | 0 .../templates/util-web-go_to_page.fn.liquid | 0 .../agent.json | 0 .../functions/change_checkbox.json | 0 .../functions/change_list_value.json | 0 .../functions/check_radio_button.json | 0 .../functions/click_button.json | 0 .../functions/click_element.json | 0 .../functions/close_browser.json | 0 .../functions/extract_data_from_page.json | 0 .../functions/go_to_page.json | 0 .../functions/input_user_password.json | 0 .../functions/input_user_text.json | 0 .../functions/open_browser.json | 0 .../functions/scroll_page.json | 0 .../functions/send_http_request.json | 0 .../functions/take_screenshot.json | 0 .../instructions/instruction.liquid | 0 .../templates/extract_data.liquid | 0 .../templates/html_parser.liquid | 0 25 files changed, 1 insertion(+), 100 deletions(-) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid (100%) rename src/{Plugins/BotSharp.Plugin.WebDriver => WebStarter}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid (100%) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj index 572b2917..327cfcb4 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj +++ b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj @@ -1,4 +1,4 @@ - + $(TargetFramework) @@ -9,12 +9,6 @@ $(GenerateDocumentationFile) $(SolutionDir)packages - - - - - - @@ -22,102 +16,9 @@ - - - - - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json b/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json rename to src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json b/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json rename to src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json b/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json rename to src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json b/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json rename to src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid b/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid rename to src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid b/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid rename to src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid b/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid similarity index 100% rename from src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid rename to src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid From d8a4dc4d17c6578912e34d11a664f85f2ee54d36 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Sat, 15 Feb 2025 11:34:00 +0800 Subject: [PATCH 04/13] IWebBrowser.IsBrowserClosed --- .../BotSharp.Abstraction/Browsing/IWebBrowser.cs | 1 + .../Drivers/PlaywrightDriver/PlaywrightWebDriver.cs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs index 9386dd8a..0e6b9ba3 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs @@ -25,6 +25,7 @@ public interface IWebBrowser Task ExtractData(BrowserActionParams actionParams); Task EvaluateScript(string contextId, string script); Task CloseBrowser(string contextId); + Task IsBrowserClosed(string contextId); Task CloseCurrentPage(MessageInfo message); Task SendHttpRequest(MessageInfo message, HttpRequestParams actionParams); Task GetAttributeValue(MessageInfo message, ElementLocatingArgs location); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.cs index 4d13e26f..67c9bf8d 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.cs @@ -78,4 +78,9 @@ public partial class PlaywrightWebDriver : IWebBrowser await page.Keyboard.PressAsync(key); } } + + public async Task IsBrowserClosed(string contextId) + { + return !_instance.Contexts.ContainsKey(contextId); + } } From 6aaaac6fa0bc6fa0e66fc3aa61bb00956d6b2b46 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Thu, 20 Feb 2025 08:13:00 +0800 Subject: [PATCH 05/13] move data back --- .../BotSharp.Plugin.WebDriver.csproj | 80 +++++++++++++++++++ .../functions/util-web-action_on_element.json | 0 .../functions/util-web-close_browser.json | 0 .../functions/util-web-go_to_page.json | 0 .../functions/util-web-locate_element.json | 0 .../util-web-action_on_element.fn.liquid | 0 .../templates/util-web-go_to_page.fn.liquid | 0 .../agent.json | 0 .../functions/change_checkbox.json | 0 .../functions/change_list_value.json | 0 .../functions/check_radio_button.json | 0 .../functions/click_button.json | 0 .../functions/click_element.json | 0 .../functions/close_browser.json | 0 .../functions/extract_data_from_page.json | 0 .../functions/go_to_page.json | 0 .../functions/input_user_password.json | 0 .../functions/input_user_text.json | 0 .../functions/open_browser.json | 0 .../functions/scroll_page.json | 0 .../functions/send_http_request.json | 0 .../functions/take_screenshot.json | 0 .../instructions/instruction.liquid | 0 .../templates/extract_data.liquid | 0 .../templates/html_parser.liquid | 0 25 files changed, 80 insertions(+) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid (100%) rename src/{WebStarter => Plugins/BotSharp.Plugin.WebDriver}/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid (100%) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj index 327cfcb4..499253de 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj +++ b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj @@ -16,9 +16,89 @@ + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + diff --git a/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json similarity index 100% rename from src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-action_on_element.json diff --git a/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json similarity index 100% rename from src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-close_browser.json diff --git a/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json similarity index 100% rename from src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-go_to_page.json diff --git a/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json similarity index 100% rename from src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-web-locate_element.json diff --git a/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid similarity index 100% rename from src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-action_on_element.fn.liquid diff --git a/src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid similarity index 100% rename from src/WebStarter/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/util-web-go_to_page.fn.liquid diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/agent.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_checkbox.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/change_list_value.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/check_radio_button.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_button.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/click_element.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/close_browser.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/extract_data_from_page.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/go_to_page.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_password.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/input_user_text.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/open_browser.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/scroll_page.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/send_http_request.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/functions/take_screenshot.json diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/instructions/instruction.liquid diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/extract_data.liquid diff --git a/src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid b/src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid similarity index 100% rename from src/WebStarter/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid rename to src/Plugins/BotSharp.Plugin.WebDriver/data/agents/f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b/templates/html_parser.liquid From cd0fa0e222231f01b39e089727260d338a92a379 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Thu, 20 Feb 2025 09:14:28 -0600 Subject: [PATCH 06/13] Remove BotSharp.Core.Rules --- .../BotSharp.Plugin.WebDriver.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj index 499253de..c5436fe6 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj +++ b/src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj @@ -11,8 +11,8 @@ - - + + From 6bd2af41511b70637ab6aa5eab86e6a9c98e5a4b Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Thu, 20 Feb 2025 09:33:47 -0600 Subject: [PATCH 07/13] Remove IConversationSideCar dependency --- .../Conversations/Services/ConversationStateService.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index a2b55d13..531bf06d 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -27,7 +27,6 @@ public class ConversationStateService : IConversationStateService, IDisposable private readonly ILogger _logger; private readonly IServiceProvider _services; private readonly IBotSharpRepository _db; - private readonly IConversationSideCar _sidecar; private string _conversationId; /// /// States in the current round of conversation @@ -41,12 +40,10 @@ public class ConversationStateService : IConversationStateService, IDisposable public ConversationStateService( IServiceProvider services, IBotSharpRepository db, - IConversationSideCar sidecar, ILogger logger) { _services = services; _db = db; - _sidecar = sidecar; _logger = logger; _curStates = new ConversationState(); _historyStates = new ConversationState(); @@ -142,8 +139,9 @@ public class ConversationStateService : IConversationStateService, IDisposable _conversationId = !isReadOnly ? conversationId : null; Reset(); + var sidecar = _services.GetService(); var endNodes = new Dictionary(); - if (_sidecar?.IsEnabled() == true) + if (sidecar?.IsEnabled() == true) { return endNodes; } @@ -219,7 +217,8 @@ public class ConversationStateService : IConversationStateService, IDisposable public void Save() { - if (_conversationId == null || _sidecar?.IsEnabled() == true) + var sidecar = _services.GetService(); + if (_conversationId == null || sidecar?.IsEnabled() == true) { Reset(); return; From a2406a61a60dfcbac26a4ce19b7959c99990791a Mon Sep 17 00:00:00 2001 From: Haiping Date: Thu, 20 Feb 2025 09:43:01 -0600 Subject: [PATCH 08/13] display github action workflow badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9924c4d1..68e60006 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![QQ群聊](https://img.shields.io/static/v1?label=QQ&message=群聊&color=brightgreen)](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=sN9VVMwbWjs5L0ATpizKKxOcZdEPMrp8&authKey=RLDw41bLTrEyEgZZi%2FzT4pYk%2BwmEFgFcrhs8ZbkiVY7a4JFckzJefaYNW6Lk4yPX&noverify=0&group_code=985366726) [![Apache 2.0](https://img.shields.io/hexpm/l/plug.svg)](https://raw.githubusercontent.com/Oceania2018/BotSharp/master/LICENSE) [![NuGet](https://img.shields.io/nuget/dt/BotSharp.Core.svg)](https://www.nuget.org/packages/BotSharp.Core) -[![Build status](https://ci.appveyor.com/api/projects/status/qx2dx5ca5hjqodm5?svg=true)](https://ci.appveyor.com/project/Haiping-Chen/botsharp) +[![build](https://github.com/SciSharp/BotSharp/actions/workflows/build.yml/badge.svg)](https://github.com/SciSharp/BotSharp/actions/workflows/build.yml) [![Documentation Status](https://readthedocs.org/projects/botsharp/badge/?version=latest)](https://botsharp.readthedocs.io/en/latest/?badge=latest) *"Conversation as a platform (CaaP) is the future, so it's perfect that we're already offering the whole toolkits to our .NET developers using the BotSharp AI BOT Platform Builder to build a CaaP. It opens up as much learning power as possible for your own robots and precisely control every step of the AI processing pipeline."* From 8048524a31ffb9c01251777ffa5cc29da8c4bfba Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 20 Feb 2025 11:26:49 -0600 Subject: [PATCH 09/13] refine state --- .../Conversations/IConversationStateService.cs | 2 +- .../Conversations/Services/ConversationStateService.cs | 10 +++++----- .../Controllers/ConversationController.cs | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs index df123922..a5563cf3 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs @@ -6,7 +6,7 @@ namespace BotSharp.Abstraction.Conversations; /// /// Conversation state service to track the context in the conversation lifecycle /// -public interface IConversationStateService +public interface IConversationStateService : IDisposable { string GetConversationId(); Dictionary Load(string conversationId, bool isReadOnly = false); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 531bf06d..4d229866 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -22,11 +22,12 @@ namespace BotSharp.Core.Conversations.Services; /// /// Maintain the conversation state /// -public class ConversationStateService : IConversationStateService, IDisposable +public class ConversationStateService : IConversationStateService { private readonly ILogger _logger; private readonly IServiceProvider _services; private readonly IBotSharpRepository _db; + private readonly IConversationSideCar? _sidecar; private string _conversationId; /// /// States in the current round of conversation @@ -47,6 +48,7 @@ public class ConversationStateService : IConversationStateService, IDisposable _logger = logger; _curStates = new ConversationState(); _historyStates = new ConversationState(); + _sidecar = services.GetService(); } public string GetConversationId() => _conversationId; @@ -139,9 +141,8 @@ public class ConversationStateService : IConversationStateService, IDisposable _conversationId = !isReadOnly ? conversationId : null; Reset(); - var sidecar = _services.GetService(); var endNodes = new Dictionary(); - if (sidecar?.IsEnabled() == true) + if (_sidecar?.IsEnabled() == true) { return endNodes; } @@ -217,8 +218,7 @@ public class ConversationStateService : IConversationStateService, IDisposable public void Save() { - var sidecar = _services.GetService(); - if (_conversationId == null || sidecar?.IsEnabled() == true) + if (_conversationId == null || _sidecar?.IsEnabled() == true) { Reset(); return; diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index f41c69fe..75dc1113 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -79,8 +79,9 @@ public class ConversationController : ControllerBase [HttpGet("/conversation/{conversationId}/dialogs")] public async Task> GetDialogs([FromRoute] string conversationId) { - var storage = _services.GetRequiredService(); - var history = storage.GetDialogs(conversationId); + var conv = _services.GetRequiredService(); + conv.SetConversationId(conversationId, [], isReadOnly: true); + var history = conv.GetDialogHistory(fromBreakpoint: false); var userService = _services.GetRequiredService(); var agentService = _services.GetRequiredService(); From 816abe9310f27de62ece46f4de6b300b215f87f8 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 20 Feb 2025 11:59:59 -0600 Subject: [PATCH 10/13] clean execution log --- .../Repositories/IBotSharpRepository.cs | 7 ----- .../Evaluations/ExecutionLogger.cs | 13 ++++---- .../Repository/BotSharpDbContext.cs | 12 -------- .../FileRepository/FileRepository.Log.cs | 30 ------------------- .../FileRepository/FileRepository.cs | 3 -- .../Hooks/CommonContentGeneratingHook.cs | 3 +- .../Collections/ExecutionLogDocument.cs | 7 ----- .../MongoDbContext.cs | 3 -- .../MongoRepository.Conversation.cs | 8 ++--- .../Repository/MongoRepository.Log.cs | 26 ---------------- 10 files changed, 10 insertions(+), 102 deletions(-) delete mode 100644 src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExecutionLogDocument.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index 06582d45..235c449b 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -152,13 +152,6 @@ public interface IBotSharpRepository : IHaveServiceProvider => throw new NotImplementedException(); #endregion - #region Execution Log - void AddExecutionLogs(string conversationId, List logs) - => throw new NotImplementedException(); - List GetExecutionLogs(string conversationId) - => throw new NotImplementedException(); - #endregion - #region LLM Completion Log void SaveLlmCompletionLog(LlmCompletionLog log) => throw new NotImplementedException(); diff --git a/src/Infrastructure/BotSharp.Core/Evaluations/ExecutionLogger.cs b/src/Infrastructure/BotSharp.Core/Evaluations/ExecutionLogger.cs index f70cb59f..c00ae098 100644 --- a/src/Infrastructure/BotSharp.Core/Evaluations/ExecutionLogger.cs +++ b/src/Infrastructure/BotSharp.Core/Evaluations/ExecutionLogger.cs @@ -1,26 +1,25 @@ using BotSharp.Abstraction.Evaluations; -using BotSharp.Abstraction.Repositories; using System.Text.RegularExpressions; namespace BotSharp.Core.Evaluations; public class ExecutionLogger : IExecutionLogger { - private readonly BotSharpDatabaseSettings _dbSettings; private readonly IServiceProvider _services; + private readonly ILogger _logger; + public ExecutionLogger( - BotSharpDatabaseSettings dbSettings, - IServiceProvider services) + IServiceProvider services, + ILogger logger) { - _dbSettings = dbSettings; _services = services; + _logger = logger; } public void Append(string conversationId, string content) { content = content.Replace("\r\n", " ").Replace("\n", " "); content = Regex.Replace(content, @"\s+", " "); - var db = _services.GetRequiredService(); - db.AddExecutionLogs(conversationId, new List { content }); + _logger.LogInformation($"Execution Log: {content}"); } } diff --git a/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs b/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs index 100bbf16..587de372 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs @@ -135,18 +135,6 @@ public class BotSharpDbContext : Database, IBotSharpRepository => throw new NotImplementedException(); #endregion - #region Execution Log - public void AddExecutionLogs(string conversationId, List logs) - { - throw new NotImplementedException(); - } - - public List GetExecutionLogs(string conversationId) - { - throw new NotImplementedException(); - } - #endregion - #region LLM Completion Log public void SaveLlmCompletionLog(LlmCompletionLog log) { diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs index 08898864..f82cb6fa 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs @@ -1,40 +1,10 @@ using BotSharp.Abstraction.Loggers.Models; -using Serilog; using System.IO; namespace BotSharp.Core.Repository { public partial class FileRepository { - #region Execution Log - public void AddExecutionLogs(string conversationId, List logs) - { - if (string.IsNullOrEmpty(conversationId) || logs.IsNullOrEmpty()) return; - - var dir = Path.Combine(_dbSettings.FileRepository, "conversations", conversationId); - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } - - var file = Path.Combine(dir, EXECUTION_LOG_FILE); - File.AppendAllLines(file, logs); - } - - public List GetExecutionLogs(string conversationId) - { - var logs = new List(); - if (string.IsNullOrEmpty(conversationId)) return logs; - - var dir = Path.Combine(_dbSettings.FileRepository, "conversations", conversationId); - if (!Directory.Exists(dir)) return logs; - - var file = Path.Combine(dir, EXECUTION_LOG_FILE); - logs = File.ReadAllLines(file)?.ToList() ?? new List(); - return logs; - } - #endregion - #region LLM Completion Log public void SaveLlmCompletionLog(LlmCompletionLog log) { diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs index a5a2ffef..78e90e4b 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs @@ -50,9 +50,6 @@ public partial class FileRepository : IBotSharpRepository private const string KNOWLEDGE_DOC_FOLDER = "document"; private const string KNOWLEDGE_DOC_META_FILE = "meta.json"; - private const string EXECUTION_LOG_FILE = "execution.log"; - private const string PLUGIN_CONFIG_FILE = "config.json"; - private const string STATS_FOLDER = "stats"; private const string STATS_FILE = "stats.json"; diff --git a/src/Infrastructure/BotSharp.Logger/Hooks/CommonContentGeneratingHook.cs b/src/Infrastructure/BotSharp.Logger/Hooks/CommonContentGeneratingHook.cs index 68d83c87..d0c9c6e1 100644 --- a/src/Infrastructure/BotSharp.Logger/Hooks/CommonContentGeneratingHook.cs +++ b/src/Infrastructure/BotSharp.Logger/Hooks/CommonContentGeneratingHook.cs @@ -29,7 +29,8 @@ public class CommonContentGeneratingHook : IContentGeneratingHook MessageId = message.MessageId, AgentId = message.CurrentAgentId, Prompt = tokenStats.Prompt, - Response = message.Content + Response = message.Content, + CreateDateTime = DateTime.UtcNow }; db.SaveLlmCompletionLog(completionLog); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExecutionLogDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExecutionLogDocument.cs deleted file mode 100644 index 6b961141..00000000 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExecutionLogDocument.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace BotSharp.Plugin.MongoStorage.Collections; - -public class ExecutionLogDocument : MongoBase -{ - public string ConversationId { get; set; } = default!; - public List Logs { get; set; } = []; -} diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs index 4d7f76a4..4aa82b2e 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs @@ -154,9 +154,6 @@ public class MongoDbContext public IMongoCollection ConversationStates => CreateConversationStateIndex(); - public IMongoCollection ExectionLogs - => GetCollectionOrCreate("ExecutionLogs"); - public IMongoCollection LlmCompletionLogs => GetCollectionOrCreate("LlmCompletionLogs"); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index 7d45e972..8b6dded6 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -56,13 +56,11 @@ public partial class MongoRepository var filterConv = Builders.Filter.In(x => x.Id, conversationIds); var filterDialog = Builders.Filter.In(x => x.ConversationId, conversationIds); var filterSates = Builders.Filter.In(x => x.ConversationId, conversationIds); - var filterExeLog = Builders.Filter.In(x => x.ConversationId, conversationIds); var filterPromptLog = Builders.Filter.In(x => x.ConversationId, conversationIds); var filterContentLog = Builders.Filter.In(x => x.ConversationId, conversationIds); var filterStateLog = Builders.Filter.In(x => x.ConversationId, conversationIds); var conbTabItems = Builders.Filter.In(x => x.ConversationId, conversationIds); - var exeLogDeleted = _dc.ExectionLogs.DeleteMany(filterExeLog); var promptLogDeleted = _dc.LlmCompletionLogs.DeleteMany(filterPromptLog); var contentLogDeleted = _dc.ContentLogs.DeleteMany(filterContentLog); var stateLogDeleted = _dc.StateLogs.DeleteMany(filterStateLog); @@ -71,10 +69,8 @@ public partial class MongoRepository var cronDeleted = _dc.CrontabItems.DeleteMany(conbTabItems); var convDeleted = _dc.Conversations.DeleteMany(filterConv); - return convDeleted.DeletedCount > 0 || dialogDeleted.DeletedCount > 0 || statesDeleted.DeletedCount > 0 - || exeLogDeleted.DeletedCount > 0 || promptLogDeleted.DeletedCount > 0 - || contentLogDeleted.DeletedCount > 0 || stateLogDeleted.DeletedCount > 0 - || convDeleted.DeletedCount > 0; + return convDeleted.DeletedCount > 0 || dialogDeleted.DeletedCount > 0 || statesDeleted.DeletedCount > 0 || promptLogDeleted.DeletedCount > 0 + || contentLogDeleted.DeletedCount > 0 || stateLogDeleted.DeletedCount > 0 || convDeleted.DeletedCount > 0; } [SideCar] diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs index 2316fdab..769c943f 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs @@ -4,32 +4,6 @@ namespace BotSharp.Plugin.MongoStorage.Repository; public partial class MongoRepository { - #region Execution Log - public void AddExecutionLogs(string conversationId, List logs) - { - if (string.IsNullOrEmpty(conversationId) || logs.IsNullOrEmpty()) return; - - var filter = Builders.Filter.Eq(x => x.ConversationId, conversationId); - var update = Builders.Update - .SetOnInsert(x => x.Id, Guid.NewGuid().ToString()) - .PushEach(x => x.Logs, logs); - - _dc.ExectionLogs.UpdateOne(filter, update, _options); - } - - public List GetExecutionLogs(string conversationId) - { - List logs = []; - if (string.IsNullOrEmpty(conversationId)) return logs; - - var filter = Builders.Filter.Eq(x => x.ConversationId, conversationId); - var logCollection = _dc.ExectionLogs.Find(filter).FirstOrDefault(); - - logs = logCollection?.Logs ?? []; - return logs; - } - #endregion - #region LLM Completion Log public void SaveLlmCompletionLog(LlmCompletionLog log) { From 6e9237ca4bf8fce98180c1bddd44b95c477933ca Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 20 Feb 2025 12:17:21 -0600 Subject: [PATCH 11/13] refine llm completion log --- .../Loggers/Models/LlmCompletionLog.cs | 2 +- .../Hooks/CommonContentGeneratingHook.cs | 2 +- .../Collections/LlmCompletionLogDocument.cs | 6 +++++- .../Models/PromptLogMongoElement.cs | 11 ----------- .../Repository/MongoRepository.Log.cs | 14 +++++--------- 5 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 src/Plugins/BotSharp.Plugin.MongoStorage/Models/PromptLogMongoElement.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/LlmCompletionLog.cs b/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/LlmCompletionLog.cs index 02c5b312..5082387c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/LlmCompletionLog.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Loggers/Models/LlmCompletionLog.cs @@ -7,5 +7,5 @@ public class LlmCompletionLog public string AgentId { get; set; } = string.Empty; public string Prompt { get; set; } = string.Empty; public string? Response { get; set; } - public DateTime CreateDateTime { get; set; } = DateTime.UtcNow; + public DateTime CreatedTime { get; set; } = DateTime.UtcNow; } diff --git a/src/Infrastructure/BotSharp.Logger/Hooks/CommonContentGeneratingHook.cs b/src/Infrastructure/BotSharp.Logger/Hooks/CommonContentGeneratingHook.cs index d0c9c6e1..25f08c22 100644 --- a/src/Infrastructure/BotSharp.Logger/Hooks/CommonContentGeneratingHook.cs +++ b/src/Infrastructure/BotSharp.Logger/Hooks/CommonContentGeneratingHook.cs @@ -30,7 +30,7 @@ public class CommonContentGeneratingHook : IContentGeneratingHook AgentId = message.CurrentAgentId, Prompt = tokenStats.Prompt, Response = message.Content, - CreateDateTime = DateTime.UtcNow + CreatedTime = DateTime.UtcNow }; db.SaveLlmCompletionLog(completionLog); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/LlmCompletionLogDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/LlmCompletionLogDocument.cs index 077fddc3..f26ac9fb 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/LlmCompletionLogDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/LlmCompletionLogDocument.cs @@ -3,5 +3,9 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class LlmCompletionLogDocument : MongoBase { public string ConversationId { get; set; } = default!; - public List Logs { get; set; } = []; + public string MessageId { get; set; } = default!; + public string AgentId { get; set; } = default!; + public string Prompt { get; set; } = default!; + public string? Response { get; set; } + public DateTime CreatedTime { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/PromptLogMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/PromptLogMongoElement.cs deleted file mode 100644 index b8dabaa5..00000000 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/PromptLogMongoElement.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace BotSharp.Plugin.MongoStorage.Models; - -[BsonIgnoreExtraElements(Inherited = true)] -public class PromptLogMongoElement -{ - public string MessageId { get; set; } = default!; - public string AgentId { get; set; } = default!; - public string Prompt { get; set; } = default!; - public string? Response { get; set; } - public DateTime CreateDateTime { get; set; } -} diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs index 769c943f..e4c64527 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs @@ -12,21 +12,17 @@ public partial class MongoRepository var conversationId = log.ConversationId.IfNullOrEmptyAs(Guid.NewGuid().ToString()); var messageId = log.MessageId.IfNullOrEmptyAs(Guid.NewGuid().ToString()); - var logElement = new PromptLogMongoElement + var data = new LlmCompletionLogDocument { + Id = Guid.NewGuid().ToString(), + ConversationId = conversationId, MessageId = messageId, AgentId = log.AgentId, Prompt = log.Prompt, Response = log.Response, - CreateDateTime = log.CreateDateTime + CreatedTime = log.CreatedTime }; - - var filter = Builders.Filter.Eq(x => x.ConversationId, conversationId); - var update = Builders.Update - .SetOnInsert(x => x.Id, Guid.NewGuid().ToString()) - .Push(x => x.Logs, logElement); - - _dc.LlmCompletionLogs.UpdateOne(filter, update, _options); + _dc.LlmCompletionLogs.InsertOne(data); } #endregion From 37aa85af369b326eb53c1a47d0f0d6640e9fc565 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 20 Feb 2025 22:52:02 -0600 Subject: [PATCH 12/13] refine chat instruction --- .../BotSharp.Core/BotSharp.Core.csproj | 2 +- .../Instructs/InsturctionPlugin.cs | 23 +++++++++++++++++++ .../{ => Services}/InstructService.Execute.cs | 0 .../InstructService.Instruct.cs | 0 .../{ => Services}/InstructService.cs | 0 .../Controllers/InstructModeController.cs | 13 ++++++----- .../Instructs/InstructMessageModel.cs | 7 ++++++ 7 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Core/Instructs/InsturctionPlugin.cs rename src/Infrastructure/BotSharp.Core/Instructs/{ => Services}/InstructService.Execute.cs (100%) rename src/Infrastructure/BotSharp.Core/Instructs/{ => Services}/InstructService.Instruct.cs (100%) rename src/Infrastructure/BotSharp.Core/Instructs/{ => Services}/InstructService.cs (100%) diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index ecc736f2..6bc7596c 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -1,4 +1,4 @@ - + $(TargetFramework) diff --git a/src/Infrastructure/BotSharp.Core/Instructs/InsturctionPlugin.cs b/src/Infrastructure/BotSharp.Core/Instructs/InsturctionPlugin.cs new file mode 100644 index 00000000..7b4596ff --- /dev/null +++ b/src/Infrastructure/BotSharp.Core/Instructs/InsturctionPlugin.cs @@ -0,0 +1,23 @@ +using BotSharp.Abstraction.Plugins.Models; +using Microsoft.Extensions.Configuration; + +namespace BotSharp.Core.Instructs; + +public class InsturctionPlugin : IBotSharpPlugin +{ + public string Id => "8189e133-819c-4505-9f82-84f793bc1be0"; + public string Name => "Instruction"; + public string Description => "Handle agent instruction request"; + + public void RegisterDI(IServiceCollection services, IConfiguration config) + { + + } + + public bool AttachMenu(List menu) + { + var section = menu.First(x => x.Label == "Apps"); + menu.Add(new PluginMenuDef("Instruction", link: "page/instruction", icon: "bx bx-book-content", weight: section.Weight + 5)); + return true; + } +} diff --git a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.Execute.cs b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs similarity index 100% rename from src/Infrastructure/BotSharp.Core/Instructs/InstructService.Execute.cs rename to src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs diff --git a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.Instruct.cs b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs similarity index 100% rename from src/Infrastructure/BotSharp.Core/Instructs/InstructService.Instruct.cs rename to src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs diff --git a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.cs similarity index 100% rename from src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs rename to src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.cs diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs index 433d691a..dbce9598 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs @@ -44,7 +44,7 @@ public class InstructModeController : ControllerBase } [HttpPost("/instruct/text-completion")] - public async Task TextCompletion([FromBody] IncomingMessageModel input) + public async Task TextCompletion([FromBody] IncomingInstructRequest input) { var state = _services.GetRequiredService(); input.States.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External)); @@ -53,12 +53,12 @@ public class InstructModeController : ControllerBase .SetState("model_id", input.ModelId, source: StateSource.External); var textCompletion = CompletionProvider.GetTextCompletion(_services); - return await textCompletion.GetCompletion(input.Text, Guid.Empty.ToString(), Guid.NewGuid().ToString()); + return await textCompletion.GetCompletion(input.Text, input.AgentId ?? Guid.Empty.ToString(), Guid.NewGuid().ToString()); } #region Chat [HttpPost("/instruct/chat-completion")] - public async Task ChatCompletion([FromBody] IncomingMessageModel input) + public async Task ChatCompletion([FromBody] IncomingInstructRequest input) { var state = _services.GetRequiredService(); input.States.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External)); @@ -66,10 +66,11 @@ public class InstructModeController : ControllerBase .SetState("model", input.Model, source: StateSource.External) .SetState("model_id", input.ModelId, source: StateSource.External); - var textCompletion = CompletionProvider.GetChatCompletion(_services); - var message = await textCompletion.GetChatCompletions(new Agent() + var completion = CompletionProvider.GetChatCompletion(_services); + var message = await completion.GetChatCompletions(new Agent() { - Id = Guid.Empty.ToString(), + Id = input.AgentId ?? Guid.Empty.ToString(), + Instruction = input.Instruction }, new List { new RoleDialogModel(AgentRole.User, input.Text) diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/InstructMessageModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/InstructMessageModel.cs index b736330f..3b0303fd 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/InstructMessageModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Instructs/InstructMessageModel.cs @@ -9,3 +9,10 @@ public class InstructMessageModel : IncomingMessageModel public override string Channel { get; set; } = ConversationChannel.OpenAPI; public string? Template { get; set; } } + + +public class IncomingInstructRequest : IncomingMessageModel +{ + public string? AgentId { get; set; } + public string? Instruction { get; set; } +} \ No newline at end of file From ed8b3aa717580330ae29d3a22b6c2547c11d0db3 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 21 Feb 2025 11:37:36 -0600 Subject: [PATCH 13/13] add llm configs --- .../MLTasks/ILlmProviderService.cs | 1 + .../MLTasks/Settings/LlmConfigOptions.cs | 9 ++++ .../MLTasks/Settings/LlmProviderSetting.cs | 6 +-- .../Infrastructures/LlmProviderService.cs | 46 +++++++++++++++++++ .../Controllers/LlmProviderController.cs | 7 +++ 5 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmConfigOptions.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/MLTasks/ILlmProviderService.cs b/src/Infrastructure/BotSharp.Abstraction/MLTasks/ILlmProviderService.cs index 201f1342..2a06ece6 100644 --- a/src/Infrastructure/BotSharp.Abstraction/MLTasks/ILlmProviderService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/MLTasks/ILlmProviderService.cs @@ -8,4 +8,5 @@ public interface ILlmProviderService List GetProviders(); LlmModelSetting GetProviderModel(string provider, string id, bool? multiModal = null, bool? realTime = false, bool imageGenerate = false); List GetProviderModels(string provider); + List GetLlmConfigs(LlmConfigOptions? options = null); } diff --git a/src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmConfigOptions.cs b/src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmConfigOptions.cs new file mode 100644 index 00000000..81668059 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmConfigOptions.cs @@ -0,0 +1,9 @@ +namespace BotSharp.Abstraction.MLTasks.Settings; + +public class LlmConfigOptions +{ + public LlmModelType? Type { get; set; } + public bool? MultiModal { get; set; } + public bool? RealTime { get; set; } + public bool? ImageGeneration { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmProviderSetting.cs b/src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmProviderSetting.cs index b3a9d28e..705a9129 100644 --- a/src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmProviderSetting.cs +++ b/src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmProviderSetting.cs @@ -2,11 +2,9 @@ namespace BotSharp.Abstraction.MLTasks.Settings; public class LlmProviderSetting { - public string Provider { get; set; } - = "azure-openai"; + public string Provider { get; set; } = "azure-openai"; - public List Models { get; set; } - = new List(); + public List Models { get; set; } = []; public override string ToString() { diff --git a/src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderService.cs b/src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderService.cs index e1934f60..6d62c227 100644 --- a/src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderService.cs +++ b/src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderService.cs @@ -103,4 +103,50 @@ public class LlmProviderService : ILlmProviderService return modelSetting; } + + + public List GetLlmConfigs(LlmConfigOptions? options = null) + { + var settingService = _services.GetRequiredService(); + var providers = settingService.Bind>($"LlmProviders"); + var configs = new List(); + + if (providers.IsNullOrEmpty()) return configs; + + if (options == null) return providers ?? []; + + foreach (var provider in providers) + { + var models = provider.Models ?? []; + if (options.Type.HasValue) + { + models = models.Where(x => x.Type == options.Type.Value).ToList(); + } + + if (options.MultiModal.HasValue) + { + models = models.Where(x => x.MultiModal == options.MultiModal.Value).ToList(); + } + + if (options.ImageGeneration.HasValue) + { + models = models.Where(x => x.ImageGeneration == options.ImageGeneration.Value).ToList(); + } + + if (options.RealTime.HasValue) + { + models = models.Where(x => x.RealTime == options.RealTime.Value).ToList(); + } + + if (models.IsNullOrEmpty()) + { + continue; + } + + provider.Models = models; + configs.Add(provider); + } + + return configs; + } } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/LlmProviderController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/LlmProviderController.cs index 02282b85..6b87bec2 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/LlmProviderController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/LlmProviderController.cs @@ -27,4 +27,11 @@ public class LlmProviderController : ControllerBase var list = _llmProvider.GetProviderModels(provider); return list.Where(x => x.Type == LlmModelType.Chat); } + + [HttpGet("/llm-configs")] + public List GetLlmConfigs([FromQuery] LlmConfigOptions options) + { + var configs = _llmProvider.GetLlmConfigs(options); + return configs; + } }