| | | 1 | | using System.Collections.Concurrent; |
| | | 2 | | using Elsa.AI.Abstractions.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.AI.Host.Services; |
| | | 5 | | |
| | | 6 | | public class AIToolEnablementService |
| | | 7 | | { |
| | 65 | 8 | | private readonly ConcurrentDictionary<string, byte> _enabledToolNames = new(StringComparer.OrdinalIgnoreCase); |
| | 65 | 9 | | private readonly ConcurrentDictionary<string, byte> _enabledAdministrativeToolNames = new(StringComparer.OrdinalIgno |
| | | 10 | | |
| | | 11 | | public bool IsEnabled(AIToolDefinition definition) |
| | | 12 | | { |
| | 1051 | 13 | | if (definition.Mutability == AIToolMutability.Administrative) |
| | 3 | 14 | | return _enabledAdministrativeToolNames.ContainsKey(definition.Name); |
| | | 15 | | |
| | 1048 | 16 | | if (definition.Mutability == AIToolMutability.Proposal) |
| | 1004 | 17 | | return _enabledToolNames.ContainsKey(definition.Name); |
| | | 18 | | |
| | 44 | 19 | | if (definition.Mutability == AIToolMutability.ReadOnly) |
| | 44 | 20 | | return true; |
| | | 21 | | |
| | 0 | 22 | | if (definition.EnabledByDefault) |
| | 0 | 23 | | return true; |
| | | 24 | | |
| | 0 | 25 | | 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 | | { |
| | 503 | 33 | | _enabledToolNames.TryAdd(toolName, 0); |
| | 503 | 34 | | } |
| | | 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 | | { |
| | 1 | 41 | | _enabledAdministrativeToolNames.TryAdd(toolName, 0); |
| | 1 | 42 | | } |
| | | 43 | | |
| | | 44 | | public void Disable(string toolName) |
| | | 45 | | { |
| | 500 | 46 | | _enabledToolNames.TryRemove(toolName, out _); |
| | 500 | 47 | | _enabledAdministrativeToolNames.TryRemove(toolName, out _); |
| | 500 | 48 | | } |
| | | 49 | | } |