Implemented remaining fields for EDI assistant

This commit is contained in:
Thorsten Sommer 2024-12-08 20:41:05 +01:00
parent e1c62e8dfc
commit c6f78fce36
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
6 changed files with 273 additions and 5 deletions

View File

@ -33,8 +33,8 @@
}
</MudStack>
<MudStack Row="@false" AlignItems="AlignItems.Stretch" Class="mb-3">
<MudSelect T="DataSources" @bind-Value="@this.selectedDataSource" AdornmentIcon="@Icons.Material.Filled.Dataset" Adornment="Adornment.Start" Label="Data source" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateDataSource">
<MudStack Row="@false" Spacing="1" Class="mb-3">
<MudSelect T="DataSources" @bind-Value="@this.selectedDataSource" AdornmentIcon="@Icons.Material.Filled.Dataset" Adornment="Adornment.Start" Label="Data source" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateDataSource" SelectedValuesChanged="@this.DataSourceWasChanged">
@foreach (var dataSource in Enum.GetValues<DataSources>())
{
<MudSelectItem Value="@dataSource">@dataSource.Name()</MudSelectItem>
@ -46,14 +46,36 @@
}
</MudStack>
<MudStack Row="@false" AlignItems="AlignItems.Stretch" Class="mb-3">
@if(this.selectedDataSource > DataSources.FILE_SYSTEM)
{
<MudTextField T="string" @bind-Text="@this.dataSourceProductName" Label="Data source: product name" Validation="@this.ValidateDataSourceProductName" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
}
@if (this.NeedHostnamePort())
{
<div class="mb-3">
<MudStack Row="@true">
<MudTextField T="string" @bind-Text="@this.dataSourceHostname" Label="Data source: hostname" Validation="@this.ValidateHostname" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
<MudNumericField Label="Data source: port" Immediate="@true" Min="1" Max="65535" Validation="@this.ValidatePort" @bind-Value="@this.dataSourcePort" Variant="Variant.Outlined" Margin="Margin.Dense"/>
</MudStack>
@if (this.dataSourcePort < 1024)
{
<MudText Typo="Typo.body2">
<b>Warning:</b> Ports below 1024 are reserved for system services. Your EDI server need to run with elevated permissions (root user).
</MudText>
}
</div>
}
<MudStack Row="@false" Spacing="1" Class="mb-1">
<MudSelectExtended
T="Auth"
ShrinkLabel="@true"
MultiSelection="@true"
MultiSelectionTextFunc="@this.GetMultiSelectionAuthText"
@bind-SelectedValues="@this.selectedAuthenticationMethods"
SelectedValues="@this.selectedAuthenticationMethods"
Validation="@this.ValidateAuthenticationMethods"
SelectedValuesChanged="@this.AuthenticationMethodWasChanged"
Label="Authentication method(s)"
Variant="Variant.Outlined"
Margin="Margin.Dense">
@ -62,7 +84,20 @@
<MudSelectItemExtended Value="@authMethod">@authMethod.Name()</MudSelectItemExtended>
}
</MudSelectExtended>
<MudTextField T="string" @bind-Text="@this.authDescription" ShrinkLabel="@true" Label="Describe how you planned the authentication" Validation="@this.ValidateAuthDescription" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="3" AutoGrow="@true" MaxLines="6" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
<MudTextField T="string" @bind-Text="@this.authDescription" Label="@this.AuthDescriptionTitle()" Validation="@this.ValidateAuthDescription" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="3" AutoGrow="@true" MaxLines="6" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
</MudStack>
@if (this.selectedAuthenticationMethods.Contains(Auth.KERBEROS))
{
<MudSelect T="OperatingSystem" @bind-Value="@this.selectedOperatingSystem" Label="Operating system on which your EDI will run" Variant="Variant.Outlined" Margin="Margin.Dense" Validation="@this.ValidateOperatingSystem" Class="mb-1">
@foreach (var os in Enum.GetValues<OperatingSystem>())
{
<MudSelectItem Value="@os">@os.Name()</MudSelectItem>
}
</MudSelect>
}
<MudTextField T="string" @bind-Text="@this.retrievalDescription" Validation="@this.ValidateRetrievalDescription" Label="Describe your data retrieval process" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="6" AutoGrow="@true" MaxLines="12" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
<MudTextField T="string" @bind-Text="@this.additionalLibraries" Label="(Optional) Additional libraries" HelperText="Do you want to include additional libraries? Then name them and briefly describe what you want to achieve with them." Variant="Variant.Outlined" Margin="Margin.Normal" Lines="3" AutoGrow="@true" MaxLines="12" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>

View File

@ -35,10 +35,45 @@ public partial class AssistantEDI : AssistantBaseCore
protected override void ResetFrom()
{
if (!this.MightPreselectValues())
{
this.selectedProgrammingLanguage = ProgrammingLanguages.NONE;
this.otherProgrammingLanguage = string.Empty;
this.selectedDataSource = DataSources.NONE;
this.dataSourceProductName = string.Empty;
this.otherDataSource = string.Empty;
this.dataSourceHostname = string.Empty;
this.dataSourcePort = null;
this.selectedAuthenticationMethods = [];
this.authDescription = string.Empty;
this.selectedOperatingSystem = OperatingSystem.NONE;
this.retrievalDescription = string.Empty;
this.additionalLibraries = string.Empty;
}
}
protected override bool MightPreselectValues()
{
if (this.SettingsManager.ConfigurationData.EDI.PreselectOptions)
{
this.selectedProgrammingLanguage = this.SettingsManager.ConfigurationData.EDI.PreselectedProgrammingLanguage;
this.otherProgrammingLanguage = this.SettingsManager.ConfigurationData.EDI.PreselectedOtherProgrammingLanguage;
this.selectedDataSource = this.SettingsManager.ConfigurationData.EDI.PreselectedDataSource;
this.dataSourceProductName = this.SettingsManager.ConfigurationData.EDI.PreselectedDataSourceProductName;
this.otherDataSource = this.SettingsManager.ConfigurationData.EDI.PreselectedOtherDataSource;
this.dataSourceHostname = this.SettingsManager.ConfigurationData.EDI.PreselectedDataSourceHostname;
this.dataSourcePort = this.SettingsManager.ConfigurationData.EDI.PreselectedDataSourcePort;
var authMethods = new HashSet<Auth>(this.SettingsManager.ConfigurationData.EDI.PreselectedAuthMethods);
this.selectedAuthenticationMethods = authMethods;
this.authDescription = this.SettingsManager.ConfigurationData.EDI.PreselectedAuthDescription;
this.selectedOperatingSystem = this.SettingsManager.ConfigurationData.EDI.PreselectedOperatingSystem;
this.retrievalDescription = this.SettingsManager.ConfigurationData.EDI.PreselectedRetrievalDescription;
this.additionalLibraries = this.SettingsManager.ConfigurationData.EDI.PreselectedAdditionalLibraries;
return true;
}
return false;
}
@ -46,8 +81,14 @@ public partial class AssistantEDI : AssistantBaseCore
private string otherProgrammingLanguage = string.Empty;
private DataSources selectedDataSource = DataSources.NONE;
private string otherDataSource = string.Empty;
private string dataSourceProductName = string.Empty;
private string dataSourceHostname = string.Empty;
private int? dataSourcePort;
private IEnumerable<Auth> selectedAuthenticationMethods = new HashSet<Auth>();
private string authDescription = string.Empty;
private OperatingSystem selectedOperatingSystem = OperatingSystem.NONE;
private string retrievalDescription = string.Empty;
private string additionalLibraries = string.Empty;
private string? ValidateProgrammingLanguage(ProgrammingLanguages language)
{
@ -82,6 +123,17 @@ public partial class AssistantEDI : AssistantBaseCore
return null;
}
private string? ValidateDataSourceProductName(string productName)
{
if(this.selectedDataSource is DataSources.CUSTOM or DataSources.NONE or DataSources.FILE_SYSTEM)
return null;
if(string.IsNullOrWhiteSpace(productName))
return "Please specify the product name of the data source, e.g., 'MongoDB', 'Redis', 'PostgreSQL', 'Neo4j', or 'MinIO', etc.";
return null;
}
private string? ValidateOtherDataSource(string dataSource)
{
if(this.selectedDataSource != DataSources.CUSTOM)
@ -93,6 +145,62 @@ public partial class AssistantEDI : AssistantBaseCore
return null;
}
private string? ValidateHostname(string hostname)
{
if(!this.NeedHostnamePort())
return null;
// When using a custom data source, the hostname is optional:
if(this.selectedDataSource is DataSources.CUSTOM)
return null;
if(string.IsNullOrWhiteSpace(hostname))
return "Please provide the hostname of the data source. Use 'localhost' if the data source is on the same machine as the EDI server.";
if(hostname.Length > 255)
return "The hostname of the data source must not exceed 255 characters.";
return null;
}
private string? ValidatePort(int? port)
{
if(!this.NeedHostnamePort())
return null;
// When using a custom data source, the port is optional:
if(this.selectedDataSource is DataSources.CUSTOM)
return null;
if(port is null)
return "Please provide the port of the data source.";
if(port is < 1 or > 65535)
return "The port of the data source must be between 1 and 65535.";
return null;
}
private void DataSourceWasChanged()
{
if(this.SettingsManager.ConfigurationData.EDI.PreselectedDataSourcePort is not null)
return;
//
// Preselect the default port for the selected data source
//
this.dataSourcePort = this.selectedDataSource switch
{
DataSources.DOCUMENT_STORE => 27017,
DataSources.KEY_VALUE_STORE => 6379,
DataSources.OBJECT_STORAGE => 9000,
DataSources.RELATIONAL_DATABASE => 5432,
DataSources.GRAPH_DATABASE => 7687,
_ => null
};
}
private string? ValidateAuthenticationMethods(Auth _)
{
var authenticationMethods = (this.selectedAuthenticationMethods as HashSet<Auth>)!;
@ -102,6 +210,54 @@ public partial class AssistantEDI : AssistantBaseCore
return null;
}
private void AuthenticationMethodWasChanged(IEnumerable<Auth>? selectedValues)
{
if(selectedValues is null)
{
this.selectedAuthenticationMethods = [];
this.selectedOperatingSystem = OperatingSystem.NONE;
return;
}
this.selectedAuthenticationMethods = selectedValues;
if(!this.IsUsingKerberos())
this.selectedOperatingSystem = OperatingSystem.NONE;
}
private bool IsUsingKerberos()
{
return this.selectedAuthenticationMethods.Contains(Auth.KERBEROS);
}
private string? ValidateOperatingSystem(OperatingSystem os)
{
if(!this.IsUsingKerberos())
return null;
if(os is OperatingSystem.NONE)
return "Please select the operating system on which the EDI server will run. This is necessary when using SSO with Kerberos.";
return null;
}
private string AuthDescriptionTitle()
{
const string TITLE = "Describe how you planned the authentication process";
return this.IsAuthDescriptionOptional() ? $"(Optional) {TITLE}" : TITLE;
}
private bool IsAuthDescriptionOptional()
{
var authenticationMethods = (this.selectedAuthenticationMethods as HashSet<Auth>)!;
if(authenticationMethods.Count > 1)
return false;
if (authenticationMethods.Any(n => n == Auth.NONE) && authenticationMethods.Count > 1)
return false;
return true;
}
private string? ValidateAuthDescription(string description)
{
var authenticationMethods = (this.selectedAuthenticationMethods as HashSet<Auth>)!;
@ -124,6 +280,27 @@ public partial class AssistantEDI : AssistantBaseCore
return $"You have selected {selectedValues.Count} authentication methods";
}
private string? ValidateRetrievalDescription(string description)
{
if(string.IsNullOrWhiteSpace(description))
return "Please describe how the data retrieval process should work. This is important for the integration of the data source into AI Studio by means of the EDI.";
return null;
}
private bool NeedHostnamePort()
{
switch (this.selectedDataSource)
{
case DataSources.NONE:
case DataSources.FILE_SYSTEM:
return false;
default:
return true;
}
}
private async Task GenerateServer()
{

View File

@ -6,6 +6,7 @@ public enum DataSources
CUSTOM,
FILE_SYSTEM,
OBJECT_STORAGE,
KEY_VALUE_STORE,
DOCUMENT_STORE,

View File

@ -0,0 +1,9 @@
namespace AIStudio.Assistants.EDI;
public enum OperatingSystem
{
NONE,
WINDOWS,
LINUX,
}

View File

@ -0,0 +1,14 @@
namespace AIStudio.Assistants.EDI;
public static class OperatingSystemExtensions
{
public static string Name(this OperatingSystem os) => os switch
{
OperatingSystem.NONE => "No operating system specified",
OperatingSystem.WINDOWS => "Windows",
OperatingSystem.LINUX => "Linux",
_ => "Unknown operating system"
};
}

View File

@ -1,6 +1,8 @@
using AIStudio.Assistants.EDI;
using AIStudio.Provider;
using OperatingSystem = AIStudio.Assistants.EDI.OperatingSystem;
namespace AIStudio.Settings.DataModel;
public sealed class DataEDI
@ -25,11 +27,26 @@ public sealed class DataEDI
/// </summary>
public DataSources PreselectedDataSource { get; set; }
/// <summary>
/// Do you want to preselect a product name for the data source?
/// </summary>
public string PreselectedDataSourceProductName { get; set; } = string.Empty;
/// <summary>
/// Do you want to preselect any other data source?
/// </summary>
public string PreselectedOtherDataSource { get; set; } = string.Empty;
/// <summary>
/// Do you want to preselect a hostname for the data source?
/// </summary>
public string PreselectedDataSourceHostname { get; set; } = string.Empty;
/// <summary>
/// Do you want to preselect a port for the data source?
/// </summary>
public int? PreselectedDataSourcePort { get; set; }
/// <summary>
/// Preselect any authentication methods?
/// </summary>
@ -39,6 +56,21 @@ public sealed class DataEDI
/// Do you want to preselect any authentication description?
/// </summary>
public string PreselectedAuthDescription { get; set; } = string.Empty;
/// <summary>
/// Do you want to preselect an operating system? This is necessary when SSO with Kerberos is used.
/// </summary>
public OperatingSystem PreselectedOperatingSystem { get; set; } = OperatingSystem.NONE;
/// <summary>
/// Do you want to preselect a retrieval description?
/// </summary>
public string PreselectedRetrievalDescription { get; set; } = string.Empty;
/// <summary>
/// Do you want to preselect any additional libraries?
/// </summary>
public string PreselectedAdditionalLibraries { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.