From 16300b9a1d855c833d10aceec436d56a31e7e26b Mon Sep 17 00:00:00 2001 From: Visagan Guruparan <103048@smsassist.com> Date: Thu, 10 Jul 2025 14:22:54 -0500 Subject: [PATCH 1/5] Add hook to handle locate element for PlayWright --- .../BotSharp.Abstraction/Browsing/IWebDriverHook.cs | 1 + .../PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs | 5 +++++ .../UtilFunctions/UtilWebLocateElementFn.cs | 1 + 3 files changed, 7 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebDriverHook.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebDriverHook.cs index ce5d03b6..346f2f23 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebDriverHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebDriverHook.cs @@ -5,4 +5,5 @@ namespace BotSharp.Abstraction.Browsing; public interface IWebDriverHook { Task> GetUploadFiles(MessageInfo message); + Task OnLocateElement(MessageInfo message, string content); } diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs index e70d7f27..b4b2eb2f 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs @@ -114,6 +114,11 @@ public partial class PlaywrightWebDriver // fix if html has & result.Body = HttpUtility.HtmlDecode(html); result.IsSuccess = true; + var hooks = _services.GetServices(); + foreach (var hook in hooks) + { + await hook.OnLocateElement(message, result.Body); + } } else if (count > 1) { diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebLocateElementFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebLocateElementFn.cs index d30048c8..e2e3d34f 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebLocateElementFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebLocateElementFn.cs @@ -30,6 +30,7 @@ public class UtilWebLocateElementFn : IFunctionCallback MessageId = message.MessageId, ContextId = webDriverService.GetMessageContext(message) }; + browser.SetServiceProvider(_services); var result = await browser.LocateElement(msg, locatorArgs); message.Content = $"Locating element {(result.IsSuccess ? "success" : "failed")}. "; From b9c7f63249ea81e2f6b997dbfd3839c0b13032d3 Mon Sep 17 00:00:00 2001 From: Visagan Guruparan <103048@smsassist.com> Date: Thu, 10 Jul 2025 15:55:55 -0500 Subject: [PATCH 2/5] Update contextId for close browser utility. --- .../UtilFunctions/UtilWebCloseBrowserFn.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebCloseBrowserFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebCloseBrowserFn.cs index ff898232..6c7bfefa 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebCloseBrowserFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebCloseBrowserFn.cs @@ -28,7 +28,7 @@ public class UtilWebCloseBrowserFn : IFunctionCallback ContextId = webDriverService.GetMessageContext(message) }; - await browser.CloseBrowser(message.CurrentAgentId); + await browser.CloseBrowser(msg.ContextId); message.Content = $"Browser closed."; From c80e8ca7a04daf1b7dce003bcd4c29fc45cdb3e3 Mon Sep 17 00:00:00 2001 From: "guoqiang.yu" Date: Fri, 11 Jul 2025 12:59:09 +0800 Subject: [PATCH 3/5] fix #1097 SqlDriver: Database type mssql is not supported --- .../BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs | 2 +- .../BotSharp.Plugin.SqlDriver/Functions/GetTableDefinitionFn.cs | 2 +- src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlSelect.cs | 2 +- .../BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs | 2 +- .../UtilFunctions/GetTableDefinitionFn.cs | 2 +- .../BotSharp.Plugin.SqlDriver/UtilFunctions/SqlSelect.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs index f571fa6c..c2f0682b 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/ExecuteQueryFn.cs @@ -33,7 +33,7 @@ public class ExecuteQueryFn : IFunctionCallback var results = dbType.ToLower() switch { "mysql" => RunQueryInMySql(args.SqlStatements), - "sqlserver" => RunQueryInSqlServer(args.SqlStatements), + "sqlserver" or "mssql" => RunQueryInSqlServer(args.SqlStatements), "redshift" => RunQueryInRedshift(args.SqlStatements), _ => throw new NotImplementedException($"Database type {dbType} is not supported.") }; diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/GetTableDefinitionFn.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/GetTableDefinitionFn.cs index 283620c9..25ef526a 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/GetTableDefinitionFn.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/GetTableDefinitionFn.cs @@ -37,7 +37,7 @@ public class GetTableDefinitionFn : IFunctionCallback var tableDdls = dbType switch { "mysql" => GetDdlFromMySql(tables), - "sqlserver" => GetDdlFromSqlServer(tables), + "sqlserver" or "mssql" => GetDdlFromSqlServer(tables), "redshift" => GetDdlFromRedshift(tables), _ => throw new NotImplementedException($"Database type {dbType} is not supported.") }; diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlSelect.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlSelect.cs index eb9253e4..3e693f80 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlSelect.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlSelect.cs @@ -32,7 +32,7 @@ public class SqlSelect : IFunctionCallback var result = dbType switch { "mysql" => RunQueryInMySql(args), - "sqlserver" => RunQueryInSqlServer(args), + "sqlserver" or "mssql" => RunQueryInSqlServer(args), "redshift" => RunQueryInRedshift(args), _ => throw new NotImplementedException($"Database type {dbType} is not supported.") }; diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs index 89b38f93..1489c4a8 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs @@ -34,7 +34,7 @@ public class SqlValidateFn : IFunctionCallback var validateSql = dbType.ToLower() switch { "mysql" => $"EXPLAIN\r\n{sql.Replace("SET ", "-- SET ", StringComparison.InvariantCultureIgnoreCase).Replace(";", "; EXPLAIN ").TrimEnd("EXPLAIN ".ToCharArray())}", - "sqlserver" => $"SET PARSEONLY ON;\r\n{sql}\r\nSET PARSEONLY OFF;", + "sqlserver" or "mssql" => $"SET PARSEONLY ON;\r\n{sql}\r\nSET PARSEONLY OFF;", "redshift" => $"explain\r\n{sql}", _ => throw new NotImplementedException($"Database type {dbType} is not supported.") }; diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/UtilFunctions/GetTableDefinitionFn.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/UtilFunctions/GetTableDefinitionFn.cs index 20f35572..43005c68 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/UtilFunctions/GetTableDefinitionFn.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/UtilFunctions/GetTableDefinitionFn.cs @@ -31,7 +31,7 @@ public class GetTableDefinitionFn : IFunctionCallback var tableDdls = dbType switch { "mysql" => GetDdlFromMySql(tables), - "sqlserver" => GetDdlFromSqlServer(tables), + "sqlserver" or "mssql" => GetDdlFromSqlServer(tables), "redshift" => GetDdlFromRedshift(tables,schema), _ => throw new NotImplementedException($"Database type {dbType} is not supported.") }; diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/UtilFunctions/SqlSelect.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/UtilFunctions/SqlSelect.cs index 1ae27ac7..72bef238 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/UtilFunctions/SqlSelect.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/UtilFunctions/SqlSelect.cs @@ -30,7 +30,7 @@ public class SqlSelect : IFunctionCallback var result = dbType switch { "mysql" => RunQueryInMySql(args), - "sqlserver" => RunQueryInSqlServer(args), + "sqlserver" or "mssql" => RunQueryInSqlServer(args), "redshift" => RunQueryInRedshift(args), _ => throw new NotImplementedException($"Database type {dbType} is not supported.") }; From 2ec304b83c41f10ada6af3b7378e25677c92092c Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 11 Jul 2025 10:15:09 -0500 Subject: [PATCH 4/5] refine chat stream request --- .../BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs | 11 +++++------ .../Models/Stream/ChatStreamRequest.cs | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/Plugins/BotSharp.Plugin.ChatHub/Models/Stream/ChatStreamRequest.cs diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs b/src/Plugins/BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs index 7079c642..138d5084 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs @@ -82,8 +82,8 @@ public class ChatStreamMiddleware var (eventType, data) = MapEvents(conn, receivedText); if (eventType == "start") { - var states = InitStates(data); - await ConnectToModel(hub, webSocket, states); + var request = InitRequest(data); + await ConnectToModel(hub, webSocket, request?.States); } else if (eventType == "media") { @@ -157,16 +157,15 @@ public class ChatStreamMiddleware }); } - private List InitStates(string data) + private ChatStreamRequest? InitRequest(string data) { try { - var states = JsonSerializer.Deserialize>(data, BotSharpOptions.defaultJsonOptions); - return states ?? []; + return JsonSerializer.Deserialize(data, BotSharpOptions.defaultJsonOptions); } catch { - return []; + return null; } } } diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Models/Stream/ChatStreamRequest.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Models/Stream/ChatStreamRequest.cs new file mode 100644 index 00000000..1a72d7dc --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Models/Stream/ChatStreamRequest.cs @@ -0,0 +1,10 @@ +using BotSharp.Abstraction.Models; +using System.Text.Json.Serialization; + +namespace BotSharp.Plugin.ChatHub.Models.Stream; + +public class ChatStreamRequest +{ + [JsonPropertyName("states")] + public List States { get; set; } = []; +} From 0d0d808d44e64a070b13fb4b7a5c3e2bfb0baae1 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 11 Jul 2025 11:34:43 -0500 Subject: [PATCH 5/5] add default result --- .../BotSharp.Abstraction/Browsing/IWebDriverHook.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebDriverHook.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebDriverHook.cs index 346f2f23..30a58bb4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebDriverHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/IWebDriverHook.cs @@ -4,6 +4,6 @@ namespace BotSharp.Abstraction.Browsing; public interface IWebDriverHook { - Task> GetUploadFiles(MessageInfo message); - Task OnLocateElement(MessageInfo message, string content); + Task> GetUploadFiles(MessageInfo message) => Task.FromResult(new List()); + Task OnLocateElement(MessageInfo message, string content) => Task.CompletedTask; }