sync mongo

This commit is contained in:
Jicheng Lu 2025-10-10 14:16:35 -05:00
parent 28e3518e41
commit 835a3c71ef
6 changed files with 238 additions and 51 deletions

View file

@ -80,10 +80,10 @@ public class LlmImageEditConfig : LlmProviderModel
{
}
public class LlmRealtimeConfig : LlmProviderModel
public class LlmAudioTranscriptionConfig : LlmProviderModel
{
}
public class LlmAudioTranscriptionConfig : LlmProviderModel
public class LlmRealtimeConfig : LlmProviderModel
{
}

View file

@ -26,7 +26,7 @@ public class AgentDocument : MongoBase
public List<string> Labels { get; set; }
public List<RoutingRuleMongoElement> RoutingRules { get; set; }
public List<AgentRuleMongoElement> Rules { get; set; }
public AgentLlmConfigMongoElement? LlmConfig { get; set; }
public AgentLlmConfigMongoModel? LlmConfig { get; set; }
public DateTime CreatedTime { get; set; }
public DateTime UpdatedTime { get; set; }

View file

@ -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
};
}
}

View file

@ -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,
};
}
}

View file

@ -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,
};
}
}

View file

@ -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<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.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() ?? [],