| | | 1 | | using CShells.FastEndpoints.Features; |
| | | 2 | | using CShells.Features; |
| | | 3 | | using Elsa.AI.Host.Options; |
| | | 4 | | using Elsa.Extensions; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | | 7 | | |
| | | 8 | | namespace Elsa.AI.Host.ShellFeatures; |
| | | 9 | | |
| | | 10 | | [ShellFeature( |
| | | 11 | | "AI", |
| | | 12 | | DisplayName = "AI Host", |
| | | 13 | | Description = "Hosts Weaver AI orchestration, governed tools, proposals, and audit services", |
| | | 14 | | DependsOn = ["ElsaFastEndpoints"])] |
| | | 15 | | [UsedImplicitly] |
| | | 16 | | public class AIFeature : IFastEndpointsShellFeature |
| | | 17 | | { |
| | 0 | 18 | | private static readonly AIHostOptions DefaultOptions = new(); |
| | | 19 | | |
| | 0 | 20 | | public bool StreamingEnabled { get; set; } = DefaultOptions.StreamingEnabled; |
| | 0 | 21 | | public bool ConversationPersistenceEnabled { get; set; } = DefaultOptions.ConversationPersistenceEnabled; |
| | 0 | 22 | | public bool ProposalReviewEnabled { get; set; } = DefaultOptions.ProposalReviewEnabled; |
| | 0 | 23 | | public TimeSpan ConversationRetention { get; set; } = DefaultOptions.ConversationRetention; |
| | 0 | 24 | | public TimeSpan ReconnectGrace { get; set; } = DefaultOptions.ReconnectGrace; |
| | 0 | 25 | | public int MaxToolResultBytes { get; set; } = DefaultOptions.MaxToolResultBytes; |
| | 0 | 26 | | public int MaxResolvedContextBytes { get; set; } = DefaultOptions.MaxResolvedContextBytes; |
| | 0 | 27 | | public string? DefaultProviderName { get; set; } = DefaultOptions.DefaultProviderName; |
| | 0 | 28 | | public ICollection<AIProviderOptions> Providers { get; set; } = []; |
| | 0 | 29 | | public ICollection<AIAgentOptions> Agents { get; set; } = [..DefaultOptions.Agents]; |
| | 0 | 30 | | public ICollection<string> SupportedAttachmentKinds { get; set; } = [..DefaultOptions.SupportedAttachmentKinds]; |
| | | 31 | | |
| | | 32 | | public void ConfigureServices(IServiceCollection services) |
| | | 33 | | { |
| | 0 | 34 | | services.AddAIHostServices(ConfigureOptions); |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | private void ConfigureOptions(AIHostOptions options) |
| | | 38 | | { |
| | 0 | 39 | | options.StreamingEnabled = StreamingEnabled; |
| | 0 | 40 | | options.ConversationPersistenceEnabled = ConversationPersistenceEnabled; |
| | 0 | 41 | | options.ProposalReviewEnabled = ProposalReviewEnabled; |
| | 0 | 42 | | options.ConversationRetention = ConversationRetention; |
| | 0 | 43 | | options.ReconnectGrace = ReconnectGrace; |
| | 0 | 44 | | options.MaxToolResultBytes = MaxToolResultBytes; |
| | 0 | 45 | | options.MaxResolvedContextBytes = MaxResolvedContextBytes; |
| | 0 | 46 | | options.DefaultProviderName = DefaultProviderName; |
| | 0 | 47 | | options.Providers = [..Providers]; |
| | 0 | 48 | | options.Agents = [..Agents]; |
| | 0 | 49 | | options.SupportedAttachmentKinds = [..SupportedAttachmentKinds]; |
| | 0 | 50 | | } |
| | | 51 | | } |