< Summary

Information
Class: Elsa.AI.Host.Endpoints.AI.Capabilities.Response
Assembly: Elsa.AI.Host
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Endpoints/AI/Capabilities/Endpoint.cs
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 62
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Streaming()100%11100%
get_ConversationPersistence()100%11100%
get_ProposalReview()100%11100%
get_SupportedAttachmentKinds()100%11100%
get_Agents()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Endpoints/AI/Capabilities/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.AI.Abstractions.Contracts;
 3using Elsa.AI.Host.Options;
 4using Elsa.AI.Host.Permissions;
 5using JetBrains.Annotations;
 6using Microsoft.Extensions.Options;
 7
 8namespace Elsa.AI.Host.Endpoints.AI.Capabilities;
 9
 10[PublicAPI]
 11public class Endpoint(
 12    IOptions<AIHostOptions> options,
 13    IEnumerable<IAIProvider> providers,
 14    IEnumerable<IAIConversationStore> conversationStores,
 15    IEnumerable<IAIProposalStore> proposalStores) : ElsaEndpointWithoutRequest<Response>
 16{
 17    public override void Configure()
 18    {
 19        Get("/ai/capabilities");
 20        ConfigurePermissions(AIPermissions.ViewCapabilities);
 21    }
 22
 23    public override Task<Response> ExecuteAsync(CancellationToken cancellationToken)
 24    {
 25        var optionsValue = options.Value;
 26        var providerOptions = optionsValue.Providers.ToList();
 27        var availableProviders = providers.Where(x => providerOptions.IsProviderEnabled(x.Name)).ToList();
 28        var hasSelectableProvider = HasSelectableProvider(optionsValue.DefaultProviderName, providerOptions, availablePr
 29        var hasDurableConversationStore = conversationStores.Any(x => x is not IAITransientConversationStore);
 30
 31        return Task.FromResult(new Response(
 32            optionsValue.StreamingEnabled && hasSelectableProvider,
 33            optionsValue.ConversationPersistenceEnabled && hasDurableConversationStore,
 34            optionsValue.ProposalReviewEnabled && proposalStores.Any(),
 35            optionsValue.SupportedAttachmentKinds.ToList(),
 36            optionsValue.Agents.Select(x => new AIAgentCapability(x.Name, x.DisplayName, x.Description)).ToList()));
 37    }
 38
 39    private static bool HasSelectableProvider(string? providerName, IReadOnlyCollection<AIProviderOptions> providerOptio
 40    {
 41        if (!string.IsNullOrWhiteSpace(providerName))
 42        {
 43            var configuredProviders = providerOptions.Where(x => x.Enabled).ToList();
 44            var configuredProvider = configuredProviders.FirstOrDefault(x => string.Equals(x.Name, providerName, StringC
 45            return configuredProvider != null
 46                ? availableProviders.Any(x => string.Equals(x.Name, configuredProvider.Name, StringComparison.OrdinalIgn
 47                                              string.Equals(x.Name, configuredProvider.Provider, StringComparison.Ordina
 48                : availableProviders.Any(x => string.Equals(x.Name, providerName, StringComparison.OrdinalIgnoreCase));
 49        }
 50
 51        return availableProviders.Count == 1;
 52    }
 53}
 54
 755public record Response(
 456    bool Streaming,
 557    bool ConversationPersistence,
 258    bool ProposalReview,
 559    IReadOnlyCollection<string> SupportedAttachmentKinds,
 760    IReadOnlyCollection<AIAgentCapability> Agents);
 61
 62public record AIAgentCapability(string Name, string DisplayName, string Description);