From 513007b7ce7abee75364ecc917df183b5a962e52 Mon Sep 17 00:00:00 2001 From: chait Date: Thu, 13 Feb 2025 11:25:32 +0800 Subject: [PATCH] [update] Non empty code style constraint (default value constraint), unified optimization of the CreatedTime field and MongoDBContext methods; --- .../Conversations/Models/Conversation.cs | 24 +++---- .../Users/Models/Dashboard.cs | 2 +- .../Services/ConversationStateService.cs | 2 +- .../Services/ConversationStorage.cs | 10 +-- .../FileRepository.Conversation.cs | 2 +- .../FileRepository/FileRepository.User.cs | 14 ++-- .../Collections/AgentDocument.cs | 30 ++++----- .../Collections/AgentTaskDocument.cs | 8 +-- .../ConversationContentLogDocument.cs | 12 ++-- .../Collections/ConversationDialogDocument.cs | 6 +- .../Collections/ConversationDocument.cs | 16 ++--- .../Collections/ConversationStateDocument.cs | 8 +-- .../ConversationStateLogDocument.cs | 10 +-- .../Collections/CrontabItemDocument.cs | 14 ++-- .../Collections/ExecutionLogDocument.cs | 4 +- .../Collections/GlobalStatisticsDocument.cs | 8 +-- .../KnowledgeCollectionConfigDocument.cs | 8 +-- .../KnowledgeCollectionFileMetaDocument.cs | 16 ++--- .../Collections/LlmCompletionLogDocument.cs | 4 +- .../Collections/PluginDocument.cs | 2 +- .../Collections/RoleAgentDocument.cs | 4 +- .../Collections/RoleDocument.cs | 2 +- .../Collections/TranslationMemoryDocument.cs | 6 +- .../Collections/UserAgentDocument.cs | 4 +- .../Models/AgentKnowledgeBaseMongoElement.cs | 4 +- .../Models/AgentResponseMongoElement.cs | 6 +- .../Models/AgentRuleMongoElement.cs | 4 +- .../Models/AgentTemplateMongoElement.cs | 4 +- .../Models/AgentUtilityMongoElement.cs | 30 ++------- .../Models/ChannelInstructionMongoElement.cs | 4 +- .../Models/CronTaskMongoElement.cs | 6 +- .../Models/DialogMongoElement.cs | 28 +++----- .../Models/FunctionDefMongoElement.cs | 22 ++----- .../KnowledgeEmbeddingConfigMongoModel.cs | 4 +- .../Models/KnowledgeFileMetaRefMongoModel.cs | 8 +-- .../KnowledgeVectorStoreConfigMongoModel.cs | 2 +- .../Models/PromptLogMongoElement.cs | 6 +- .../Models/RoutingRuleMongoElement.cs | 13 ++-- .../Models/StateMongoElement.cs | 14 ++-- .../Models/TranslationMemoryMongoElement.cs | 4 +- .../BotSharp.Plugin.MongoStorage/MongoBase.cs | 2 +- .../MongoDbContext.cs | 66 ++++++++++++------- .../MongoRepository.Conversation.cs | 6 +- .../MongoRepository.KnowledgeBase.cs | 10 +-- .../Repository/MongoRepository.Log.cs | 8 +-- .../Repository/MongoRepository.Translation.cs | 4 +- .../Repository/MongoRepository.User.cs | 14 ++-- 47 files changed, 231 insertions(+), 254 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs index a485a9c4..ac1efb04 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs @@ -16,10 +16,10 @@ public class Conversation public string TitleAlias { get; set; } = string.Empty; [JsonIgnore] - public List Dialogs { get; set; } = new(); + public List Dialogs { get; set; } = []; [JsonIgnore] - public Dictionary States { get; set; } = new(); + public Dictionary States { get; set; } = []; public string Status { get; set; } = ConversationStatus.Open; @@ -28,11 +28,11 @@ public class Conversation /// /// Channel id, like phone number, email address, etc. /// - public string ChannelId { get; set; } + public string ChannelId { get; set; } = default!; public int DialogCount { get; set; } - public List Tags { get; set; } = new(); + public List Tags { get; set; } = []; public DateTime UpdatedTime { get; set; } = DateTime.UtcNow; public DateTime CreatedTime { get; set; } = DateTime.UtcNow; @@ -41,10 +41,10 @@ public class Conversation public class DialogElement { [JsonPropertyName("meta_data")] - public DialogMetaData MetaData { get; set; } + public DialogMetaData MetaData { get; set; } = new(); [JsonPropertyName("content")] - public string Content { get; set; } + public string Content { get; set; } = default!; [JsonPropertyName("secondary_content")] public string? SecondaryContent { get; set; } @@ -76,23 +76,23 @@ public class DialogElement public override string ToString() { - return $"{MetaData.Role}: {Content} [{MetaData?.CreateTime}]"; + return $"{MetaData.Role}: {Content} [{MetaData?.CreatedTime}]"; } } public class DialogMetaData { [JsonPropertyName("role")] - public string Role { get; set; } + public string Role { get; set; } = default!; [JsonPropertyName("agent_id")] - public string AgentId { get; set; } + public string AgentId { get; set; } = default!; [JsonPropertyName("message_id")] - public string MessageId { get; set; } + public string MessageId { get; set; } = default!; [JsonPropertyName("message_type")] - public string MessageType { get; set; } + public string MessageType { get; set; } = default!; [JsonPropertyName("function_name")] public string? FunctionName { get; set; } @@ -101,5 +101,5 @@ public class DialogMetaData public string? SenderId { get; set; } [JsonPropertyName("create_at")] - public DateTime CreateTime { get; set; } + public DateTime CreatedTime { get; set; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/Models/Dashboard.cs b/src/Infrastructure/BotSharp.Abstraction/Users/Models/Dashboard.cs index 753cb390..c59ffbcf 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/Models/Dashboard.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/Models/Dashboard.cs @@ -15,6 +15,6 @@ public class DashboardComponent public class DashboardConversation : DashboardComponent { public string? ConversationId { get; set; } - public string? Instruction { get; set; } = ""; + public string? Instruction { get; set; } } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 52dcd032..c0dcc195 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -151,7 +151,7 @@ public class ConversationStateService : IConversationStateService, IDisposable var userDialogs = dialogs.Where(x => x.MetaData?.Role == AgentRole.User) .GroupBy(x => x.MetaData?.MessageId) .Select(g => g.First()) - .OrderBy(x => x.MetaData?.CreateTime) + .OrderBy(x => x.MetaData?.CreatedTime) .ToList(); var curMsgIndex = userDialogs.FindIndex(x => !string.IsNullOrEmpty(curMsgId) && x.MetaData?.MessageId == curMsgId); curMsgIndex = curMsgIndex < 0 ? userDialogs.Count() : curMsgIndex; diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs index f9ba5b12..75d1a501 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs @@ -39,7 +39,7 @@ public class ConversationStorage : IConversationStorage MessageId = dialog.MessageId, MessageType = dialog.MessageType, FunctionName = dialog.FunctionName, - CreateTime = dialog.CreatedAt + CreatedTime = dialog.CreatedAt }; var content = dialog.Content.RemoveNewLine(); @@ -65,7 +65,7 @@ public class ConversationStorage : IConversationStorage MessageType = dialog.MessageType, SenderId = dialog.SenderId, FunctionName = dialog.FunctionName, - CreateTime = dialog.CreatedAt + CreatedTime = dialog.CreatedAt }; var content = dialog.Content.RemoveNewLine(); @@ -108,7 +108,7 @@ public class ConversationStorage : IConversationStorage MessageId = dialog.MessageId, MessageType = dialog.MessageType, FunctionName = dialog.FunctionName, - CreateTime = dialog.CreatedAt + CreatedTime = dialog.CreatedAt }; var content = dialog.Content.RemoveNewLine(); @@ -134,7 +134,7 @@ public class ConversationStorage : IConversationStorage MessageType = dialog.MessageType, SenderId = dialog.SenderId, FunctionName = dialog.FunctionName, - CreateTime = dialog.CreatedAt + CreatedTime = dialog.CreatedAt }; var content = dialog.Content.RemoveNewLine(); @@ -179,7 +179,7 @@ public class ConversationStorage : IConversationStorage var messageType = meta.MessageType; var function = meta.FunctionName; var senderId = role == AgentRole.Function ? currentAgentId : meta.SenderId; - var createdAt = meta.CreateTime; + var createdAt = meta.CreatedTime; var richContent = !string.IsNullOrEmpty(dialog.RichContent) ? JsonSerializer.Deserialize>(dialog.RichContent, _options.JsonSerializerOptions) : null; var secondaryRichContent = !string.IsNullOrEmpty(dialog.SecondaryRichContent) ? diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs index 25682662..8afcdc5d 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs @@ -583,7 +583,7 @@ public partial class FileRepository var isSaved = HandleTruncatedDialogs(convDir, dialogDir, dialogs, foundIdx); // Handle truncated states - var refTime = dialogs.ElementAt(foundIdx).MetaData.CreateTime; + var refTime = dialogs.ElementAt(foundIdx).MetaData.CreatedTime; var stateDir = Path.Combine(convDir, STATE_FILE); var states = CollectConversationStates(stateDir); isSaved = HandleTruncatedStates(stateDir, states, messageId, refTime); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index 6b543c8b..c8f1fbd6 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -50,7 +50,7 @@ public partial class FileRepository return Users.FirstOrDefault(x => x.Phone == phone && x.Type == UserType.Affiliate); } - public User? GetUserById(string id = null) + public User? GetUserById(string? id = null) { return Users.FirstOrDefault(x => x.Id == id || (x.ExternalId != null && x.ExternalId == id)); } @@ -65,12 +65,12 @@ public partial class FileRepository return Users.Where(x => x.AffiliateId == affiliateId).ToList(); } - public User? GetUserByUserName(string userName = null) + public User? GetUserByUserName(string? userName = null) { return Users.FirstOrDefault(x => x.UserName == userName.ToLower()); } - public Dashboard? GetDashboard(string userId = null) + public Dashboard? GetDashboard(string? userId = null) { return Dashboards.FirstOrDefault(); } @@ -97,6 +97,8 @@ public partial class FileRepository public void UpdateUserVerified(string userId) { var user = GetUserById(userId); + if (user == null) return; + user.Verified = true; var dir = Path.Combine(_dbSettings.FileRepository, USERS_FOLDER, user.Id); var path = Path.Combine(dir, USER_FILE); @@ -147,7 +149,7 @@ public partial class FileRepository public List SearchLoginUsers(User filter, string source = UserSource.Internal) { - List searchResult = new List(); + List searchResult = []; // search by filters if (!string.IsNullOrWhiteSpace(filter.Id)) @@ -183,7 +185,7 @@ public partial class FileRepository else if (!string.IsNullOrWhiteSpace(filter.Email)) { var curUser = Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Email == filter.Email.ToString()); - User user = curUser != null ? curUser : null; + User? user = curUser != null ? curUser : null; if (user != null) { searchResult.Add(user); @@ -194,7 +196,7 @@ public partial class FileRepository if (searchResult.Count == 0 && !string.IsNullOrWhiteSpace(filter.UserName)) { var curUser = Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.UserName == filter.UserName); - User user = curUser != null ? curUser : null; + User? user = curUser != null ? curUser : null; if (user != null) { searchResult.Add(user); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs index 8457bfce..bdfdbe80 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs @@ -2,27 +2,27 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class AgentDocument : MongoBase { - public string Name { get; set; } - public string Description { get; set; } - public string Type { get; set; } + public string Name { get; set; } = default!; + public string Description { get; set; } = default!; + public string Type { get; set; } = default!; public string? InheritAgentId { get; set; } public string? IconUrl { get; set; } - public string Instruction { get; set; } + public string Instruction { get; set; } = default!; public bool IsPublic { get; set; } public bool Disabled { get; set; } public bool MergeUtility { get; set; } public int? MaxMessageCount { get; set; } - public List ChannelInstructions { get; set; } - public List Templates { get; set; } - public List Functions { get; set; } - public List Responses { get; set; } - public List Samples { get; set; } - public List Utilities { get; set; } - public List KnowledgeBases { get; set; } - public List Profiles { get; set; } - public List Labels { get; set; } - public List RoutingRules { get; set; } - public List Rules { get; set; } + public List ChannelInstructions { get; set; } = []; + public List Templates { get; set; } = []; + public List Functions { get; set; } = []; + public List Responses { get; set; } = []; + public List Samples { get; set; } = []; + public List Utilities { get; set; } = []; + public List KnowledgeBases { get; set; } = []; + public List Profiles { get; set; } = []; + public List Labels { get; set; } = []; + public List RoutingRules { get; set; } = []; + public List Rules { get; set; } = []; public AgentLlmConfigMongoElement? LlmConfig { get; set; } public DateTime CreatedTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentTaskDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentTaskDocument.cs index 9259f688..7f09318a 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentTaskDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentTaskDocument.cs @@ -4,12 +4,12 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class AgentTaskDocument : MongoBase { - public string Name { get; set; } + public string Name { get; set; } = default!; public string? Description { get; set; } - public string Content { get; set; } + public string Content { get; set; } = default!; public bool Enabled { get; set; } - public string AgentId { get; set; } - public string Status { get; set; } + public string AgentId { get; set; } = default!; + public string Status { get; set; } = default!; public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationContentLogDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationContentLogDocument.cs index 8626898a..ceac22c4 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationContentLogDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationContentLogDocument.cs @@ -2,12 +2,12 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class ConversationContentLogDocument : MongoBase { - public string ConversationId { get; set; } - public string MessageId { get; set; } + public string ConversationId { get; set; } = default!; + public string MessageId { get; set; } = default!; public string? Name { get; set; } public string? AgentId { get; set; } - public string Role { get; set; } - public string Source { get; set; } - public string Content { get; set; } - public DateTime CreateTime { get; set; } + public string Role { get; set; } = default!; + public string Source { get; set; } = default!; + public string Content { get; set; } = default!; + public DateTime CreatedTime { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDialogDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDialogDocument.cs index a0e66e98..a3f6ee69 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDialogDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDialogDocument.cs @@ -2,8 +2,8 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class ConversationDialogDocument : MongoBase { - public string ConversationId { get; set; } - public string AgentId { get; set; } + public string ConversationId { get; set; } = default!; + public string AgentId { get; set; } = default!; public DateTime UpdatedTime { get; set; } - public List Dialogs { get; set; } + public List Dialogs { get; set; } = []; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs index 52c26b52..ace9472d 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDocument.cs @@ -2,16 +2,16 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class ConversationDocument : MongoBase { - public string AgentId { get; set; } - public string UserId { get; set; } + public string AgentId { get; set; } = default!; + public string UserId { get; set; } = default!; public string? TaskId { get; set; } - public string Title { get; set; } - public string TitleAlias { get; set; } - public string Channel { get; set; } - public string ChannelId { get; set; } - public string Status { get; set; } + public string Title { get; set; } = default!; + public string TitleAlias { get; set; } = default!; + public string Channel { get; set; } = default!; + public string ChannelId { get; set; } = default!; + public string Status { get; set; } = default!; public int DialogCount { get; set; } - public List Tags { get; set; } + public List Tags { get; set; } = []; public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateDocument.cs index d83945a8..3df58594 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateDocument.cs @@ -2,9 +2,9 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class ConversationStateDocument : MongoBase { - public string ConversationId { get; set; } - public string AgentId { get; set; } + public string ConversationId { get; set; } = default!; + public string AgentId { get; set; } = default!; public DateTime UpdatedTime { get; set; } - public List States { get; set; } = new List(); - public List Breakpoints { get; set; } = new List(); + public List States { get; set; } = []; + public List Breakpoints { get; set; } = []; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateLogDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateLogDocument.cs index 131ef60c..a3a38c93 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateLogDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateLogDocument.cs @@ -2,9 +2,9 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class ConversationStateLogDocument : MongoBase { - public string ConversationId { get; set; } - public string AgentId { get; set; } - public string MessageId { get; set; } - public Dictionary States { get; set; } - public DateTime CreateTime { get; set; } + public string ConversationId { get; set; } = default!; + public string AgentId { get; set; } = default!; + public string MessageId { get; set; } = default!; + public Dictionary States { get; set; } = []; + public DateTime CreatedTime { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/CrontabItemDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/CrontabItemDocument.cs index 9c697310..17a49c2b 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/CrontabItemDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/CrontabItemDocument.cs @@ -4,13 +4,13 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class CrontabItemDocument : MongoBase { - public string UserId { get; set; } - public string AgentId { get; set; } - public string ConversationId { get; set; } - public string ExecutionResult { get; set; } - public string Cron { get; set; } - public string Title { get; set; } - public string Description { get; set; } + public string UserId { get; set; } = default!; + public string AgentId { get; set; } = default!; + public string ConversationId { get; set; } = default!; + public string ExecutionResult { get; set; } = default!; + public string Cron { get; set; } = default!; + public string Title { get; set; } = default!; + public string Description { get; set; } = default!; public int ExecutionCount { get; set; } public int MaxExecutionCount { get; set; } public int ExpireSeconds { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExecutionLogDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExecutionLogDocument.cs index 955b22a9..6b961141 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExecutionLogDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ExecutionLogDocument.cs @@ -2,6 +2,6 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class ExecutionLogDocument : MongoBase { - public string ConversationId { get; set; } - public List Logs { get; set; } + public string ConversationId { get; set; } = default!; + public List Logs { get; set; } = []; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/GlobalStatisticsDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/GlobalStatisticsDocument.cs index 80d51c44..161ed4eb 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/GlobalStatisticsDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/GlobalStatisticsDocument.cs @@ -2,12 +2,12 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class GlobalStatisticsDocument : MongoBase { - public string Metric { get; set; } - public string Dimension { get; set; } - public string DimRefVal { get; set; } + public string Metric { get; set; } = default!; + public string Dimension { get; set; } = default!; + public string DimRefVal { get; set; } = default!; public IDictionary Data { get; set; } = new Dictionary(); public DateTime RecordTime { get; set; } public DateTime StartTime { get; set; } public DateTime EndTime { get; set; } - public string Interval { get; set; } + public string Interval { get; set; } = default!; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/KnowledgeCollectionConfigDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/KnowledgeCollectionConfigDocument.cs index 0970b2cc..c8c08d37 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/KnowledgeCollectionConfigDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/KnowledgeCollectionConfigDocument.cs @@ -2,8 +2,8 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class KnowledgeCollectionConfigDocument : MongoBase { - public string Name { get; set; } - public string Type { get; set; } - public KnowledgeVectorStoreConfigMongoModel VectorStore { get; set; } - public KnowledgeEmbeddingConfigMongoModel TextEmbedding { get; set; } + public string Name { get; set; } = default!; + public string Type { get; set; } = default!; + public KnowledgeVectorStoreConfigMongoModel VectorStore { get; set; } = new(); + public KnowledgeEmbeddingConfigMongoModel TextEmbedding { get; set; } = new(); } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/KnowledgeCollectionFileMetaDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/KnowledgeCollectionFileMetaDocument.cs index 9fbe2ec1..90df611d 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/KnowledgeCollectionFileMetaDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/KnowledgeCollectionFileMetaDocument.cs @@ -2,14 +2,14 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class KnowledgeCollectionFileMetaDocument : MongoBase { - public string Collection { get; set; } + public string Collection { get; set; } = default!; public Guid FileId { get; set; } - public string FileName { get; set; } - public string FileSource { get; set; } - public string ContentType { get; set; } - public string VectorStoreProvider { get; set; } - public IEnumerable VectorDataIds { get; set; } = new List(); + public string FileName { get; set; } = default!; + public string FileSource { get; set; } = default!; + public string ContentType { get; set; } = default!; + public string VectorStoreProvider { get; set; } = default!; + public IEnumerable VectorDataIds { get; set; } = []; public KnowledgeFileMetaRefMongoModel? RefData { get; set; } - public DateTime CreateDate { get; set; } - public string CreateUserId { get; set; } + public DateTime CreatedDate { get; set; } + public string CreateUserId { get; set; } = default!; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/LlmCompletionLogDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/LlmCompletionLogDocument.cs index f5b96c0a..077fddc3 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/LlmCompletionLogDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/LlmCompletionLogDocument.cs @@ -2,6 +2,6 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class LlmCompletionLogDocument : MongoBase { - public string ConversationId { get; set; } - public List Logs { get; set; } + public string ConversationId { get; set; } = default!; + public List Logs { get; set; } = []; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/PluginDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/PluginDocument.cs index a4c045c4..fb4baedb 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/PluginDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/PluginDocument.cs @@ -2,5 +2,5 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class PluginDocument : MongoBase { - public List EnabledPlugins { get; set; } + public List EnabledPlugins { get; set; } = []; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/RoleAgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/RoleAgentDocument.cs index 037158d0..f96d8cc1 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/RoleAgentDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/RoleAgentDocument.cs @@ -4,8 +4,8 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class RoleAgentDocument : MongoBase { - public string RoleId { get; set; } - public string AgentId { get; set; } + public string RoleId { get; set; } = default!; + public string AgentId { get; set; } = default!; public IEnumerable Actions { get; set; } = []; public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/RoleDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/RoleDocument.cs index 557f219a..da8d0d74 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/RoleDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/RoleDocument.cs @@ -4,7 +4,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class RoleDocument : MongoBase { - public string Name { get; set; } + public string Name { get; set; } = default!; public IEnumerable Permissions { get; set; } = []; public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/TranslationMemoryDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/TranslationMemoryDocument.cs index 54c11b3e..4dd3e26d 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/TranslationMemoryDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/TranslationMemoryDocument.cs @@ -2,7 +2,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class TranslationMemoryDocument : MongoBase { - public string OriginalText { get; set; } - public string HashText { get; set; } - public List Translations { get; set; } = new List(); + public string OriginalText { get; set; } = default!; + public string HashText { get; set; } = default!; + public List Translations { get; set; } = []; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/UserAgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/UserAgentDocument.cs index 9de5345f..1b9d91b7 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/UserAgentDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/UserAgentDocument.cs @@ -2,8 +2,8 @@ namespace BotSharp.Plugin.MongoStorage.Collections; public class UserAgentDocument : MongoBase { - public string UserId { get; set; } - public string AgentId { get; set; } + public string UserId { get; set; } = default!; + public string AgentId { get; set; } = default!; public IEnumerable Actions { get; set; } = []; public DateTime CreatedTime { get; set; } public DateTime UpdatedTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentKnowledgeBaseMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentKnowledgeBaseMongoElement.cs index b82c6c47..2aca84a2 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentKnowledgeBaseMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentKnowledgeBaseMongoElement.cs @@ -5,8 +5,8 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class AgentKnowledgeBaseMongoElement { - public string Name { get; set; } - public string Type { get; set; } + public string Name { get; set; } = default!; + public string Type { get; set; } = default!; public bool Disabled { get; set; } public static AgentKnowledgeBaseMongoElement ToMongoElement(AgentKnowledgeBase knowledgeBase) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentResponseMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentResponseMongoElement.cs index 99cad6a5..8995c5c8 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentResponseMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentResponseMongoElement.cs @@ -5,9 +5,9 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class AgentResponseMongoElement { - public string Prefix { get; set; } - public string Intent { get; set; } - public string Content { get; set; } + public string Prefix { get; set; } = default!; + public string Intent { get; set; } = default!; + public string Content { get; set; } = default!; public static AgentResponseMongoElement ToMongoElement(AgentResponse response) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs index 718ffe17..4205fdc4 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs @@ -5,9 +5,9 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class AgentRuleMongoElement { - public string TriggerName { get; set; } + public string TriggerName { get; set; } = default!; public bool Disabled { get; set; } - public string Criteria { get; set; } + public string Criteria { get; set; } = default!; public static AgentRuleMongoElement ToMongoElement(AgentRule rule) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentTemplateMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentTemplateMongoElement.cs index f7aa1275..6021ef3c 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentTemplateMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentTemplateMongoElement.cs @@ -5,8 +5,8 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class AgentTemplateMongoElement { - public string Name { get; set; } - public string Content { get; set; } + public string Name { get; set; } = default!; + public string Content { get; set; } = default!; public static AgentTemplateMongoElement ToMongoElement(AgentTemplate template) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentUtilityMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentUtilityMongoElement.cs index f398b37c..131226b3 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentUtilityMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentUtilityMongoElement.cs @@ -5,7 +5,7 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class AgentUtilityMongoElement { - public string Name { get; set; } + public string Name { get; set; } = default!; public bool Disabled { get; set; } public List Functions { get; set; } = []; public List Templates { get; set; } = []; @@ -33,32 +33,12 @@ public class AgentUtilityMongoElement } } -public class UtilityFunctionMongoElement +public class UtilityFunctionMongoElement(string name) { - public string Name { get; set; } - - public UtilityFunctionMongoElement() - { - - } - - public UtilityFunctionMongoElement(string name) - { - Name = name; - } + public string Name { get; set; } = name; } -public class UtilityTemplateMongoElement +public class UtilityTemplateMongoElement(string name) { - public string Name { get; set; } - - public UtilityTemplateMongoElement() - { - - } - - public UtilityTemplateMongoElement(string name) - { - Name = name; - } + public string Name { get; set; } = name; } \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/ChannelInstructionMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/ChannelInstructionMongoElement.cs index 91ad7c3a..ac9033cb 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/ChannelInstructionMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/ChannelInstructionMongoElement.cs @@ -5,8 +5,8 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class ChannelInstructionMongoElement { - public string Channel { get; set; } - public string Instruction { get; set; } + public string Channel { get; set; } = default!; + public string Instruction { get; set; } = default!; public static ChannelInstructionMongoElement ToMongoElement(ChannelInstruction instruction) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/CronTaskMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/CronTaskMongoElement.cs index 06120581..3090b9f4 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/CronTaskMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/CronTaskMongoElement.cs @@ -5,9 +5,9 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class CronTaskMongoElement { - public string Topic { get; set; } - public string Script { get; set; } - public string Language { get; set; } + public string Topic { get; set; } = default!; + public string Script { get; set; } = default!; + public string Language { get; set; } = default!; public static CronTaskMongoElement ToMongoElement(ScheduleTaskItemArgs model) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/DialogMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/DialogMongoElement.cs index 126dfee8..a7c31ffa 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/DialogMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/DialogMongoElement.cs @@ -5,18 +5,13 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class DialogMongoElement { - public DialogMetaDataMongoElement MetaData { get; set; } - public string Content { get; set; } + public DialogMetaDataMongoElement MetaData { get; set; } = new(); + public string Content { get; set; } = default!; public string? SecondaryContent { get; set; } public string? RichContent { get; set; } public string? SecondaryRichContent { get; set; } public string? Payload { get; set; } - public DialogMongoElement() - { - - } - public static DialogMongoElement ToMongoElement(DialogElement dialog) { return new DialogMongoElement @@ -46,18 +41,13 @@ public class DialogMongoElement public class DialogMetaDataMongoElement { - public string Role { get; set; } - public string AgentId { get; set; } - public string MessageId { get; set; } - public string MessageType { get; set; } + public string Role { get; set; } = default!; + public string AgentId { get; set; } = default!; + public string MessageId { get; set; } = default!; + public string MessageType { get; set; } = default!; public string? FunctionName { get; set; } public string? SenderId { get; set; } - public DateTime CreateTime { get; set; } - - public DialogMetaDataMongoElement() - { - - } + public DateTime CreatedTime { get; set; } public static DialogMetaData ToDomainElement(DialogMetaDataMongoElement meta) { @@ -69,7 +59,7 @@ public class DialogMetaDataMongoElement MessageType = meta.MessageType, FunctionName = meta.FunctionName, SenderId = meta.SenderId, - CreateTime = meta.CreateTime, + CreatedTime = meta.CreatedTime, }; } @@ -83,7 +73,7 @@ public class DialogMetaDataMongoElement MessageType = meta.MessageType, FunctionName = meta.FunctionName, SenderId = meta.SenderId, - CreateTime = meta.CreateTime, + CreatedTime = meta.CreatedTime, }; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs index a0078397..f274eb0c 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/FunctionDefMongoElement.cs @@ -6,17 +6,12 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class FunctionDefMongoElement { - public string Name { get; set; } - public string Description { get; set; } + public string Name { get; set; } = default!; + public string Description { get; set; } = default!; public List? Channels { get; set; } public string? VisibilityExpression { get; set; } public string? Impact { get; set; } - public FunctionParametersDefMongoElement Parameters { get; set; } = new FunctionParametersDefMongoElement(); - - public FunctionDefMongoElement() - { - - } + public FunctionParametersDefMongoElement Parameters { get; set; } = new(); public static FunctionDefMongoElement ToMongoElement(FunctionDef function) { @@ -57,12 +52,7 @@ public class FunctionDefMongoElement public class FunctionParametersDefMongoElement { - public string Type { get; set; } - public string Properties { get; set; } - public List Required { get; set; } = new List(); - - public FunctionParametersDefMongoElement() - { - - } + public string Type { get; set; } = default!; + public string Properties { get; set; } = default!; + public List Required { get; set; } = []; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeEmbeddingConfigMongoModel.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeEmbeddingConfigMongoModel.cs index de6638ee..d75be85a 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeEmbeddingConfigMongoModel.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeEmbeddingConfigMongoModel.cs @@ -5,8 +5,8 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class KnowledgeEmbeddingConfigMongoModel { - public string Provider { get; set; } - public string Model { get; set; } + public string Provider { get; set; } = default!; + public string Model { get; set; } = default!; public int Dimension { get; set; } public static KnowledgeEmbeddingConfigMongoModel ToMongoModel(KnowledgeEmbeddingConfig model) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeFileMetaRefMongoModel.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeFileMetaRefMongoModel.cs index 9d09e53c..c0f04748 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeFileMetaRefMongoModel.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeFileMetaRefMongoModel.cs @@ -5,10 +5,10 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class KnowledgeFileMetaRefMongoModel { - public string Id { get; set; } - public string Name { get; set; } - public string Type { get; set; } - public string Url { get; set; } + public string Id { get; set; } = default!; + public string Name { get; set; } = default!; + public string Type { get; set; } = default!; + public string Url { get; set; } = default!; public IDictionary? Data { get; set; } public static KnowledgeFileMetaRefMongoModel? ToMongoModel(DocMetaRefData? model) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeVectorStoreConfigMongoModel.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeVectorStoreConfigMongoModel.cs index 3cf23314..55495bc6 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeVectorStoreConfigMongoModel.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/KnowledgeVectorStoreConfigMongoModel.cs @@ -5,7 +5,7 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class KnowledgeVectorStoreConfigMongoModel { - public string Provider { get; set; } + public string Provider { get; set; } = default!; public static KnowledgeVectorStoreConfigMongoModel ToMongoModel(VectorStoreConfig model) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/PromptLogMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/PromptLogMongoElement.cs index 94723817..b8dabaa5 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/PromptLogMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/PromptLogMongoElement.cs @@ -3,9 +3,9 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class PromptLogMongoElement { - public string MessageId { get; set; } - public string AgentId { get; set; } - public string Prompt { get; set; } + public string MessageId { get; set; } = default!; + public string AgentId { get; set; } = default!; + public string Prompt { get; set; } = default!; public string? Response { get; set; } public DateTime CreateDateTime { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs index 3b8e495c..15b9c8ef 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs @@ -5,17 +5,12 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class RoutingRuleMongoElement { - public string Field { get; set; } - public string Description { get; set; } + public string Field { get; set; } = default!; + public string Description { get; set; } = default!; public bool Required { get; set; } public string? RedirectTo { get; set; } - public string Type { get; set; } - public string FieldType { get; set; } - - public RoutingRuleMongoElement() - { - - } + public string Type { get; set; } = default!; + public string FieldType { get; set; } = default!; public static RoutingRuleMongoElement ToMongoElement(RoutingRule routingRule) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/StateMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/StateMongoElement.cs index 276b17aa..01aa6f4f 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/StateMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/StateMongoElement.cs @@ -5,10 +5,10 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class StateMongoElement { - public string Key { get; set; } + public string Key { get; set; } = default!; public bool Versioning { get; set; } public bool Readonly { get; set; } - public List Values { get; set; } + public List Values { get; set; } = []; public static StateMongoElement ToMongoElement(StateKeyValue state) { @@ -17,7 +17,7 @@ public class StateMongoElement Key = state.Key, Versioning = state.Versioning, Readonly = state.Readonly, - Values = state.Values?.Select(x => StateValueMongoElement.ToMongoElement(x))?.ToList() ?? new List() + Values = state.Values?.Select(x => StateValueMongoElement.ToMongoElement(x))?.ToList() ?? [] }; } @@ -28,19 +28,19 @@ public class StateMongoElement Key = state.Key, Versioning = state.Versioning, Readonly = state.Readonly, - Values = state.Values?.Select(x => StateValueMongoElement.ToDomainElement(x))?.ToList() ?? new List() + Values = state.Values?.Select(x => StateValueMongoElement.ToDomainElement(x))?.ToList() ?? [] }; } } public class StateValueMongoElement { - public string Data { get; set; } + public string Data { get; set; } = default!; public string? MessageId { get; set; } public bool Active { get; set; } public int ActiveRounds { get; set; } - public string DataType { get; set; } - public string Source { get; set; } + public string DataType { get; set; } = default!; + public string Source { get; set; } = default!; public DateTime UpdateTime { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/TranslationMemoryMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/TranslationMemoryMongoElement.cs index e5a7ede5..525819b7 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/TranslationMemoryMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/TranslationMemoryMongoElement.cs @@ -3,8 +3,8 @@ namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] public class TranslationMemoryMongoElement { - public string TranslatedText { get; set; } - public string Language { get; set; } + public string TranslatedText { get; set; } = default!; + public string Language { get; set; } = default!; public static TranslationMemoryMongoElement ToMongoElement(TranslationMemoryItem item) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoBase.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoBase.cs index 0c3c12b0..1b31ac69 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoBase.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoBase.cs @@ -4,5 +4,5 @@ namespace BotSharp.Plugin.MongoStorage; public abstract class MongoBase { [BsonId(IdGenerator = typeof(StringGuidIdGenerator))] - public string Id { get; set; } + public string Id { get; set; } = default!; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs index 050ebedf..91e668f3 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs @@ -46,12 +46,32 @@ public class MongoDbContext return databaseName; } - private IMongoDatabase Database { get { return _mongoClient.GetDatabase(_mongoDbDatabaseName); } } + private IMongoDatabase Database => _mongoClient.GetDatabase(_mongoDbDatabaseName); + + private bool CollectionExists(IMongoDatabase database, string collectionName) + { + var filter = Builders.Filter.Eq("name", collectionName); + var collections = database.ListCollections(new ListCollectionsOptions { Filter = filter }); + return collections.Any(); + } + + private IMongoCollection GetCollectionOrCreate(string name) + { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException($"The collection {name} cannot be empty."); + + string collectionName = $"{_collectionPrefix}_{name}"; + if (!CollectionExists(Database, collectionName)) + Database.CreateCollection(collectionName); + + var collection = Database.GetCollection(collectionName); + return collection; + } #region Indexes private IMongoCollection CreateConversationIndex() { - var collection = Database.GetCollection($"{_collectionPrefix}_Conversations"); + var collection = GetCollectionOrCreate("Conversations"); var indexes = collection.Indexes.List().ToList(); var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreatedTime")); if (createTimeIndex == null) @@ -64,7 +84,7 @@ public class MongoDbContext private IMongoCollection CreateConversationStateIndex() { - var collection = Database.GetCollection($"{_collectionPrefix}_ConversationStates"); + var collection = GetCollectionOrCreate("ConversationStates"); var indexes = collection.Indexes.List().ToList(); var stateIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("States.Key")); if (stateIndex == null) @@ -77,7 +97,7 @@ public class MongoDbContext private IMongoCollection CreateAgentTaskIndex() { - var collection = Database.GetCollection($"{_collectionPrefix}_AgentTasks"); + var collection = GetCollectionOrCreate("AgentTasks"); var indexes = collection.Indexes.List().ToList(); var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreatedTime")); if (createTimeIndex == null) @@ -90,12 +110,12 @@ public class MongoDbContext private IMongoCollection CreateContentLogIndex() { - var collection = Database.GetCollection($"{_collectionPrefix}_ConversationContentLogs"); + var collection = GetCollectionOrCreate("ConversationContentLogs"); var indexes = collection.Indexes.List().ToList(); var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreateTime")); if (createTimeIndex == null) { - var indexDef = Builders.IndexKeys.Ascending(x => x.CreateTime); + var indexDef = Builders.IndexKeys.Ascending(x => x.CreatedTime); collection.Indexes.CreateOne(new CreateIndexModel(indexDef)); } return collection; @@ -103,12 +123,12 @@ public class MongoDbContext private IMongoCollection CreateStateLogIndex() { - var collection = Database.GetCollection($"{_collectionPrefix}_ConversationStateLogs"); + var collection = GetCollectionOrCreate("ConversationStateLogs"); var indexes = collection.Indexes.List().ToList(); var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreateTime")); if (createTimeIndex == null) { - var indexDef = Builders.IndexKeys.Ascending(x => x.CreateTime); + var indexDef = Builders.IndexKeys.Ascending(x => x.CreatedTime); collection.Indexes.CreateOne(new CreateIndexModel(indexDef)); } return collection; @@ -116,7 +136,7 @@ public class MongoDbContext #endregion public IMongoCollection Agents - => Database.GetCollection($"{_collectionPrefix}_Agents"); + => GetCollectionOrCreate("Agents"); public IMongoCollection AgentTasks => CreateAgentTaskIndex(); @@ -125,16 +145,16 @@ public class MongoDbContext => CreateConversationIndex(); public IMongoCollection ConversationDialogs - => Database.GetCollection($"{_collectionPrefix}_ConversationDialogs"); + => GetCollectionOrCreate("ConversationDialogs"); public IMongoCollection ConversationStates => CreateConversationStateIndex(); public IMongoCollection ExectionLogs - => Database.GetCollection($"{_collectionPrefix}_ExecutionLogs"); + => GetCollectionOrCreate("ExecutionLogs"); public IMongoCollection LlmCompletionLogs - => Database.GetCollection($"{_collectionPrefix}_LlmCompletionLogs"); + => GetCollectionOrCreate("LlmCompletionLogs"); public IMongoCollection ContentLogs => CreateContentLogIndex(); @@ -143,33 +163,33 @@ public class MongoDbContext => CreateStateLogIndex(); public IMongoCollection Users - => Database.GetCollection($"{_collectionPrefix}_Users"); + => GetCollectionOrCreate("Users"); public IMongoCollection UserAgents - => Database.GetCollection($"{_collectionPrefix}_UserAgents"); + => GetCollectionOrCreate("UserAgents"); public IMongoCollection Plugins - => Database.GetCollection($"{_collectionPrefix}_Plugins"); + => GetCollectionOrCreate("Plugins"); public IMongoCollection TranslationMemories - => Database.GetCollection($"{_collectionPrefix}_TranslationMemories"); + => GetCollectionOrCreate("TranslationMemories"); public IMongoCollection KnowledgeCollectionConfigs - => Database.GetCollection($"{_collectionPrefix}_KnowledgeCollectionConfigs"); + => GetCollectionOrCreate("KnowledgeCollectionConfigs"); public IMongoCollection KnowledgeCollectionFileMeta - => Database.GetCollection($"{_collectionPrefix}_KnowledgeCollectionFileMeta"); + => GetCollectionOrCreate("KnowledgeCollectionFileMeta"); public IMongoCollection Roles - => Database.GetCollection($"{_collectionPrefix}_Roles"); + => GetCollectionOrCreate("Roles"); public IMongoCollection RoleAgents - => Database.GetCollection($"{_collectionPrefix}_RoleAgents"); + => GetCollectionOrCreate("RoleAgents"); public IMongoCollection CrontabItems - => Database.GetCollection($"{_collectionPrefix}_CronTabItems"); + => GetCollectionOrCreate("CronTabItems"); public IMongoCollection GlobalStatistics - => Database.GetCollection($"{_collectionPrefix}_GlobalStatistics"); + => GetCollectionOrCreate("GlobalStatistics"); -} +} \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index cabaecd2..4c579bc5 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -534,7 +534,7 @@ public partial class MongoRepository var truncatedDialogs = foundDialog.Dialogs.Where((x, idx) => idx < foundIdx).ToList(); // Handle truncated states - var refTime = foundDialog.Dialogs.ElementAt(foundIdx).MetaData.CreateTime; + var refTime = foundDialog.Dialogs.ElementAt(foundIdx).MetaData.CreatedTime; var stateFilter = Builders.Filter.Eq(x => x.ConversationId, conversationId); var foundStates = _dc.ConversationStates.Find(stateFilter).FirstOrDefault(); @@ -596,12 +596,12 @@ public partial class MongoRepository var contentLogFilters = new List>() { contentLogBuilder.Eq(x => x.ConversationId, conversationId), - contentLogBuilder.Gte(x => x.CreateTime, refTime) + contentLogBuilder.Gte(x => x.CreatedTime, refTime) }; var stateLogFilters = new List>() { stateLogBuilder.Eq(x => x.ConversationId, conversationId), - stateLogBuilder.Gte(x => x.CreateTime, refTime) + stateLogBuilder.Gte(x => x.CreatedTime, refTime) }; _dc.ContentLogs.DeleteMany(contentLogBuilder.And(contentLogFilters)); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs index 1ceffb44..e47ed1c3 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs @@ -17,7 +17,7 @@ public partial class MongoRepository Type = x.Type, VectorStore = KnowledgeVectorStoreConfigMongoModel.ToMongoModel(x.VectorStore), TextEmbedding = KnowledgeEmbeddingConfigMongoModel.ToMongoModel(x.TextEmbedding) - })?.ToList() ?? new List(); + })?.ToList() ?? []; if (reset) { @@ -136,7 +136,7 @@ public partial class MongoRepository VectorStoreProvider = metaData.VectorStoreProvider, VectorDataIds = metaData.VectorDataIds, RefData = KnowledgeFileMetaRefMongoModel.ToMongoModel(metaData.RefData), - CreateDate = metaData.CreateDate, + CreatedDate = metaData.CreateDate, CreateUserId = metaData.CreateUserId }; @@ -208,7 +208,7 @@ public partial class MongoRepository } var filterDef = builder.And(docFilters); - var sortDef = Builders.Sort.Descending(x => x.CreateDate); + var sortDef = Builders.Sort.Descending(x => x.CreatedDate); var docs = _dc.KnowledgeCollectionFileMeta.Find(filterDef).Sort(sortDef).Skip(filter.Offset).Limit(filter.Size).ToList(); var count = _dc.KnowledgeCollectionFileMeta.CountDocuments(filterDef); @@ -222,9 +222,9 @@ public partial class MongoRepository VectorStoreProvider = x.VectorStoreProvider, VectorDataIds = x.VectorDataIds, RefData = KnowledgeFileMetaRefMongoModel.ToDomainModel(x.RefData), - CreateDate = x.CreateDate, + CreateDate = x.CreatedDate, CreateUserId = x.CreateUserId - })?.ToList() ?? new(); + })?.ToList() ?? []; return new PagedItems { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs index f053177f..88f6ed30 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs @@ -74,7 +74,7 @@ public partial class MongoRepository Role = log.Role, Source = log.Source, Content = log.Content, - CreateTime = log.CreateTime + CreatedTime = log.CreateTime }; _dc.ContentLogs.InsertOne(logDoc); @@ -94,7 +94,7 @@ public partial class MongoRepository Role = x.Role, Source = x.Source, Content = x.Content, - CreateTime = x.CreateTime + CreateTime = x.CreatedTime }) .OrderBy(x => x.CreateTime) .ToList(); @@ -116,7 +116,7 @@ public partial class MongoRepository AgentId= log.AgentId, MessageId = log.MessageId, States = log.States, - CreateTime = log.CreateTime + CreatedTime = log.CreateTime }; _dc.StateLogs.InsertOne(logDoc); @@ -133,7 +133,7 @@ public partial class MongoRepository AgentId = x.AgentId, MessageId = x.MessageId, States = x.States, - CreateTime = x.CreateTime + CreateTime = x.CreatedTime }) .OrderBy(x => x.CreateTime) .ToList(); diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Translation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Translation.cs index 5f0e987e..6ab26792 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Translation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Translation.cs @@ -49,7 +49,7 @@ public partial class MongoRepository var hashTexts = inputs.Where(x => !string.IsNullOrEmpty(x.HashText)).Select(x => x.HashText).ToList(); var filter = Builders.Filter.In(x => x.HashText, hashTexts); - var memories = _dc.TranslationMemories.Find(filter)?.ToList() ?? new List(); + var memories = _dc.TranslationMemories.Find(filter)?.ToList() ?? []; var newMemories = new List(); var updateMemories = new List(); @@ -90,7 +90,7 @@ public partial class MongoRepository if (foundMemory.Translations == null) { - foundMemory.Translations = new List { newItem }; + foundMemory.Translations = [newItem]; } else { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs index 9c88e8bd..a6f316f2 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs @@ -76,13 +76,13 @@ public partial class MongoRepository public List GetUserByIds(List ids) { var users = _dc.Users.AsQueryable().Where(x => ids.Contains(x.Id) || (x.ExternalId != null && ids.Contains(x.ExternalId))).ToList(); - return users?.Any() == true ? users.Select(x => x.ToUser()).ToList() : new List(); + return users?.Any() == true ? users.Select(x => x.ToUser()).ToList() : []; } public List GetUsersByAffiliateId(string affiliateId) { var users = _dc.Users.AsQueryable().Where(x => x.AffiliateId == affiliateId).ToList(); - return users?.Any() == true ? users.Select(x => x.ToUser()).ToList() : new List(); + return users?.Any() == true ? users.Select(x => x.ToUser()).ToList() : []; } public User? GetUserByUserName(string userName) @@ -259,13 +259,13 @@ public partial class MongoRepository public List SearchLoginUsers(User filter, string source = UserSource.Internal) { - List searchResult = new List(); + List searchResult = []; // search by filters if (!string.IsNullOrWhiteSpace(filter.Id)) { var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Id == filter.Id.ToLower()); - User user = curUser != null ? curUser.ToUser() : null; + User? user = curUser != null ? curUser.ToUser() : null; if (user != null) { searchResult.Add(user); @@ -307,7 +307,7 @@ public partial class MongoRepository else if (!string.IsNullOrWhiteSpace(filter.Email)) { var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Email == filter.Email.ToLower()); - User user = curUser != null ? curUser.ToUser() : null; + User? user = curUser != null ? curUser.ToUser() : null; if (user != null) { searchResult.Add(user); @@ -318,7 +318,7 @@ public partial class MongoRepository if (searchResult.Count == 0 && !string.IsNullOrWhiteSpace(filter.UserName)) { var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.UserName == filter.UserName); - User user = curUser != null ? curUser.ToUser() : null; + User? user = curUser != null ? curUser.ToUser() : null; if (user != null) { searchResult.Add(user); @@ -429,7 +429,7 @@ public partial class MongoRepository return true; } - public Dashboard? GetDashboard(string userId = null) + public Dashboard? GetDashboard(string? userId = null) { return null; }