Resolved warnings

This commit is contained in:
Thorsten Sommer 2026-04-09 09:52:03 +02:00
parent c28410400c
commit a927fb7fb7
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
27 changed files with 130 additions and 161 deletions

View File

@ -6,7 +6,6 @@ using AIStudio.Settings;
using AIStudio.Tools.PluginSystem; using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.PluginSystem.Assistants; using AIStudio.Tools.PluginSystem.Assistants;
using AIStudio.Tools.Services; using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Agents.AssistantAudit; namespace AIStudio.Agents.AssistantAudit;
@ -251,7 +250,7 @@ public sealed class AssistantAuditAgent(ILogger<AssistantAuditAgent> logger, ILo
/// </summary> /// </summary>
private static AssistantAuditResult NormalizeResult(AssistantAuditResult result) private static AssistantAuditResult NormalizeResult(AssistantAuditResult result)
{ {
var normalizedFindings = result.Findings ?? []; var normalizedFindings = result.Findings;
var parsedLevel = AssistantAuditLevelExtensions.Parse(result.Level); var parsedLevel = AssistantAuditLevelExtensions.Parse(result.Level);
var lowestFindingLevel = GetMostSevereFindingLevel(normalizedFindings); var lowestFindingLevel = GetMostSevereFindingLevel(normalizedFindings);
if (lowestFindingLevel != AssistantAuditLevel.UNKNOWN && (parsedLevel == AssistantAuditLevel.UNKNOWN || lowestFindingLevel < parsedLevel)) if (lowestFindingLevel != AssistantAuditLevel.UNKNOWN && (parsedLevel == AssistantAuditLevel.UNKNOWN || lowestFindingLevel < parsedLevel))

View File

@ -30,7 +30,7 @@ public sealed class AssistantAuditFinding
_ => "unknown", _ => "unknown",
}; };
init => this.Severity = value?.Trim().ToLowerInvariant() switch init => this.Severity = value.Trim().ToLowerInvariant() switch
{ {
"critical" => AssistantAuditLevel.DANGEROUS, "critical" => AssistantAuditLevel.DANGEROUS,
"medium" => AssistantAuditLevel.CAUTION, "medium" => AssistantAuditLevel.CAUTION,

View File

@ -56,16 +56,16 @@
<div id="@BEFORE_RESULT_DIV_ID" class="mt-3"> <div id="@BEFORE_RESULT_DIV_ID" class="mt-3">
</div> </div>
@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)
{ {
<ContentBlockComponent Role="@(this.resultingContentBlock.Role)" Type="@(this.resultingContentBlock.ContentType)" Time="@(this.resultingContentBlock.Time)" Content="@(this.resultingContentBlock.Content)"/> <ContentBlockComponent Role="@(this.resultingContentBlock.Role)" Type="@(this.resultingContentBlock.ContentType)" Time="@(this.resultingContentBlock.Time)" Content="@this.resultingContentBlock.Content"/>
} }
@if(this.ShowResult && this.ShowEntireChatThread && this.chatThread is not null) @if(this.ShowResult && this.ShowEntireChatThread && this.chatThread is not null)
{ {
foreach (var block in this.chatThread.Blocks.OrderBy(n => n.Time)) foreach (var block in this.chatThread.Blocks.OrderBy(n => n.Time))
{ {
@if (!block.HideFromUser) @if (block is { HideFromUser: false, Content: not null })
{ {
<ContentBlockComponent Role="@block.Role" Type="@block.ContentType" Time="@block.Time" Content="@block.Content"/> <ContentBlockComponent Role="@block.Role" Type="@block.ContentType" Time="@block.Time" Content="@block.Content"/>
} }

View File

@ -1,6 +1,5 @@
@attribute [Route(Routes.ASSISTANT_DYNAMIC)] @attribute [Route(Routes.ASSISTANT_DYNAMIC)]
@using AIStudio.Agents.AssistantAudit @using AIStudio.Agents.AssistantAudit
@using AIStudio.Settings
@using AIStudio.Tools.PluginSystem.Assistants.DataModel @using AIStudio.Tools.PluginSystem.Assistants.DataModel
@using AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout @using AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.NoSettingsPanel> @inherits AssistantBaseCore<AIStudio.Dialogs.Settings.NoSettingsPanel>
@ -44,17 +43,17 @@ else
@code { @code {
private RenderFragment RenderSwitch(AssistantSwitch assistantSwitch) => @<MudSwitch T="bool" private RenderFragment RenderSwitch(AssistantSwitch assistantSwitch) => @<MudSwitch T="bool"
Value="@this.assistantState.Bools[assistantSwitch.Name]" Value="@this.assistantState.Booleans[assistantSwitch.Name]"
ValueChanged="@((bool value) => ExecuteSwitchChangedAsync(assistantSwitch, value))" ValueChanged="@(value => this.ExecuteSwitchChangedAsync(assistantSwitch, value))"
LabelPlacement="@assistantSwitch.GetLabelPlacement()" LabelPlacement="@assistantSwitch.GetLabelPlacement()"
Color="@assistantSwitch.GetColor(assistantSwitch.CheckedColor)" Color="@AssistantSwitch.GetColor(assistantSwitch.CheckedColor)"
UncheckedColor="@assistantSwitch.GetColor(assistantSwitch.UncheckedColor)" UncheckedColor="@AssistantSwitch.GetColor(assistantSwitch.UncheckedColor)"
ThumbIcon="@assistantSwitch.GetIconSvg()" ThumbIcon="@assistantSwitch.GetIconSvg()"
ThumbIconColor="@assistantSwitch.GetColor(assistantSwitch.IconColor)" ThumbIconColor="@AssistantSwitch.GetColor(assistantSwitch.IconColor)"
Disabled="@(assistantSwitch.Disabled || IsSwitchActionRunning(assistantSwitch.Name))" Disabled="@(assistantSwitch.Disabled || this.IsSwitchActionRunning(assistantSwitch.Name))"
Class="@assistantSwitch.Class" Class="@assistantSwitch.Class"
Style="@GetOptionalStyle(assistantSwitch.Style)"> Style="@GetOptionalStyle(assistantSwitch.Style)">
@(this.assistantState.Bools[assistantSwitch.Name] ? assistantSwitch.LabelOn : assistantSwitch.LabelOff) @(this.assistantState.Booleans[assistantSwitch.Name] ? assistantSwitch.LabelOn : assistantSwitch.LabelOff)
</MudSwitch>; </MudSwitch>;
} }
@ -76,7 +75,7 @@ else
<MudTextField T="string" <MudTextField T="string"
Text="@this.assistantState.Text[textArea.Name]" Text="@this.assistantState.Text[textArea.Name]"
TextChanged="@((string value) => this.assistantState.Text[textArea.Name] = value)" TextChanged="@(value => this.assistantState.Text[textArea.Name] = value)"
Label="@textArea.Label" Label="@textArea.Label"
HelperText="@textArea.HelperText" HelperText="@textArea.HelperText"
HelperTextOnFocus="@textArea.HelperTextOnFocus" HelperTextOnFocus="@textArea.HelperTextOnFocus"
@ -93,7 +92,7 @@ else
AutoGrow="@autoGrow" AutoGrow="@autoGrow"
MaxLines="12" MaxLines="12"
Class='@MergeClass(textArea.Class, "mb-3")' Class='@MergeClass(textArea.Class, "mb-3")'
Style="@this.GetOptionalStyle(textArea.Style)" /> Style="@GetOptionalStyle(textArea.Style)" />
} }
break; break;
@ -105,7 +104,7 @@ else
{ {
var image = assistantImage; var image = assistantImage;
<div Class="mb-4"> <div Class="mb-4">
<MudImage Fluid="true" Src="@resolvedSource" Alt="@image.Alt" Class='@MergeClass(image.Class, "rounded-lg mb-2")' Style="@this.GetOptionalStyle(image.Style)" Elevation="20" /> <MudImage Fluid="true" Src="@resolvedSource" Alt="@image.Alt" Class='@MergeClass(image.Class, "rounded-lg mb-2")' Style="@GetOptionalStyle(image.Style)" Elevation="20" />
@if (!string.IsNullOrWhiteSpace(image.Caption)) @if (!string.IsNullOrWhiteSpace(image.Caption))
{ {
<MudText Typo="Typo.caption" Align="Align.Center">@image.Caption</MudText> <MudText Typo="Typo.caption" Align="Align.Center">@image.Caption</MudText>
@ -119,7 +118,7 @@ else
if (component is AssistantWebContentReader webContent) if (component is AssistantWebContentReader webContent)
{ {
var webState = this.assistantState.WebContent[webContent.Name]; var webState = this.assistantState.WebContent[webContent.Name];
<div class="@webContent.Class" style="@this.GetOptionalStyle(webContent.Style)"> <div class="@webContent.Class" style="@GetOptionalStyle(webContent.Style)">
<ReadWebContent @bind-Content="@webState.Content" <ReadWebContent @bind-Content="@webState.Content"
ProviderSettings="@this.providerSettings" ProviderSettings="@this.providerSettings"
@bind-AgentIsRunning="@webState.AgentIsRunning" @bind-AgentIsRunning="@webState.AgentIsRunning"
@ -133,7 +132,7 @@ else
if (component is AssistantFileContentReader fileContent) if (component is AssistantFileContentReader fileContent)
{ {
var fileState = this.assistantState.FileContent[fileContent.Name]; var fileState = this.assistantState.FileContent[fileContent.Name];
<div class="@fileContent.Class" style="@this.GetOptionalStyle(fileContent.Style)"> <div class="@fileContent.Class" style="@GetOptionalStyle(fileContent.Style)">
<ReadFileContent @bind-FileContent="@fileState.Content" /> <ReadFileContent @bind-FileContent="@fileState.Content" />
</div> </div>
} }
@ -159,13 +158,13 @@ else
HasSelectAll="@assistantDropdown.HasSelectAll" HasSelectAll="@assistantDropdown.HasSelectAll"
SelectAllText="@assistantDropdown.SelectAllText" SelectAllText="@assistantDropdown.SelectAllText"
Class="@assistantDropdown.Class" Class="@assistantDropdown.Class"
Style="@this.GetOptionalStyle(assistantDropdown.Style)" /> Style="@GetOptionalStyle(assistantDropdown.Style)" />
} }
else else
{ {
<DynamicAssistantDropdown Items="@assistantDropdown.Items" <DynamicAssistantDropdown Items="@assistantDropdown.Items"
Value="@this.assistantState.SingleSelect[assistantDropdown.Name]" Value="@this.assistantState.SingleSelect[assistantDropdown.Name]"
ValueChanged="@((string value) => this.assistantState.SingleSelect[assistantDropdown.Name] = value)" ValueChanged="@(value => this.assistantState.SingleSelect[assistantDropdown.Name] = value)"
Default="@assistantDropdown.Default" Default="@assistantDropdown.Default"
Label="@assistantDropdown.Label" Label="@assistantDropdown.Label"
HelperText="@assistantDropdown.HelperText" HelperText="@assistantDropdown.HelperText"
@ -177,7 +176,7 @@ else
HasSelectAll="@assistantDropdown.HasSelectAll" HasSelectAll="@assistantDropdown.HasSelectAll"
SelectAllText="@assistantDropdown.SelectAllText" SelectAllText="@assistantDropdown.SelectAllText"
Class="@assistantDropdown.Class" Class="@assistantDropdown.Class"
Style="@this.GetOptionalStyle(assistantDropdown.Style)" /> Style="@GetOptionalStyle(assistantDropdown.Style)" />
} }
} }
break; break;
@ -194,7 +193,7 @@ else
var variant = button.GetButtonVariant(); var variant = button.GetButtonVariant();
var disabled = this.IsButtonActionRunning(button.Name); var disabled = this.IsButtonActionRunning(button.Name);
var buttonClass = MergeClass(button.Class, ""); var buttonClass = MergeClass(button.Class, "");
var style = this.GetOptionalStyle(button.Style); var style = GetOptionalStyle(button.Style);
if (!button.IsIconButton) if (!button.IsIconButton)
{ {
@ -238,7 +237,7 @@ else
Vertical="@buttonGroup.Vertical" Vertical="@buttonGroup.Vertical"
DropShadow="@buttonGroup.DropShadow" DropShadow="@buttonGroup.DropShadow"
Class='@MergeClass(buttonGroup.Class, "mb-3")' Class='@MergeClass(buttonGroup.Class, "mb-3")'
Style="@this.GetOptionalStyle(buttonGroup.Style)"> Style="@GetOptionalStyle(buttonGroup.Style)">
@this.RenderChildren(buttonGroup.Children) @this.RenderChildren(buttonGroup.Children)
</MudButtonGroup> </MudButtonGroup>
} }
@ -251,7 +250,7 @@ else
<MudGrid Justify="@(AssistantComponentPropHelper.GetJustify(grid.Justify) ?? Justify.FlexStart)" <MudGrid Justify="@(AssistantComponentPropHelper.GetJustify(grid.Justify) ?? Justify.FlexStart)"
Spacing="@grid.Spacing" Spacing="@grid.Spacing"
Class="@grid.Class" Class="@grid.Class"
Style="@this.GetOptionalStyle(grid.Style)"> Style="@GetOptionalStyle(grid.Style)">
@this.RenderChildren(grid.Children) @this.RenderChildren(grid.Children)
</MudGrid> </MudGrid>
} }
@ -291,7 +290,7 @@ else
Wrap="@(AssistantComponentPropHelper.GetWrap(stack.Wrap) ?? Wrap.Wrap)" Wrap="@(AssistantComponentPropHelper.GetWrap(stack.Wrap) ?? Wrap.Wrap)"
Spacing="@stack.Spacing" Spacing="@stack.Spacing"
Class="@stack.Class" Class="@stack.Class"
Style="@this.GetOptionalStyle(stack.Style)"> Style="@GetOptionalStyle(stack.Style)">
@this.RenderChildren(stack.Children) @this.RenderChildren(stack.Children)
</MudStack> </MudStack>
} }
@ -308,7 +307,7 @@ else
Elevation="@accordion.Elevation" Elevation="@accordion.Elevation"
Gutters="@accordion.HasSectionPaddings" Gutters="@accordion.HasSectionPaddings"
Class="@MergeClass(accordion.Class, "my-6")" Class="@MergeClass(accordion.Class, "my-6")"
Style="@this.GetOptionalStyle(accordion.Style)"> Style="@GetOptionalStyle(accordion.Style)">
@this.RenderChildren(accordion.Children) @this.RenderChildren(accordion.Children)
</MudExpansionPanels> </MudExpansionPanels>
} }
@ -328,7 +327,7 @@ else
Icon="@AssistantComponentPropHelper.GetIconSvg(accordionSection.ExpandIcon)" Icon="@AssistantComponentPropHelper.GetIconSvg(accordionSection.ExpandIcon)"
MaxHeight="@accordionSection.MaxHeight" MaxHeight="@accordionSection.MaxHeight"
Class="@accordionSection.Class" Class="@accordionSection.Class"
Style="@this.GetOptionalStyle(accordionSection.Style)"> Style="@GetOptionalStyle(accordionSection.Style)">
<TitleContent> <TitleContent>
<div class="d-flex"> <div class="d-flex">
<MudIcon Icon="@AssistantComponentPropHelper.GetIconSvg(accordionSection.HeaderIcon)" class="mr-3"></MudIcon> <MudIcon Icon="@AssistantComponentPropHelper.GetIconSvg(accordionSection.HeaderIcon)" class="mr-3"></MudIcon>
@ -349,7 +348,7 @@ else
case AssistantComponentType.PROVIDER_SELECTION: case AssistantComponentType.PROVIDER_SELECTION:
if (component is AssistantProviderSelection providerSelection) if (component is AssistantProviderSelection providerSelection)
{ {
<div class="@providerSelection.Class" style="@this.GetOptionalStyle(providerSelection.Style)"> <div class="@providerSelection.Class" style="@GetOptionalStyle(providerSelection.Style)">
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider" /> <ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider" />
</div> </div>
} }
@ -359,8 +358,8 @@ else
if (component is AssistantProfileSelection profileSelection) if (component is AssistantProfileSelection profileSelection)
{ {
var selection = profileSelection; var selection = profileSelection;
<div class="@selection.Class" style="@this.GetOptionalStyle(selection.Style)"> <div class="@selection.Class" style="@GetOptionalStyle(selection.Style)">
<ProfileFormSelection Validation="@((Profile profile) => this.ValidateProfileSelection(selection, profile))" @bind-Profile="@this.currentProfile" /> <ProfileFormSelection Validation="@(profile => this.ValidateProfileSelection(selection, profile))" @bind-Profile="@this.currentProfile" />
</div> </div>
} }
break; break;
@ -395,7 +394,7 @@ else
_ => Typo.h5 _ => Typo.h5
}; };
<MudText Typo="@typo" Class="@heading.Class" Style="@this.GetOptionalStyle(heading.Style)">@heading.Text</MudText> <MudText Typo="@typo" Class="@heading.Class" Style="@GetOptionalStyle(heading.Style)">@heading.Text</MudText>
} }
break; break;
@ -403,7 +402,7 @@ else
if (component is AssistantText assistantText) if (component is AssistantText assistantText)
{ {
var text = assistantText; var text = assistantText;
<MudText Typo="Typo.body1" Class='@MergeClass(text.Class, "mb-3")' Style="@this.GetOptionalStyle(text.Style)">@text.Content</MudText> <MudText Typo="Typo.body1" Class='@MergeClass(text.Class, "mb-3")' Style="@GetOptionalStyle(text.Style)">@text.Content</MudText>
} }
break; break;
@ -411,7 +410,7 @@ else
if (component is AssistantList assistantList) if (component is AssistantList assistantList)
{ {
var list = assistantList; var list = assistantList;
<MudList T="string" Class='@MergeClass(list.Class, "mb-6")' Style="@this.GetOptionalStyle(list.Style)"> <MudList T="string" Class='@MergeClass(list.Class, "mb-6")' Style="@GetOptionalStyle(list.Style)">
@foreach (var item in list.Items) @foreach (var item in list.Items)
{ {
var iconColor = AssistantComponentPropHelper.GetColor(item.IconColor, Color.Default); var iconColor = AssistantComponentPropHelper.GetColor(item.IconColor, Color.Default);
@ -439,7 +438,7 @@ else
<MudItem Class="d-flex"> <MudItem Class="d-flex">
<MudColorPicker Text="@this.assistantState.Colors[colorPicker.Name]" <MudColorPicker Text="@this.assistantState.Colors[colorPicker.Name]"
TextChanged="@((string value) => this.assistantState.Colors[colorPicker.Name] = value)" TextChanged="@(value => this.assistantState.Colors[colorPicker.Name] = value)"
Label="@colorPicker.Label" Label="@colorPicker.Label"
Placeholder="@colorPicker.Placeholder" Placeholder="@colorPicker.Placeholder"
ShowAlpha="@colorPicker.ShowAlpha" ShowAlpha="@colorPicker.ShowAlpha"
@ -462,7 +461,7 @@ else
<MudPaper Class="d-flex" Elevation="0"> <MudPaper Class="d-flex" Elevation="0">
<MudDatePicker Date="@datePicker.ParseValue(this.assistantState.Dates[datePicker.Name])" <MudDatePicker Date="@datePicker.ParseValue(this.assistantState.Dates[datePicker.Name])"
DateChanged="@((DateTime? value) => this.assistantState.Dates[datePicker.Name] = datePicker.FormatValue(value))" DateChanged="@(value => this.assistantState.Dates[datePicker.Name] = datePicker.FormatValue(value))"
Label="@datePicker.Label" Label="@datePicker.Label"
Color="@AssistantComponentPropHelper.GetColor(datePicker.Color, Color.Primary)" Color="@AssistantComponentPropHelper.GetColor(datePicker.Color, Color.Primary)"
Placeholder="@datePicker.Placeholder" Placeholder="@datePicker.Placeholder"
@ -472,7 +471,7 @@ else
PickerVariant="@AssistantComponentPropHelper.GetPickerVariant(datePicker.PickerVariant, PickerVariant.Static)" PickerVariant="@AssistantComponentPropHelper.GetPickerVariant(datePicker.PickerVariant, PickerVariant.Static)"
Variant="Variant.Outlined" Variant="Variant.Outlined"
Class='@MergeClass(datePicker.Class, "mb-3")' Class='@MergeClass(datePicker.Class, "mb-3")'
Style="@this.GetOptionalStyle(datePicker.Style)" Style="@GetOptionalStyle(datePicker.Style)"
/> />
</MudPaper> </MudPaper>
} }
@ -485,6 +484,7 @@ else
var format = dateRangePicker.GetDateFormat(); var format = dateRangePicker.GetDateFormat();
<MudPaper Class="d-flex" Elevation="0"> <MudPaper Class="d-flex" Elevation="0">
@* ReSharper disable CSharpWarnings::CS8619 *@
<MudDateRangePicker DateRange="@dateRangePicker.ParseValue(this.assistantState.DateRanges[dateRangePicker.Name])" <MudDateRangePicker DateRange="@dateRangePicker.ParseValue(this.assistantState.DateRanges[dateRangePicker.Name])"
DateRangeChanged="@(value => this.assistantState.DateRanges[dateRangePicker.Name] = dateRangePicker.FormatValue(value))" DateRangeChanged="@(value => this.assistantState.DateRanges[dateRangePicker.Name] = dateRangePicker.FormatValue(value))"
Label="@dateRangePicker.Label" Label="@dateRangePicker.Label"
@ -497,8 +497,9 @@ else
Elevation="@dateRangePicker.Elevation" Elevation="@dateRangePicker.Elevation"
Variant="Variant.Outlined" Variant="Variant.Outlined"
Class='@MergeClass(dateRangePicker.Class, "mb-3")' Class='@MergeClass(dateRangePicker.Class, "mb-3")'
Style="@this.GetOptionalStyle(dateRangePicker.Style)" Style="@GetOptionalStyle(dateRangePicker.Style)"
/> />
@* ReSharper restore CSharpWarnings::CS8619 *@
</MudPaper> </MudPaper>
} }
break; break;
@ -511,7 +512,7 @@ else
<MudPaper Class="d-flex" Elevation="0"> <MudPaper Class="d-flex" Elevation="0">
<MudTimePicker Time="@timePicker.ParseValue(this.assistantState.Times[timePicker.Name])" <MudTimePicker Time="@timePicker.ParseValue(this.assistantState.Times[timePicker.Name])"
TimeChanged="@((TimeSpan? value) => this.assistantState.Times[timePicker.Name] = timePicker.FormatValue(value))" TimeChanged="@(value => this.assistantState.Times[timePicker.Name] = timePicker.FormatValue(value))"
Label="@timePicker.Label" Label="@timePicker.Label"
Color="@AssistantComponentPropHelper.GetColor(timePicker.Color, Color.Primary)" Color="@AssistantComponentPropHelper.GetColor(timePicker.Color, Color.Primary)"
Placeholder="@timePicker.Placeholder" Placeholder="@timePicker.Placeholder"
@ -522,7 +523,7 @@ else
Elevation="@timePicker.Elevation" Elevation="@timePicker.Elevation"
Variant="Variant.Outlined" Variant="Variant.Outlined"
Class='@MergeClass(timePicker.Class, "mb-3")' Class='@MergeClass(timePicker.Class, "mb-3")'
Style="@this.GetOptionalStyle(timePicker.Style)"/> Style="@GetOptionalStyle(timePicker.Style)"/>
</MudPaper> </MudPaper>
} }
break; break;
@ -573,7 +574,7 @@ else
if (!string.IsNullOrWhiteSpace(itemClass)) if (!string.IsNullOrWhiteSpace(itemClass))
builder.AddAttribute(7, nameof(MudItem.Class), itemClass); builder.AddAttribute(7, nameof(MudItem.Class), itemClass);
var itemStyle = this.GetOptionalStyle(item.Style); var itemStyle = GetOptionalStyle(item.Style);
if (!string.IsNullOrWhiteSpace(itemStyle)) if (!string.IsNullOrWhiteSpace(itemStyle))
builder.AddAttribute(8, nameof(MudItem.Style), itemStyle); builder.AddAttribute(8, nameof(MudItem.Style), itemStyle);

View File

@ -13,7 +13,7 @@ namespace AIStudio.Assistants.Dynamic;
public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel> public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel>
{ {
[Parameter] [Parameter]
public AssistantForm? RootComponent { get; set; } = null!; public AssistantForm? RootComponent { get; set; }
protected override string Title => this.title; protected override string Title => this.title;
protected override string Description => this.description; protected override string Description => this.description;
@ -171,9 +171,8 @@ public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel>
private LuaTable BuildPromptInput() private LuaTable BuildPromptInput()
{ {
var state = new LuaTable();
var rootComponent = this.RootComponent; var rootComponent = this.RootComponent;
state = rootComponent is not null var state = rootComponent is not null
? this.assistantState.ToLuaTable(rootComponent.Children) ? this.assistantState.ToLuaTable(rootComponent.Children)
: new LuaTable(); : new LuaTable();
@ -184,8 +183,8 @@ public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel>
["Actions"] = this.currentProfile.Actions, ["Actions"] = this.currentProfile.Actions,
["Num"] = this.currentProfile.Num, ["Num"] = this.currentProfile.Num,
}; };
state["profile"] = profile;
state["profile"] = profile;
return state; return state;
} }
@ -218,7 +217,7 @@ public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel>
return string.IsNullOrEmpty(trimmedFallback) ? trimmedCustom : $"{trimmedCustom} {trimmedFallback}"; 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 IsButtonActionRunning(string buttonName) => this.executingButtonActions.Contains(buttonName);
private bool IsSwitchActionRunning(string switchName) => this.executingSwitchActions.Contains(switchName); private bool IsSwitchActionRunning(string switchName) => this.executingSwitchActions.Contains(switchName);
@ -251,7 +250,7 @@ public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel>
if (string.IsNullOrWhiteSpace(switchComponent.Name)) if (string.IsNullOrWhiteSpace(switchComponent.Name))
return; return;
this.assistantState.Bools[switchComponent.Name] = value; this.assistantState.Booleans[switchComponent.Name] = value;
if (this.assistantPlugin is null || switchComponent.OnChanged is null) if (this.assistantPlugin is null || switchComponent.OnChanged is null)
{ {

View File

@ -364,8 +364,6 @@ public partial class ContentBlockComponent : MSGComponentBase, IAsyncDisposable
AddMarkdownSegment(markdownSegmentStart, lineStart); AddMarkdownSegment(markdownSegmentStart, lineStart);
mathContentStart = nextLineStart; mathContentStart = nextLineStart;
activeMathBlockFenceType = MathBlockFenceType.BRACKET; activeMathBlockFenceType = MathBlockFenceType.BRACKET;
lineStart = nextLineStart;
continue;
} }
} }
else if (activeMathBlockFenceType is MathBlockFenceType.DOLLAR && trimmedLine.SequenceEqual(MATH_BLOCK_MARKER_DOLLAR.AsSpan())) 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; markdownSegmentStart = nextLineStart;
activeMathBlockFenceType = MathBlockFenceType.NONE; activeMathBlockFenceType = MathBlockFenceType.NONE;
lineStart = nextLineStart;
continue;
} }
else if (activeMathBlockFenceType is MathBlockFenceType.BRACKET && trimmedLine.SequenceEqual(MATH_BLOCK_MARKER_BRACKET_CLOSE.AsSpan())) 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; markdownSegmentStart = nextLineStart;
activeMathBlockFenceType = MathBlockFenceType.NONE; activeMathBlockFenceType = MathBlockFenceType.NONE;
lineStart = nextLineStart;
continue;
} }
lineStart = nextLineStart; lineStart = nextLineStart;

View File

@ -3,7 +3,6 @@ using System.Text.Json.Serialization;
using AIStudio.Provider; using AIStudio.Provider;
using AIStudio.Settings; using AIStudio.Settings;
using AIStudio.Tools;
using AIStudio.Tools.PluginSystem; using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.RAG.RAGProcesses; using AIStudio.Tools.RAG.RAGProcesses;

View File

@ -13,7 +13,7 @@
var block = blocks[i]; var block = blocks[i];
var isLastBlock = i == blocks.Count - 1; var isLastBlock = i == blocks.Count - 1;
var isSecondLastBlock = i == blocks.Count - 2; var isSecondLastBlock = i == blocks.Count - 2;
@if (!block.HideFromUser) @if (block is { HideFromUser: false, Content: not null })
{ {
<ContentBlockComponent <ContentBlockComponent
@key="@block" @key="@block"

View File

@ -1,5 +1,4 @@
@using AIStudio.Tools.PluginSystem.Assistants.DataModel <MudStack Row="true" Class='@MergeClasses(this.Class, "mb-3")' Style="@this.Style">
<MudStack Row="true" Class='@this.MergeClasses(this.Class, "mb-3")' Style="@this.Style">
@if (this.IsMultiselect) @if (this.IsMultiselect)
{ {
<MudSelect <MudSelect

View File

@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AIStudio.Tools.PluginSystem.Assistants.DataModel; using AIStudio.Tools.PluginSystem.Assistants.DataModel;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using MudBlazor;
namespace AIStudio.Components namespace AIStudio.Components
{ {
@ -92,7 +87,7 @@ namespace AIStudio.Components
private List<AssistantDropdownItem> GetRenderedItems() private List<AssistantDropdownItem> GetRenderedItems()
{ {
var items = this.Items ?? []; var items = this.Items;
if (string.IsNullOrWhiteSpace(this.Default.Value)) if (string.IsNullOrWhiteSpace(this.Default.Value))
return items; return items;
@ -122,10 +117,10 @@ namespace AIStudio.Components
return item?.Display ?? value; 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 trimmedCustom = custom.Trim();
var trimmedFallback = fallback?.Trim() ?? string.Empty; var trimmedFallback = fallback.Trim();
if (string.IsNullOrEmpty(trimmedCustom)) if (string.IsNullOrEmpty(trimmedCustom))
return trimmedFallback; return trimmedFallback;

View File

@ -24,7 +24,7 @@ else
case TreeItemData treeItem: case TreeItemData treeItem:
@if (treeItem.Type is TreeItemType.LOADING) @if (treeItem.Type is TreeItemType.LOADING)
{ {
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@false" Items="@treeItem.Children"> <MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@false" Items="@treeItem.Children!">
<BodyContent> <BodyContent>
<MudSkeleton Width="85%" Height="22px"/> <MudSkeleton Width="85%" Height="22px"/>
</BodyContent> </BodyContent>
@ -32,7 +32,7 @@ else
} }
else if (treeItem.Type is TreeItemType.CHAT) else if (treeItem.Type is TreeItemType.CHAT)
{ {
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@treeItem.Expandable" Items="@treeItem.Children" OnClick="@(() => this.LoadChatAsync(treeItem.Path, true))"> <MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@treeItem.Expandable" Items="@treeItem.Children!" OnClick="@(() => this.LoadChatAsync(treeItem.Path, true))">
<BodyContent> <BodyContent>
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%"> <div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;"> <MudText Style="justify-self: start;">
@ -65,7 +65,7 @@ else
} }
else if (treeItem.Type is TreeItemType.WORKSPACE) else if (treeItem.Type is TreeItemType.WORKSPACE)
{ {
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@treeItem.Expandable" Items="@treeItem.Children" OnClick="@(() => this.OnWorkspaceClicked(treeItem))"> <MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@treeItem.Expandable" Items="@treeItem.Children!" OnClick="@(() => this.OnWorkspaceClicked(treeItem))">
<BodyContent> <BodyContent>
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%"> <div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;"> <MudText Style="justify-self: start;">
@ -86,7 +86,7 @@ else
} }
else else
{ {
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@treeItem.Expandable" Items="@treeItem.Children"> <MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@treeItem.Expandable" Items="@treeItem.Children!">
<BodyContent> <BodyContent>
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%"> <div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;"> <MudText Style="justify-self: start;">

View File

@ -32,7 +32,6 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase
private PluginAssistantAudit? audit; private PluginAssistantAudit? audit;
private string promptPreview = string.Empty; private string promptPreview = string.Empty;
private string promptFallbackPreview = string.Empty; private string promptFallbackPreview = string.Empty;
private string componentSummary = string.Empty;
private ImmutableDictionary<string, string> luaFiles = ImmutableDictionary.Create<string, string>(); private ImmutableDictionary<string, string> luaFiles = ImmutableDictionary.Create<string, string>();
private IReadOnlyCollection<TreeItemData<ITreeItem>> componentTreeItems = []; private IReadOnlyCollection<TreeItemData<ITreeItem>> componentTreeItems = [];
private IReadOnlyCollection<TreeItemData<ITreeItem>> fileSystemTreeItems = []; private IReadOnlyCollection<TreeItemData<ITreeItem>> fileSystemTreeItems = [];
@ -77,7 +76,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase
{ {
this.promptPreview = await this.plugin.BuildAuditPromptPreviewAsync(); this.promptPreview = await this.plugin.BuildAuditPromptPreviewAsync();
this.promptFallbackPreview = this.plugin.BuildAuditPromptFallbackPreview(); this.promptFallbackPreview = this.plugin.BuildAuditPromptFallbackPreview();
this.componentSummary = this.plugin.CreateAuditComponentSummary(); this.plugin.CreateAuditComponentSummary();
this.componentTreeItems = this.CreateAuditTreeItems(this.plugin.RootComponent); this.componentTreeItems = this.CreateAuditTreeItems(this.plugin.RootComponent);
this.fileSystemTreeItems = this.CreatePluginFileSystemTreeItems(this.plugin.PluginPath); this.fileSystemTreeItems = this.CreatePluginFileSystemTreeItems(this.plugin.PluginPath);
this.luaFiles = this.plugin.ReadAllLuaFiles(); this.luaFiles = this.plugin.ReadAllLuaFiles();
@ -262,7 +261,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase
if (value is IDictionary dictionary) if (value is IDictionary dictionary)
return this.CreateDictionaryChildren(dictionary, depth); 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.CreateEnumerableChildren(enumerable, depth);
return this.CreateObjectChildren(value, depth); return this.CreateObjectChildren(value, depth);
@ -328,11 +327,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase
}; };
} }
private TreeItemData<ITreeItem> CreateFileTreeItem(string filePath, int depth) private TreeItemData<ITreeItem> CreateFileTreeItem(string filePath, int depth) => new()
{
var fileInfo = new FileInfo(filePath);
return new TreeItemData<ITreeItem>
{ {
Expanded = depth < 2, Expanded = depth < 2,
Expandable = false, Expandable = false,
@ -340,14 +335,13 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase
{ {
Text = Path.GetFileName(filePath), Text = Path.GetFileName(filePath),
Caption = string.Empty, Caption = string.Empty,
Icon = this.GetFileIcon(filePath), Icon = GetFileIcon(filePath),
Expandable = false, Expandable = false,
IsComponent = false, IsComponent = false,
}, },
}; };
}
private string GetFileIcon(string filePath) private static string GetFileIcon(string filePath)
{ {
var extension = Path.GetExtension(filePath); var extension = Path.GetExtension(filePath);
return extension.ToLowerInvariant() switch return extension.ToLowerInvariant() switch
@ -376,7 +370,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase
/// <summary> /// <summary>
/// Falls back to public instance properties for simple DTO-style values such as dropdown items. /// 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.
/// </summary> /// </summary>
private List<TreeItemData<ITreeItem>> CreateObjectChildren(object value, int depth) private List<TreeItemData<ITreeItem>> CreateObjectChildren(object value, int depth)
{ {

View File

@ -19,7 +19,7 @@ public sealed class AssistantPluginAuditService(AssistantAuditAgent auditAgent)
PluginHash = plugin.ComputeAuditHash(), PluginHash = plugin.ComputeAuditHash(),
AuditedAtUtc = DateTimeOffset.UtcNow, AuditedAtUtc = DateTimeOffset.UtcNow,
AuditProviderId = provider.Id, AuditProviderId = provider.Id,
AuditProviderName = provider == AIStudio.Settings.Provider.NONE AuditProviderName = provider == Settings.Provider.NONE
? string.Empty ? string.Empty
: provider.InstanceName, : provider.InstanceName,
Level = AssistantAuditLevelExtensions.Parse(result.Level), Level = AssistantAuditLevelExtensions.Parse(result.Level),

View File

@ -16,7 +16,7 @@ public sealed class AssistantButton : NamedAssistantComponentBase
public bool IsIconButton 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsIconButton), value);
} }
@ -40,7 +40,7 @@ public sealed class AssistantButton : NamedAssistantComponentBase
public bool IsFullWidth 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsFullWidth), value);
} }

View File

@ -26,13 +26,13 @@ public sealed class AssistantButtonGroup : NamedAssistantComponentBase
public bool OverrideStyles 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.OverrideStyles), value);
} }
public bool Vertical 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Vertical), value);
} }

View File

@ -7,31 +7,23 @@ internal static class AssistantComponentPropHelper
public static string ReadString(Dictionary<string, object> props, string key) public static string ReadString(Dictionary<string, object> props, string key)
{ {
if (props.TryGetValue(key, out var value)) if (props.TryGetValue(key, out var value))
{ return value.ToString() ?? string.Empty;
return value?.ToString() ?? string.Empty;
}
return string.Empty; return string.Empty;
} }
public static void WriteString(Dictionary<string, object> props, string key, string value) public static void WriteString(Dictionary<string, object> props, string key, string value) => props[key] = value;
{
props[key] = value ?? string.Empty;
}
public static int ReadInt(Dictionary<string, object> props, string key, int fallback = 0) public static int ReadInt(Dictionary<string, object> props, string key, int fallback = 0)
{ {
return props.TryGetValue(key, out var value) && int.TryParse(value?.ToString(), out var i) ? i : fallback; return props.TryGetValue(key, out var value) && int.TryParse(value.ToString(), out var i) ? i : fallback;
} }
public static void WriteInt(Dictionary<string, object> props, string key, int value) public static void WriteInt(Dictionary<string, object> props, string key, int value) => props[key] = value;
{
props[key] = value;
}
public static int? ReadNullableInt(Dictionary<string, object> props, string key) public static int? ReadNullableInt(Dictionary<string, object> 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<string, object> props, string key, int? value) public static void WriteNullableInt(Dictionary<string, object> 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; return props.TryGetValue(key, out var value) && bool.TryParse(value.ToString(), out var b) ? b : fallback;
} }
public static void WriteBool(Dictionary<string, object> props, string key, bool value) public static void WriteBool(Dictionary<string, object> props, string key, bool value) => props[key] = value;
{
props[key] = value;
}
public static void WriteObject(Dictionary<string, object> props, string key, object? value) public static void WriteObject(Dictionary<string, object> props, string key, object? value)
{ {
@ -60,9 +49,9 @@ internal static class AssistantComponentPropHelper
props[key] = value; props[key] = value;
} }
public static MudBlazor.Color GetColor(string value, Color fallback) => Enum.TryParse<MudBlazor.Color>(value, out var color) ? color : fallback; public static Color GetColor(string value, Color fallback) => Enum.TryParse<Color>(value, out var color) ? color : fallback;
public static MudBlazor.Variant GetVariant(string value, Variant fallback) => Enum.TryParse<MudBlazor.Variant>(value, out var variant) ? variant : fallback; public static Variant GetVariant(string value, Variant fallback) => Enum.TryParse<Variant>(value, out var variant) ? variant : fallback;
public static MudBlazor.Adornment GetAdornment(string value, Adornment fallback) => Enum.TryParse<MudBlazor.Adornment>(value, out var adornment) ? adornment : fallback; public static Adornment GetAdornment(string value, Adornment fallback) => Enum.TryParse<Adornment>(value, out var adornment) ? adornment : fallback;
public static string GetIconSvg(string value) => MudBlazorIconRegistry.TryGetSvg(value.TrimStart('@'), out var svg) ? svg : string.Empty; 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<Size>(value, out var size) ? size : fallback; public static Size GetComponentSize(string value, Size fallback) => Enum.TryParse<Size>(value, out var size) ? size : fallback;
public static Justify? GetJustify(string value) => Enum.TryParse<Justify>(value, out var justify) ? justify : null; public static Justify? GetJustify(string value) => Enum.TryParse<Justify>(value, out var justify) ? justify : null;

View File

@ -1,5 +1,4 @@
using System.Globalization; using System.Globalization;
using MudBlazor;
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel; namespace AIStudio.Tools.PluginSystem.Assistants.DataModel;

View File

@ -42,13 +42,13 @@ internal sealed class AssistantDropdown : StatefulAssistantComponentBase
public bool IsMultiselect 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsMultiselect), value);
} }
public bool HasSelectAll 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.HasSelectAll), value);
} }

View File

@ -8,7 +8,7 @@ public sealed class AssistantState
public readonly Dictionary<string, string> Text = new(StringComparer.Ordinal); public readonly Dictionary<string, string> Text = new(StringComparer.Ordinal);
public readonly Dictionary<string, string> SingleSelect = new(StringComparer.Ordinal); public readonly Dictionary<string, string> SingleSelect = new(StringComparer.Ordinal);
public readonly Dictionary<string, HashSet<string>> MultiSelect = new(StringComparer.Ordinal); public readonly Dictionary<string, HashSet<string>> MultiSelect = new(StringComparer.Ordinal);
public readonly Dictionary<string, bool> Bools = new(StringComparer.Ordinal); public readonly Dictionary<string, bool> Booleans = new(StringComparer.Ordinal);
public readonly Dictionary<string, WebContentState> WebContent = new(StringComparer.Ordinal); public readonly Dictionary<string, WebContentState> WebContent = new(StringComparer.Ordinal);
public readonly Dictionary<string, FileContentState> FileContent = new(StringComparer.Ordinal); public readonly Dictionary<string, FileContentState> FileContent = new(StringComparer.Ordinal);
public readonly Dictionary<string, string> Colors = new(StringComparer.Ordinal); public readonly Dictionary<string, string> Colors = new(StringComparer.Ordinal);
@ -21,7 +21,7 @@ public sealed class AssistantState
this.Text.Clear(); this.Text.Clear();
this.SingleSelect.Clear(); this.SingleSelect.Clear();
this.MultiSelect.Clear(); this.MultiSelect.Clear();
this.Bools.Clear(); this.Booleans.Clear();
this.WebContent.Clear(); this.WebContent.Clear();
this.FileContent.Clear(); this.FileContent.Clear();
this.Colors.Clear(); this.Colors.Clear();
@ -40,7 +40,7 @@ public sealed class AssistantState
if (!value.TryRead<string>(out var textValue)) if (!value.TryRead<string>(out var textValue))
return false; return false;
this.Text[fieldName] = textValue ?? string.Empty; this.Text[fieldName] = textValue;
return true; return true;
} }
@ -50,7 +50,7 @@ public sealed class AssistantState
if (!value.TryRead<string>(out var singleSelectValue)) if (!value.TryRead<string>(out var singleSelectValue))
return false; return false;
this.SingleSelect[fieldName] = singleSelectValue ?? string.Empty; this.SingleSelect[fieldName] = singleSelectValue;
return true; return true;
} }
@ -70,13 +70,13 @@ public sealed class AssistantState
return true; return true;
} }
if (this.Bools.ContainsKey(fieldName)) if (this.Booleans.ContainsKey(fieldName))
{ {
expectedType = "boolean"; expectedType = "boolean";
if (!value.TryRead<bool>(out var boolValue)) if (!value.TryRead<bool>(out var boolValue))
return false; return false;
this.Bools[fieldName] = boolValue; this.Booleans[fieldName] = boolValue;
return true; return true;
} }
@ -86,7 +86,7 @@ public sealed class AssistantState
if (!value.TryRead<string>(out var webContentValue)) if (!value.TryRead<string>(out var webContentValue))
return false; return false;
webContentState.Content = webContentValue ?? string.Empty; webContentState.Content = webContentValue;
return true; return true;
} }
@ -96,7 +96,7 @@ public sealed class AssistantState
if (!value.TryRead<string>(out var fileContentValue)) if (!value.TryRead<string>(out var fileContentValue))
return false; return false;
fileContentState.Content = fileContentValue ?? string.Empty; fileContentState.Content = fileContentValue;
return true; return true;
} }
@ -106,7 +106,7 @@ public sealed class AssistantState
if (!value.TryRead<string>(out var colorValue)) if (!value.TryRead<string>(out var colorValue))
return false; return false;
this.Colors[fieldName] = colorValue ?? string.Empty; this.Colors[fieldName] = colorValue;
return true; return true;
} }
@ -116,7 +116,7 @@ public sealed class AssistantState
if (!value.TryRead<string>(out var dateValue)) if (!value.TryRead<string>(out var dateValue))
return false; return false;
this.Dates[fieldName] = dateValue ?? string.Empty; this.Dates[fieldName] = dateValue;
return true; return true;
} }
@ -126,7 +126,7 @@ public sealed class AssistantState
if (!value.TryRead<string>(out var dateRangeValue)) if (!value.TryRead<string>(out var dateRangeValue))
return false; return false;
this.DateRanges[fieldName] = dateRangeValue ?? string.Empty; this.DateRanges[fieldName] = dateRangeValue;
return true; return true;
} }
@ -136,7 +136,7 @@ public sealed class AssistantState
if (!value.TryRead<string>(out var timeValue)) if (!value.TryRead<string>(out var timeValue))
return false; return false;
this.Times[fieldName] = timeValue ?? string.Empty; this.Times[fieldName] = timeValue;
return true; return true;
} }
@ -158,7 +158,7 @@ public sealed class AssistantState
{ {
target[named.Name] = new LuaTable target[named.Name] = new LuaTable
{ {
["Type"] = Enum.GetName<AssistantComponentType>(component.Type) ?? string.Empty, ["Type"] = Enum.GetName(component.Type) ?? string.Empty,
["Value"] = component is IStatefulAssistantComponent ? this.ReadValueForLua(named.Name) : LuaValue.Nil, ["Value"] = component is IStatefulAssistantComponent ? this.ReadValueForLua(named.Name) : LuaValue.Nil,
["Props"] = this.CreatePropsTable(component), ["Props"] = this.CreatePropsTable(component),
}; };
@ -177,12 +177,12 @@ public sealed class AssistantState
return singleSelectValue; return singleSelectValue;
if (this.MultiSelect.TryGetValue(name, out var multiSelectValue)) if (this.MultiSelect.TryGetValue(name, out var multiSelectValue))
return AssistantLuaConversion.CreateLuaArray(multiSelectValue.OrderBy(static value => value, StringComparer.Ordinal)); 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; return boolValue;
if (this.WebContent.TryGetValue(name, out var webContentValue)) if (this.WebContent.TryGetValue(name, out var webContentValue))
return webContentValue.Content ?? string.Empty; return webContentValue.Content;
if (this.FileContent.TryGetValue(name, out var fileContentValue)) if (this.FileContent.TryGetValue(name, out var fileContentValue))
return fileContentValue.Content ?? string.Empty; return fileContentValue.Content;
if (this.Colors.TryGetValue(name, out var colorValue)) if (this.Colors.TryGetValue(name, out var colorValue))
return colorValue; return colorValue;
if (this.Dates.TryGetValue(name, out var dateValue)) if (this.Dates.TryGetValue(name, out var dateValue))
@ -211,6 +211,7 @@ public sealed class AssistantState
continue; continue;
if (!AssistantLuaConversion.TryWriteAssistantValue(table, key, value)) if (!AssistantLuaConversion.TryWriteAssistantValue(table, key, value))
// ReSharper disable once RedundantJumpStatement
continue; continue;
} }

View File

@ -17,13 +17,13 @@ public sealed class AssistantSwitch : StatefulAssistantComponentBase
public bool Value 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Value), value);
} }
public bool Disabled 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Disabled), value);
} }
@ -91,19 +91,19 @@ public sealed class AssistantSwitch : StatefulAssistantComponentBase
public override void InitializeState(AssistantState state) public override void InitializeState(AssistantState state)
{ {
if (!state.Bools.ContainsKey(this.Name)) if (!state.Booleans.ContainsKey(this.Name))
state.Bools[this.Name] = this.Value; state.Booleans[this.Name] = this.Value;
} }
public override string UserPromptFallback(AssistantState state) 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()); return this.BuildAuditPromptBlock(userDecision.ToString());
} }
#endregion #endregion
public MudBlazor.Color GetColor(string colorString) => Enum.TryParse<Color>(colorString, out var color) ? color : MudBlazor.Color.Inherit; public static Color GetColor(string colorString) => Enum.TryParse<Color>(colorString, out var color) ? color : Color.Inherit;
public Placement GetLabelPlacement() => Enum.TryParse<Placement>(this.LabelPlacement, out var placement) ? placement : Placement.Right; public Placement GetLabelPlacement() => Enum.TryParse<Placement>(this.LabelPlacement, out var placement) ? placement : Placement.Right;
public string GetIconSvg() => MudBlazorIconRegistry.TryGetSvg(this.Icon, out var svg) ? svg : string.Empty; public string GetIconSvg() => MudBlazorIconRegistry.TryGetSvg(this.Icon, out var svg) ? svg : string.Empty;
} }

View File

@ -1,5 +1,3 @@
using AIStudio.Tools.PluginSystem.Assistants.Icons;
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel; namespace AIStudio.Tools.PluginSystem.Assistants.DataModel;
internal sealed class AssistantTextArea : StatefulAssistantComponentBase internal sealed class AssistantTextArea : StatefulAssistantComponentBase
@ -22,7 +20,7 @@ internal sealed class AssistantTextArea : StatefulAssistantComponentBase
public bool HelperTextOnFocus 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.HelperTextOnFocus), value);
} }
@ -76,13 +74,13 @@ internal sealed class AssistantTextArea : StatefulAssistantComponentBase
public bool IsSingleLine 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsSingleLine), value);
} }
public bool ReadOnly 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.ReadOnly), value);
} }
@ -114,7 +112,7 @@ internal sealed class AssistantTextArea : StatefulAssistantComponentBase
#endregion #endregion
public Adornment GetAdornmentPos() => Enum.TryParse<MudBlazor.Adornment>(this.Adornment, out var position) ? position : MudBlazor.Adornment.Start; public Adornment GetAdornmentPos() => Enum.TryParse<Adornment>(this.Adornment, out var position) ? position : MudBlazor.Adornment.Start;
public Color GetAdornmentColor() => Enum.TryParse<Color>(this.AdornmentColor, out var color) ? color : Color.Default; public Color GetAdornmentColor() => Enum.TryParse<Color>(this.AdornmentColor, out var color) ? color : Color.Default;
} }

View File

@ -49,7 +49,7 @@ internal sealed class AssistantTimePicker : StatefulAssistantComponentBase
public bool AmPm 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.AmPm), value);
} }

View File

@ -8,13 +8,13 @@ internal sealed class AssistantAccordion : NamedAssistantComponentBase
public bool AllowMultiSelection 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.AllowMultiSelection), value);
} }
public bool IsDense 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsDense), value);
} }
@ -26,13 +26,13 @@ internal sealed class AssistantAccordion : NamedAssistantComponentBase
public bool IsSquare 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsSquare), value);
} }
public int Elevation 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); set => AssistantComponentPropHelper.WriteInt(this.Props, nameof(this.Elevation), value);
} }

View File

@ -40,19 +40,19 @@ internal sealed class AssistantAccordionSection : NamedAssistantComponentBase
public bool IsDisabled 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsDisabled), value);
} }
public bool IsExpanded 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsExpanded), value);
} }
public bool IsDense 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsDense), value);
} }
@ -64,7 +64,7 @@ internal sealed class AssistantAccordionSection : NamedAssistantComponentBase
public bool HideIcon 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.HideIcon), value);
} }

View File

@ -50,13 +50,13 @@ internal sealed class AssistantPaper : NamedAssistantComponentBase
public bool IsOutlined 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsOutlined), value);
} }
public bool IsSquare 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsSquare), value);
} }

View File

@ -8,13 +8,13 @@ internal sealed class AssistantStack : NamedAssistantComponentBase
public bool IsRow 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsRow), value);
} }
public bool IsReverse 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); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.IsReverse), value);
} }

View File

@ -52,6 +52,7 @@ public static class PluginAssistantSecurityResolver
return MudBlazor.Icons.Material.Filled.LockOpen; return MudBlazor.Icons.Material.Filled.LockOpen;
} }
// ReSharper disable UnusedParameter.Local
private static string GetSecurityBadgeIcon(bool requiresAudit, bool hasAudit, bool hasHashMismatch, bool isBlocked, bool canOverride) private static string GetSecurityBadgeIcon(bool requiresAudit, bool hasAudit, bool hasHashMismatch, bool isBlocked, bool canOverride)
{ {
if (hasHashMismatch) if (hasHashMismatch)
@ -61,6 +62,7 @@ public static class PluginAssistantSecurityResolver
return MudBlazor.Icons.Material.Filled.Security; return MudBlazor.Icons.Material.Filled.Security;
} }
// ReSharper restore UnusedParameter.Local
/// <summary> /// <summary>
/// Resolves the effective security state for an assistant plugin. /// Resolves the effective security state for an assistant plugin.