diff --git a/app/MindWork AI Studio/Agents/AssistantAudit/AssistantAuditAgent.cs b/app/MindWork AI Studio/Agents/AssistantAudit/AssistantAuditAgent.cs index 221dcabc..b54beff4 100644 --- a/app/MindWork AI Studio/Agents/AssistantAudit/AssistantAuditAgent.cs +++ b/app/MindWork AI Studio/Agents/AssistantAudit/AssistantAuditAgent.cs @@ -6,7 +6,6 @@ using AIStudio.Settings; using AIStudio.Tools.PluginSystem; using AIStudio.Tools.PluginSystem.Assistants; using AIStudio.Tools.Services; -using Microsoft.AspNetCore.Components; namespace AIStudio.Agents.AssistantAudit; @@ -251,7 +250,7 @@ public sealed class AssistantAuditAgent(ILogger logger, ILo /// private static AssistantAuditResult NormalizeResult(AssistantAuditResult result) { - var normalizedFindings = result.Findings ?? []; + var normalizedFindings = result.Findings; var parsedLevel = AssistantAuditLevelExtensions.Parse(result.Level); var lowestFindingLevel = GetMostSevereFindingLevel(normalizedFindings); if (lowestFindingLevel != AssistantAuditLevel.UNKNOWN && (parsedLevel == AssistantAuditLevel.UNKNOWN || lowestFindingLevel < parsedLevel)) diff --git a/app/MindWork AI Studio/Agents/AssistantAudit/AssistantAuditFinding.cs b/app/MindWork AI Studio/Agents/AssistantAudit/AssistantAuditFinding.cs index 7163b950..449052e1 100644 --- a/app/MindWork AI Studio/Agents/AssistantAudit/AssistantAuditFinding.cs +++ b/app/MindWork AI Studio/Agents/AssistantAudit/AssistantAuditFinding.cs @@ -30,7 +30,7 @@ public sealed class AssistantAuditFinding _ => "unknown", }; - init => this.Severity = value?.Trim().ToLowerInvariant() switch + init => this.Severity = value.Trim().ToLowerInvariant() switch { "critical" => AssistantAuditLevel.DANGEROUS, "medium" => AssistantAuditLevel.CAUTION, diff --git a/app/MindWork AI Studio/Assistants/AssistantBase.razor b/app/MindWork AI Studio/Assistants/AssistantBase.razor index 3268612d..a0542fcd 100644 --- a/app/MindWork AI Studio/Assistants/AssistantBase.razor +++ b/app/MindWork AI Studio/Assistants/AssistantBase.razor @@ -56,16 +56,16 @@
- @if (this.ShowResult && !this.ShowEntireChatThread && this.resultingContentBlock is not null) + @if (this.ShowResult && !this.ShowEntireChatThread && this.resultingContentBlock is not null && this.resultingContentBlock.Content is not null) { - + } @if(this.ShowResult && this.ShowEntireChatThread && this.chatThread is not null) { foreach (var block in this.chatThread.Blocks.OrderBy(n => n.Time)) { - @if (!block.HideFromUser) + @if (block is { HideFromUser: false, Content: not null }) { } diff --git a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor index ede99ec2..a4fd1bd5 100644 --- a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor +++ b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor @@ -1,6 +1,5 @@ @attribute [Route(Routes.ASSISTANT_DYNAMIC)] @using AIStudio.Agents.AssistantAudit -@using AIStudio.Settings @using AIStudio.Tools.PluginSystem.Assistants.DataModel @using AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout @inherits AssistantBaseCore @@ -44,17 +43,17 @@ else @code { private RenderFragment RenderSwitch(AssistantSwitch assistantSwitch) => @ - @(this.assistantState.Bools[assistantSwitch.Name] ? assistantSwitch.LabelOn : assistantSwitch.LabelOff) + @(this.assistantState.Booleans[assistantSwitch.Name] ? assistantSwitch.LabelOn : assistantSwitch.LabelOff) ; } @@ -76,7 +75,7 @@ else + Style="@GetOptionalStyle(textArea.Style)" /> } break; @@ -105,7 +104,7 @@ else { var image = assistantImage;
- + @if (!string.IsNullOrWhiteSpace(image.Caption)) { @image.Caption @@ -119,7 +118,7 @@ else if (component is AssistantWebContentReader webContent) { var webState = this.assistantState.WebContent[webContent.Name]; -
+
+
} @@ -159,13 +158,13 @@ else HasSelectAll="@assistantDropdown.HasSelectAll" SelectAllText="@assistantDropdown.SelectAllText" Class="@assistantDropdown.Class" - Style="@this.GetOptionalStyle(assistantDropdown.Style)" /> + Style="@GetOptionalStyle(assistantDropdown.Style)" /> } else { + Style="@GetOptionalStyle(assistantDropdown.Style)" /> } } break; @@ -194,7 +193,7 @@ else var variant = button.GetButtonVariant(); var disabled = this.IsButtonActionRunning(button.Name); var buttonClass = MergeClass(button.Class, ""); - var style = this.GetOptionalStyle(button.Style); + var style = GetOptionalStyle(button.Style); if (!button.IsIconButton) { @@ -238,7 +237,7 @@ else Vertical="@buttonGroup.Vertical" DropShadow="@buttonGroup.DropShadow" Class='@MergeClass(buttonGroup.Class, "mb-3")' - Style="@this.GetOptionalStyle(buttonGroup.Style)"> + Style="@GetOptionalStyle(buttonGroup.Style)"> @this.RenderChildren(buttonGroup.Children) } @@ -251,7 +250,7 @@ else + Style="@GetOptionalStyle(grid.Style)"> @this.RenderChildren(grid.Children) } @@ -291,7 +290,7 @@ else Wrap="@(AssistantComponentPropHelper.GetWrap(stack.Wrap) ?? Wrap.Wrap)" Spacing="@stack.Spacing" Class="@stack.Class" - Style="@this.GetOptionalStyle(stack.Style)"> + Style="@GetOptionalStyle(stack.Style)"> @this.RenderChildren(stack.Children) } @@ -308,7 +307,7 @@ else Elevation="@accordion.Elevation" Gutters="@accordion.HasSectionPaddings" Class="@MergeClass(accordion.Class, "my-6")" - Style="@this.GetOptionalStyle(accordion.Style)"> + Style="@GetOptionalStyle(accordion.Style)"> @this.RenderChildren(accordion.Children) } @@ -328,7 +327,7 @@ else Icon="@AssistantComponentPropHelper.GetIconSvg(accordionSection.ExpandIcon)" MaxHeight="@accordionSection.MaxHeight" Class="@accordionSection.Class" - Style="@this.GetOptionalStyle(accordionSection.Style)"> + Style="@GetOptionalStyle(accordionSection.Style)">
@@ -349,7 +348,7 @@ else case AssistantComponentType.PROVIDER_SELECTION: if (component is AssistantProviderSelection providerSelection) { -
+
} @@ -359,8 +358,8 @@ else if (component is AssistantProfileSelection profileSelection) { var selection = profileSelection; -
- +
+
} break; @@ -395,7 +394,7 @@ else _ => Typo.h5 }; - @heading.Text + @heading.Text } break; @@ -403,7 +402,7 @@ else if (component is AssistantText assistantText) { var text = assistantText; - @text.Content + @text.Content } break; @@ -411,7 +410,7 @@ else if (component is AssistantList assistantList) { var list = assistantList; - + @foreach (var item in list.Items) { var iconColor = AssistantComponentPropHelper.GetColor(item.IconColor, Color.Default); @@ -439,7 +438,7 @@ else } @@ -485,6 +484,7 @@ else var format = dateRangePicker.GetDateFormat(); + @* ReSharper disable CSharpWarnings::CS8619 *@ - + @* ReSharper restore CSharpWarnings::CS8619 *@ + } break; @@ -511,7 +512,7 @@ else + Style="@GetOptionalStyle(timePicker.Style)"/> } break; @@ -573,7 +574,7 @@ else if (!string.IsNullOrWhiteSpace(itemClass)) builder.AddAttribute(7, nameof(MudItem.Class), itemClass); - var itemStyle = this.GetOptionalStyle(item.Style); + var itemStyle = GetOptionalStyle(item.Style); if (!string.IsNullOrWhiteSpace(itemStyle)) builder.AddAttribute(8, nameof(MudItem.Style), itemStyle); diff --git a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor.cs b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor.cs index a9e793c0..7703ff97 100644 --- a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor.cs +++ b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor.cs @@ -13,7 +13,7 @@ namespace AIStudio.Assistants.Dynamic; public partial class AssistantDynamic : AssistantBaseCore { [Parameter] - public AssistantForm? RootComponent { get; set; } = null!; + public AssistantForm? RootComponent { get; set; } protected override string Title => this.title; protected override string Description => this.description; @@ -171,9 +171,8 @@ public partial class AssistantDynamic : AssistantBaseCore private LuaTable BuildPromptInput() { - var state = new LuaTable(); var rootComponent = this.RootComponent; - state = rootComponent is not null + var state = rootComponent is not null ? this.assistantState.ToLuaTable(rootComponent.Children) : new LuaTable(); @@ -184,8 +183,8 @@ public partial class AssistantDynamic : AssistantBaseCore ["Actions"] = this.currentProfile.Actions, ["Num"] = this.currentProfile.Num, }; + state["profile"] = profile; - return state; } @@ -218,7 +217,7 @@ public partial class AssistantDynamic : AssistantBaseCore return string.IsNullOrEmpty(trimmedFallback) ? trimmedCustom : $"{trimmedCustom} {trimmedFallback}"; } - private string? GetOptionalStyle(string? style) => string.IsNullOrWhiteSpace(style) ? null : style; + private static string GetOptionalStyle(string? style) => string.IsNullOrWhiteSpace(style) ? string.Empty : style; private bool IsButtonActionRunning(string buttonName) => this.executingButtonActions.Contains(buttonName); private bool IsSwitchActionRunning(string switchName) => this.executingSwitchActions.Contains(switchName); @@ -251,7 +250,7 @@ public partial class AssistantDynamic : AssistantBaseCore if (string.IsNullOrWhiteSpace(switchComponent.Name)) return; - this.assistantState.Bools[switchComponent.Name] = value; + this.assistantState.Booleans[switchComponent.Name] = value; if (this.assistantPlugin is null || switchComponent.OnChanged is null) { diff --git a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs index e0b035ce..0dcb910c 100644 --- a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs +++ b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs @@ -364,8 +364,6 @@ public partial class ContentBlockComponent : MSGComponentBase, IAsyncDisposable AddMarkdownSegment(markdownSegmentStart, lineStart); mathContentStart = nextLineStart; activeMathBlockFenceType = MathBlockFenceType.BRACKET; - lineStart = nextLineStart; - continue; } } else if (activeMathBlockFenceType is MathBlockFenceType.DOLLAR && trimmedLine.SequenceEqual(MATH_BLOCK_MARKER_DOLLAR.AsSpan())) @@ -375,8 +373,6 @@ public partial class ContentBlockComponent : MSGComponentBase, IAsyncDisposable markdownSegmentStart = nextLineStart; activeMathBlockFenceType = MathBlockFenceType.NONE; - lineStart = nextLineStart; - continue; } else if (activeMathBlockFenceType is MathBlockFenceType.BRACKET && trimmedLine.SequenceEqual(MATH_BLOCK_MARKER_BRACKET_CLOSE.AsSpan())) { @@ -385,8 +381,6 @@ public partial class ContentBlockComponent : MSGComponentBase, IAsyncDisposable markdownSegmentStart = nextLineStart; activeMathBlockFenceType = MathBlockFenceType.NONE; - lineStart = nextLineStart; - continue; } lineStart = nextLineStart; diff --git a/app/MindWork AI Studio/Chat/ContentText.cs b/app/MindWork AI Studio/Chat/ContentText.cs index a48e53d5..93d0fcb2 100644 --- a/app/MindWork AI Studio/Chat/ContentText.cs +++ b/app/MindWork AI Studio/Chat/ContentText.cs @@ -3,7 +3,6 @@ using System.Text.Json.Serialization; using AIStudio.Provider; using AIStudio.Settings; -using AIStudio.Tools; using AIStudio.Tools.PluginSystem; using AIStudio.Tools.RAG.RAGProcesses; diff --git a/app/MindWork AI Studio/Components/ChatComponent.razor b/app/MindWork AI Studio/Components/ChatComponent.razor index 20bb5ec4..6ab7d977 100644 --- a/app/MindWork AI Studio/Components/ChatComponent.razor +++ b/app/MindWork AI Studio/Components/ChatComponent.razor @@ -13,7 +13,7 @@ var block = blocks[i]; var isLastBlock = i == blocks.Count - 1; var isSecondLastBlock = i == blocks.Count - 2; - @if (!block.HideFromUser) + @if (block is { HideFromUser: false, Content: not null }) { + @if (this.IsMultiselect) { GetRenderedItems() { - var items = this.Items ?? []; + var items = this.Items; if (string.IsNullOrWhiteSpace(this.Default.Value)) return items; @@ -122,10 +117,10 @@ namespace AIStudio.Components return item?.Display ?? value; } - private string MergeClasses(string custom, string fallback) + private static string MergeClasses(string custom, string fallback) { - var trimmedCustom = custom?.Trim() ?? string.Empty; - var trimmedFallback = fallback?.Trim() ?? string.Empty; + var trimmedCustom = custom.Trim(); + var trimmedFallback = fallback.Trim(); if (string.IsNullOrEmpty(trimmedCustom)) return trimmedFallback; diff --git a/app/MindWork AI Studio/Components/Workspaces.razor b/app/MindWork AI Studio/Components/Workspaces.razor index 56e5e59e..25a9ef3f 100644 --- a/app/MindWork AI Studio/Components/Workspaces.razor +++ b/app/MindWork AI Studio/Components/Workspaces.razor @@ -24,7 +24,7 @@ else case TreeItemData treeItem: @if (treeItem.Type is TreeItemType.LOADING) { - + @@ -32,7 +32,7 @@ else } else if (treeItem.Type is TreeItemType.CHAT) { - +
@@ -65,7 +65,7 @@ else } else if (treeItem.Type is TreeItemType.WORKSPACE) { - +
@@ -86,7 +86,7 @@ else } else { - +
diff --git a/app/MindWork AI Studio/Dialogs/AssistantPluginAuditDialog.razor.cs b/app/MindWork AI Studio/Dialogs/AssistantPluginAuditDialog.razor.cs index c8390a96..122b6e40 100644 --- a/app/MindWork AI Studio/Dialogs/AssistantPluginAuditDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/AssistantPluginAuditDialog.razor.cs @@ -32,7 +32,6 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase private PluginAssistantAudit? audit; private string promptPreview = string.Empty; private string promptFallbackPreview = string.Empty; - private string componentSummary = string.Empty; private ImmutableDictionary luaFiles = ImmutableDictionary.Create(); private IReadOnlyCollection> componentTreeItems = []; private IReadOnlyCollection> fileSystemTreeItems = []; @@ -77,7 +76,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase { this.promptPreview = await this.plugin.BuildAuditPromptPreviewAsync(); this.promptFallbackPreview = this.plugin.BuildAuditPromptFallbackPreview(); - this.componentSummary = this.plugin.CreateAuditComponentSummary(); + this.plugin.CreateAuditComponentSummary(); this.componentTreeItems = this.CreateAuditTreeItems(this.plugin.RootComponent); this.fileSystemTreeItems = this.CreatePluginFileSystemTreeItems(this.plugin.PluginPath); this.luaFiles = this.plugin.ReadAllLuaFiles(); @@ -262,7 +261,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase if (value is IDictionary dictionary) return this.CreateDictionaryChildren(dictionary, depth); - if (value is IEnumerable enumerable && value is not string) + if (value is IEnumerable enumerable and not string) return this.CreateEnumerableChildren(enumerable, depth); return this.CreateObjectChildren(value, depth); @@ -328,26 +327,21 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase }; } - private TreeItemData CreateFileTreeItem(string filePath, int depth) + private TreeItemData CreateFileTreeItem(string filePath, int depth) => new() { - var fileInfo = new FileInfo(filePath); - - return new TreeItemData + Expanded = depth < 2, + Expandable = false, + Value = new AssistantAuditTreeItem { - Expanded = depth < 2, + Text = Path.GetFileName(filePath), + Caption = string.Empty, + Icon = GetFileIcon(filePath), Expandable = false, - Value = new AssistantAuditTreeItem - { - Text = Path.GetFileName(filePath), - Caption = string.Empty, - Icon = this.GetFileIcon(filePath), - Expandable = false, - IsComponent = false, - }, - }; - } + IsComponent = false, + }, + }; - private string GetFileIcon(string filePath) + private static string GetFileIcon(string filePath) { var extension = Path.GetExtension(filePath); return extension.ToLowerInvariant() switch @@ -376,7 +370,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase /// /// Falls back to public instance properties for simple DTO-style values such as dropdown items. - /// Getter failures are treated defensively so the audit dialog never crashes because of a problematic property. + /// Getter failures are treated defensively, so the audit dialog never crashes because of a problematic property. /// private List> CreateObjectChildren(object value, int depth) { diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/AssistantPluginAuditService.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/AssistantPluginAuditService.cs index ec60abc2..3bd282dd 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/AssistantPluginAuditService.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/AssistantPluginAuditService.cs @@ -19,7 +19,7 @@ public sealed class AssistantPluginAuditService(AssistantAuditAgent auditAgent) PluginHash = plugin.ComputeAuditHash(), AuditedAtUtc = DateTimeOffset.UtcNow, AuditProviderId = provider.Id, - AuditProviderName = provider == AIStudio.Settings.Provider.NONE + AuditProviderName = provider == Settings.Provider.NONE ? string.Empty : provider.InstanceName, Level = AssistantAuditLevelExtensions.Parse(result.Level), diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButton.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButton.cs index 9853797b..5a49341d 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButton.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButton.cs @@ -16,7 +16,7 @@ public sealed class AssistantButton : NamedAssistantComponentBase public bool IsIconButton { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsIconButton), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsIconButton)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsIconButton), value); } @@ -40,7 +40,7 @@ public sealed class AssistantButton : NamedAssistantComponentBase public bool IsFullWidth { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsFullWidth), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsFullWidth)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsFullWidth), value); } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButtonGroup.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButtonGroup.cs index 95004b44..24b2742e 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButtonGroup.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantButtonGroup.cs @@ -26,13 +26,13 @@ public sealed class AssistantButtonGroup : NamedAssistantComponentBase public bool OverrideStyles { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.OverrideStyles), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.OverrideStyles)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.OverrideStyles), value); } public bool Vertical { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Vertical), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Vertical)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Vertical), value); } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantComponentPropHelper.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantComponentPropHelper.cs index 5dd0b96a..88272b60 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantComponentPropHelper.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantComponentPropHelper.cs @@ -7,31 +7,23 @@ internal static class AssistantComponentPropHelper public static string ReadString(Dictionary props, string key) { if (props.TryGetValue(key, out var value)) - { - return value?.ToString() ?? string.Empty; - } + return value.ToString() ?? string.Empty; return string.Empty; } - public static void WriteString(Dictionary props, string key, string value) - { - props[key] = value ?? string.Empty; - } + public static void WriteString(Dictionary props, string key, string value) => props[key] = value; public static int ReadInt(Dictionary props, string key, int fallback = 0) { - return props.TryGetValue(key, out var value) && int.TryParse(value?.ToString(), out var i) ? i : fallback; - } - - public static void WriteInt(Dictionary props, string key, int value) - { - props[key] = value; + return props.TryGetValue(key, out var value) && int.TryParse(value.ToString(), out var i) ? i : fallback; } + public static void WriteInt(Dictionary props, string key, int value) => props[key] = value; + public static int? ReadNullableInt(Dictionary props, string key) { - return props.TryGetValue(key, out var value) && int.TryParse(value?.ToString(), out var i) ? i : null; + return props.TryGetValue(key, out var value) && int.TryParse(value.ToString(), out var i) ? i : null; } public static void WriteNullableInt(Dictionary props, string key, int? value) @@ -47,10 +39,7 @@ internal static class AssistantComponentPropHelper return props.TryGetValue(key, out var value) && bool.TryParse(value.ToString(), out var b) ? b : fallback; } - public static void WriteBool(Dictionary props, string key, bool value) - { - props[key] = value; - } + public static void WriteBool(Dictionary props, string key, bool value) => props[key] = value; public static void WriteObject(Dictionary props, string key, object? value) { @@ -60,9 +49,9 @@ internal static class AssistantComponentPropHelper props[key] = value; } - public static MudBlazor.Color GetColor(string value, Color fallback) => Enum.TryParse(value, out var color) ? color : fallback; - public static MudBlazor.Variant GetVariant(string value, Variant fallback) => Enum.TryParse(value, out var variant) ? variant : fallback; - public static MudBlazor.Adornment GetAdornment(string value, Adornment fallback) => Enum.TryParse(value, out var adornment) ? adornment : fallback; + public static Color GetColor(string value, Color fallback) => Enum.TryParse(value, out var color) ? color : fallback; + public static Variant GetVariant(string value, Variant fallback) => Enum.TryParse(value, out var variant) ? variant : fallback; + public static Adornment GetAdornment(string value, Adornment fallback) => Enum.TryParse(value, out var adornment) ? adornment : fallback; public static string GetIconSvg(string value) => MudBlazorIconRegistry.TryGetSvg(value.TrimStart('@'), out var svg) ? svg : string.Empty; public static Size GetComponentSize(string value, Size fallback) => Enum.TryParse(value, out var size) ? size : fallback; public static Justify? GetJustify(string value) => Enum.TryParse(value, out var justify) ? justify : null; diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDateRangePicker.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDateRangePicker.cs index 714920ea..c55229e9 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDateRangePicker.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDateRangePicker.cs @@ -1,5 +1,4 @@ using System.Globalization; -using MudBlazor; namespace AIStudio.Tools.PluginSystem.Assistants.DataModel; diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdown.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdown.cs index 66d9bb3b..cc878be8 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdown.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantDropdown.cs @@ -42,13 +42,13 @@ internal sealed class AssistantDropdown : StatefulAssistantComponentBase public bool IsMultiselect { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsMultiselect), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsMultiselect)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsMultiselect), value); } public bool HasSelectAll { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.HasSelectAll), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.HasSelectAll)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.HasSelectAll), value); } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantState.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantState.cs index 5676d0b3..5d8ebbcf 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantState.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantState.cs @@ -8,7 +8,7 @@ public sealed class AssistantState public readonly Dictionary Text = new(StringComparer.Ordinal); public readonly Dictionary SingleSelect = new(StringComparer.Ordinal); public readonly Dictionary> MultiSelect = new(StringComparer.Ordinal); - public readonly Dictionary Bools = new(StringComparer.Ordinal); + public readonly Dictionary Booleans = new(StringComparer.Ordinal); public readonly Dictionary WebContent = new(StringComparer.Ordinal); public readonly Dictionary FileContent = new(StringComparer.Ordinal); public readonly Dictionary Colors = new(StringComparer.Ordinal); @@ -21,7 +21,7 @@ public sealed class AssistantState this.Text.Clear(); this.SingleSelect.Clear(); this.MultiSelect.Clear(); - this.Bools.Clear(); + this.Booleans.Clear(); this.WebContent.Clear(); this.FileContent.Clear(); this.Colors.Clear(); @@ -40,7 +40,7 @@ public sealed class AssistantState if (!value.TryRead(out var textValue)) return false; - this.Text[fieldName] = textValue ?? string.Empty; + this.Text[fieldName] = textValue; return true; } @@ -50,7 +50,7 @@ public sealed class AssistantState if (!value.TryRead(out var singleSelectValue)) return false; - this.SingleSelect[fieldName] = singleSelectValue ?? string.Empty; + this.SingleSelect[fieldName] = singleSelectValue; return true; } @@ -70,13 +70,13 @@ public sealed class AssistantState return true; } - if (this.Bools.ContainsKey(fieldName)) + if (this.Booleans.ContainsKey(fieldName)) { expectedType = "boolean"; if (!value.TryRead(out var boolValue)) return false; - this.Bools[fieldName] = boolValue; + this.Booleans[fieldName] = boolValue; return true; } @@ -86,7 +86,7 @@ public sealed class AssistantState if (!value.TryRead(out var webContentValue)) return false; - webContentState.Content = webContentValue ?? string.Empty; + webContentState.Content = webContentValue; return true; } @@ -96,7 +96,7 @@ public sealed class AssistantState if (!value.TryRead(out var fileContentValue)) return false; - fileContentState.Content = fileContentValue ?? string.Empty; + fileContentState.Content = fileContentValue; return true; } @@ -106,7 +106,7 @@ public sealed class AssistantState if (!value.TryRead(out var colorValue)) return false; - this.Colors[fieldName] = colorValue ?? string.Empty; + this.Colors[fieldName] = colorValue; return true; } @@ -116,7 +116,7 @@ public sealed class AssistantState if (!value.TryRead(out var dateValue)) return false; - this.Dates[fieldName] = dateValue ?? string.Empty; + this.Dates[fieldName] = dateValue; return true; } @@ -126,7 +126,7 @@ public sealed class AssistantState if (!value.TryRead(out var dateRangeValue)) return false; - this.DateRanges[fieldName] = dateRangeValue ?? string.Empty; + this.DateRanges[fieldName] = dateRangeValue; return true; } @@ -136,7 +136,7 @@ public sealed class AssistantState if (!value.TryRead(out var timeValue)) return false; - this.Times[fieldName] = timeValue ?? string.Empty; + this.Times[fieldName] = timeValue; return true; } @@ -158,7 +158,7 @@ public sealed class AssistantState { target[named.Name] = new LuaTable { - ["Type"] = Enum.GetName(component.Type) ?? string.Empty, + ["Type"] = Enum.GetName(component.Type) ?? string.Empty, ["Value"] = component is IStatefulAssistantComponent ? this.ReadValueForLua(named.Name) : LuaValue.Nil, ["Props"] = this.CreatePropsTable(component), }; @@ -177,12 +177,12 @@ public sealed class AssistantState return singleSelectValue; if (this.MultiSelect.TryGetValue(name, out var multiSelectValue)) return AssistantLuaConversion.CreateLuaArray(multiSelectValue.OrderBy(static value => value, StringComparer.Ordinal)); - if (this.Bools.TryGetValue(name, out var boolValue)) + if (this.Booleans.TryGetValue(name, out var boolValue)) return boolValue; if (this.WebContent.TryGetValue(name, out var webContentValue)) - return webContentValue.Content ?? string.Empty; + return webContentValue.Content; if (this.FileContent.TryGetValue(name, out var fileContentValue)) - return fileContentValue.Content ?? string.Empty; + return fileContentValue.Content; if (this.Colors.TryGetValue(name, out var colorValue)) return colorValue; if (this.Dates.TryGetValue(name, out var dateValue)) @@ -211,6 +211,7 @@ public sealed class AssistantState continue; if (!AssistantLuaConversion.TryWriteAssistantValue(table, key, value)) + // ReSharper disable once RedundantJumpStatement continue; } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantSwitch.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantSwitch.cs index 568b3f75..8c779914 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantSwitch.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantSwitch.cs @@ -17,13 +17,13 @@ public sealed class AssistantSwitch : StatefulAssistantComponentBase public bool Value { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Value), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Value)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Value), value); } public bool Disabled { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Disabled), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Disabled)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Disabled), value); } @@ -91,19 +91,19 @@ public sealed class AssistantSwitch : StatefulAssistantComponentBase public override void InitializeState(AssistantState state) { - if (!state.Bools.ContainsKey(this.Name)) - state.Bools[this.Name] = this.Value; + if (!state.Booleans.ContainsKey(this.Name)) + state.Booleans[this.Name] = this.Value; } public override string UserPromptFallback(AssistantState state) { - state.Bools.TryGetValue(this.Name, out var userDecision); + state.Booleans.TryGetValue(this.Name, out var userDecision); return this.BuildAuditPromptBlock(userDecision.ToString()); } #endregion - public MudBlazor.Color GetColor(string colorString) => Enum.TryParse(colorString, out var color) ? color : MudBlazor.Color.Inherit; + public static Color GetColor(string colorString) => Enum.TryParse(colorString, out var color) ? color : Color.Inherit; public Placement GetLabelPlacement() => Enum.TryParse(this.LabelPlacement, out var placement) ? placement : Placement.Right; public string GetIconSvg() => MudBlazorIconRegistry.TryGetSvg(this.Icon, out var svg) ? svg : string.Empty; } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTextArea.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTextArea.cs index 692e3ab8..c64ee900 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTextArea.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTextArea.cs @@ -1,5 +1,3 @@ -using AIStudio.Tools.PluginSystem.Assistants.Icons; - namespace AIStudio.Tools.PluginSystem.Assistants.DataModel; internal sealed class AssistantTextArea : StatefulAssistantComponentBase @@ -22,7 +20,7 @@ internal sealed class AssistantTextArea : StatefulAssistantComponentBase public bool HelperTextOnFocus { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.HelperTextOnFocus), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.HelperTextOnFocus)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.HelperTextOnFocus), value); } @@ -76,13 +74,13 @@ internal sealed class AssistantTextArea : StatefulAssistantComponentBase public bool IsSingleLine { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsSingleLine), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsSingleLine)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsSingleLine), value); } public bool ReadOnly { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.ReadOnly), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.ReadOnly)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.ReadOnly), value); } @@ -114,7 +112,7 @@ internal sealed class AssistantTextArea : StatefulAssistantComponentBase #endregion - public Adornment GetAdornmentPos() => Enum.TryParse(this.Adornment, out var position) ? position : MudBlazor.Adornment.Start; + public Adornment GetAdornmentPos() => Enum.TryParse(this.Adornment, out var position) ? position : MudBlazor.Adornment.Start; public Color GetAdornmentColor() => Enum.TryParse(this.AdornmentColor, out var color) ? color : Color.Default; } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTimePicker.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTimePicker.cs index b4eebcb0..72c0e7c4 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTimePicker.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantTimePicker.cs @@ -49,7 +49,7 @@ internal sealed class AssistantTimePicker : StatefulAssistantComponentBase public bool AmPm { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.AmPm), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.AmPm)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.AmPm), value); } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantAccordion.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantAccordion.cs index 09b0e24d..b019a032 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantAccordion.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantAccordion.cs @@ -8,13 +8,13 @@ internal sealed class AssistantAccordion : NamedAssistantComponentBase public bool AllowMultiSelection { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.AllowMultiSelection), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.AllowMultiSelection)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.AllowMultiSelection), value); } public bool IsDense { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsDense), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsDense)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsDense), value); } @@ -26,13 +26,13 @@ internal sealed class AssistantAccordion : NamedAssistantComponentBase public bool IsSquare { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsSquare), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsSquare)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsSquare), value); } public int Elevation { - get => AssistantComponentPropHelper.ReadInt(this.Props, nameof(this.Elevation), 0); + get => AssistantComponentPropHelper.ReadInt(this.Props, nameof(this.Elevation)); set => AssistantComponentPropHelper.WriteInt(this.Props, nameof(this.Elevation), value); } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantAccordionSection.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantAccordionSection.cs index 1cf1cf51..2c752e5f 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantAccordionSection.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantAccordionSection.cs @@ -40,19 +40,19 @@ internal sealed class AssistantAccordionSection : NamedAssistantComponentBase public bool IsDisabled { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsDisabled), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsDisabled)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsDisabled), value); } public bool IsExpanded { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsExpanded), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsExpanded)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsExpanded), value); } public bool IsDense { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsDense), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsDense)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsDense), value); } @@ -64,7 +64,7 @@ internal sealed class AssistantAccordionSection : NamedAssistantComponentBase public bool HideIcon { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.HideIcon), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.HideIcon)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.HideIcon), value); } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantPaper.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantPaper.cs index 2a09e334..8f77dd94 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantPaper.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantPaper.cs @@ -50,13 +50,13 @@ internal sealed class AssistantPaper : NamedAssistantComponentBase public bool IsOutlined { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsOutlined), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsOutlined)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsOutlined), value); } public bool IsSquare { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsSquare), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsSquare)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsSquare), value); } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantStack.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantStack.cs index 89ef38d8..de2875c0 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantStack.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/Layout/AssistantStack.cs @@ -8,13 +8,13 @@ internal sealed class AssistantStack : NamedAssistantComponentBase public bool IsRow { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsRow), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsRow)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsRow), value); } public bool IsReverse { - get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsReverse), false); + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.IsReverse)); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsReverse), value); } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/PluginAssistantSecurityResolver.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/PluginAssistantSecurityResolver.cs index 50097165..596b19e4 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/PluginAssistantSecurityResolver.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/PluginAssistantSecurityResolver.cs @@ -52,6 +52,7 @@ public static class PluginAssistantSecurityResolver return MudBlazor.Icons.Material.Filled.LockOpen; } + // ReSharper disable UnusedParameter.Local private static string GetSecurityBadgeIcon(bool requiresAudit, bool hasAudit, bool hasHashMismatch, bool isBlocked, bool canOverride) { if (hasHashMismatch) @@ -61,6 +62,7 @@ public static class PluginAssistantSecurityResolver return MudBlazor.Icons.Material.Filled.Security; } + // ReSharper restore UnusedParameter.Local /// /// Resolves the effective security state for an assistant plugin.