< Summary

Information
Class: Elsa.AI.Host.Services.AIToolEnablementService
Assembly: Elsa.AI.Host
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Services/AIToolEnablementService.cs
Line coverage
83%
Covered lines: 15
Uncovered lines: 3
Coverable lines: 18
Total lines: 49
Line coverage: 83.3%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
IsEnabled(...)62.5%10866.66%
Enable(...)100%11100%
EnableAdministrative(...)100%11100%
Disable(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Services/AIToolEnablementService.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2using Elsa.AI.Abstractions.Models;
 3
 4namespace Elsa.AI.Host.Services;
 5
 6public class AIToolEnablementService
 7{
 658    private readonly ConcurrentDictionary<string, byte> _enabledToolNames = new(StringComparer.OrdinalIgnoreCase);
 659    private readonly ConcurrentDictionary<string, byte> _enabledAdministrativeToolNames = new(StringComparer.OrdinalIgno
 10
 11    public bool IsEnabled(AIToolDefinition definition)
 12    {
 105113        if (definition.Mutability == AIToolMutability.Administrative)
 314            return _enabledAdministrativeToolNames.ContainsKey(definition.Name);
 15
 104816        if (definition.Mutability == AIToolMutability.Proposal)
 100417            return _enabledToolNames.ContainsKey(definition.Name);
 18
 4419        if (definition.Mutability == AIToolMutability.ReadOnly)
 4420            return true;
 21
 022        if (definition.EnabledByDefault)
 023            return true;
 24
 025        return _enabledToolNames.ContainsKey(definition.Name);
 26    }
 27
 28    /// <summary>
 29    /// Enables a non-administrative tool by name. Administrative tools remain disabled by this service and must be expo
 30    /// </summary>
 31    public void Enable(string toolName)
 32    {
 50333        _enabledToolNames.TryAdd(toolName, 0);
 50334    }
 35
 36    /// <summary>
 37    /// Enables an administrative tool by name. Callers must wrap this in their own governed approval and audit path.
 38    /// </summary>
 39    public void EnableAdministrative(string toolName)
 40    {
 141        _enabledAdministrativeToolNames.TryAdd(toolName, 0);
 142    }
 43
 44    public void Disable(string toolName)
 45    {
 50046        _enabledToolNames.TryRemove(toolName, out _);
 50047        _enabledAdministrativeToolNames.TryRemove(toolName, out _);
 50048    }
 49}