diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs index 1a6445e7..1544a985 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs @@ -4,6 +4,7 @@ using FunctionDef = BotSharp.Abstraction.Functions.Models.FunctionDef; using BotSharp.Abstraction.Users.Models; using BotSharp.Abstraction.Agents.Models; using MongoDB.Driver; +using BotSharp.Abstraction.Routing.Models; namespace BotSharp.Core.Repository; @@ -240,6 +241,18 @@ public class FileRepository : IBotSharpRepository case AgentField.IsPublic: UpdateAgentIsPublic(agent.Id, agent.IsPublic); break; + case AgentField.Disabled: + UpdateAgentDisabled(agent.Id, agent.Disabled); + break; + case AgentField.AllowRouting: + UpdateAgentAllowRouting(agent.Id, agent.AllowRouting); + break; + case AgentField.Profiles: + UpdateAgentProfiles(agent.Id, agent.Profiles); + break; + case AgentField.RoutingRules: + UpdateAgentRoutingRules(agent.Id, agent.RoutingRules); + break; case AgentField.Instruction: UpdateAgentInstruction(agent.Id, agent.Instruction); break; @@ -298,6 +311,50 @@ public class FileRepository : IBotSharpRepository File.WriteAllText(agentFile, json); } + private void UpdateAgentDisabled(string agentId, bool disabled) + { + var (agent, agentFile) = GetAgentFromFile(agentId); + if (agent == null) return; + + agent.Disabled = disabled; + agent.UpdatedDateTime = DateTime.UtcNow; + var json = JsonSerializer.Serialize(agent, _options); + File.WriteAllText(agentFile, json); + } + + private void UpdateAgentAllowRouting(string agentId, bool allowRouting) + { + var (agent, agentFile) = GetAgentFromFile(agentId); + if (agent == null) return; + + agent.AllowRouting = allowRouting; + agent.UpdatedDateTime = DateTime.UtcNow; + var json = JsonSerializer.Serialize(agent, _options); + File.WriteAllText(agentFile, json); + } + + private void UpdateAgentProfiles(string agentId, List profiles) + { + var (agent, agentFile) = GetAgentFromFile(agentId); + if (agent == null) return; + + agent.Profiles = profiles; + agent.UpdatedDateTime = DateTime.UtcNow; + var json = JsonSerializer.Serialize(agent, _options); + File.WriteAllText(agentFile, json); + } + + private void UpdateAgentRoutingRules(string agentId, List rules) + { + var (agent, agentFile) = GetAgentFromFile(agentId); + if (agent == null) return; + + agent.RoutingRules = rules; + agent.UpdatedDateTime = DateTime.UtcNow; + var json = JsonSerializer.Serialize(agent, _options); + File.WriteAllText(agentFile, json); + } + private void UpdateAgentInstruction(string agentId, string instruction) { if (string.IsNullOrEmpty(instruction)) return; diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentCollection.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentCollection.cs index 0f3d5ab8..4b92b87e 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentCollection.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentCollection.cs @@ -15,7 +15,7 @@ public class AgentCollection : MongoBase public bool AllowRouting { get; set; } public bool Disabled { get; set; } public List Profiles { get; set; } - public List RoutingRules { get; set; } + public List RoutingRules { get; set; } public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs index d436b7b2..e1616cce 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.cs @@ -218,8 +218,8 @@ public class MongoRepository : IBotSharpRepository Disabled = x.Disabled, Profiles = x.Profiles, RoutingRules = x.RoutingRules? - .Select(r => RoutingRuleElement.ToMongoElement(r))? - .ToList() ?? new List(), + .Select(r => RoutingRuleElement.ToMongoElement(r))? + .ToList() ?? new List(), CreatedTime = x.CreatedDateTime, UpdatedTime = x.UpdatedDateTime }).ToList();