< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Workflows.Middleware.TranscriptLoggingChatClient
Assembly: NexusLabs.Needlr.AgentFramework.Workflows
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Middleware/TranscriptLoggingChatClient.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 64
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_CurrentStageName()100%11100%
set_CurrentStageName(...)100%11100%
GetResponseAsync()50%22100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Middleware/TranscriptLoggingChatClient.cs

#LineLine coverage
 1using Microsoft.Extensions.AI;
 2
 3namespace NexusLabs.Needlr.AgentFramework.Workflows.Middleware;
 4
 5/// <summary>
 6/// <see cref="DelegatingChatClient"/> middleware that intercepts
 7/// <see cref="GetResponseAsync"/> calls and writes request/response pairs to an
 8/// <see cref="ITranscriptWriter"/>.
 9/// </summary>
 10/// <remarks>
 11/// <para>
 12/// Set <see cref="CurrentStageName"/> before each pipeline stage to tag
 13/// transcript entries with the originating stage. If not set, entries default
 14/// to <c>"unknown"</c>.
 15/// </para>
 16/// <para>
 17/// This middleware does not buffer or transform messages — it records them
 18/// as-is and delegates to the inner client unchanged.
 19/// </para>
 20/// </remarks>
 21[DoNotAutoRegister]
 22public sealed class TranscriptLoggingChatClient : DelegatingChatClient
 23{
 24    private readonly ITranscriptWriter _writer;
 425    private string _currentStageName = "unknown";
 26
 27    /// <param name="innerClient">The inner chat client to delegate to.</param>
 28    /// <param name="writer">The transcript writer to record entries into.</param>
 29    public TranscriptLoggingChatClient(
 30        IChatClient innerClient,
 31        ITranscriptWriter writer)
 432        : base(innerClient)
 33    {
 434        ArgumentNullException.ThrowIfNull(writer);
 435        _writer = writer;
 436    }
 37
 38    /// <summary>
 39    /// Gets or sets the current stage name used to tag transcript entries.
 40    /// Call this before each stage execution.
 41    /// </summary>
 42    public string CurrentStageName
 43    {
 144        get => _currentStageName;
 145        set => _currentStageName = value;
 46    }
 47
 48    /// <inheritdoc />
 49    public override async Task<ChatResponse> GetResponseAsync(
 50        IEnumerable<ChatMessage> messages,
 51        ChatOptions? options = null,
 52        CancellationToken cancellationToken = default)
 53    {
 354        var messagesList = messages as IList<ChatMessage> ?? messages.ToList();
 355        _writer.WriteRequest(_currentStageName, messagesList, options);
 56
 357        var response = await base
 358            .GetResponseAsync(messagesList, options, cancellationToken)
 359            .ConfigureAwait(false);
 60
 361        _writer.WriteResponse(_currentStageName, response);
 362        return response;
 363    }
 64}