< Summary

Information
Class: Intentum.Persistence.Serialization.IntentHistoryDocument
Assembly: Intentum.Persistence
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Persistence/Serialization/IntentHistorySerialization.cs
Line coverage
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 62
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
From(...)100%22100%
ToRecord()100%44100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Persistence/Serialization/IntentHistorySerialization.cs

#LineLine coverage
 1using System.Text.Json;
 2using Intentum.Persistence.Repositories;
 3using Intentum.Runtime.Policy;
 4
 5namespace Intentum.Persistence.Serialization;
 6
 7/// <summary>
 8/// Shared JSON options and document type for intent history across MongoDB and Redis.
 9/// </summary>
 10public static class IntentHistorySerialization
 11{
 12    public static readonly JsonSerializerOptions JsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase
 13}
 14
 15/// <summary>
 16/// Document shape for intent history (MongoDB and Redis).
 17/// </summary>
 18public sealed class IntentHistoryDocument
 19{
 3920    public string Id { get; set; } = "";
 3921    public string BehaviorSpaceId { get; set; } = "";
 2422    public string? EntityId { get; set; }
 3923    public string IntentName { get; set; } = "";
 3924    public string ConfidenceLevel { get; set; } = "";
 2625    public double ConfidenceScore { get; set; }
 3926    public string Decision { get; set; } = "";
 2627    public DateTimeOffset RecordedAt { get; set; }
 5428    public string MetadataJson { get; set; } = "{}";
 29
 30    public static IntentHistoryDocument From(IntentHistoryRecord record)
 1131    {
 1132        return new IntentHistoryDocument
 1133        {
 1134            Id = record.Id,
 1135            BehaviorSpaceId = record.BehaviorSpaceId,
 1136            EntityId = record.EntityId,
 1137            IntentName = record.IntentName,
 1138            ConfidenceLevel = record.ConfidenceLevel,
 1139            ConfidenceScore = record.ConfidenceScore,
 1140            Decision = record.Decision.ToString(),
 1141            RecordedAt = record.RecordedAt,
 1142            MetadataJson = record.Metadata != null ? JsonSerializer.Serialize(record.Metadata, IntentHistorySerializatio
 1143        };
 1144    }
 45
 46    public IntentHistoryRecord ToRecord()
 1247    {
 1248        var metadata = string.IsNullOrEmpty(MetadataJson) || MetadataJson == "{}"
 1249            ? null
 1250            : JsonSerializer.Deserialize<Dictionary<string, object>>(MetadataJson);
 1251        return new IntentHistoryRecord(
 1252            Id,
 1253            BehaviorSpaceId,
 1254            IntentName,
 1255            ConfidenceLevel,
 1256            ConfidenceScore,
 1257            Enum.Parse<PolicyDecision>(Decision),
 1258            RecordedAt,
 1259            Metadata: metadata,
 1260            EntityId: EntityId);
 1261    }
 62}