< Summary

Information
Class: UIBlazor.Agents.InternalExecutor
Assembly: UIBlazor
File(s): /home/runner/work/InvAit/InvAit/UIBlazor/Agents/InternalExecutor.cs
Tag: 71_26091983037
Line coverage
55%
Covered lines: 22
Uncovered lines: 18
Coverable lines: 40
Total lines: 89
Line coverage: 55%
Branch coverage
28%
Covered branches: 9
Total branches: 32
Branch coverage: 28.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteToolAsync()90%101095.45%
ExecuteAskUserAsync(...)0%506220%

File(s)

/home/runner/work/InvAit/InvAit/UIBlazor/Agents/InternalExecutor.cs

#LineLine coverage
 1using UIBlazor.Services;
 2
 3namespace UIBlazor.Agents;
 4
 5/// <summary>
 6/// То что не должно идти в VS а обрабатывается прямо тут
 7/// </summary>
 198public class InternalExecutor(IServiceProvider serviceProvider) : IInternalExecutor
 9{
 10    public async Task<VsToolResult> ExecuteToolAsync(string name, IReadOnlyDictionary<string, object> args, Cancellation
 11    {
 1912        if (name == BasicEnum.SwitchMode)
 13        {
 1714            if (args != null && args.TryGetValue("param1", out var modeObj))
 15            {
 1416                if (Enum.TryParse<AppMode>(modeObj.ToString(), true, out var mode))
 17                {
 1318                    serviceProvider.GetRequiredService<IChatService>().Session.Mode = mode;
 1319                    return new VsToolResult
 1320                    {
 1321                        Success = true,
 1322                        Result = $"Switched to {mode} mode successfully. Now you have access to different set of tools."
 1323                    };
 24                }
 25            }
 426            return new VsToolResult
 427            {
 428                Success = false,
 429                ErrorMessage = "Not supported mode"
 430            };
 31        }
 32
 233        if (name == BasicEnum.AskUser)
 34        {
 035            return ExecuteAskUserAsync(args);
 36        }
 37
 238        return new VsToolResult
 239        {
 240            Success = false,
 241            ErrorMessage = $"Not supported tool {name}"
 242        };
 1943    }
 44
 45    /// <summary>
 46    /// Execute ask_user tool.
 47    /// param1 = question, param2+ = options
 48    /// Returns JSON with question and options for UI to render.
 49    /// </summary>
 50    private static VsToolResult ExecuteAskUserAsync(IReadOnlyDictionary<string, object> args)
 51    {
 052        var question = string.Empty;
 053        var options = new List<string>();
 54
 055        if (args != null)
 56        {
 57            // Get param keys
 058            var paramKeys = args.Keys.ToList();
 59
 60            // First param is the question
 061            if (paramKeys.Count > 0 && args.TryGetValue(paramKeys[0], out var questionObj))
 62            {
 063                question = questionObj?.ToString()?.Trim() ?? string.Empty;
 64            }
 65
 66            // Remaining params are options
 067            for (var i = 1; i < paramKeys.Count; i++)
 68            {
 069                if (args.TryGetValue(paramKeys[i], out var optionObj))
 70                {
 071                    var option = optionObj?.ToString()?.Trim();
 072                    if (!string.IsNullOrEmpty(option))
 73                    {
 074                        options.Add(option);
 75                    }
 76                }
 77            }
 78        }
 79
 80        // Return result with question and options as JSON
 081        var resultJson = JsonSerializer.Serialize(new { question, options });
 82
 083        return new VsToolResult
 084        {
 085            Success = true,
 086            Result = resultJson
 087        };
 88    }
 89}