< Summary

Information
Class: Elsa.AI.Host.Tools.Runtime.IncidentsSearchTool
Assembly: Elsa.AI.Host
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.AI.Host/Tools/Runtime/IncidentsSearchTool.cs
Line coverage
92%
Covered lines: 23
Uncovered lines: 2
Coverable lines: 25
Total lines: 38
Line coverage: 92%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
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()50%2290.9%

File(s)

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

#LineLine coverage
 1using Elsa.AI.Abstractions.Models;
 2using Elsa.AI.Host.Services;
 3using Elsa.Common.Models;
 4
 5namespace Elsa.AI.Host.Tools.Runtime;
 6
 457public class IncidentsSearchTool(IServiceProvider serviceProvider, RuntimeGroundingMapper mapper, AIGroundingResultForma
 8{
 919    public override AIToolDefinition Definition { get; } = ReadOnlyDefinition(
 4510        "incidents.search",
 4511        "Search incidents",
 4512        "Search incidents across authorized workflow instances in an explicit workflow, status, or time scope.",
 4513        GroundingToolSchemas.WithProperties(
 4514            ("definitionId", GroundingToolSchemas.String("Workflow definition ID.")),
 4515            ("instanceId", GroundingToolSchemas.String("Workflow instance ID.")),
 4516            ("query", GroundingToolSchemas.String("Free-text incident or instance search term.")),
 4517            ("from", GroundingToolSchemas.String("Updated-at range start.")),
 4518            ("to", GroundingToolSchemas.String("Updated-at range end."))));
 19
 20    public override async ValueTask<AIToolResult> ExecuteAsync(AIToolExecutionContext context, CancellationToken cancell
 21    {
 122        var store = WorkflowInstanceStore;
 123        if (store == null)
 024            return InstanceStoreUnavailable();
 25
 126        var filter = CreateInstanceFilter(context.Arguments);
 127        filter.HasIncidents = true;
 128        var page = await store.FindManyAsync(filter, PageArgs.FromRange(0, 100), cancellationToken);
 129        var incidents = page.Items
 130            .Where(x => IsTenantAllowed(x, context.TenantId))
 231            .SelectMany(x => x.WorkflowState.Incidents.Select(incident => mapper.MapIncident(x.Id, incident)))
 032            .OrderByDescending(x => x.Timestamp)
 133            .ToList();
 134        var items = incidents.Select(AIGroundingJson.ToJsonObject);
 35
 136        return Formatter.CreateResult($"Found {incidents.Count} incidents.", items, incidents.Count, ["WorkflowInstanceS
 137    }
 38}