< Summary

Information
Class: UIBlazor.Agents.NativePropertyDefinition
Assembly: UIBlazor
File(s): /home/runner/work/InvAit/InvAit/UIBlazor/Agents/NativeToolDefinition.cs
Tag: 71_26091983037
Line coverage
42%
Covered lines: 11
Uncovered lines: 15
Coverable lines: 26
Total lines: 154
Line coverage: 42.3%
Branch coverage
21%
Covered branches: 3
Total branches: 14
Branch coverage: 21.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()75%44100%
set_Type(...)0%110100%
SetSingleType(...)100%11100%
SetUnionTypes(...)100%11100%
get_IsUnionType()100%11100%
get_Description()100%11100%
get_Items()100%11100%
get_Properties()100%11100%

File(s)

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

#LineLine coverage
 1namespace UIBlazor.Agents;
 2
 3/// <summary>
 4/// Описание функции для нативного туллинга
 5/// </summary>
 6public class NativeToolDefinition
 7{
 8    /// <summary>
 9    /// Тип всегда функция
 10    /// </summary>
 11    [JsonPropertyName("type")]
 12    public string Type { get; set; } = "function";
 13
 14    /// <summary>
 15    /// Вот и сама функция
 16    /// </summary>
 17    [JsonPropertyName("function")]
 18    public required NativeToolFunction Function { get; set; }
 19}
 20
 21/// <summary>
 22/// Функция для нативного туллинга
 23/// </summary>
 24public class NativeToolFunction
 25{
 26    [JsonPropertyName("name")]
 27    public required string Name { get; set; }
 28
 29    [JsonPropertyName("description")]
 30    public required string Description { get; set; }
 31
 32    /// <summary>
 33    /// Все поля обязательны или нет
 34    /// </summary>
 35    [JsonPropertyName("strict")]
 36    public bool Strict { get; set; } = true;
 37
 38    [JsonPropertyName("parameters")]
 39    public required NativeParameters Parameters { get; set; }
 40}
 41
 42/// <summary>
 43/// Параметры функции для нативного туллинга
 44/// </summary>
 45public class NativeParameters
 46{
 47    /// <summary>
 48    /// Тип параметра
 49    /// </summary>
 50    [JsonPropertyName("type")]
 51    public required string Type { get; set; } = NativeToolType.String;
 52
 53    /// <summary>
 54    /// Все свойства
 55    /// </summary>
 56    [JsonPropertyName("properties")]
 57    public required Dictionary<string, NativePropertyDefinition> Properties { get; set; }
 58
 59    /// <summary>
 60    /// Массив с обязательными свойствами. При<see cref="NativeToolFunction.Strict"/> все должны быть обязательны
 61    /// </summary>
 62    [JsonPropertyName("required")]
 63    public List<string> Required { get; set; } = [];
 64
 65    [JsonPropertyName("additionalProperties")]
 66    public bool AdditionalProperties { get; } = false;
 67}
 68
 69/// <summary>
 70/// Описание свойства функции для нативного туллинга
 71/// </summary>
 72public class NativePropertyDefinition
 73{
 74    private string? _singleType;
 75    private string[]? _unionTypes;
 76
 77    /// <summary>
 78    /// Тип свойства. Может быть строкой или массивом строк для union типов.
 79    /// "string", "number", "integer", "boolean", "array", "object", "null"
 80    /// Для optional полей в Strict Mode: ["string", "null"]
 81    /// </summary>
 82    [JsonPropertyName("type")]
 83    public object Type
 84    {
 15785        get => (object?)_unionTypes ?? _singleType ?? NativeToolType.Object;
 86        set
 87        {
 088            switch (value)
 89            {
 90                case string s:
 091                    _singleType = s;
 092                    _unionTypes = null;
 093                    break;
 94                case string[] arr:
 095                    _unionTypes = arr;
 096                    _singleType = null;
 097                    break;
 098                case JsonElement el when el.ValueKind == JsonValueKind.String:
 099                    _singleType = el.GetString()!;
 0100                    _unionTypes = null;
 0101                    break;
 0102                case JsonElement el when el.ValueKind == JsonValueKind.Array:
 0103                    _unionTypes = el.EnumerateArray().Select(e => e.GetString()!).ToArray();
 0104                    _singleType = null;
 105                    break;
 106            }
 0107        }
 108    }
 109
 110    /// <summary>
 111    /// Установить один тип
 112    /// </summary>
 113    public void SetSingleType(string type)
 114    {
 752115        _singleType = type;
 752116        _unionTypes = null;
 752117    }
 118
 119    /// <summary>
 120    /// Установить union типы для optional полей в Strict Mode
 121    /// </summary>
 122    public void SetUnionTypes(params string[] types)
 123    {
 70124        _unionTypes = types;
 70125        _singleType = null;
 70126    }
 127
 128    /// <summary>
 129    /// Проверить, является ли тип union (массив типов)
 130    /// </summary>
 131    [JsonIgnore]
 5132    public bool IsUnionType => _unionTypes != null;
 133
 134    /// <summary>
 135    /// Текст для LLM
 136    /// </summary>
 137    [JsonPropertyName("description")]
 138    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
 837139    public string? Description { get; set; }
 140
 141    /// <summary>
 142    /// Если Type = "array"
 143    /// </summary>
 144    [JsonPropertyName("items")]
 145    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
 142146    public object? Items { get; set; }
 147
 148    /// <summary>
 149    /// Если Type = "object"
 150    /// </summary>
 151    [JsonPropertyName("properties")]
 152    [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
 794153    public Dictionary<string, NativePropertyDefinition>? Properties { get; set; }
 154}