< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%

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{
 112    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{
 20    public string Id { get; set; } = "";
 21    public string BehaviorSpaceId { get; set; } = "";
 22    public string? EntityId { get; set; }
 23    public string IntentName { get; set; } = "";
 24    public string ConfidenceLevel { get; set; } = "";
 25    public double ConfidenceScore { get; set; }
 26    public string Decision { get; set; } = "";
 27    public DateTimeOffset RecordedAt { get; set; }
 28    public string MetadataJson { get; set; } = "{}";
 29
 30    public static IntentHistoryDocument From(IntentHistoryRecord record)
 31    {
 32        return new IntentHistoryDocument
 33        {
 34            Id = record.Id,
 35            BehaviorSpaceId = record.BehaviorSpaceId,
 36            EntityId = record.EntityId,
 37            IntentName = record.IntentName,
 38            ConfidenceLevel = record.ConfidenceLevel,
 39            ConfidenceScore = record.ConfidenceScore,
 40            Decision = record.Decision.ToString(),
 41            RecordedAt = record.RecordedAt,
 42            MetadataJson = record.Metadata != null ? JsonSerializer.Serialize(record.Metadata, IntentHistorySerializatio
 43        };
 44    }
 45
 46    public IntentHistoryRecord ToRecord()
 47    {
 48        var metadata = string.IsNullOrEmpty(MetadataJson) || MetadataJson == "{}"
 49            ? null
 50            : JsonSerializer.Deserialize<Dictionary<string, object>>(MetadataJson);
 51        return new IntentHistoryRecord(
 52            Id,
 53            BehaviorSpaceId,
 54            IntentName,
 55            ConfidenceLevel,
 56            ConfidenceScore,
 57            Enum.Parse<PolicyDecision>(Decision),
 58            RecordedAt,
 59            Metadata: metadata,
 60            EntityId: EntityId);
 61    }
 62}

Methods/Properties

.cctor()