feat: Implement compact JSON serialization for history entries, improve history loading robustness, and add a new LLM model option.
This commit is contained in:
@@ -30,7 +30,7 @@ public static class HistoryManager
|
||||
DurationMs = durationMs
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(entry, AppJsonSerializerContext.Default.HistoryEntry);
|
||||
var json = JsonSerializer.Serialize(entry, CompactJsonSerializerContext.Default.HistoryEntry);
|
||||
|
||||
// Thread-safe append
|
||||
lock (HistoryFile)
|
||||
@@ -60,15 +60,25 @@ public static class HistoryManager
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line)) continue;
|
||||
var entry = JsonSerializer.Deserialize(line, AppJsonSerializerContext.Default.HistoryEntry);
|
||||
if (entry != null)
|
||||
if (!line.Trim().StartsWith("{") || !line.Trim().EndsWith("}")) continue; // Skip malformed old multiline json entries
|
||||
|
||||
try
|
||||
{
|
||||
entries.Add(entry);
|
||||
var entry = JsonSerializer.Deserialize(line, CompactJsonSerializerContext.Default.HistoryEntry);
|
||||
if (entry != null)
|
||||
{
|
||||
entries.Add(entry);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Skip entry if deserialization fails
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"CRASH IN LOAD ENTRIES: {ex}");
|
||||
Logger.LogDebug($"Failed to load history: {ex.Message}");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user