| | | 1 | | using Elsa.AI.Abstractions.Contracts; |
| | | 2 | | using Elsa.AI.Host.Context; |
| | | 3 | | using Elsa.AI.Host.Options; |
| | | 4 | | using Elsa.AI.Host.Services; |
| | | 5 | | using Elsa.AI.Host.Streaming; |
| | | 6 | | using Elsa.AI.Host.Tools.Activities; |
| | | 7 | | using Elsa.AI.Host.Tools.Runtime; |
| | | 8 | | using Elsa.AI.Host.Tools.Workflows; |
| | | 9 | | using Microsoft.Extensions.DependencyInjection; |
| | | 10 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 11 | | using Microsoft.Extensions.Hosting; |
| | | 12 | | |
| | | 13 | | // ReSharper disable once CheckNamespace |
| | | 14 | | namespace Elsa.Extensions; |
| | | 15 | | |
| | | 16 | | public static class ServiceCollectionExtensions |
| | | 17 | | { |
| | | 18 | | public static IServiceCollection AddAIHostServices(this IServiceCollection services, Action<AIHostOptions>? configur |
| | | 19 | | { |
| | 56 | 20 | | if (configureOptions != null) |
| | 12 | 21 | | services.Configure(configureOptions); |
| | | 22 | | |
| | 56 | 23 | | services.AddLogging(); |
| | 56 | 24 | | services.AddOptions<AIHostOptions>(); |
| | 56 | 25 | | services.TryAddSingleton<InMemoryAIConversationStore>(); |
| | 95 | 26 | | services.TryAddSingleton<IAIConversationStore>(sp => sp.GetRequiredService<InMemoryAIConversationStore>()); |
| | 56 | 27 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IAIContextProvider, WorkflowDefinitionContextProvider>()); |
| | 56 | 28 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IAIContextProvider, WorkflowInstanceContextProvider>()); |
| | 56 | 29 | | services.TryAddSingleton<AIContextResolver>(); |
| | 56 | 30 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, AIContextProviderValidationHostedService>( |
| | 56 | 31 | | services.TryAddSingleton<AIToolEnablementService>(); |
| | 56 | 32 | | services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, AIToolEnablementConfigurationHostedService |
| | 56 | 33 | | services.TryAddSingleton<IAIToolRegistry, AIToolRegistry>(); |
| | 56 | 34 | | services.TryAddSingleton<AIGroundingResultFormatter>(); |
| | 56 | 35 | | services.TryAddSingleton<ActivityGroundingMapper>(); |
| | 56 | 36 | | services.TryAddSingleton<ActivityGroundingSearchService>(); |
| | 56 | 37 | | services.TryAddSingleton<WorkflowGroundingMapper>(); |
| | 56 | 38 | | services.TryAddSingleton<RuntimeGroundingMapper>(); |
| | 56 | 39 | | services.TryAddSingleton<WorkflowDraftValidationService>(); |
| | 56 | 40 | | services.TryAddSingleton<WorkflowProposalDiffService>(); |
| | 56 | 41 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, ActivitiesSearchTool>()); |
| | 56 | 42 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, ActivityDescriptorTool>()); |
| | 56 | 43 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowsSearchTool>()); |
| | 56 | 44 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowDefinitionTool>()); |
| | 56 | 45 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowDefinitionGraphTool>()); |
| | 56 | 46 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowUsageSearchTool>()); |
| | 56 | 47 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowValidateDraftTool>()); |
| | 56 | 48 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowProposeCreateTool>()); |
| | 56 | 49 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowProposeUpdateTool>()); |
| | 56 | 50 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, InstancesSearchTool>()); |
| | 56 | 51 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowInstanceTool>()); |
| | 56 | 52 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowInstanceExecutionHistoryTool>()); |
| | 56 | 53 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, WorkflowInstanceActivityStateTool>()); |
| | 56 | 54 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, IncidentsSearchTool>()); |
| | 56 | 55 | | services.TryAddEnumerable(ServiceDescriptor.Transient<IAITool, IncidentTool>()); |
| | 56 | 56 | | services.TryAddScoped<IAIOrchestrator, AIOrchestrator>(); |
| | 56 | 57 | | services.TryAddSingleton<AIStreamSessionManager>(); |
| | 56 | 58 | | services.TryAddSingleton<AIStreamEventMapper>(); |
| | 56 | 59 | | services.TryAddSingleton<AIAuditSink>(); |
| | 96 | 60 | | services.TryAddSingleton<IAIAuditSink>(sp => sp.GetRequiredService<AIAuditSink>()); |
| | | 61 | | |
| | 56 | 62 | | return services; |
| | | 63 | | } |
| | | 64 | | } |