< Summary

Information
Class: Intentum.Persistence.Repositories.IntentHistoryRecord
Assembly: Intentum.Persistence
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Persistence/Repositories/IIntentHistoryRepository.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 102
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
.ctor(...)100%11100%
Create(...)100%11100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Persistence/Repositories/IIntentHistoryRepository.cs

#LineLine coverage
 1using Intentum.Core.Intents;
 2using Intentum.Runtime.Policy;
 3
 4namespace Intentum.Persistence.Repositories;
 5
 6/// <summary>
 7/// Repository interface for storing intent inference results and policy decisions.
 8/// </summary>
 9public interface IIntentHistoryRepository
 10{
 11    /// <summary>
 12    /// Saves an intent inference result with policy decision.
 13    /// </summary>
 14    /// <param name="behaviorSpaceId">Identifier of the behavior space.</param>
 15    /// <param name="intent">The inferred intent.</param>
 16    /// <param name="decision">The policy decision.</param>
 17    /// <param name="metadata">Optional metadata (e.g. EventsSummary, Source) to show where the inference came from.</pa
 18    /// <param name="entityId">Optional entity identifier (e.g. userId) for timeline and entity-scoped queries.</param>
 19    /// <param name="cancellationToken">Cancellation token.</param>
 20    Task<string> SaveAsync(
 21        string behaviorSpaceId,
 22        Intent intent,
 23        PolicyDecision decision,
 24        IReadOnlyDictionary<string, object>? metadata = null,
 25        string? entityId = null,
 26        CancellationToken cancellationToken = default);
 27
 28    /// <summary>
 29    /// Gets intent history by behavior space ID.
 30    /// </summary>
 31    Task<IReadOnlyList<IntentHistoryRecord>> GetByBehaviorSpaceIdAsync(
 32        string behaviorSpaceId,
 33        CancellationToken cancellationToken = default);
 34
 35    /// <summary>
 36    /// Gets intent history by confidence level.
 37    /// </summary>
 38    Task<IReadOnlyList<IntentHistoryRecord>> GetByConfidenceLevelAsync(
 39        string confidenceLevel,
 40        CancellationToken cancellationToken = default);
 41
 42    /// <summary>
 43    /// Gets intent history by policy decision.
 44    /// </summary>
 45    Task<IReadOnlyList<IntentHistoryRecord>> GetByDecisionAsync(
 46        PolicyDecision decision,
 47        CancellationToken cancellationToken = default);
 48
 49    /// <summary>
 50    /// Gets intent history within a time window.
 51    /// </summary>
 52    Task<IReadOnlyList<IntentHistoryRecord>> GetByTimeWindowAsync(
 53        DateTimeOffset start,
 54        DateTimeOffset end,
 55        CancellationToken cancellationToken = default);
 56
 57    /// <summary>
 58    /// Gets intent history for an entity (e.g. userId) within a time window, ordered by RecordedAt.
 59    /// When entityId was not stored, use behaviorSpaceId as entity scope.
 60    /// </summary>
 61    Task<IReadOnlyList<IntentHistoryRecord>> GetByEntityIdAsync(
 62        string entityId,
 63        DateTimeOffset start,
 64        DateTimeOffset end,
 65        CancellationToken cancellationToken = default);
 66}
 67
 68/// <summary>
 69/// Record representing a stored intent inference result.
 70/// </summary>
 13771public sealed record IntentHistoryRecord(
 9572    string Id,
 7073    string BehaviorSpaceId,
 8874    string IntentName,
 5475    string ConfidenceLevel,
 6776    double ConfidenceScore,
 6477    PolicyDecision Decision,
 28578    DateTimeOffset RecordedAt,
 2079    IReadOnlyDictionary<string, object>? Metadata = null,
 3980    string? EntityId = null
 13781)
 82{
 83    /// <summary>
 84    /// Creates a new record with a generated ID and current UTC time. Use when saving to any store (Mongo, Redis, etc.)
 85    /// </summary>
 86    public static IntentHistoryRecord Create(
 87        string behaviorSpaceId,
 88        Intent intent,
 89        PolicyDecision decision,
 90        IReadOnlyDictionary<string, object>? metadata = null,
 91        string? entityId = null) =>
 7292        new(
 7293            Id: Guid.NewGuid().ToString(),
 7294            BehaviorSpaceId: behaviorSpaceId,
 7295            IntentName: intent.Name,
 7296            ConfidenceLevel: intent.Confidence.Level,
 7297            ConfidenceScore: intent.Confidence.Score,
 7298            Decision: decision,
 7299            RecordedAt: DateTimeOffset.UtcNow,
 72100            Metadata: metadata,
 72101            EntityId: entityId);
 102}