< Summary

Information
Class: Elsa.AI.Host.Tools.Runtime.IncidentTool
Assembly: Elsa.AI.Host
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Tools/Runtime/IncidentTool.cs
Line coverage
39%
Covered lines: 9
Uncovered lines: 14
Coverable lines: 23
Total lines: 38
Line coverage: 39.1%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
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_Definition()100%11100%
ExecuteAsync()0%2040%
Matches(...)0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Tools/Runtime/IncidentTool.cs

#LineLine coverage
 1using Elsa.AI.Abstractions.Models;
 2using Elsa.AI.Host.Services;
 3
 4namespace Elsa.AI.Host.Tools.Runtime;
 5
 456public class IncidentTool(IServiceProvider serviceProvider, RuntimeGroundingMapper mapper, AIGroundingResultFormatter fo
 7{
 908    public override AIToolDefinition Definition { get; } = ReadOnlyDefinition(
 459        "incidents.get",
 4510        "Get incident",
 4511        "Get a redacted incident by workflow instance and activity or node ID.",
 4512        GroundingToolSchemas.WithProperties(
 4513            ("instanceId", GroundingToolSchemas.String("Workflow instance ID.")),
 4514            ("activityId", GroundingToolSchemas.String("Activity ID.")),
 4515            ("activityNodeId", GroundingToolSchemas.String("Activity node ID."))));
 16
 17    public override async ValueTask<AIToolResult> ExecuteAsync(AIToolExecutionContext context, CancellationToken cancell
 18    {
 019        if (WorkflowInstanceStore == null)
 020            return InstanceStoreUnavailable();
 21
 022        var instance = await FindAuthorizedInstanceAsync(context.Arguments, context.TenantId, cancellationToken);
 023        if (instance == null)
 024            return new AIToolResult { Status = AIToolInvocationStatus.Failed, Error = "Workflow instance was not found."
 25
 026        var activityId = GetString(context.Arguments, "activityId");
 027        var activityNodeId = GetString(context.Arguments, "activityNodeId");
 028        var incidents = instance.WorkflowState.Incidents
 029            .Where(x => Matches(x.ActivityId, activityId) || Matches(x.ActivityNodeId, activityNodeId))
 030            .Select(x => mapper.MapIncident(instance.Id, x))
 031            .ToList();
 32
 033        return Formatter.CreateResult($"Resolved {incidents.Count} incidents for workflow instance {instance.Id}.", inci
 034    }
 35
 36    private static bool Matches(string? value, string? expected) =>
 037        !string.IsNullOrWhiteSpace(value) && !string.IsNullOrWhiteSpace(expected) && string.Equals(value, expected, Stri
 38}