| | | 1 | | using Elsa.AI.Host.Options; |
| | | 2 | | using Elsa.AI.Host.Services; |
| | | 3 | | using Elsa.Extensions; |
| | | 4 | | using Elsa.Features.Abstractions; |
| | | 5 | | using Elsa.Features.Services; |
| | | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | | 7 | | |
| | | 8 | | namespace Elsa.AI.Host.Features; |
| | | 9 | | |
| | 0 | 10 | | public class AIFeature(IModule module) : FeatureBase(module) |
| | | 11 | | { |
| | 0 | 12 | | public Action<AIHostOptions>? ConfigureOptions { get; set; } |
| | 0 | 13 | | public Action<AIToolEnablementService>? ConfigureToolEnablement { get; set; } |
| | | 14 | | |
| | | 15 | | public override void Configure() |
| | | 16 | | { |
| | 0 | 17 | | Module.AddFastEndpointsAssembly<AIFeature>(); |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public override void Apply() |
| | | 21 | | { |
| | 0 | 22 | | Services.AddAIHostServices(ConfigureOptions); |
| | 0 | 23 | | if (ConfigureToolEnablement != null) |
| | 0 | 24 | | Services.AddSingleton(ConfigureToolEnablement); |
| | 0 | 25 | | Module.AddFastEndpointsFromModule(); |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | public AIFeature EnableWorkflowProposalTools() |
| | | 29 | | { |
| | 0 | 30 | | ConfigureToolEnablement += enablement => |
| | 0 | 31 | | { |
| | 0 | 32 | | enablement.Enable("workflows.proposeCreate"); |
| | 0 | 33 | | enablement.Enable("workflows.proposeUpdate"); |
| | 0 | 34 | | }; |
| | 0 | 35 | | return this; |
| | | 36 | | } |
| | | 37 | | } |