< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Langfuse.LangfuseScoreConfigClient
Assembly: NexusLabs.Needlr.AgentFramework.Langfuse
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Langfuse/LangfuseScoreConfigClient.cs
Line coverage
82%
Covered lines: 23
Uncovered lines: 5
Coverable lines: 28
Total lines: 69
Line coverage: 82.1%
Branch coverage
58%
Covered branches: 7
Total branches: 12
Branch coverage: 58.3%
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_IsEnabled()100%210%
EnsureScoreConfigAsync()100%22100%
ConfigExistsAsync()57.14%191471.42%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Langfuse/LangfuseScoreConfigClient.cs

#LineLine coverage
 1namespace NexusLabs.Needlr.AgentFramework.Langfuse;
 2
 3/// <summary>
 4/// Default <see cref="ILangfuseScoreConfigClient"/> that ensures score configs via the shared
 5/// <see cref="LangfuseApiClient"/>. Existence is checked by paging
 6/// <c>GET /api/public/score-configs</c> and matching on name; a config is created only when absent.
 7/// </summary>
 8internal sealed class LangfuseScoreConfigClient : ILangfuseScoreConfigClient
 9{
 10    private const int PageSize = 100;
 11
 12    private readonly LangfuseApiClient _apiClient;
 13
 414    public LangfuseScoreConfigClient(LangfuseApiClient apiClient)
 15    {
 416        ArgumentNullException.ThrowIfNull(apiClient);
 17
 418        _apiClient = apiClient;
 419    }
 20
 21    /// <inheritdoc />
 022    public bool IsEnabled => true;
 23
 24    /// <inheritdoc />
 25    public async Task EnsureScoreConfigAsync(LangfuseScoreConfig config, CancellationToken cancellationToken = default)
 26    {
 327        ArgumentNullException.ThrowIfNull(config);
 328        ArgumentException.ThrowIfNullOrWhiteSpace(config.Name);
 29
 330        if (await ConfigExistsAsync(config.Name, cancellationToken).ConfigureAwait(false))
 31        {
 132            return;
 33        }
 34
 235        await _apiClient
 236            .PostAsync("api/public/score-configs", LangfuseScoreConfigRequest.From(config), cancellationToken)
 237            .ConfigureAwait(false);
 338    }
 39
 40    private async Task<bool> ConfigExistsAsync(string name, CancellationToken cancellationToken)
 41    {
 342        var page = 1;
 043        while (true)
 44        {
 345            var response = await _apiClient
 346                .GetAsync<LangfuseScoreConfigsResponse>(
 347                    $"api/public/score-configs?page={page}&limit={PageSize}",
 348                    cancellationToken)
 349                .ConfigureAwait(false);
 50
 351            if (response?.Data is not { Count: > 0 } items)
 52            {
 253                return false;
 54            }
 55
 256            if (items.Any(c => string.Equals(c.Name, name, StringComparison.Ordinal)))
 57            {
 158                return true;
 59            }
 60
 061            if (response.Meta is not { } meta || page >= meta.TotalPages)
 62            {
 063                return false;
 64            }
 65
 066            page++;
 67        }
 368    }
 69}