From c6f78fce36c317e0829d3bea73c261521bb08230 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 8 Dec 2024 20:41:05 +0100 Subject: [PATCH] Implemented remaining fields for EDI assistant --- .../Assistants/EDI/AssistantEDI.razor | 45 ++++- .../Assistants/EDI/AssistantEDI.razor.cs | 177 ++++++++++++++++++ .../Assistants/EDI/DataSources.cs | 1 + .../Assistants/EDI/OperatingSystem.cs | 9 + .../EDI/OperatingSystemExtensions.cs | 14 ++ .../Settings/DataModel/DataEDI.cs | 32 ++++ 6 files changed, 273 insertions(+), 5 deletions(-) create mode 100644 app/MindWork AI Studio/Assistants/EDI/OperatingSystem.cs create mode 100644 app/MindWork AI Studio/Assistants/EDI/OperatingSystemExtensions.cs diff --git a/app/MindWork AI Studio/Assistants/EDI/AssistantEDI.razor b/app/MindWork AI Studio/Assistants/EDI/AssistantEDI.razor index 8071c5a4..f933a0cf 100644 --- a/app/MindWork AI Studio/Assistants/EDI/AssistantEDI.razor +++ b/app/MindWork AI Studio/Assistants/EDI/AssistantEDI.razor @@ -33,8 +33,8 @@ } - - + + @foreach (var dataSource in Enum.GetValues()) { @dataSource.Name() @@ -46,14 +46,36 @@ } - +@if(this.selectedDataSource > DataSources.FILE_SYSTEM) +{ + +} + +@if (this.NeedHostnamePort()) +{ +
+ + + + + @if (this.dataSourcePort < 1024) + { + + Warning: Ports below 1024 are reserved for system services. Your EDI server need to run with elevated permissions (root user). + + } +
+} + + @@ -62,7 +84,20 @@ @authMethod.Name() } - + +@if (this.selectedAuthenticationMethods.Contains(Auth.KERBEROS)) +{ + + @foreach (var os in Enum.GetValues()) + { + @os.Name() + } + +} + + + + \ No newline at end of file diff --git a/app/MindWork AI Studio/Assistants/EDI/AssistantEDI.razor.cs b/app/MindWork AI Studio/Assistants/EDI/AssistantEDI.razor.cs index 3974223d..b3cf2646 100644 --- a/app/MindWork AI Studio/Assistants/EDI/AssistantEDI.razor.cs +++ b/app/MindWork AI Studio/Assistants/EDI/AssistantEDI.razor.cs @@ -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(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 selectedAuthenticationMethods = new HashSet(); 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)!; @@ -102,6 +210,54 @@ public partial class AssistantEDI : AssistantBaseCore return null; } + private void AuthenticationMethodWasChanged(IEnumerable? 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)!; + 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)!; @@ -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() { diff --git a/app/MindWork AI Studio/Assistants/EDI/DataSources.cs b/app/MindWork AI Studio/Assistants/EDI/DataSources.cs index 33e788f4..9df36ca0 100644 --- a/app/MindWork AI Studio/Assistants/EDI/DataSources.cs +++ b/app/MindWork AI Studio/Assistants/EDI/DataSources.cs @@ -6,6 +6,7 @@ public enum DataSources CUSTOM, FILE_SYSTEM, + OBJECT_STORAGE, KEY_VALUE_STORE, DOCUMENT_STORE, diff --git a/app/MindWork AI Studio/Assistants/EDI/OperatingSystem.cs b/app/MindWork AI Studio/Assistants/EDI/OperatingSystem.cs new file mode 100644 index 00000000..20f0ec33 --- /dev/null +++ b/app/MindWork AI Studio/Assistants/EDI/OperatingSystem.cs @@ -0,0 +1,9 @@ +namespace AIStudio.Assistants.EDI; + +public enum OperatingSystem +{ + NONE, + + WINDOWS, + LINUX, +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Assistants/EDI/OperatingSystemExtensions.cs b/app/MindWork AI Studio/Assistants/EDI/OperatingSystemExtensions.cs new file mode 100644 index 00000000..72604ff8 --- /dev/null +++ b/app/MindWork AI Studio/Assistants/EDI/OperatingSystemExtensions.cs @@ -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" + }; +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Settings/DataModel/DataEDI.cs b/app/MindWork AI Studio/Settings/DataModel/DataEDI.cs index 647d4e39..d06225e2 100644 --- a/app/MindWork AI Studio/Settings/DataModel/DataEDI.cs +++ b/app/MindWork AI Studio/Settings/DataModel/DataEDI.cs @@ -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 /// public DataSources PreselectedDataSource { get; set; } + /// + /// Do you want to preselect a product name for the data source? + /// + public string PreselectedDataSourceProductName { get; set; } = string.Empty; + /// /// Do you want to preselect any other data source? /// public string PreselectedOtherDataSource { get; set; } = string.Empty; + /// + /// Do you want to preselect a hostname for the data source? + /// + public string PreselectedDataSourceHostname { get; set; } = string.Empty; + + /// + /// Do you want to preselect a port for the data source? + /// + public int? PreselectedDataSourcePort { get; set; } + /// /// Preselect any authentication methods? /// @@ -39,6 +56,21 @@ public sealed class DataEDI /// Do you want to preselect any authentication description? /// public string PreselectedAuthDescription { get; set; } = string.Empty; + + /// + /// Do you want to preselect an operating system? This is necessary when SSO with Kerberos is used. + /// + public OperatingSystem PreselectedOperatingSystem { get; set; } = OperatingSystem.NONE; + + /// + /// Do you want to preselect a retrieval description? + /// + public string PreselectedRetrievalDescription { get; set; } = string.Empty; + + /// + /// Do you want to preselect any additional libraries? + /// + public string PreselectedAdditionalLibraries { get; set; } = string.Empty; /// /// The minimum confidence level required for a provider to be considered.