Size: 3.8 KB Modified: 4/07/2026 1:36 AM
namespace KaiChat.Models;

public class ChatMessage
{
    public string Id { get; set; } = Guid.NewGuid().ToString("N")[..8];
    public string Role { get; set; } = "";
    public string Content { get; set; } = "";
    public string? Thinking { get; set; }
    public ToolMessage? Tool { get; set; }
    public List<StoredToolCall> ToolCalls { get; set; } = new();
    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
    public CompactionMessage? Compaction { get; set; }
    public MemorySweepMessage? MemorySweep { get; set; }
}

public class StoredToolCall
{
    public string Id { get; set; } = "";
    public string Name { get; set; } = "";
    public string Arguments { get; set; } = "";
}

public class ToolMessage
{
    public int Round { get; set; }
    public string ToolCallId { get; set; } = "";
    public string Method { get; set; } = "";
    public string Path { get; set; } = "";
    public string Body { get; set; } = "";
    public string Status { get; set; } = "";
    public bool IsError { get; set; }
    public string Result { get; set; } = "";
}

public class Conversation
{
    public string Id { get; set; } = Guid.NewGuid().ToString("N")[..8];
    public string Title { get; set; } = "New Chat";
    public bool TitleAutoGenerated { get; set; } = true;
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
    public List<ChatMessage> Messages { get; set; } = new();
    public string? CompactedSummary { get; set; }      // Summarized history after compaction
    public int CompactionCount { get; set; } = 0;       // How many times this convo was compacted
    public List<CompactionArchiveEntry> CompactionArchives { get; set; } = new();
}

public class CompactionArchiveEntry
{
    public int CompactionNumber { get; set; }
    public string ArchivePath { get; set; } = "";
    public string? PreviousArchivePath { get; set; }
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    public int ArchivedMessageCount { get; set; }
    public string? FirstArchivedMessageId { get; set; }
    public string? LastArchivedMessageId { get; set; }
    public DateTime? FirstArchivedTimestamp { get; set; }
    public DateTime? LastArchivedTimestamp { get; set; }
    public int EstimatedArchivedTokens { get; set; }
    public string SummaryHash { get; set; } = "";
}

public class CompactionMessage
{
    public int CompactionNumber { get; set; }
    public string? ArchivePath { get; set; }
    public string? PreviousArchivePath { get; set; }
    public int MessagesToCompact { get; set; }
    public int MessagesToKeep { get; set; }
    public int ChunkCount { get; set; }
    public int EstimatedApiTokens { get; set; }
    public int EstimatedPostCompactionApiTokens { get; set; }
    public DateTime StartedAt { get; set; } = DateTime.UtcNow;
    public DateTime CompletedAt { get; set; } = DateTime.UtcNow;
}

public class MemorySweepMessage
{
    public int CompactionNumber { get; set; }
    public int MessagesSwept { get; set; }
    public bool Changed { get; set; }
    public bool Success { get; set; }
    public int OperationCount { get; set; }
    public int WriteCount { get; set; }
    public int DeleteCount { get; set; }
    public int FailedCount { get; set; }
    public string Status { get; set; } = "";
    public string RawResponsePreview { get; set; } = "";
    public List<MemorySweepOperation> Operations { get; set; } = new();
    public DateTime StartedAt { get; set; } = DateTime.UtcNow;
    public DateTime CompletedAt { get; set; } = DateTime.UtcNow;
}

public class MemorySweepOperation
{
    public string Action { get; set; } = "";
    public string Path { get; set; } = "";
    public bool Success { get; set; }
    public string Message { get; set; } = "";
    public string? Reason { get; set; }
}
Offline