Skip to content

Commit 035412f

Browse files
Adding providers can now be disabled using config plugins (#522)
Co-authored-by: Thorsten Sommer <[email protected]>
1 parent 6116c03 commit 035412f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+663
-219
lines changed

app/MindWork AI Studio/Assistants/AssistantBase.razor

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2 mr-3" StretchItems="StretchItems.Start">
88
<MudText Typo="Typo.h3">
9-
@(this.Title)
9+
@this.Title
1010
</MudText>
1111

12-
<MudIconButton Variant="Variant.Text" Icon="@Icons.Material.Filled.Settings" OnClick="() => this.OpenSettingsDialog()"/>
12+
<MudIconButton Variant="Variant.Text" Icon="@Icons.Material.Filled.Settings" OnClick="@(async () => await this.OpenSettingsDialog())"/>
1313
</MudStack>
1414

1515
<InnerScrolling>
@@ -26,13 +26,13 @@
2626
</CascadingValue>
2727

2828
<MudStack Row="true" AlignItems="AlignItems.Center" StretchItems="StretchItems.Start" Class="mb-3">
29-
<MudButton Disabled="@this.SubmitDisabled" Variant="Variant.Filled" OnClick="async () => await this.Start()" Style="@this.SubmitButtonStyle">
29+
<MudButton Disabled="@this.SubmitDisabled" Variant="Variant.Filled" OnClick="@(async () => await this.Start())" Style="@this.SubmitButtonStyle">
3030
@this.SubmitText
3131
</MudButton>
3232
@if (this.isProcessing && this.cancellationTokenSource is not null)
3333
{
3434
<MudTooltip Text="@TB("Stop generation")">
35-
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Filled.Stop" Color="Color.Error" OnClick="() => this.CancelStreaming()"/>
35+
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Filled.Stop" Color="Color.Error" OnClick="@(async () => await this.CancelStreaming())"/>
3636
</MudTooltip>
3737
}
3838
</MudStack>
@@ -80,7 +80,7 @@
8080
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="@TB("Send to ...")" Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
8181
@foreach (var assistant in Enum.GetValues<Components>().Where(n => n.AllowSendTo()).OrderBy(n => n.Name().Length))
8282
{
83-
<MudMenuItem OnClick="() => this.SendToAssistant(assistant, new())">
83+
<MudMenuItem OnClick="@(async () => await this.SendToAssistant(assistant, new()))">
8484
@assistant.Name()
8585
</MudMenuItem>
8686
}
@@ -94,14 +94,14 @@
9494
{
9595
case ButtonData buttonData when !string.IsNullOrWhiteSpace(buttonData.Tooltip):
9696
<MudTooltip Text="@buttonData.Tooltip">
97-
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" Disabled="@buttonData.DisabledAction()" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="async () => await buttonData.AsyncAction()">
97+
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" Disabled="@buttonData.DisabledAction()" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="@(async () => await buttonData.AsyncAction())">
9898
@buttonData.Text
9999
</MudButton>
100100
</MudTooltip>
101101
break;
102102

103103
case ButtonData buttonData:
104-
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" Disabled="@buttonData.DisabledAction()" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="async () => await buttonData.AsyncAction()">
104+
<MudButton Variant="Variant.Filled" Color="@buttonData.Color" Disabled="@buttonData.DisabledAction()" StartIcon="@GetButtonIcon(buttonData.Icon)" OnClick="@(async () => await buttonData.AsyncAction())">
105105
@buttonData.Text
106106
</MudButton>
107107
break;
@@ -110,7 +110,7 @@
110110
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="@TB("Send to ...")" Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
111111
@foreach (var assistant in Enum.GetValues<Components>().Where(n => n.AllowSendTo()).OrderBy(n => n.Name().Length))
112112
{
113-
<MudMenuItem OnClick="() => this.SendToAssistant(assistant, sendToButton)">
113+
<MudMenuItem OnClick="@(async () => await this.SendToAssistant(assistant, sendToButton))">
114114
@assistant.Name()
115115
</MudMenuItem>
116116
}
@@ -121,14 +121,14 @@
121121

122122
@if (this.ShowCopyResult)
123123
{
124-
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.ContentCopy" OnClick="() => this.CopyToClipboard()">
124+
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.ContentCopy" OnClick="@(async () => await this.CopyToClipboard())">
125125
@TB("Copy result")
126126
</MudButton>
127127
}
128128

129129
@if (this.ShowReset)
130130
{
131-
<MudButton Variant="Variant.Filled" Style="@this.GetResetColor()" StartIcon="@Icons.Material.Filled.Refresh" OnClick="() => this.InnerResetForm()">
131+
<MudButton Variant="Variant.Filled" Style="@this.GetResetColor()" StartIcon="@Icons.Material.Filled.Refresh" OnClick="@(async () => await this.InnerResetForm())">
132132
@TB("Reset")
133133
</MudButton>
134134
}

app/MindWork AI Studio/Assistants/I18N/allTexts.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIDENCEINFO::T3243388657"] = "Confiden
14501450
-- Shows and hides the confidence card with information about the selected LLM provider.
14511451
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIDENCEINFO::T847071819"] = "Shows and hides the confidence card with information about the selected LLM provider."
14521452

1453+
-- This feature is managed by your organization and has therefore been disabled.
1454+
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIGURATIONBASE::T1416426626"] = "This feature is managed by your organization and has therefore been disabled."
1455+
14531456
-- Choose the minimum confidence level that all LLM providers must meet. This way, you can ensure that only trustworthy providers are used. You cannot use any provider that falls below this level.
14541457
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIGURATIONMINCONFIDENCESELECTION::T2526727283"] = "Choose the minimum confidence level that all LLM providers must meet. This way, you can ensure that only trustworthy providers are used. You cannot use any provider that falls below this level."
14551458

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
@inherits MSGComponentBase
1+
@inherits MSGComponentBase
2+
3+
@if (this.Body is not null)
4+
{
5+
@if (!this.Disabled() && this.IsLocked())
6+
{
7+
<MudField Label="@this.Label" Variant="@this.Variant" Underline="false" HelperText="@this.OptionHelp" Class="@this.Classes" InnerPadding="false">
8+
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.FlexStart" Wrap="Wrap.NoWrap" StretchItems="this.StretchItems">
9+
@* MudTooltip.RootStyle is set as a workaround for issue -> https://github.com/MudBlazor/MudBlazor/issues/10882 *@
10+
<MudTooltip Text="@TB("This feature is managed by your organization and has therefore been disabled.")" Arrow="true" Placement="Placement.Right" RootStyle="display:inline-flex;">
11+
<MudIcon Icon="@Icons.Material.Filled.Lock" Color="Color.Error" Size="Size.Small" Class="mr-1"/>
12+
</MudTooltip>
13+
@this.Body
14+
</MudStack>
15+
</MudField>
16+
}
17+
else
18+
{
19+
<MudField Label="@this.Label" Variant="@this.Variant" Underline="false" HelperText="@this.OptionHelp" Class="@this.Classes" InnerPadding="false">
20+
@this.Body
21+
</MudField>
22+
}
23+
}

app/MindWork AI Studio/Components/ConfigurationBase.razor.cs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace AIStudio.Components;
55
/// <summary>
66
/// A base class for configuration options.
77
/// </summary>
8-
public partial class ConfigurationBase : MSGComponentBase
8+
public abstract partial class ConfigurationBase : MSGComponentBase
99
{
1010
/// <summary>
1111
/// The description of the option, i.e., the name. Should be
@@ -26,7 +26,42 @@ public partial class ConfigurationBase : MSGComponentBase
2626
[Parameter]
2727
public Func<bool> Disabled { get; set; } = () => false;
2828

29-
protected const string MARGIN_CLASS = "mb-6";
29+
/// <summary>
30+
/// Is the option locked by a configuration plugin?
31+
/// </summary>
32+
[Parameter]
33+
public Func<bool> IsLocked { get; set; } = () => false;
34+
35+
/// <summary>
36+
/// Should the option be stretched to fill the available space?
37+
/// </summary>
38+
protected abstract bool Stretch { get; }
39+
40+
/// <summary>
41+
/// The CSS class to apply to the component.
42+
/// </summary>
43+
protected virtual string GetClassForBase => string.Empty;
44+
45+
/// <summary>
46+
/// The visual variant of the option.
47+
/// </summary>
48+
protected virtual Variant Variant => Variant.Text;
49+
50+
/// <summary>
51+
/// The label to display for the option.
52+
/// </summary>
53+
protected virtual string Label => string.Empty;
54+
55+
private StretchItems StretchItems => this.Stretch ? StretchItems.End : StretchItems.None;
56+
57+
protected bool IsDisabled => this.Disabled() || this.IsLocked();
58+
59+
private string Classes => $"{this.GetClassForBase} {MARGIN_CLASS}";
60+
61+
private protected virtual RenderFragment? Body => null;
62+
63+
private const string MARGIN_CLASS = "mb-6";
64+
3065
protected static readonly Dictionary<string, object?> SPELLCHECK_ATTRIBUTES = new();
3166

3267
#region Overrides of ComponentBase
@@ -39,7 +74,9 @@ protected override async Task OnInitializedAsync()
3974
}
4075

4176
#endregion
42-
77+
78+
private string TB(string fallbackEN) => this.T(fallbackEN, typeof(ConfigurationBase).Namespace, nameof(ConfigurationBase));
79+
4380
protected async Task InformAboutChange() => await this.MessageBus.SendMessage<bool>(this, Event.CONFIGURATION_CHANGED);
4481

4582
#region Overrides of MSGComponentBase
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.AspNetCore.Components;
2+
using Microsoft.AspNetCore.Components.Rendering;
3+
4+
namespace AIStudio.Components;
5+
6+
public abstract class ConfigurationBaseCore : ConfigurationBase
7+
{
8+
private protected sealed override RenderFragment Body => this.BuildRenderTree;
9+
10+
// Allow content to be provided by a .razor file but without
11+
// overriding the content of the base class
12+
protected new virtual void BuildRenderTree(RenderTreeBuilder builder)
13+
{
14+
}
15+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@using AIStudio.Settings
22
@inherits MSGComponentBase
3-
<ConfigurationSelect Disabled="@this.Disabled" OptionDescription="@T("Select a minimum confidence level")" SelectedValue="@this.FilteredSelectedValue" Data="@ConfigurationSelectDataFactory.GetConfidenceLevelsData(this.SettingsManager, this.RestrictToGlobalMinimumConfidence)" SelectionUpdate="@this.SelectionUpdate" OptionHelp="@T("Choose the minimum confidence level that all LLM providers must meet. This way, you can ensure that only trustworthy providers are used. You cannot use any provider that falls below this level.")"/>
3+
<ConfigurationSelect IsLocked="this.IsLocked" Disabled="this.Disabled" OptionDescription="@T("Select a minimum confidence level")" SelectedValue="@this.FilteredSelectedValue" Data="@ConfigurationSelectDataFactory.GetConfidenceLevelsData(this.SettingsManager, this.RestrictToGlobalMinimumConfidence)" SelectionUpdate="@this.SelectionUpdate" OptionHelp="@T("Choose the minimum confidence level that all LLM providers must meet. This way, you can ensure that only trustworthy providers are used. You cannot use any provider that falls below this level.")"/>

app/MindWork AI Studio/Components/ConfigurationMinConfidenceSelection.razor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ public partial class ConfigurationMinConfidenceSelection : MSGComponentBase
1818
[Parameter]
1919
public Action<ConfidenceLevel> SelectionUpdate { get; set; } = _ => { };
2020

21-
/// <summary>
22-
/// Is the selection component disabled?
23-
/// </summary>
24-
[Parameter]
25-
public Func<bool> Disabled { get; set; } = () => false;
26-
2721
/// <summary>
2822
/// Boolean value indicating whether the selection is restricted to a global minimum confidence level.
2923
/// </summary>
3024
[Parameter]
3125
public bool RestrictToGlobalMinimumConfidence { get; set; }
26+
27+
[Parameter]
28+
public Func<bool> Disabled { get; set; } = () => false;
29+
30+
[Parameter]
31+
public Func<bool> IsLocked { get; set; } = () => false;
3232

3333
private ConfidenceLevel FilteredSelectedValue()
3434
{

app/MindWork AI Studio/Components/ConfigurationMultiSelect.razor

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@inherits ConfigurationBase
1+
@inherits ConfigurationBaseCore
22
@typeparam TData
33

44
<MudSelectExtended
@@ -7,12 +7,10 @@
77
MultiSelectionTextFunc="@this.GetMultiSelectionText"
88
SelectedValues="@this.SelectedValues()"
99
Strict="@true"
10-
Disabled="@this.Disabled()"
10+
Disabled="@this.IsDisabled"
1111
Margin="Margin.Dense"
12-
Label="@this.OptionDescription"
13-
Class="@GetClass"
14-
Variant="Variant.Outlined"
15-
HelperText="@this.OptionHelp"
12+
Class="rounded-lg"
13+
Underline="false"
1614
SelectedValuesChanged="@this.OptionChanged">
1715
@foreach (var data in this.Data)
1816
{

app/MindWork AI Studio/Components/ConfigurationMultiSelect.razor.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace AIStudio.Components;
88
/// Configuration component for selecting many values from a list.
99
/// </summary>
1010
/// <typeparam name="TData">The type of the value to select.</typeparam>
11-
public partial class ConfigurationMultiSelect<TData> : ConfigurationBase
11+
public partial class ConfigurationMultiSelect<TData> : ConfigurationBaseCore
1212
{
1313
/// <summary>
1414
/// The data to select from.
@@ -28,6 +28,17 @@ public partial class ConfigurationMultiSelect<TData> : ConfigurationBase
2828
[Parameter]
2929
public Action<HashSet<TData>> SelectionUpdate { get; set; } = _ => { };
3030

31+
#region Overrides of ConfigurationBase
32+
33+
/// <inheritdoc />
34+
protected override bool Stretch => true;
35+
36+
protected override Variant Variant => Variant.Outlined;
37+
38+
protected override string Label => this.OptionDescription;
39+
40+
#endregion
41+
3142
private async Task OptionChanged(IEnumerable<TData?>? updatedValues)
3243
{
3344
if(updatedValues is null)
@@ -39,8 +50,6 @@ private async Task OptionChanged(IEnumerable<TData?>? updatedValues)
3950
await this.InformAboutChange();
4051
}
4152

42-
private static string GetClass => $"{MARGIN_CLASS} rounded-lg";
43-
4453
private string GetMultiSelectionText(List<TData?>? selectedValues)
4554
{
4655
if(selectedValues is null || selectedValues.Count == 0)
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
@inherits ConfigurationBase
1+
@inherits ConfigurationBaseCore
22

3-
<MudField Disabled="@this.Disabled()" Label="@this.OptionDescription" Variant="Variant.Outlined" HelperText="@this.OptionHelp" Class="@MARGIN_CLASS">
4-
<MudSwitch T="bool" Disabled="@this.Disabled()" Value="@this.State()" ValueChanged="@this.OptionChanged" Color="Color.Primary">
5-
@(this.State() ? this.LabelOn : this.LabelOff)
6-
</MudSwitch>
7-
</MudField>
3+
<MudSwitch T="bool" Disabled="@this.IsDisabled" Value="@this.State()" ValueChanged="@this.OptionChanged" Color="Color.Primary">
4+
@(this.State() ? this.LabelOn : this.LabelOff)
5+
</MudSwitch>

0 commit comments

Comments
 (0)