< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Diagnostics.AgentRunDiagnosticsTimelineExtensions
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Diagnostics/AgentRunDiagnosticsTimelineExtensions.cs
Line coverage
97%
Covered lines: 34
Uncovered lines: 1
Coverable lines: 35
Total lines: 64
Line coverage: 97.1%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetOrderedTimeline(...)80%101097.14%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Diagnostics/AgentRunDiagnosticsTimelineExtensions.cs

#LineLine coverage
 1namespace NexusLabs.Needlr.AgentFramework.Diagnostics;
 2
 3/// <summary>
 4/// Extensions for producing ordered timeline views of an <see cref="IAgentRunDiagnostics"/>.
 5/// </summary>
 6public static class AgentRunDiagnosticsTimelineExtensions
 7{
 8    /// <summary>
 9    /// Merges the chat completions and tool calls into a single list ordered by
 10    /// <see cref="DiagnosticsTimelineEntry.StartedAt"/> (ascending), with
 11    /// <see cref="DiagnosticsTimelineEntry.Sequence"/> as a tiebreaker within the same
 12    /// kind.
 13    /// </summary>
 14    /// <param name="diagnostics">The agent run diagnostics to project.</param>
 15    /// <returns>A snapshot list of timeline entries. Never <see langword="null"/>; may be empty.</returns>
 16    public static IReadOnlyList<DiagnosticsTimelineEntry> GetOrderedTimeline(
 17        this IAgentRunDiagnostics diagnostics)
 18    {
 1519        ArgumentNullException.ThrowIfNull(diagnostics);
 20
 1421        var entries = new List<DiagnosticsTimelineEntry>(
 1422            diagnostics.ChatCompletions.Count + diagnostics.ToolCalls.Count);
 23
 5024        foreach (var chat in diagnostics.ChatCompletions)
 25        {
 1126            entries.Add(new DiagnosticsTimelineEntry(
 1127                Kind: DiagnosticsTimelineEntryKind.ChatCompletion,
 1128                Sequence: chat.Sequence,
 1129                StartedAt: chat.StartedAt,
 1130                CompletedAt: chat.CompletedAt,
 1131                ChatCompletion: chat,
 1132                ToolCall: null));
 33        }
 34
 4435        foreach (var tool in diagnostics.ToolCalls)
 36        {
 837            entries.Add(new DiagnosticsTimelineEntry(
 838                Kind: DiagnosticsTimelineEntryKind.ToolCall,
 839                Sequence: tool.Sequence,
 840                StartedAt: tool.StartedAt,
 841                CompletedAt: tool.CompletedAt,
 842                ChatCompletion: null,
 843                ToolCall: tool));
 44        }
 45
 1446        entries.Sort(static (a, b) =>
 1447        {
 1348            var startedComparison = a.StartedAt.CompareTo(b.StartedAt);
 1349            if (startedComparison != 0)
 1450            {
 1251                return startedComparison;
 1452            }
 1453
 154            if (a.Kind == b.Kind)
 1455            {
 056                return a.Sequence.CompareTo(b.Sequence);
 1457            }
 1458
 159            return a.Kind == DiagnosticsTimelineEntryKind.ChatCompletion ? -1 : 1;
 1460        });
 61
 1462        return entries;
 63    }
 64}