< Summary

Information
Class: Elsa.AI.Host.Services.ActivityGroundingSearchService
Assembly: Elsa.AI.Host
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Services/ActivityGroundingSearchService.cs
Line coverage
68%
Covered lines: 22
Uncovered lines: 10
Coverable lines: 32
Total lines: 64
Line coverage: 68.7%
Branch coverage
36%
Covered branches: 17
Total branches: 46
Branch coverage: 36.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Search(...)40.9%602257.14%
Map(...)100%11100%
MatchesQuery(...)31.81%232287.5%
MatchesText(...)50%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Services/ActivityGroundingSearchService.cs

#LineLine coverage
 1using Elsa.Workflows;
 2using Elsa.Workflows.Models;
 3
 4namespace Elsa.AI.Host.Services;
 5
 446public class ActivityGroundingSearchService(ActivityGroundingMapper mapper)
 7{
 8    public IReadOnlyCollection<ActivityDescriptor> Search(
 9        IActivityRegistry registry,
 10        string? query,
 11        string? category,
 12        string? type,
 13        int? version,
 14        string? input,
 15        string? output,
 16        bool? trigger)
 17    {
 118        var descriptors = registry.ListAll().AsEnumerable();
 19
 120        if (!string.IsNullOrWhiteSpace(query))
 221            descriptors = descriptors.Where(x => MatchesQuery(x, query));
 22
 123        if (!string.IsNullOrWhiteSpace(category))
 024            descriptors = descriptors.Where(x => string.Equals(x.Category, category, StringComparison.OrdinalIgnoreCase)
 25
 126        if (!string.IsNullOrWhiteSpace(type))
 027            descriptors = descriptors.Where(x => string.Equals(x.TypeName, type, StringComparison.OrdinalIgnoreCase) ||
 028                                                 string.Equals(x.Name, type, StringComparison.OrdinalIgnoreCase));
 29
 130        if (version != null)
 031            descriptors = descriptors.Where(x => x.Version == version);
 32
 133        if (!string.IsNullOrWhiteSpace(input))
 034            descriptors = descriptors.Where(x => x.Inputs.Any(inputDescriptor => MatchesText(inputDescriptor.Name, input
 35
 136        if (!string.IsNullOrWhiteSpace(output))
 037            descriptors = descriptors.Where(x => x.Outputs.Any(outputDescriptor => MatchesText(outputDescriptor.Name, ou
 38
 139        if (trigger != null)
 240            descriptors = descriptors.Where(x => x.IsStart == trigger);
 41
 142        return descriptors
 043            .OrderBy(x => x.Category)
 044            .ThenBy(x => x.DisplayName ?? x.Name)
 045            .ThenByDescending(x => x.Version)
 146            .ToList();
 47    }
 48
 49    public JsonObject Map(ActivityDescriptor descriptor) =>
 150        AIGroundingJson.ToJsonObject(mapper.Map(descriptor));
 51
 52    private static bool MatchesQuery(ActivityDescriptor descriptor, string query) =>
 153        MatchesText(descriptor.Name, query) ||
 154        MatchesText(descriptor.DisplayName, query) ||
 155        MatchesText(descriptor.Description, query) ||
 156        MatchesText(descriptor.Category, query) ||
 157        MatchesText(descriptor.Namespace, query) ||
 158        MatchesText(descriptor.TypeName, query) ||
 059        descriptor.Inputs.Any(x => MatchesText(x.Name, query) || MatchesText(x.DisplayName, query) || MatchesText(x.Desc
 160        descriptor.Outputs.Any(x => MatchesText(x.Name, query) || MatchesText(x.DisplayName, query) || MatchesText(x.Des
 61
 62    private static bool MatchesText(string? value, string query) =>
 163        !string.IsNullOrWhiteSpace(value) && value.Contains(query, StringComparison.OrdinalIgnoreCase);
 64}