From c59216659bb8e0af7b3e0ca322fc7ae35ef40413 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 21 Jul 2025 14:38:54 +0800 Subject: [PATCH 1/6] fix concurrent issue Operations that change non-concurrent collections must have exclusive access --- .../Agents/Services/AgentService.Rendering.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs index ffaffb47..9059dbf2 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs @@ -17,13 +17,14 @@ public partial class AgentService instructions.AddRange(secondaryInstructions); // update states + var renderDict = new Dictionary(agent.TemplateDict); foreach (var t in conv.States.GetStates()) { - agent.TemplateDict[t.Key] = t.Value; + renderDict[t.Key] = t.Value; } - agent.TemplateDict[TemplateRenderConstant.RENDER_AGENT] = agent; - var res = render.Render(string.Join("\r\n", instructions), agent.TemplateDict); + renderDict[TemplateRenderConstant.RENDER_AGENT] = agent; + var res = render.Render(string.Join("\r\n", instructions), renderDict); return res; } @@ -143,4 +144,4 @@ public partial class AgentService return result.IsEqualTo("visible"); } -} \ No newline at end of file +} From 3d236399184e552ba02dfcb1b0fe8f4b1cf2f3ed Mon Sep 17 00:00:00 2001 From: Yanan Wang Date: Sat, 26 Jul 2025 16:07:35 -0500 Subject: [PATCH 2/6] Fixes a bug where SetCurrentState mistakenly copied internal _curStates instead of the provided input state. --- .../Conversations/Services/ConversationStateService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index c8665179..ff61fde2 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -443,7 +443,7 @@ public class ConversationStateService : IConversationStateService public void SetCurrentState(ConversationState state) { - var values = _curStates.Values.ToList(); + var values = state.Values.ToList(); var copy = JsonSerializer.Deserialize>(JsonSerializer.Serialize(values)); _curStates = new ConversationState(copy ?? []); } From 181fb4ac003da412890a6949c7efd4ad89e17b67 Mon Sep 17 00:00:00 2001 From: Yanan Wang Date: Sun, 27 Jul 2025 14:04:29 -0500 Subject: [PATCH 3/6] Support element."); + } + + var selectedText = await locator.Locator("option:checked").InnerTextAsync(); + + if (!string.Equals(selectedText?.Trim(), action.Content.Trim(), StringComparison.OrdinalIgnoreCase)) + { + await locator.SelectOptionAsync(new SelectOptionValue + { + Label = action.Content + }); + + await page.WaitForLoadStateAsync(LoadState.NetworkIdle); + _logger.LogInformation($"Dropdown changed to: {action.Content}"); + } + else + { + _logger.LogInformation($"Dropdown already on correct option: {action.Content}"); + } + } } From 09945a0d21dc8358b5a87432da3a5a59b3703584 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Mon, 28 Jul 2025 19:19:13 -0500 Subject: [PATCH 4/6] add option agents --- .../BotSharp.Abstraction/Agents/IAgentService.cs | 2 +- .../Agents/Services/AgentService.RefreshAgents.cs | 12 +++++++++--- .../BotSharp.OpenAPI/Controllers/AgentController.cs | 4 ++-- .../ViewModels/Agents/Request/AgentMigrationModel.cs | 10 ++++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentMigrationModel.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs index b86e5916..87d8f415 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs @@ -10,7 +10,7 @@ namespace BotSharp.Abstraction.Agents; public interface IAgentService { Task CreateAgent(Agent agent); - Task RefreshAgents(); + Task RefreshAgents(IEnumerable? agentIds = null); Task> GetAgents(AgentFilter filter); Task> GetAgentOptions(List? agentIds = null, bool byName = false); Task> GetAgentUtilityOptions(); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs index 9603d1e5..506e00bb 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs @@ -6,7 +6,7 @@ namespace BotSharp.Core.Agents.Services; public partial class AgentService { - public async Task RefreshAgents() + public async Task RefreshAgents(IEnumerable? agentIds = null) { string refreshResult; var dbSettings = _services.GetRequiredService(); @@ -28,7 +28,13 @@ public partial class AgentService } var refreshedAgents = new List(); - foreach (var dir in Directory.GetDirectories(agentDir)) + var dirs = Directory.GetDirectories(agentDir); + if (!agentIds.IsNullOrEmpty()) + { + dirs = dirs.Where(x => agentIds.Contains(x.Split(Path.DirectorySeparatorChar).Last())).ToArray(); + } + + foreach (var dir in dirs) { try { @@ -78,7 +84,7 @@ public partial class AgentService } else { - refreshResult = "No agent gets refreshed!"; + refreshResult = "No agent gets migrated!"; } _logger.LogInformation(refreshResult); diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 2b2a72f6..4543fe19 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -111,9 +111,9 @@ public class AgentController : ControllerBase [BotSharpAuth] [HttpPost("/refresh-agents")] - public async Task RefreshAgents() + public async Task RefreshAgents([FromBody] AgentMigrationModel request) { - return await _agentService.RefreshAgents(); + return await _agentService.RefreshAgents(request?.AgentIds); } [HttpPut("/agent/file/{agentId}")] diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentMigrationModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentMigrationModel.cs new file mode 100644 index 00000000..19053c65 --- /dev/null +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentMigrationModel.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; + +namespace BotSharp.OpenAPI.ViewModels.Agents; + +public class AgentMigrationModel +{ + [JsonPropertyName("agent_ids")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IEnumerable? AgentIds { get; set; } +} From a3efa9c811158b2a64b4d5a0d5aeeb16156680fd Mon Sep 17 00:00:00 2001 From: Haiping Date: Thu, 31 Jul 2025 16:15:41 -0500 Subject: [PATCH 5/6] Update RoutingService.InvokeFunction.cs --- .../BotSharp.Core/Routing/RoutingService.InvokeFunction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs index 1001dede..20c691f8 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs @@ -64,7 +64,7 @@ public partial class RoutingService } catch (JsonException ex) { - _logger.LogError($"The input does not contain any JSON tokens:\r\n{message.Content}"); + _logger.LogError($"The input does not contain any JSON tokens:\r\n{message.Content}\r\n{ex.Message}"); message.StopCompletion = true; message.Content = ex.Message; } From 14a541562bc65e019d6d4541e008fc4422104a3d Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Fri, 1 Aug 2025 13:45:13 +0800 Subject: [PATCH 6/6] optimize ConvertToString --- .../BotSharp.Abstraction/Utilities/StringExtensions.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs index ea6bb8ec..0270133c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs @@ -122,6 +122,11 @@ public static class StringExtensions return s; } + if (value is DateTime d) + { + return d.ToString("o"); + } + if (value is JsonElement elem && elem.ValueKind == JsonValueKind.String) {