From 9fd3ea98a4b592ab8372f3ee9d73b95b29ef0541 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 8 Apr 2024 13:50:06 -0500 Subject: [PATCH 01/17] IsPopup --- .../Models/RichContent/Template/GenericTemplateMessage.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs index c86bca59..6578b363 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/GenericTemplateMessage.cs @@ -19,6 +19,9 @@ public class GenericTemplateMessage : IRichMessage, ITemplateMessage [JsonPropertyName("is_horizontal")] public bool IsHorizontal { get; set; } + [JsonPropertyName("is_popup")] + public bool IsPopup { get; set; } + [JsonPropertyName("element_type")] public string ElementType => typeof(T).Name; } From d59c99c712c60b8f2d23e5635aea2cad7d0cbcf1 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Mon, 8 Apr 2024 18:06:50 -0500 Subject: [PATCH 02/17] add file editor --- .../BotSharp.Abstraction/Messaging/Enums/EditorTypeEnum.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/EditorTypeEnum.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/EditorTypeEnum.cs index f190e5e5..9516bb13 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/EditorTypeEnum.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Enums/EditorTypeEnum.cs @@ -12,6 +12,7 @@ public static class EditorTypeEnum public const string DateTimePicker = "datetime-picker"; public const string DateTimeRangePicker = "datetime-range-picker"; public const string Email = "email"; + public const string File = "file"; /// /// Regex, set the expression in editor_attributes From 63ad880b1c789ae6fe54e6f7ad5f51da0609d255 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Tue, 9 Apr 2024 07:37:30 -0500 Subject: [PATCH 03/17] Release v1.3.1 --- Directory.Build.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 56e1a108..99a8ba4c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,8 +2,8 @@ net8.0 10.0 - 1.2.1 - true + 1.3.1 + false false \ No newline at end of file From f6cf392267a6fb0cd2038ff7f6a3e9330b82c00e Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 9 Apr 2024 15:52:21 -0500 Subject: [PATCH 04/17] add visible property --- .../Agents/IAgentService.cs | 2 + .../Agents/Services/AgentService.Rendering.cs | 59 +++++++++++++++++++ .../Providers/ChatCompletionProvider.cs | 3 +- .../Providers/ChatCompletionProvider.cs | 2 +- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs index c8aee271..e67cd6b8 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs @@ -26,6 +26,8 @@ public interface IAgentService bool RenderFunction(Agent agent, FunctionDef def); + FunctionParametersDef? RenderFunctionProperty(Agent agent, FunctionDef def); + /// /// Get agent detail without trigger any hook. /// diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs index 9ce7a7a8..810e101a 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs @@ -1,5 +1,6 @@ using BotSharp.Abstraction.Loggers; using BotSharp.Abstraction.Templating; +using Newtonsoft.Json.Linq; namespace BotSharp.Core.Agents.Services; @@ -32,6 +33,64 @@ public partial class AgentService return true; } + public FunctionParametersDef? RenderFunctionProperty(Agent agent, FunctionDef def) + { + var parameterDef = def?.Parameters; + var propertyDef = parameterDef?.Properties; + if (propertyDef == null) return null; + + var visibleExpress = "visibility_expression"; + var root = propertyDef.RootElement; + var iterator = root.EnumerateObject(); + var list = new List(); + while (iterator.MoveNext()) + { + var prop = iterator.Current; + var name = prop.Name; + var node = prop.Value; + var matched = true; + if (node.TryGetProperty(visibleExpress, out var element)) + { + var expression = element.GetString(); + var render = _services.GetRequiredService(); + var result = render.Render(expression, new Dictionary + { + { "states", agent.TemplateDict } + }); + matched = result == "visible"; + } + + if (matched) + { + list.Add(name); + } + } + + var rootObject = JObject.Parse(root.GetRawText()); + var clonedRoot = rootObject.DeepClone() as JObject; + var required = parameterDef?.Required ?? new List(); + foreach (var property in rootObject.Properties()) + { + if (list.Contains(property.Name)) + { + var value = clonedRoot.GetValue(property.Name) as JObject; + if (value != null && value.ContainsKey(visibleExpress)) + { + value.Remove(visibleExpress); + } + } + else + { + clonedRoot.Remove(property.Name); + required.Remove(property.Name); + } + } + + parameterDef.Properties = JsonSerializer.Deserialize(clonedRoot.ToString()); + parameterDef.Required = required; + return parameterDef; ; + } + public string RenderedTemplate(Agent agent, string templateName) { // render liquid template diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs index e3f6afca..0e5cc0ab 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs @@ -221,11 +221,12 @@ public class ChatCompletionProvider : IChatCompletion { if (agentService.RenderFunction(agent, function)) { + var property = agentService.RenderFunctionProperty(agent, function); chatCompletionsOptions.Functions.Add(new FunctionDefinition { Name = function.Name, Description = function.Description, - Parameters = BinaryData.FromObjectAsJson(function.Parameters) + Parameters = BinaryData.FromObjectAsJson(property) }); } } diff --git a/src/Plugins/BotSharp.Plugin.SparkDesk/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.SparkDesk/Providers/ChatCompletionProvider.cs index 3423347e..7d529df1 100644 --- a/src/Plugins/BotSharp.Plugin.SparkDesk/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.SparkDesk/Providers/ChatCompletionProvider.cs @@ -222,7 +222,7 @@ public class ChatCompletionProvider : IChatCompletion return (prompt, messages.ToArray(), functions.ToArray()); } - private string GetPrompt(List messages,List functions) + private string GetPrompt(List messages, List functions) { var prompt = string.Empty; From ed729bf18dccd53581ec964b5de820742f6965b7 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 9 Apr 2024 16:00:53 -0500 Subject: [PATCH 05/17] minor change --- .../BotSharp.Core/Agents/Services/AgentService.Rendering.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs index 810e101a..a0b2f130 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs @@ -42,7 +42,7 @@ public partial class AgentService var visibleExpress = "visibility_expression"; var root = propertyDef.RootElement; var iterator = root.EnumerateObject(); - var list = new List(); + var visibleProps = new List(); while (iterator.MoveNext()) { var prop = iterator.Current; @@ -62,7 +62,7 @@ public partial class AgentService if (matched) { - list.Add(name); + visibleProps.Add(name); } } @@ -71,7 +71,7 @@ public partial class AgentService var required = parameterDef?.Required ?? new List(); foreach (var property in rootObject.Properties()) { - if (list.Contains(property.Name)) + if (visibleProps.Contains(property.Name)) { var value = clonedRoot.GetValue(property.Name) as JObject; if (value != null && value.ContainsKey(visibleExpress)) From 90c0ef014de8191972b9cd41ffe560404d318235 Mon Sep 17 00:00:00 2001 From: jli238 <40345639+jli238@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:17:55 -0500 Subject: [PATCH 06/17] Update args definition for router agent Update args definition for router agent, to provide a more stable args response output from agent. Tested solid on GPT Playground. --- .../01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/instruction.liquid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/instruction.liquid b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/instruction.liquid index 9caf041d..93960782 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/instruction.liquid +++ b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/instruction.liquid @@ -4,7 +4,7 @@ You're {{router.name}} ({{router.description}}). Follow these steps to handle us 3. Determine which agent is suitable to handle this conversation. 4. Re-think on whether the function you chose matches the reason. 5. For agent required arguments, think carefully, leave it as blank object if user doesn't provide specific arguments. -6. Please do not make up any parameters when there is no exact value provided, you must set the parameter value as null. +6. You must include all required args when using selected FUNCTIONS, but you must not make up any parameters when there is no exact value provided, those parameters must set value as null if not declared. 7. Response must be in JSON format. {% if routing_requirements and routing_requirements != empty %} From 45fd30aaf84a64c1806bbffd872489419b79531f Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 10 Apr 2024 12:45:35 -0500 Subject: [PATCH 07/17] add readonly load state --- .../Conversations/IConversationStateService.cs | 2 +- .../Conversations/Services/ConversationStateService.cs | 6 +++--- .../BotSharp.OpenAPI/Controllers/ConversationController.cs | 2 +- .../Repository/MongoRepository.Conversation.cs | 5 +---- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs index 655e657a..fe3f9193 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs @@ -9,7 +9,7 @@ namespace BotSharp.Abstraction.Conversations; public interface IConversationStateService { string GetConversationId(); - Dictionary Load(string conversationId); + Dictionary Load(string conversationId, bool isReadOnly = false); string GetState(string name, string defaultValue = ""); bool ContainsState(string name); Dictionary GetStates(); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 36b2ddeb..7a08b10b 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -117,9 +117,9 @@ public class ConversationStateService : IConversationStateService, IDisposable return this; } - public Dictionary Load(string conversationId) + public Dictionary Load(string conversationId, bool isReadOnly = false) { - _conversationId = conversationId; + _conversationId = !isReadOnly ? conversationId : null; var routingCtx = _services.GetRequiredService(); var curMsgId = routingCtx.MessageId; @@ -320,7 +320,7 @@ public class ConversationStateService : IConversationStateService, IDisposable public void Dispose() { - Save(); + } public bool ContainsState(string name) diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index e01a0f46..8bf3b757 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -125,7 +125,7 @@ public class ConversationController : ControllerBase var result = ConversationViewModel.FromSession(conversations.Items.First()); var state = _services.GetRequiredService(); - result.States = state.Load(conversationId); + result.States = state.Load(conversationId, isReadOnly: true); var user = await userService.GetUser(result.User.Id); result.User = UserViewModel.FromUser(user); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index ac5a47d5..ed15803e 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -191,14 +191,11 @@ public partial class MongoRepository { if (string.IsNullOrEmpty(conversationId) || states == null) return; - var filterConv = Builders.Filter.Eq(x => x.Id, conversationId); var filterStates = Builders.Filter.Eq(x => x.ConversationId, conversationId); var saveStates = states.Select(x => StateMongoElement.ToMongoElement(x)).ToList(); var updateStates = Builders.Update.Set(x => x.States, saveStates); - var updateConv = Builders.Update.Set(x => x.UpdatedTime, DateTime.UtcNow); _dc.ConversationStates.UpdateOne(filterStates, updateStates); - _dc.Conversations.UpdateOne(filterConv, updateConv); } public void UpdateConversationStatus(string conversationId, string status) @@ -391,7 +388,7 @@ public partial class MongoRepository { var skip = (page - 1) * batchSize; var candidates = _dc.Conversations.AsQueryable() - .Where(x => (x.DialogCount <= messageLimit) && x.UpdatedTime <= utcNow.AddHours(-bufferHours)) + .Where(x => x.DialogCount <= messageLimit && x.UpdatedTime <= utcNow.AddHours(-bufferHours)) .Skip(skip) .Take(batchSize) .Select(x => x.Id) From cb812171e657596d9702027f4fdd3eea160da305 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 10 Apr 2024 12:47:51 -0500 Subject: [PATCH 08/17] revert code --- .../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 7a08b10b..de54dbb9 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -320,7 +320,7 @@ public class ConversationStateService : IConversationStateService, IDisposable public void Dispose() { - + Save(); } public bool ContainsState(string name) From 84220a8a71bf9509f563bad21a1954074d1afde6 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 10 Apr 2024 12:49:12 -0500 Subject: [PATCH 09/17] minor change --- .../Conversations/Services/ConversationStateService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index de54dbb9..e86f4610 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -124,8 +124,8 @@ public class ConversationStateService : IConversationStateService, IDisposable var routingCtx = _services.GetRequiredService(); var curMsgId = routingCtx.MessageId; - _historyStates = _db.GetConversationStates(_conversationId); - var dialogs = _db.GetConversationDialogs(_conversationId); + _historyStates = _db.GetConversationStates(conversationId); + var dialogs = _db.GetConversationDialogs(conversationId); var userDialogs = dialogs.Where(x => x.MetaData?.Role == AgentRole.User || x.MetaData?.Role == UserRole.Client) .OrderBy(x => x.MetaData?.CreateTime) .ToList(); @@ -177,7 +177,7 @@ public class ConversationStateService : IConversationStateService, IDisposable _logger.LogInformation($"[STATE] {key} : {data}"); } - _logger.LogInformation($"Loaded conversation states: {_conversationId}"); + _logger.LogInformation($"Loaded conversation states: {conversationId}"); var hooks = _services.GetServices(); foreach (var hook in hooks) { From 5564287871efe44226eef406898162d98b402c80 Mon Sep 17 00:00:00 2001 From: "C. Oceania" Date: Wed, 10 Apr 2024 15:02:19 -0500 Subject: [PATCH 10/17] Agent Name is contaminated. --- .../Routing/Planning/NaivePlanner.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Infrastructure/BotSharp.Core/Routing/Planning/NaivePlanner.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/NaivePlanner.cs index eefb88f7..aeed1a78 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Planning/NaivePlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/NaivePlanner.cs @@ -165,6 +165,22 @@ public class NaivePlanner : IPlaner malformed = true; } + // Agent Name is contaminated. + if (args.Function == "route_to_agent") + { + // Action agent name + if (!agents.Any(x => x.Name == args.AgentName)) + { + args.AgentName = agents.FirstOrDefault(x => args.AgentName.Contains(x.Name))?.Name ?? args.AgentName; + } + + // Goal agent name + if (!agents.Any(x => x.Name == args.OriginalAgent)) + { + args.OriginalAgent = agents.FirstOrDefault(x => args.OriginalAgent.Contains(x.Name))?.Name ?? args.OriginalAgent; + } + } + if (malformed) { _logger.LogWarning($"Captured LLM malformed response"); From 32a084289e46b21b0cbc4c9942c2b0435be122d6 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Thu, 11 Apr 2024 02:00:17 -0500 Subject: [PATCH 11/17] refine agent refresh --- .../Agents/IAgentService.cs | 4 +- .../Repositories/IBotSharpRepository.cs | 3 +- .../Services/AgentService.RefreshAgents.cs | 86 ++++++++++++------- .../Services/AgentService.UpdateAgent.cs | 27 ++++-- .../Repository/BotSharpDbContext.cs | 69 +++++---------- .../FileRepository/FileRepository.Agent.cs | 10 +-- .../FileRepository.AgentTask.cs | 16 ++-- .../Tasks/Services/AgentTaskService.cs | 2 +- .../Controllers/AgentController.cs | 8 +- .../Repository/MongoRepository.Agent.cs | 20 +++++ .../Repository/MongoRepository.AgentTask.cs | 12 ++- 11 files changed, 145 insertions(+), 112 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs index e67cd6b8..5ab249b8 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(); Task> GetAgents(AgentFilter filter); /// @@ -37,7 +37,7 @@ public interface IAgentService Task DeleteAgent(string id); Task UpdateAgent(Agent agent, AgentField updateField); - Task UpdateAgentFromFile(string id); + Task UpdateAgentFromFile(string id); string GetDataDir(); string GetAgentDataDir(string agentId); diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index e177b354..a1124975 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -32,6 +32,7 @@ public interface IBotSharpRepository void BulkInsertAgents(List agents); void BulkInsertUserAgents(List userAgents); bool DeleteAgents(); + bool DeleteAgent(string agentId); List GetAgentResponses(string agentId, string prefix, string intent); string GetAgentTemplate(string agentId, string templateName); #endregion @@ -42,7 +43,7 @@ public interface IBotSharpRepository void InsertAgentTask(AgentTask task); void BulkInsertAgentTasks(List tasks); void UpdateAgentTask(AgentTask task, AgentTaskField field); - bool DeleteAgentTask(string agentId, string taskId); + bool DeleteAgentTask(string agentId, List taskIds); bool DeleteAgentTasks(); #endregion diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs index 9c3b34f9..3077e929 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs @@ -1,55 +1,79 @@ -using BotSharp.Abstraction.Tasks.Models; using System.IO; namespace BotSharp.Core.Agents.Services; public partial class AgentService { - public async Task RefreshAgents() + public async Task RefreshAgents() { - var isAgentDeleted = _db.DeleteAgents(); - var isTaskDeleted = _db.DeleteAgentTasks(); - if (!isAgentDeleted) return; - var dbSettings = _services.GetRequiredService(); var agentDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dbSettings.FileRepository, _agentSettings.DataDir); + string refreshResult; + if (!Directory.Exists(agentDir)) + { + refreshResult = $"Cannot find the directory: {agentDir}"; + return refreshResult; + } + var user = _db.GetUserById(_user.Id); - var agents = new List(); - var userAgents = new List(); - var agentTasks = new List(); + var refreshedAgents = new List(); foreach (var dir in Directory.GetDirectories(agentDir)) { - var agentJson = File.ReadAllText(Path.Combine(dir, "agent.json")); - var agent = JsonSerializer.Deserialize(agentJson, _options); - if (agent == null) continue; + try + { + var agentJson = File.ReadAllText(Path.Combine(dir, "agent.json")); + var agent = JsonSerializer.Deserialize(agentJson, _options); + + if (agent == null) + { + _logger.LogError($"Cannot find agent in file directory: {dir}"); + continue; + } - var functions = FetchFunctionsFromFile(dir); - var instruction = FetchInstructionFromFile(dir); - var responses = FetchResponsesFromFile(dir); - var templates = FetchTemplatesFromFile(dir); - var samples = FetchSamplesFromFile(dir); - agent.SetInstruction(instruction) - .SetTemplates(templates) - .SetFunctions(functions) - .SetResponses(responses) - .SetSamples(samples); - agents.Add(agent); + var functions = FetchFunctionsFromFile(dir); + var instruction = FetchInstructionFromFile(dir); + var responses = FetchResponsesFromFile(dir); + var templates = FetchTemplatesFromFile(dir); + var samples = FetchSamplesFromFile(dir); + agent.SetInstruction(instruction) + .SetTemplates(templates) + .SetFunctions(functions) + .SetResponses(responses) + .SetSamples(samples); - var userAgent = BuildUserAgent(agent.Id, user.Id); - userAgents.Add(userAgent); + var userAgent = BuildUserAgent(agent.Id, user.Id); + var tasks = FetchTasksFromFile(dir); - var tasks = FetchTasksFromFile(dir); - agentTasks.AddRange(tasks); + var isAgentDeleted = _db.DeleteAgent(agent.Id); + if (isAgentDeleted) + { + _db.BulkInsertAgents(new List { agent }); + _db.BulkInsertUserAgents(new List { userAgent }); + _db.BulkInsertAgentTasks(tasks); + refreshedAgents.Add(agent.Name); + } + } + catch (Exception ex) + { + _logger.LogError($"Failed to migrate agent in file directory: {dir}\r\nError: {ex.Message}"); + } } - _db.BulkInsertAgents(agents); - _db.BulkInsertUserAgents(userAgents); - _db.BulkInsertAgentTasks(agentTasks); + if (!refreshedAgents.IsNullOrEmpty()) + { + Utilities.ClearCache(); + refreshResult = $"Agents are migrated! {string.Join("\r\n", refreshedAgents)}"; + } + else + { + refreshResult = "No agent gets refreshed!"; + } - Utilities.ClearCache(); + _logger.LogInformation(refreshResult); + return refreshResult; } } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index 4577af6d..5eca3f8c 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -39,11 +39,13 @@ public partial class AgentService await Task.CompletedTask; } - public async Task UpdateAgentFromFile(string id) + public async Task UpdateAgentFromFile(string id) { var agent = _db.GetAgent(id); - - if (agent == null) return; + if (agent == null) + { + return $"Cannot find agent ${id}"; + } var dbSettings = _services.GetRequiredService(); var agentSettings = _services.GetRequiredService(); @@ -53,7 +55,12 @@ public partial class AgentService var clonedAgent = Agent.Clone(agent); var foundAgent = FetchAgentFileById(agent.Id, filePath); - if (foundAgent != null) + if (foundAgent == null) + { + return $"Cannot find agent {agent.Name} in file directory: {filePath}"; + } + + try { clonedAgent.SetId(foundAgent.Id) .SetName(foundAgent.Name) @@ -71,15 +78,19 @@ public partial class AgentService .SetLlmConfig(foundAgent.LlmConfig); _db.UpdateAgent(clonedAgent, AgentField.All); - Utilities.ClearCache(); + return $"Agent {agent.Name} has been migrated!"; + } + catch (Exception ex) + { + return $"Failed to migrate agent {agent.Name} in file directory {filePath}.\r\nError: {ex.Message}"; } - - await Task.CompletedTask; } - private Agent FetchAgentFileById(string agentId, string filePath) + private Agent? FetchAgentFileById(string agentId, string filePath) { + if (!Directory.Exists(filePath)) return null; + foreach (var dir in Directory.GetDirectories(filePath)) { var agentJson = File.ReadAllText(Path.Combine(dir, "agent.json")); diff --git a/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs b/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs index d1361d02..0605c525 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs @@ -73,86 +73,57 @@ public class BotSharpDbContext : Database, IBotSharpRepository #region Agent public Agent GetAgent(string agentId) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public List GetAgents(AgentFilter filter) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public List GetAgentsByUser(string userId) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public void UpdateAgent(Agent agent, AgentField field) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public string GetAgentTemplate(string agentId, string templateName) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public List GetAgentResponses(string agentId, string prefix, string intent) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public void BulkInsertAgents(List agents) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public void BulkInsertUserAgents(List userAgents) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public bool DeleteAgents() - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); + + public bool DeleteAgent(string agentId) + => throw new NotImplementedException(); #endregion #region Agent Task public PagedItems GetAgentTasks(AgentTaskFilter filter) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public AgentTask? GetAgentTask(string agentId, string taskId) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public void InsertAgentTask(AgentTask task) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public void BulkInsertAgentTasks(List tasks) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); public void UpdateAgentTask(AgentTask task, AgentTaskField field) - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); - public bool DeleteAgentTask(string agentId, string taskId) - { - throw new NotImplementedException(); - } + public bool DeleteAgentTask(string agentId, List taskIds) + => throw new NotImplementedException(); public bool DeleteAgentTasks() - { - throw new NotImplementedException(); - } + => throw new NotImplementedException(); #endregion #region Conversation diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index 1fbca99c..20f8bcdd 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -1,9 +1,4 @@ -using BotSharp.Abstraction.Agents.Models; -using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Repositories.Filters; using BotSharp.Abstraction.Routing.Models; -using BotSharp.Abstraction.Tasks.Models; -using Microsoft.Extensions.Logging; using System.IO; namespace BotSharp.Core.Repository @@ -419,5 +414,10 @@ namespace BotSharp.Core.Repository { return false; } + + public bool DeleteAgent(string agentId) + { + return false; + } } } diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs index 73a8e3ed..df80bc8b 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs @@ -1,7 +1,5 @@ -using BotSharp.Abstraction.Repositories.Filters; using BotSharp.Abstraction.Tasks.Models; using System.IO; -using System.Threading.Tasks; namespace BotSharp.Core.Repository; @@ -192,18 +190,22 @@ public partial class FileRepository File.WriteAllText(taskFile, fileContent); } - public bool DeleteAgentTask(string agentId, string taskId) + public bool DeleteAgentTask(string agentId, List taskIds) { var agentDir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId); - if (!Directory.Exists(agentDir)) return false; + if (!Directory.Exists(agentDir) || taskIds.IsNullOrEmpty()) return false; var taskDir = Path.Combine(agentDir, "tasks"); if (!Directory.Exists(taskDir)) return false; - var taskFile = FindTaskFileById(taskDir, taskId); - if (string.IsNullOrWhiteSpace(taskFile)) return false; + foreach (var taskId in taskIds) + { + var taskFile = FindTaskFileById(taskDir, taskId); + if (string.IsNullOrWhiteSpace(taskFile)) return false; - File.Delete(taskFile); + File.Delete(taskFile); + } + return true; } diff --git a/src/Infrastructure/BotSharp.Core/Tasks/Services/AgentTaskService.cs b/src/Infrastructure/BotSharp.Core/Tasks/Services/AgentTaskService.cs index 1e7cdfdf..13ffc646 100644 --- a/src/Infrastructure/BotSharp.Core/Tasks/Services/AgentTaskService.cs +++ b/src/Infrastructure/BotSharp.Core/Tasks/Services/AgentTaskService.cs @@ -72,7 +72,7 @@ public class AgentTaskService : IAgentTaskService public async Task DeleteTask(string agentId, string taskId) { var db = _services.GetRequiredService(); - var isDeleted = db.DeleteAgentTask(agentId, taskId); + var isDeleted = db.DeleteAgentTask(agentId, new List { taskId }); return await Task.FromResult(isDeleted); } } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 5d7f7b56..77f73061 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -84,15 +84,15 @@ public class AgentController : ControllerBase } [HttpPost("/refresh-agents")] - public async Task RefreshAgents() + public async Task RefreshAgents() { - await _agentService.RefreshAgents(); + return await _agentService.RefreshAgents(); } [HttpPut("/agent/file/{agentId}")] - public async Task UpdateAgentFromFile([FromRoute] string agentId) + public async Task UpdateAgentFromFile([FromRoute] string agentId) { - await _agentService.UpdateAgentFromFile(agentId); + return await _agentService.UpdateAgentFromFile(agentId); } [HttpPut("/agent/{agentId}")] diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index 3272930b..07d30984 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -398,7 +398,27 @@ public partial class MongoRepository { return false; } + } + public bool DeleteAgent(string agentId) + { + try + { + if (string.IsNullOrEmpty(agentId)) return false; + + var agentFilter = Builders.Filter.Eq(x => x.Id, agentId); + var agentUserFilter = Builders.Filter.Eq(x => x.AgentId, agentId); + var agentTaskFilter = Builders.Filter.Eq(x => x.AgentId, agentId); + + _dc.Agents.DeleteOne(agentFilter); + _dc.UserAgents.DeleteMany(agentUserFilter); + _dc.AgentTasks.DeleteMany(agentTaskFilter); + return true; + } + catch + { + return false; + } } private Agent TransformAgentDocument(AgentDocument? agentDoc) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs index 125f3cd8..a3df61da 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentTask.cs @@ -155,12 +155,16 @@ public partial class MongoRepository _dc.AgentTasks.ReplaceOne(filter, taskDoc); } - public bool DeleteAgentTask(string agentId, string taskId) + public bool DeleteAgentTask(string agentId, List taskIds) { - if (string.IsNullOrEmpty(taskId)) return false; + if (taskIds.IsNullOrEmpty()) return false; - var filter = Builders.Filter.Eq(x => x.Id, taskId); - var taskDeleted = _dc.AgentTasks.DeleteOne(filter); + var builder = Builders.Filter; + var filters = new List> + { + builder.In(x => x.Id, taskIds) + }; + var taskDeleted = _dc.AgentTasks.DeleteMany(builder.And(filters)); return taskDeleted.DeletedCount > 0; } From e4e3ee56682af77ace0f0bd11c2479bee966d401 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Thu, 11 Apr 2024 02:04:54 -0500 Subject: [PATCH 12/17] minor change --- .../Repository/FileRepository/FileRepository.AgentTask.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs index df80bc8b..d542b28b 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentTask.cs @@ -198,15 +198,17 @@ public partial class FileRepository var taskDir = Path.Combine(agentDir, "tasks"); if (!Directory.Exists(taskDir)) return false; + var deletedTasks = new List(); foreach (var taskId in taskIds) { var taskFile = FindTaskFileById(taskDir, taskId); - if (string.IsNullOrWhiteSpace(taskFile)) return false; + if (string.IsNullOrWhiteSpace(taskFile)) continue; File.Delete(taskFile); + deletedTasks.Add(taskId); } - return true; + return deletedTasks.Any(); } public bool DeleteAgentTasks() From 2af4102b65ebff7ef0e80faa2172277bbde018a7 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 11 Apr 2024 10:19:57 -0500 Subject: [PATCH 13/17] add log in agent refresh --- .../Services/AgentService.RefreshAgents.cs | 4 +++- .../Services/AgentService.UpdateAgent.cs | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs index 3077e929..356707a8 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs @@ -51,10 +51,12 @@ public partial class AgentService var isAgentDeleted = _db.DeleteAgent(agent.Id); if (isAgentDeleted) { + await Task.Delay(100); _db.BulkInsertAgents(new List { agent }); _db.BulkInsertUserAgents(new List { userAgent }); _db.BulkInsertAgentTasks(tasks); refreshedAgents.Add(agent.Name); + _logger.LogInformation($"Agent {agent.Name} has been migrated."); } } catch (Exception ex) @@ -66,7 +68,7 @@ public partial class AgentService if (!refreshedAgents.IsNullOrEmpty()) { Utilities.ClearCache(); - refreshResult = $"Agents are migrated! {string.Join("\r\n", refreshedAgents)}"; + refreshResult = $"Agents are migrated!\r\n{string.Join("\r\n", refreshedAgents)}"; } else { diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index 5eca3f8c..747bd11c 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -41,10 +41,13 @@ public partial class AgentService public async Task UpdateAgentFromFile(string id) { + string updateResult; var agent = _db.GetAgent(id); if (agent == null) { - return $"Cannot find agent ${id}"; + updateResult = $"Cannot find agent ${id}"; + _logger.LogError(updateResult); + return updateResult; } var dbSettings = _services.GetRequiredService(); @@ -57,7 +60,9 @@ public partial class AgentService var foundAgent = FetchAgentFileById(agent.Id, filePath); if (foundAgent == null) { - return $"Cannot find agent {agent.Name} in file directory: {filePath}"; + updateResult = $"Cannot find agent {agent.Name} in file directory: {filePath}"; + _logger.LogError(updateResult); + return updateResult; } try @@ -79,11 +84,16 @@ public partial class AgentService _db.UpdateAgent(clonedAgent, AgentField.All); Utilities.ClearCache(); - return $"Agent {agent.Name} has been migrated!"; + + updateResult = $"Agent {agent.Name} has been migrated!"; + _logger.LogInformation(updateResult); + return updateResult; } catch (Exception ex) { - return $"Failed to migrate agent {agent.Name} in file directory {filePath}.\r\nError: {ex.Message}"; + updateResult = $"Failed to migrate agent {agent.Name} in file directory {filePath}.\r\nError: {ex.Message}"; + _logger.LogError(updateResult); + return updateResult; } } From 4aa5b92b926c9a1bad24e876d8c06fb6cb73c0ea Mon Sep 17 00:00:00 2001 From: sylviachency <33144082+sylviachency@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:41:48 -0500 Subject: [PATCH 14/17] Update HumanInterventionNeededHandler.cs address transfer to person issue --- .../Routing/Handlers/HumanInterventionNeededHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs index f0de3a9c..4aca2c3a 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs @@ -6,7 +6,7 @@ public class HumanInterventionNeededHandler : RoutingHandlerBase, IRoutingHandle { public string Name => "human_intervention_needed"; - public string Description => "Reach out to human being, customer service or customer representative."; + public string Description => "Reach out to human customer service."; public List Parameters => new List { From d7524162d8804bc8ef3e285f766b62d0b2602210 Mon Sep 17 00:00:00 2001 From: sylviachency <33144082+sylviachency@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:43:43 -0500 Subject: [PATCH 15/17] Update planner_prompt.naive.liquid address transfer to person issue --- .../templates/planner_prompt.naive.liquid | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.naive.liquid b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.naive.liquid index 2b42efaa..3a332350 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.naive.liquid +++ b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.naive.liquid @@ -10,5 +10,5 @@ Expected user goal agent is {{ expected_user_goal_agent }}. {%- else -%} User goal agent is inferred based on user initial request. {%- endif %} -If user wants to speak to customer service, use function human_intervention_needed. -If user wants to or is processing with a specific task that can be handled by agents, respond in appropriate output format defined to let proper agent to handle the task. \ No newline at end of file +If user wants to speak to human customer service, use function human_intervention_needed. +If user wants to or is processing with a specific task that can be handled by agents, respond in appropriate output format defined to let proper agent to handle the task. From e319992206bcf801b63b160f8c34e26954556db5 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 12 Apr 2024 10:00:55 -0500 Subject: [PATCH 16/17] add repository enum --- .../Repositories/Enums/RepositoryEnum.cs | 7 +++++++ .../Agents/Services/AgentService.RefreshAgents.cs | 10 +++++++++- .../Agents/Services/AgentService.UpdateAgent.cs | 13 +++++++++++-- .../BotSharp.Core/Repository/RepositoryPlugin.cs | 3 ++- .../MongoStoragePlugin.cs | 3 ++- 5 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Repositories/Enums/RepositoryEnum.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/Enums/RepositoryEnum.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/Enums/RepositoryEnum.cs new file mode 100644 index 00000000..f71845a5 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/Enums/RepositoryEnum.cs @@ -0,0 +1,7 @@ +namespace BotSharp.Abstraction.Repositories.Enums; + +public static class RepositoryEnum +{ + public const string FileRepository = nameof(FileRepository); + public const string MongoRepository = nameof(MongoRepository); +} diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs index 356707a8..0b61977e 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.RefreshAgents.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Repositories.Enums; using System.IO; namespace BotSharp.Core.Agents.Services; @@ -6,12 +7,19 @@ public partial class AgentService { public async Task RefreshAgents() { + string refreshResult; var dbSettings = _services.GetRequiredService(); + if (dbSettings.Default == RepositoryEnum.FileRepository) + { + refreshResult = $"Invalid database repository setting: {dbSettings.Default}"; + _logger.LogWarning(refreshResult); + return refreshResult; + } + var agentDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dbSettings.FileRepository, _agentSettings.DataDir); - string refreshResult; if (!Directory.Exists(agentDir)) { refreshResult = $"Cannot find the directory: {agentDir}"; diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index 747bd11c..0cce4209 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -1,6 +1,7 @@ using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Repositories; +using BotSharp.Abstraction.Repositories.Enums; using BotSharp.Abstraction.Routing.Models; using System.IO; @@ -42,6 +43,16 @@ public partial class AgentService public async Task UpdateAgentFromFile(string id) { string updateResult; + var dbSettings = _services.GetRequiredService(); + var agentSettings = _services.GetRequiredService(); + + if (dbSettings.Default == RepositoryEnum.FileRepository) + { + updateResult = $"Invalid database repository setting: {dbSettings.Default}"; + _logger.LogWarning(updateResult); + return updateResult; + } + var agent = _db.GetAgent(id); if (agent == null) { @@ -50,8 +61,6 @@ public partial class AgentService return updateResult; } - var dbSettings = _services.GetRequiredService(); - var agentSettings = _services.GetRequiredService(); var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dbSettings.FileRepository, agentSettings.DataDir); diff --git a/src/Infrastructure/BotSharp.Core/Repository/RepositoryPlugin.cs b/src/Infrastructure/BotSharp.Core/Repository/RepositoryPlugin.cs index ee397e38..3160597a 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/RepositoryPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/RepositoryPlugin.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Repositories.Enums; using BotSharp.Abstraction.Settings; using Microsoft.Extensions.Configuration; @@ -32,7 +33,7 @@ public class RepositoryPlugin : IBotSharpPlugin var myDatabaseSettings = new BotSharpDatabaseSettings(); config.Bind("Database", myDatabaseSettings); - if (myDatabaseSettings.Default == "FileRepository") + if (myDatabaseSettings.Default == RepositoryEnum.FileRepository) { services.AddScoped(); } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs index a7a574fa..8c4c43b9 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Plugins.Models; +using BotSharp.Abstraction.Repositories.Enums; using BotSharp.Plugin.MongoStorage.Repository; namespace BotSharp.Plugin.MongoStorage; @@ -18,7 +19,7 @@ public class MongoStoragePlugin : IBotSharpPlugin var dbSettings = new BotSharpDatabaseSettings(); config.Bind("Database", dbSettings); - if (dbSettings.Default == "MongoRepository") + if (dbSettings.Default == RepositoryEnum.MongoRepository) { services.AddScoped((IServiceProvider x) => { From 8df609ad2c176a8ed24a25f287e465bfd6772ae2 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 12 Apr 2024 11:37:38 -0500 Subject: [PATCH 17/17] add post action disclaimer --- .../Messaging/Models/RichContent/ElementButton.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementButton.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementButton.cs index bc13660a..294b1835 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementButton.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/ElementButton.cs @@ -20,4 +20,7 @@ public class ElementButton [JsonPropertyName("is_secondary")] public bool IsSecondary { get; set; } + + [JsonPropertyName("post_action_disclaimer")] + public string? PostActionDisclaimer { get; set; } }