< Summary

Information
Class: Elsa.AI.Host.Context.WorkflowDefinitionContextProvider
Assembly: Elsa.AI.Host
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Context/WorkflowDefinitionContextProvider.cs
Line coverage
27%
Covered lines: 8
Uncovered lines: 21
Coverable lines: 29
Total lines: 50
Line coverage: 27.5%
Branch coverage
10%
Covered branches: 1
Total branches: 10
Branch coverage: 10%
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_Kind()100%11100%
ResolveAsync()12.5%40820.83%
Unavailable(...)100%11100%
NotFound(...)100%210%
NormalizeTenant(...)0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Context/WorkflowDefinitionContextProvider.cs

#LineLine coverage
 1using Elsa.AI.Abstractions.Contracts;
 2using Elsa.AI.Abstractions.Models;
 3using Elsa.AI.Host.Services;
 4using Elsa.Workflows.Management;
 5using Elsa.Workflows.Management.Filters;
 6
 7namespace Elsa.AI.Host.Context;
 8
 419public class WorkflowDefinitionContextProvider(IServiceProvider serviceProvider, WorkflowGroundingMapper mapper) : IAICo
 10{
 4411    public string Kind => AIContextAttachmentKinds.WorkflowDefinition;
 12
 13    public async ValueTask<AIResolvedContext> ResolveAsync(AIContextResolutionRequest request, CancellationToken cancell
 14    {
 115        var attachment = request.Attachment;
 116        var store = serviceProvider.GetService(typeof(IWorkflowDefinitionStore)) as IWorkflowDefinitionStore;
 117        if (store == null)
 118            return Unavailable(attachment);
 19
 020        var definition = await store.FindAsync(new WorkflowDefinitionFilter { Id = attachment.ReferenceId }, cancellatio
 021            ?? await store.FindAsync(new WorkflowDefinitionFilter
 022            {
 023                DefinitionId = attachment.ReferenceId,
 024                VersionOptions = Elsa.Common.Models.VersionOptions.Latest
 025            }, cancellationToken);
 026        if (definition == null || !string.Equals(NormalizeTenant(definition.TenantId), NormalizeTenant(request.TenantId)
 027            return NotFound(attachment);
 28
 029        return new AIResolvedContext
 030        {
 031            Kind = Kind,
 032            ReferenceId = attachment.ReferenceId,
 033            Summary = $"Workflow definition {definition.DefinitionId} v{definition.Version}: {definition.Name}",
 034            Data = AIGroundingJson.ToJsonObject(mapper.Map(definition)),
 035            Metadata = new JsonObject
 036            {
 037                ["activityId"] = attachment.ActivityId
 038            }
 039        };
 140    }
 41
 42    private AIResolvedContext Unavailable(AIContextAttachment attachment) =>
 143        new() { Kind = Kind, ReferenceId = attachment.ReferenceId, Summary = "Workflow definition store is not available
 44
 45    private AIResolvedContext NotFound(AIContextAttachment attachment) =>
 046        new() { Kind = Kind, ReferenceId = attachment.ReferenceId, Summary = "Workflow definition was not found or is no
 47
 48    private static string NormalizeTenant(string? tenantId) =>
 049        string.IsNullOrWhiteSpace(tenantId) ? "" : tenantId;
 50}