From 835a3c71efbaacd279019b9bd1a359597b0bdec3 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 10 Oct 2025 14:16:35 -0500 Subject: [PATCH] sync mongo --- .../Agents/Models/AgentLlmConfig.cs | 4 +- .../Collections/AgentDocument.cs | 2 +- .../Models/AgentLlmConfigMongoElement.cs | 44 ---- .../Models/AgentLlmConfigMongoModel.cs | 193 ++++++++++++++++++ .../Models/LlmProviderModelMongoModel.cs | 38 ++++ .../Repository/MongoRepository.Agent.cs | 8 +- 6 files changed, 238 insertions(+), 51 deletions(-) delete mode 100644 src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoElement.cs create mode 100644 src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoModel.cs create mode 100644 src/Plugins/BotSharp.Plugin.MongoStorage/Models/LlmProviderModelMongoModel.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs index 7c7c5325..6ed259a3 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs @@ -80,10 +80,10 @@ public class LlmImageEditConfig : LlmProviderModel { } -public class LlmRealtimeConfig : LlmProviderModel +public class LlmAudioTranscriptionConfig : LlmProviderModel { } -public class LlmAudioTranscriptionConfig : LlmProviderModel +public class LlmRealtimeConfig : LlmProviderModel { } \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs index 16184265..7a239026 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs @@ -26,7 +26,7 @@ public class AgentDocument : MongoBase public List Labels { get; set; } public List RoutingRules { get; set; } public List Rules { get; set; } - public AgentLlmConfigMongoElement? LlmConfig { get; set; } + public AgentLlmConfigMongoModel? LlmConfig { get; set; } public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoElement.cs deleted file mode 100644 index 63bc3b20..00000000 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoElement.cs +++ /dev/null @@ -1,44 +0,0 @@ -using BotSharp.Abstraction.Agents.Models; - -namespace BotSharp.Plugin.MongoStorage.Models; - -[BsonIgnoreExtraElements(Inherited = true)] -public class AgentLlmConfigMongoElement -{ - public string? Provider { get; set; } - public string? Model { get; set; } - public bool IsInherit { get; set; } - public int MaxRecursionDepth { get; set; } - public int? MaxOutputTokens { get; set; } - public string? ReasoningEffortLevel { get; set; } - - public static AgentLlmConfigMongoElement? ToMongoElement(AgentLlmConfig? config) - { - if (config == null) return null; - - return new AgentLlmConfigMongoElement - { - Provider = config.Provider, - Model = config.Model, - IsInherit = config.IsInherit, - MaxRecursionDepth = config.MaxRecursionDepth, - MaxOutputTokens = config.MaxOutputTokens, - ReasoningEffortLevel = config.ReasoningEffortLevel - }; - } - - public static AgentLlmConfig? ToDomainElement(AgentLlmConfigMongoElement? config) - { - if (config == null) return null; - - return new AgentLlmConfig - { - Provider = config.Provider, - Model = config.Model, - IsInherit = config.IsInherit, - MaxRecursionDepth = config.MaxRecursionDepth, - MaxOutputTokens = config.MaxOutputTokens, - ReasoningEffortLevel = config.ReasoningEffortLevel - }; - } -} diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoModel.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoModel.cs new file mode 100644 index 00000000..165a590a --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoModel.cs @@ -0,0 +1,193 @@ +using BotSharp.Abstraction.Agents.Models; + +namespace BotSharp.Plugin.MongoStorage.Models; + +[BsonIgnoreExtraElements(Inherited = true)] +public class AgentLlmConfigMongoModel +{ + public string? Provider { get; set; } + public string? Model { get; set; } + public bool IsInherit { get; set; } + public int MaxRecursionDepth { get; set; } + public int? MaxOutputTokens { get; set; } + public string? ReasoningEffortLevel { get; set; } + + public LlmImageGenerationConfigMongoModel? ImageGeneration { get; set; } + public LlmImageEditConfigMongoModel? ImageEdit { get; set; } + public LlmAudioTranscriptionConfigMongoModel? AudioTranscription { get; set; } + public LlmRealtimeConfigMongoModel? Realtime { get; set; } + + + + public static AgentLlmConfigMongoModel? ToMongoElement(AgentLlmConfig? config) + { + if (config == null) + { + return null; + } + + return new AgentLlmConfigMongoModel + { + Provider = config.Provider, + Model = config.Model, + IsInherit = config.IsInherit, + MaxRecursionDepth = config.MaxRecursionDepth, + MaxOutputTokens = config.MaxOutputTokens, + ReasoningEffortLevel = config.ReasoningEffortLevel, + ImageGeneration = LlmImageGenerationConfigMongoModel.ToMongoModel(config.ImageGeneration), + ImageEdit = LlmImageEditConfigMongoModel.ToMongoModel(config.ImageEdit), + AudioTranscription = LlmAudioTranscriptionConfigMongoModel.ToMongoModel(config.AudioTranscription), + Realtime = LlmRealtimeConfigMongoModel.ToMongoModel(config.Realtime) + }; + } + + public static AgentLlmConfig? ToDomainElement(AgentLlmConfigMongoModel? config) + { + if (config == null) + { + return null; + } + + return new AgentLlmConfig + { + Provider = config.Provider, + Model = config.Model, + IsInherit = config.IsInherit, + MaxRecursionDepth = config.MaxRecursionDepth, + MaxOutputTokens = config.MaxOutputTokens, + ReasoningEffortLevel = config.ReasoningEffortLevel, + ImageGeneration = LlmImageGenerationConfigMongoModel.ToDomainModel(config.ImageGeneration), + ImageEdit = LlmImageEditConfigMongoModel.ToDomainModel(config.ImageEdit), + AudioTranscription = LlmAudioTranscriptionConfigMongoModel.ToDomainModel(config.AudioTranscription), + Realtime = LlmRealtimeConfigMongoModel.ToDomainModel(config.Realtime) + }; + } +} + +[BsonIgnoreExtraElements(Inherited = true)] +public class LlmImageGenerationConfigMongoModel : LlmProviderModelMongoModel +{ + public static LlmImageGenerationConfig? ToDomainModel(LlmImageGenerationConfigMongoModel? config) + { + if (config == null) + { + return null; + } + + return new LlmImageGenerationConfig + { + Provider = config.Provider, + Model = config.Model, + }; + } + + public static LlmImageGenerationConfigMongoModel? ToMongoModel(LlmImageGenerationConfig? config) + { + if (config == null) + { + return null; + } + + return new LlmImageGenerationConfigMongoModel + { + Provider = config.Provider, + Model = config.Model, + }; + } +} + +[BsonIgnoreExtraElements(Inherited = true)] +public class LlmImageEditConfigMongoModel : LlmProviderModelMongoModel +{ + public static LlmImageEditConfig? ToDomainModel(LlmImageEditConfigMongoModel? config) + { + if (config == null) + { + return null; + } + + return new LlmImageEditConfig + { + Provider = config.Provider, + Model = config.Model, + }; + } + + public static LlmImageEditConfigMongoModel? ToMongoModel(LlmImageEditConfig? config) + { + if (config == null) + { + return null; + } + + return new LlmImageEditConfigMongoModel + { + Provider = config.Provider, + Model = config.Model, + }; + } +} + +[BsonIgnoreExtraElements(Inherited = true)] +public class LlmAudioTranscriptionConfigMongoModel : LlmProviderModelMongoModel +{ + public static LlmAudioTranscriptionConfig? ToDomainModel(LlmAudioTranscriptionConfigMongoModel? config) + { + if (config == null) + { + return null; + } + + return new LlmAudioTranscriptionConfig + { + Provider = config.Provider, + Model = config.Model, + }; + } + + public static LlmAudioTranscriptionConfigMongoModel? ToMongoModel(LlmAudioTranscriptionConfig? config) + { + if (config == null) + { + return null; + } + + return new LlmAudioTranscriptionConfigMongoModel + { + Provider = config.Provider, + Model = config.Model, + }; + } +} + +[BsonIgnoreExtraElements(Inherited = true)] +public class LlmRealtimeConfigMongoModel : LlmProviderModelMongoModel +{ + public static LlmRealtimeConfig? ToDomainModel(LlmRealtimeConfigMongoModel? config) + { + if (config == null) + { + return null; + } + + return new LlmRealtimeConfig + { + Provider = config.Provider, + Model = config.Model, + }; + } + + public static LlmRealtimeConfigMongoModel? ToMongoModel(LlmRealtimeConfig? config) + { + if (config == null) + { + return null; + } + + return new LlmRealtimeConfigMongoModel + { + Provider = config.Provider, + Model = config.Model, + }; + } +} \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/LlmProviderModelMongoModel.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/LlmProviderModelMongoModel.cs new file mode 100644 index 00000000..ae5e6b20 --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/LlmProviderModelMongoModel.cs @@ -0,0 +1,38 @@ +using BotSharp.Abstraction.Models; + +namespace BotSharp.Plugin.MongoStorage.Models; + +[BsonIgnoreExtraElements(Inherited = true)] +public class LlmProviderModelMongoModel +{ + public string? Provider { get; set; } + public string? Model { get; set; } + + public static LlmProviderModel? ToDomainModel(LlmProviderModelMongoModel? config) + { + if (config == null) + { + return null; + } + + return new LlmProviderModel + { + Provider = config.Provider, + Model = config.Model, + }; + } + + public static LlmProviderModelMongoModel? ToMongoModel(LlmProviderModel? config) + { + if (config == null) + { + return null; + } + + return new LlmProviderModelMongoModel + { + Provider = config.Provider, + Model = config.Model, + }; + } +} diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index 76cadd32..044a52b1 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -333,7 +333,7 @@ public partial class MongoRepository private void UpdateAgentLlmConfig(string agentId, AgentLlmConfig? config) { - var llmConfig = AgentLlmConfigMongoElement.ToMongoElement(config); + var llmConfig = AgentLlmConfigMongoModel.ToMongoElement(config); var filter = Builders.Filter.Eq(x => x.Id, agentId); var update = Builders.Update .Set(x => x.LlmConfig, llmConfig) @@ -377,7 +377,7 @@ public partial class MongoRepository .Set(x => x.McpTools, agent.McpTools.Select(u => AgentMcpToolMongoElement.ToMongoElement(u)).ToList()) .Set(x => x.KnowledgeBases, agent.KnowledgeBases.Select(u => AgentKnowledgeBaseMongoElement.ToMongoElement(u)).ToList()) .Set(x => x.Rules, agent.Rules.Select(e => AgentRuleMongoElement.ToMongoElement(e)).ToList()) - .Set(x => x.LlmConfig, AgentLlmConfigMongoElement.ToMongoElement(agent.LlmConfig)) + .Set(x => x.LlmConfig, AgentLlmConfigMongoModel.ToMongoElement(agent.LlmConfig)) .Set(x => x.IsPublic, agent.IsPublic) .Set(x => x.UpdatedTime, DateTime.UtcNow); @@ -550,7 +550,7 @@ public partial class MongoRepository MaxMessageCount = x.MaxMessageCount, Profiles = x.Profiles ?? [], Labels = x.Labels ?? [], - LlmConfig = AgentLlmConfigMongoElement.ToMongoElement(x.LlmConfig), + LlmConfig = AgentLlmConfigMongoModel.ToMongoElement(x.LlmConfig), ChannelInstructions = x.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToMongoElement(i))?.ToList() ?? [], Templates = x.Templates?.Select(t => AgentTemplateMongoElement.ToMongoElement(t))?.ToList() ?? [], Functions = x.Functions?.Select(f => FunctionDefMongoElement.ToMongoElement(f))?.ToList() ?? [], @@ -651,7 +651,7 @@ public partial class MongoRepository Profiles = agentDoc.Profiles ?? [], Labels = agentDoc.Labels ?? [], MaxMessageCount = agentDoc.MaxMessageCount, - LlmConfig = AgentLlmConfigMongoElement.ToDomainElement(agentDoc.LlmConfig), + LlmConfig = AgentLlmConfigMongoModel.ToDomainElement(agentDoc.LlmConfig), ChannelInstructions = agentDoc.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToDomainElement(i))?.ToList() ?? [], Templates = agentDoc.Templates?.Select(t => AgentTemplateMongoElement.ToDomainElement(t))?.ToList() ?? [], Functions = agentDoc.Functions?.Select(f => FunctionDefMongoElement.ToDomainElement(f)).ToList() ?? [],