refine document

This commit is contained in:
Jicheng Lu 2025-03-06 17:44:49 -06:00
parent 8fd5ac1315
commit 6c735a0aad
4 changed files with 30 additions and 14 deletions

View file

@ -13,6 +13,9 @@ public class PluginMenuDef(string label, string? link = null, string? icon = nul
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Link { get; set; } = link;
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? IFrameUrl { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool? IsHeader { get; set; }

View file

@ -2,7 +2,7 @@ using BotSharp.Abstraction.Loggers.Models;
namespace BotSharp.Plugin.MongoStorage.Collections;
public class InstructionLogBetaDocument : MongoBase
public class InstructionLogDocument : MongoBase
{
public string? AgentId { get; set; }
public string Provider { get; set; } = default!;
@ -15,9 +15,9 @@ public class InstructionLogBetaDocument : MongoBase
public Dictionary<string, BsonDocument> States { get; set; } = new();
public DateTime CreatedTime { get; set; }
public static InstructionLogBetaDocument ToMongoModel(InstructionLogModel log)
public static InstructionLogDocument ToMongoModel(InstructionLogModel log)
{
return new InstructionLogBetaDocument
return new InstructionLogDocument
{
AgentId = log.AgentId,
Provider = log.Provider,
@ -31,7 +31,7 @@ public class InstructionLogBetaDocument : MongoBase
};
}
public static InstructionLogModel ToDomainModel(InstructionLogBetaDocument log)
public static InstructionLogModel ToDomainModel(InstructionLogDocument log)
{
return new InstructionLogModel
{

View file

@ -115,7 +115,7 @@ public class MongoDbContext
{
var collection = GetCollectionOrCreate<ConversationContentLogDocument>("ConversationContentLogs");
var indexes = collection.Indexes.List().ToList();
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreateTime"));
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreatedTime"));
if (createTimeIndex == null)
{
var indexDef = Builders<ConversationContentLogDocument>.IndexKeys.Ascending(x => x.CreatedTime);
@ -128,7 +128,7 @@ public class MongoDbContext
{
var collection = GetCollectionOrCreate<ConversationStateLogDocument>("ConversationStateLogs");
var indexes = collection.Indexes.List().ToList();
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreateTime"));
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreatedTime"));
if (createTimeIndex == null)
{
var indexDef = Builders<ConversationStateLogDocument>.IndexKeys.Ascending(x => x.CreatedTime);
@ -136,6 +136,19 @@ public class MongoDbContext
}
return collection;
}
private IMongoCollection<InstructionLogDocument> CreateInstructionLogIndex()
{
var collection = GetCollectionOrCreate<InstructionLogDocument>("InstructionLogs");
var indexes = collection.Indexes.List().ToList();
var createTimeIndex = indexes.FirstOrDefault(x => x.GetElement("name").ToString().StartsWith("CreatedTime"));
if (createTimeIndex == null)
{
var indexDef = Builders<InstructionLogDocument>.IndexKeys.Descending(x => x.CreatedTime);
collection.Indexes.CreateOne(new CreateIndexModel<InstructionLogDocument>(indexDef));
}
return collection;
}
#endregion
#endregion
@ -193,6 +206,6 @@ public class MongoDbContext
public IMongoCollection<GlobalStatisticsDocument> GlobalStatistics
=> GetCollectionOrCreate<GlobalStatisticsDocument>("GlobalStatistics");
public IMongoCollection<InstructionLogBetaDocument> InstructionLogs
=> GetCollectionOrCreate<InstructionLogBetaDocument>("InstructionLogs");
public IMongoCollection<InstructionLogDocument> InstructionLogs
=> CreateInstructionLogIndex();
}

View file

@ -119,10 +119,10 @@ public partial class MongoRepository
{
if (logs.IsNullOrEmpty()) return false;
var docs = new List<InstructionLogBetaDocument>();
var docs = new List<InstructionLogDocument>();
foreach (var log in logs)
{
var doc = InstructionLogBetaDocument.ToMongoModel(log);
var doc = InstructionLogDocument.ToMongoModel(log);
foreach (var pair in log.States)
{
try
@ -152,8 +152,8 @@ public partial class MongoRepository
filter = InstructLogFilter.Empty();
}
var builder = Builders<InstructionLogBetaDocument>.Filter;
var filters = new List<FilterDefinition<InstructionLogBetaDocument>>() { builder.Empty };
var builder = Builders<InstructionLogDocument>.Filter;
var filters = new List<FilterDefinition<InstructionLogDocument>>() { builder.Empty };
// Filter logs
if (!filter.AgentIds.IsNullOrEmpty())
@ -174,13 +174,13 @@ public partial class MongoRepository
}
var filterDef = builder.And(filters);
var sortDef = Builders<InstructionLogBetaDocument>.Sort.Descending(x => x.CreatedTime);
var sortDef = Builders<InstructionLogDocument>.Sort.Descending(x => x.CreatedTime);
var docs = _dc.InstructionLogs.Find(filterDef).Sort(sortDef).Skip(filter.Offset).Limit(filter.Size).ToList();
var count = _dc.InstructionLogs.CountDocuments(filterDef);
var logs = docs.Select(x =>
{
var log = InstructionLogBetaDocument.ToDomainModel(x);
var log = InstructionLogDocument.ToDomainModel(x);
log.States = x.States.ToDictionary(p => p.Key, p =>
{
var jsonStr = p.Value.ToJson();