Added more text content to the I18N system (#446)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2025-05-04 14:59:30 +02:00
1 parent cfc2103b43
commit 7a08baf99b
43 files changed
+3356 -354

No files matched your search

@@ -1,16 +1,19 @@
using AIStudio.Tools.ERIClient.DataModel;
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools;
public static class AuthMethodsV1Extensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(AuthMethodsV1Extensions).Namespace, nameof(AuthMethodsV1Extensions));
public static string DisplayName(this AuthMethod authMethod) => authMethod switch
{
AuthMethod.NONE => "None",
AuthMethod.USERNAME_PASSWORD => "Username & Password",
AuthMethod.KERBEROS => "SSO (Kerberos)",
AuthMethod.TOKEN => "Access Token",
AuthMethod.NONE => TB("None"),
AuthMethod.USERNAME_PASSWORD => TB("Username & Password"),
AuthMethod.KERBEROS => TB("SSO (Kerberos)"),
AuthMethod.TOKEN => TB("Access Token"),
_ => "Unknown authentication method",
_ => TB("Unknown authentication method"),
};
}
@@ -1,23 +1,27 @@
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools;
public static class CommonLanguageExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(CommonLanguageExtensions).Namespace, nameof(CommonLanguageExtensions));
public static string Name(this CommonLanguages language) => language switch
{
CommonLanguages.AS_IS => "Do not change the language",
CommonLanguages.AS_IS => TB("Do not change the language"),
CommonLanguages.EN_US => "English (US)",
CommonLanguages.EN_GB => "English (UK)",
CommonLanguages.ZH_CN => "Chinese (Simplified)",
CommonLanguages.HI_IN => "Hindi (India)",
CommonLanguages.ES_ES => "Spanish (Spain)",
CommonLanguages.FR_FR => "French (France)",
CommonLanguages.DE_DE => "German (Germany)",
CommonLanguages.DE_AT => "German (Austria)",
CommonLanguages.DE_CH => "German (Switzerland)",
CommonLanguages.JA_JP => "Japanese (Japan)",
CommonLanguages.EN_US => TB("English (US)"),
CommonLanguages.EN_GB => TB("English (UK)"),
CommonLanguages.ZH_CN => TB("Chinese (Simplified)"),
CommonLanguages.HI_IN => TB("Hindi (India)"),
CommonLanguages.ES_ES => TB("Spanish (Spain)"),
CommonLanguages.FR_FR => TB("French (France)"),
CommonLanguages.DE_DE => TB("German (Germany)"),
CommonLanguages.DE_AT => TB("German (Austria)"),
CommonLanguages.DE_CH => TB("German (Switzerland)"),
CommonLanguages.JA_JP => TB("Japanese (Japan)"),
_ => "Other",
_ => TB("Other"),
};
public static string ToIETFTag(this CommonLanguages language) => language switch
@@ -56,7 +60,7 @@ public static class CommonLanguageExtensions
public static string NameSelecting(this CommonLanguages language)
{
if(language is CommonLanguages.AS_IS)
return "Please select the target language";
return TB("Please select the target language");
return language.Name();
}
@@ -64,7 +68,7 @@ public static class CommonLanguageExtensions
public static string NameSelectingOptional(this CommonLanguages language)
{
if(language is CommonLanguages.AS_IS)
return "Do not specify the language";
return TB("Do not specify the language");
return language.Name();
}
@@ -2,11 +2,14 @@ using System.Diagnostics.CodeAnalysis;
using AIStudio.Provider;
using AIStudio.Settings;
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools;
public static class ComponentsExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ComponentsExtensions).Namespace, nameof(ComponentsExtensions));
public static bool AllowSendTo(this Components component) => component switch
{
Components.NONE => false,
@@ -26,22 +29,22 @@ public static class ComponentsExtensions
public static string Name(this Components component) => component switch
{
Components.GRAMMAR_SPELLING_ASSISTANT => "Grammar & Spelling Assistant",
Components.TEXT_SUMMARIZER_ASSISTANT => "Text Summarizer Assistant",
Components.ICON_FINDER_ASSISTANT => "Icon Finder Assistant",
Components.TRANSLATION_ASSISTANT => "Translation Assistant",
Components.REWRITE_ASSISTANT => "Rewrite Assistant",
Components.AGENDA_ASSISTANT => "Agenda Assistant",
Components.CODING_ASSISTANT => "Coding Assistant",
Components.EMAIL_ASSISTANT => "E-Mail Assistant",
Components.LEGAL_CHECK_ASSISTANT => "Legal Check Assistant",
Components.SYNONYMS_ASSISTANT => "Synonym Assistant",
Components.MY_TASKS_ASSISTANT => "My Tasks Assistant",
Components.JOB_POSTING_ASSISTANT => "Job Posting Assistant",
Components.ERI_ASSISTANT => "ERI Server",
Components.I18N_ASSISTANT => "Localization Assistant",
Components.GRAMMAR_SPELLING_ASSISTANT => TB("Grammar & Spelling Assistant"),
Components.TEXT_SUMMARIZER_ASSISTANT => TB("Text Summarizer Assistant"),
Components.ICON_FINDER_ASSISTANT => TB("Icon Finder Assistant"),
Components.TRANSLATION_ASSISTANT => TB("Translation Assistant"),
Components.REWRITE_ASSISTANT => TB("Rewrite Assistant"),
Components.AGENDA_ASSISTANT => TB("Agenda Assistant"),
Components.CODING_ASSISTANT => TB("Coding Assistant"),
Components.EMAIL_ASSISTANT => TB("E-Mail Assistant"),
Components.LEGAL_CHECK_ASSISTANT => TB("Legal Check Assistant"),
Components.SYNONYMS_ASSISTANT => TB("Synonym Assistant"),
Components.MY_TASKS_ASSISTANT => TB("My Tasks Assistant"),
Components.JOB_POSTING_ASSISTANT => TB("Job Posting Assistant"),
Components.ERI_ASSISTANT => TB("ERI Server"),
Components.I18N_ASSISTANT => TB("Localization Assistant"),
Components.CHAT => "New Chat",
Components.CHAT => TB("New Chat"),
_ => Enum.GetName(typeof(Components), component)!,
};
@@ -1,18 +1,22 @@
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools;
public static class ConfidenceSchemesExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ConfidenceSchemesExtensions).Namespace, nameof(ConfidenceSchemesExtensions));
public static string GetListDescription(this ConfidenceSchemes scheme) => scheme switch
{
ConfidenceSchemes.TRUST_ALL => "Trust all LLM providers",
ConfidenceSchemes.TRUST_USA_EUROPE => "Trust LLM providers from the USA and Europe",
ConfidenceSchemes.TRUST_USA => "Trust LLM providers from the USA",
ConfidenceSchemes.TRUST_EUROPE => "Trust LLM providers from Europe",
ConfidenceSchemes.TRUST_ASIA => "Trust LLM providers from Asia",
ConfidenceSchemes.LOCAL_TRUST_ONLY => "Trust only local LLM providers",
ConfidenceSchemes.TRUST_ALL => TB("Trust all LLM providers"),
ConfidenceSchemes.TRUST_USA_EUROPE => TB("Trust LLM providers from the USA and Europe"),
ConfidenceSchemes.TRUST_USA => TB("Trust LLM providers from the USA"),
ConfidenceSchemes.TRUST_EUROPE => TB("Trust LLM providers from Europe"),
ConfidenceSchemes.TRUST_ASIA => TB("Trust LLM providers from Asia"),
ConfidenceSchemes.LOCAL_TRUST_ONLY => TB("Trust only local LLM providers"),
ConfidenceSchemes.CUSTOM => "Configure your own confidence scheme",
ConfidenceSchemes.CUSTOM => TB("Configure your own confidence scheme"),
_ => "Unknown confidence scheme"
_ => TB("Unknown confidence scheme"),
};
}
@@ -1,13 +1,17 @@
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools.ERIClient.DataModel;
public static class ProviderTypeExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ProviderTypeExtensions).Namespace, nameof(ProviderTypeExtensions));
public static string Explain(this ProviderType providerType) => providerType switch
{
ProviderType.NONE => "The related data is not allowed to be sent to any LLM provider. This means that this data source cannot be used at the moment.",
ProviderType.ANY => "The related data can be sent to any provider, regardless of where it is hosted (cloud or self-hosted).",
ProviderType.SELF_HOSTED => "The related data can be sent to a provider that is hosted by the same organization, either on-premises or locally. Cloud-based providers are not allowed.",
ProviderType.NONE => TB("The related data is not allowed to be sent to any LLM provider. This means that this data source cannot be used at the moment."),
ProviderType.ANY => TB("The related data can be sent to any provider, regardless of where it is hosted (cloud or self-hosted)."),
ProviderType.SELF_HOSTED => TB("The related data can be sent to a provider that is hosted by the same organization, either on-premises or locally. Cloud-based providers are not allowed."),
_ => "Unknown configuration. This data source cannot be used at the moment.",
_ => TB("Unknown configuration. This data source cannot be used at the moment."),
};
}
@@ -3,12 +3,15 @@ using System.Text.Json;
using AIStudio.Settings;
using AIStudio.Tools.ERIClient.DataModel;
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Services;
namespace AIStudio.Tools.ERIClient;
public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource), IERIClient
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ERIClientV1).Namespace, nameof(ERIClientV1));
#region Implementation of IERIClient
public async Task<APIResponse<List<AuthScheme>>> GetAuthMethodsAsync(CancellationToken cancellationToken = default)
@@ -21,7 +24,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the authentication methods: there was an issue communicating with the ERI server. Code: {response.StatusCode}, Reason: {response.ReasonPhrase}"
Message = string.Format(TB("Failed to retrieve the authentication methods: there was an issue communicating with the ERI server. Code: {0}, Reason: {1}"), response.StatusCode, response.ReasonPhrase)
};
}
@@ -31,7 +34,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the authentication methods: the ERI server did not return a valid response."
Message = TB("Failed to retrieve the authentication methods: the ERI server did not return a valid response.")
};
}
@@ -46,7 +49,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the authentication methods: the request was canceled either by the user or due to a timeout."
Message = TB("Failed to retrieve the authentication methods: the request was canceled either by the user or due to a timeout.")
};
}
catch (Exception e)
@@ -54,7 +57,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the authentication methods due to an exception: {e.Message}"
Message = string.Format(TB("Failed to retrieve the authentication methods due to an exception: {0}"), e.Message)
};
}
}
@@ -76,7 +79,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to authenticate with the ERI server. Code: {noneAuthResponse.StatusCode}, Reason: {noneAuthResponse.ReasonPhrase}"
Message = string.Format(TB("Failed to authenticate with the ERI server. Code: {0}, Reason: {1}"), noneAuthResponse.StatusCode, noneAuthResponse.ReasonPhrase)
};
}
@@ -86,7 +89,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to authenticate with the ERI server: the response was invalid."
Message = TB("Failed to authenticate with the ERI server: the response was invalid.")
};
}
@@ -108,7 +111,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the password."
Message = TB("Failed to retrieve the password.")
};
}
@@ -130,7 +133,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to authenticate with the ERI server. Code: {usernamePasswordAuthResponse.StatusCode}, Reason: {usernamePasswordAuthResponse.ReasonPhrase}"
Message = string.Format(TB("Failed to authenticate with the ERI server. Code: {0}, Reason: {1}"), usernamePasswordAuthResponse.StatusCode, usernamePasswordAuthResponse.ReasonPhrase)
};
}
@@ -140,7 +143,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to authenticate with the server: the response was invalid."
Message = TB("Failed to authenticate with the server: the response was invalid.")
};
}
@@ -162,7 +165,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the access token."
Message = TB("Failed to retrieve the access token.")
};
}
@@ -181,7 +184,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to authenticate with the ERI server. Code: {tokenAuthResponse.StatusCode}, Reason: {tokenAuthResponse.ReasonPhrase}"
Message = string.Format(TB("Failed to authenticate with the ERI server. Code: {0}, Reason: {1}"), tokenAuthResponse.StatusCode, tokenAuthResponse.ReasonPhrase)
};
}
@@ -191,7 +194,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to authenticate with the ERI server: the response was invalid."
Message = TB("Failed to authenticate with the ERI server: the response was invalid.")
};
}
@@ -208,7 +211,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "The authentication method is not supported yet."
Message = TB("The authentication method is not supported yet.")
};
}
}
@@ -217,7 +220,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to authenticate with the ERI server: the request was canceled either by the user or due to a timeout."
Message = TB("Failed to authenticate with the ERI server: the request was canceled either by the user or due to a timeout.")
};
}
catch (Exception e)
@@ -225,7 +228,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to authenticate with the ERI server due to an exception: {e.Message}"
Message = string.Format(TB("Failed to authenticate with the ERI server due to an exception: {0}"), e.Message)
};
}
}
@@ -243,7 +246,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the data source information: there was an issue communicating with the ERI server. Code: {response.StatusCode}, Reason: {response.ReasonPhrase}"
Message = string.Format(TB("Failed to retrieve the data source information: there was an issue communicating with the ERI server. Code: {0}, Reason: {1}"), response.StatusCode, response.ReasonPhrase)
};
}
@@ -253,7 +256,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the data source information: the ERI server did not return a valid response."
Message = TB("Failed to retrieve the data source information: the ERI server did not return a valid response.")
};
}
@@ -268,7 +271,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the data source information: the request was canceled either by the user or due to a timeout."
Message = TB("Failed to retrieve the data source information: the request was canceled either by the user or due to a timeout.")
};
}
catch (Exception e)
@@ -276,7 +279,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the data source information due to an exception: {e.Message}"
Message = string.Format(TB("Failed to retrieve the data source information due to an exception: {0}"), e.Message)
};
}
}
@@ -294,7 +297,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the embedding information: there was an issue communicating with the ERI server. Code: {response.StatusCode}, Reason: {response.ReasonPhrase}"
Message = string.Format(TB("Failed to retrieve the embedding information: there was an issue communicating with the ERI server. Code: {0}, Reason: {1}"), response.StatusCode, response.ReasonPhrase)
};
}
@@ -304,7 +307,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the embedding information: the ERI server did not return a valid response."
Message = TB("Failed to retrieve the embedding information: the ERI server did not return a valid response.")
};
}
@@ -319,7 +322,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the embedding information: the request was canceled either by the user or due to a timeout."
Message = TB("Failed to retrieve the embedding information: the request was canceled either by the user or due to a timeout.")
};
}
catch (Exception e)
@@ -327,7 +330,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the embedding information due to an exception: {e.Message}"
Message = string.Format(TB("Failed to retrieve the embedding information due to an exception: {0}"), e.Message)
};
}
}
@@ -345,7 +348,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the retrieval information: there was an issue communicating with the ERI server. Code: {response.StatusCode}, Reason: {response.ReasonPhrase}"
Message = string.Format(TB("Failed to retrieve the retrieval information: there was an issue communicating with the ERI server. Code: {0}, Reason: {1}"), response.StatusCode, response.ReasonPhrase)
};
}
@@ -355,7 +358,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the retrieval information: the ERI server did not return a valid response."
Message = TB("Failed to retrieve the retrieval information: the ERI server did not return a valid response.")
};
}
@@ -370,7 +373,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the retrieval information: the request was canceled either by the user or due to a timeout."
Message = TB("Failed to retrieve the retrieval information: the request was canceled either by the user or due to a timeout.")
};
}
catch (Exception e)
@@ -378,7 +381,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the retrieval information due to an exception: {e.Message}"
Message = string.Format(TB("Failed to retrieve the retrieval information due to an exception: {0}"), e.Message)
};
}
}
@@ -399,7 +402,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to execute the retrieval request: there was an issue communicating with the ERI server. Code: {response.StatusCode}, Reason: {response.ReasonPhrase}"
Message = string.Format(TB("Failed to execute the retrieval request: there was an issue communicating with the ERI server. Code: {0}, Reason: {1}"), response.StatusCode, response.ReasonPhrase)
};
}
@@ -409,7 +412,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to execute the retrieval request: the ERI server did not return a valid response."
Message = TB("Failed to execute the retrieval request: the ERI server did not return a valid response.")
};
}
@@ -424,7 +427,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to execute the retrieval request: the request was canceled either by the user or due to a timeout."
Message = TB("Failed to execute the retrieval request: the request was canceled either by the user or due to a timeout.")
};
}
catch (Exception e)
@@ -432,7 +435,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to execute the retrieval request due to an exception: {e.Message}"
Message = string.Format(TB("Failed to execute the retrieval request due to an exception: {0}"), e.Message)
};
}
}
@@ -450,7 +453,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the security requirements: there was an issue communicating with the ERI server. Code: {response.StatusCode}, Reason: {response.ReasonPhrase}"
Message = string.Format(TB("Failed to retrieve the security requirements: there was an issue communicating with the ERI server. Code: {0}, Reason: {1}"), response.StatusCode, response.ReasonPhrase)
};
}
@@ -460,7 +463,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the security requirements: the ERI server did not return a valid response."
Message = TB("Failed to retrieve the security requirements: the ERI server did not return a valid response.")
};
}
@@ -475,7 +478,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = "Failed to retrieve the security requirements: the request was canceled either by the user or due to a timeout."
Message = TB("Failed to retrieve the security requirements: the request was canceled either by the user or due to a timeout.")
};
}
catch (Exception e)
@@ -483,7 +486,7 @@ public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource),
return new()
{
Successful = false,
Message = $"Failed to retrieve the security requirements due to an exception: {e.Message}"
Message = string.Format(TB("Failed to retrieve the security requirements due to an exception: {0}"), e.Message)
};
}
}
@@ -5,7 +5,7 @@ public class I18N : ILang
public static readonly I18N I = new();
private static readonly ILogger<I18N> LOG = Program.LOGGER_FACTORY.CreateLogger<I18N>();
private ILanguagePlugin language = PluginFactory.BaseLanguage;
private ILanguagePlugin? language = PluginFactory.BaseLanguage;
private I18N()
{
@@ -18,12 +18,18 @@ public class I18N : ILang
public string T(string fallbackEN)
{
LOG.LogWarning("Using I18N.I.T without namespace and type is probably wrong, because the I18N key collection process of the build system will not find those keys.");
return this.GetText(this.language, fallbackEN);
if(this.language is not null)
return this.GetText(this.language, fallbackEN);
return fallbackEN;
}
public string T(string fallbackEN, string? typeNamespace, string? typeName)
{
return this.GetText(this.language, fallbackEN, typeNamespace, typeName);
if(this.language is not null)
return this.GetText(this.language, fallbackEN, typeNamespace, typeName);
return fallbackEN;
}
#endregion
@@ -8,6 +8,8 @@ namespace AIStudio.Tools.PluginSystem;
/// </summary>
public abstract partial class PluginBase : IPluginMetadata
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginBase).Namespace, nameof(PluginBase));
private readonly IReadOnlyCollection<string> baseIssues;
protected readonly LuaState state;
@@ -155,21 +157,21 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["ID"].TryRead<string>(out var idText))
{
message = "The field ID does not exist or is not a valid string.";
message = TB("The field ID does not exist or is not a valid string.");
id = Guid.Empty;
return false;
}
if (!Guid.TryParse(idText, out id))
{
message = "The field ID is not a valid GUID / UUID. The ID must be formatted in the 8-4-4-4-12 format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX).";
message = TB("The field ID is not a valid GUID / UUID. The ID must be formatted in the 8-4-4-4-12 format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX).");
id = Guid.Empty;
return false;
}
if(id == Guid.Empty)
{
message = "The field ID is empty. The ID must be formatted in the 8-4-4-4-12 format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX).";
message = TB("The field ID is empty. The ID must be formatted in the 8-4-4-4-12 format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX).");
return false;
}
@@ -187,14 +189,14 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["NAME"].TryRead(out name))
{
message = "The field NAME does not exist or is not a valid string.";
message = TB("The field NAME does not exist or is not a valid string.");
name = string.Empty;
return false;
}
if(string.IsNullOrWhiteSpace(name))
{
message = "The field NAME is empty. The name must be a non-empty string.";
message = TB("The field NAME is empty. The name must be a non-empty string.");
return false;
}
@@ -212,14 +214,14 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["DESCRIPTION"].TryRead(out description))
{
message = "The field DESCRIPTION does not exist or is not a valid string.";
message = TB("The field DESCRIPTION does not exist or is not a valid string.");
description = string.Empty;
return false;
}
if(string.IsNullOrWhiteSpace(description))
{
message = "The field DESCRIPTION is empty. The description must be a non-empty string.";
message = TB("The field DESCRIPTION is empty. The description must be a non-empty string.");
return false;
}
@@ -237,21 +239,21 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["VERSION"].TryRead<string>(out var versionText))
{
message = "The field VERSION does not exist or is not a valid string.";
message = TB("The field VERSION does not exist or is not a valid string.");
version = PluginVersion.NONE;
return false;
}
if (!PluginVersion.TryParse(versionText, out version))
{
message = "The field VERSION is not a valid version number. The version number must be formatted as string in the major.minor.patch format (X.X.X).";
message = TB("The field VERSION is not a valid version number. The version number must be formatted as string in the major.minor.patch format (X.X.X).");
version = PluginVersion.NONE;
return false;
}
if(version == PluginVersion.NONE)
{
message = "The field VERSION is empty. The version number must be formatted as string in the major.minor.patch format (X.X.X).";
message = TB("The field VERSION is empty. The version number must be formatted as string in the major.minor.patch format (X.X.X).");
return false;
}
@@ -270,7 +272,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["AUTHORS"].TryRead<LuaTable>(out var authorsTable))
{
authors = [];
message = "The table AUTHORS does not exist or is using an invalid syntax.";
message = TB("The table AUTHORS does not exist or is using an invalid syntax.");
return false;
}
@@ -282,7 +284,7 @@ public abstract partial class PluginBase : IPluginMetadata
authors = authorList.ToArray();
if(authorList.Count == 0)
{
message = "The table AUTHORS is empty. At least one author must be specified.";
message = TB("The table AUTHORS is empty. At least one author must be specified.");
return false;
}
@@ -301,13 +303,13 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["SUPPORT_CONTACT"].TryRead(out contact))
{
contact = string.Empty;
message = "The field SUPPORT_CONTACT does not exist or is not a valid string.";
message = TB("The field SUPPORT_CONTACT does not exist or is not a valid string.");
return false;
}
if(string.IsNullOrWhiteSpace(contact))
{
message = "The field SUPPORT_CONTACT is empty. The support contact must be a non-empty string.";
message = TB("The field SUPPORT_CONTACT is empty. The support contact must be a non-empty string.");
return false;
}
@@ -326,14 +328,14 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["SOURCE_URL"].TryRead(out url))
{
url = string.Empty;
message = "The field SOURCE_URL does not exist or is not a valid string.";
message = TB("The field SOURCE_URL does not exist or is not a valid string.");
return false;
}
if (!url.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) && !url.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
{
url = string.Empty;
message = "The field SOURCE_URL is not a valid URL. The URL must start with 'http://' or 'https://'.";
message = TB("The field SOURCE_URL is not a valid URL. The URL must start with 'http://' or 'https://'.");
return false;
}
@@ -352,7 +354,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["CATEGORIES"].TryRead<LuaTable>(out var categoriesTable))
{
categories = [];
message = "The table CATEGORIES does not exist or is using an invalid syntax.";
message = TB("The table CATEGORIES does not exist or is using an invalid syntax.");
return false;
}
@@ -365,7 +367,7 @@ public abstract partial class PluginBase : IPluginMetadata
categories = categoryList.ToArray();
if(categoryList.Count == 0)
{
message = $"The table CATEGORIES is empty. At least one category is necessary. Valid categories are: {CommonTools.GetAllEnumValues(PluginCategory.NONE)}.";
message = string.Format(TB("The table CATEGORIES is empty. At least one category is necessary. Valid categories are: {0}."), CommonTools.GetAllEnumValues(PluginCategory.NONE));
return false;
}
@@ -384,7 +386,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["TARGET_GROUPS"].TryRead<LuaTable>(out var targetGroupsTable))
{
targetGroups = [];
message = "The table TARGET_GROUPS does not exist or is using an invalid syntax.";
message = TB("The table TARGET_GROUPS does not exist or is using an invalid syntax.");
return false;
}
@@ -397,7 +399,7 @@ public abstract partial class PluginBase : IPluginMetadata
targetGroups = targetGroupList.ToArray();
if(targetGroups.Length == 0)
{
message = "The table TARGET_GROUPS is empty or is not a valid table of strings. Valid target groups are: {CommonTools.GetAllEnumValues(PluginTargetGroup.NONE)}.";
message = string.Format(TB("The table TARGET_GROUPS is empty or is not a valid table of strings. Valid target groups are: {0}."), CommonTools.GetAllEnumValues(PluginTargetGroup.NONE));
return false;
}
@@ -416,7 +418,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["IS_MAINTAINED"].TryRead(out isMaintained))
{
isMaintained = false;
message = "The field IS_MAINTAINED does not exist or is not a valid boolean.";
message = TB("The field IS_MAINTAINED does not exist or is not a valid boolean.");
return false;
}
@@ -435,7 +437,7 @@ public abstract partial class PluginBase : IPluginMetadata
if (!this.state.Environment["DEPRECATION_MESSAGE"].TryRead(out deprecationMessage))
{
deprecationMessage = string.Empty;
message = "The field DEPRECATION_MESSAGE does not exist, is not a valid string. This message is optional: use an empty string to indicate that the plugin is not deprecated.";
message = TB("The field DEPRECATION_MESSAGE does not exist, is not a valid string. This message is optional: use an empty string to indicate that the plugin is not deprecated.");
return false;
}
@@ -453,7 +455,7 @@ public abstract partial class PluginBase : IPluginMetadata
{
if (!this.state.Environment["UI_TEXT_CONTENT"].TryRead<LuaTable>(out var textTable))
{
message = "The UI_TEXT_CONTENT table does not exist or is not a valid table.";
message = TB("The UI_TEXT_CONTENT table does not exist or is not a valid table.");
pluginContent = [];
return false;
}
@@ -2,37 +2,39 @@ namespace AIStudio.Tools.PluginSystem;
public static class PluginCategoryExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginCategoryExtensions).Namespace, nameof(PluginCategoryExtensions));
public static string GetName(this PluginCategory type) => type switch
{
PluginCategory.NONE => "None",
PluginCategory.CORE => "AI Studio Core",
PluginCategory.NONE => TB("None"),
PluginCategory.CORE => TB("AI Studio Core"),
PluginCategory.BUSINESS => "Business",
PluginCategory.INDUSTRY => "Industry",
PluginCategory.UTILITY => "Utility",
PluginCategory.SOFTWARE_DEVELOPMENT => "Software Development",
PluginCategory.GAMING => "Gaming",
PluginCategory.EDUCATION => "Education",
PluginCategory.ENTERTAINMENT => "Entertainment",
PluginCategory.SOCIAL => "Social",
PluginCategory.SHOPPING => "Shopping",
PluginCategory.TRAVEL => "Travel",
PluginCategory.HEALTH => "Health",
PluginCategory.FITNESS => "Fitness",
PluginCategory.FOOD => "Food",
PluginCategory.PARTY => "Party",
PluginCategory.SPORTS => "Sports",
PluginCategory.NEWS => "News",
PluginCategory.WEATHER => "Weather",
PluginCategory.MUSIC => "Music",
PluginCategory.POLITICAL => "Political",
PluginCategory.SCIENCE => "Science",
PluginCategory.TECHNOLOGY => "Technology",
PluginCategory.ART => "Art",
PluginCategory.FICTION => "Fiction",
PluginCategory.WRITING => "Writing",
PluginCategory.CONTENT_CREATION => "Content Creation",
PluginCategory.BUSINESS => TB("Business"),
PluginCategory.INDUSTRY => TB("Industry"),
PluginCategory.UTILITY => TB("Utility"),
PluginCategory.SOFTWARE_DEVELOPMENT => TB("Software Development"),
PluginCategory.GAMING => TB("Gaming"),
PluginCategory.EDUCATION => TB("Education"),
PluginCategory.ENTERTAINMENT => TB("Entertainment"),
PluginCategory.SOCIAL => TB("Social"),
PluginCategory.SHOPPING => TB("Shopping"),
PluginCategory.TRAVEL => TB("Travel"),
PluginCategory.HEALTH => TB("Health"),
PluginCategory.FITNESS => TB("Fitness"),
PluginCategory.FOOD => TB("Food"),
PluginCategory.PARTY => TB("Party"),
PluginCategory.SPORTS => TB("Sports"),
PluginCategory.NEWS => TB("News"),
PluginCategory.WEATHER => TB("Weather"),
PluginCategory.MUSIC => TB("Music"),
PluginCategory.POLITICAL => TB("Political"),
PluginCategory.SCIENCE => TB("Science"),
PluginCategory.TECHNOLOGY => TB("Technology"),
PluginCategory.ART => TB("Art"),
PluginCategory.FICTION => TB("Fiction"),
PluginCategory.WRITING => TB("Writing"),
PluginCategory.CONTENT_CREATION => TB("Content Creation"),
_ => "Unknown plugin category",
_ => TB("Unknown plugin category"),
};
}
@@ -4,6 +4,7 @@ namespace AIStudio.Tools.PluginSystem;
public sealed class PluginLanguage : PluginBase, ILanguagePlugin
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginLanguage).Namespace, nameof(PluginLanguage));
private static readonly ILogger<PluginLanguage> LOGGER = Program.LOGGER_FACTORY.CreateLogger<PluginLanguage>();
private readonly Dictionary<string, string> content = [];
@@ -53,28 +54,28 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
{
if (!this.state.Environment["IETF_TAG"].TryRead(out readLangCultureTag))
{
message = "The field IETF_TAG does not exist or is not a valid string.";
message = TB("The field IETF_TAG does not exist or is not a valid string.");
readLangCultureTag = string.Empty;
return false;
}
if (string.IsNullOrWhiteSpace(readLangCultureTag))
{
message = "The field IETF_TAG is empty. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is empty. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
if (readLangCultureTag.Length != 5)
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
if (readLangCultureTag[2] != '-')
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
@@ -83,7 +84,7 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
for (var i = 0; i < 2; i++)
if (!char.IsLower(readLangCultureTag[i]))
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
@@ -92,7 +93,7 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
for (var i = 3; i < 5; i++)
if (!char.IsUpper(readLangCultureTag[i]))
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
message = TB("The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.");
readLangCultureTag = string.Empty;
return false;
}
@@ -105,14 +106,14 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
{
if (!this.state.Environment["LANG_NAME"].TryRead(out readLangName))
{
message = "The field LANG_NAME does not exist or is not a valid string.";
message = TB("The field LANG_NAME does not exist or is not a valid string.");
readLangName = string.Empty;
return false;
}
if (string.IsNullOrWhiteSpace(readLangName))
{
message = "The field LANG_NAME is empty. Use a valid language name.";
message = TB("The field LANG_NAME is empty. Use a valid language name.");
readLangName = string.Empty;
return false;
}
@@ -2,24 +2,26 @@ namespace AIStudio.Tools.PluginSystem;
public static class PluginTargetGroupExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginTargetGroupExtensions).Namespace, nameof(PluginTargetGroupExtensions));
public static string Name(this PluginTargetGroup group) => group switch
{
PluginTargetGroup.NONE => "No target group",
PluginTargetGroup.NONE => TB("No target group"),
PluginTargetGroup.EVERYONE => "Everyone",
PluginTargetGroup.CHILDREN => "Children",
PluginTargetGroup.TEENAGERS => "Teenagers",
PluginTargetGroup.STUDENTS => "Students",
PluginTargetGroup.ADULTS => "Adults",
PluginTargetGroup.EVERYONE => TB("Everyone"),
PluginTargetGroup.CHILDREN => TB("Children"),
PluginTargetGroup.TEENAGERS => TB("Teenagers"),
PluginTargetGroup.STUDENTS => TB("Students"),
PluginTargetGroup.ADULTS => TB("Adults"),
PluginTargetGroup.INDUSTRIAL_WORKERS => "Industrial workers",
PluginTargetGroup.OFFICE_WORKERS => "Office workers",
PluginTargetGroup.BUSINESS_PROFESSIONALS => "Business professionals",
PluginTargetGroup.SOFTWARE_DEVELOPERS => "Software developers",
PluginTargetGroup.SCIENTISTS => "Scientists",
PluginTargetGroup.TEACHERS => "Teachers",
PluginTargetGroup.ARTISTS => "Artists",
PluginTargetGroup.INDUSTRIAL_WORKERS => TB("Industrial workers"),
PluginTargetGroup.OFFICE_WORKERS => TB("Office workers"),
PluginTargetGroup.BUSINESS_PROFESSIONALS => TB("Business professionals"),
PluginTargetGroup.SOFTWARE_DEVELOPERS => TB("Software developers"),
PluginTargetGroup.SCIENTISTS => TB("Scientists"),
PluginTargetGroup.TEACHERS => TB("Teachers"),
PluginTargetGroup.ARTISTS => TB("Artists"),
_ => "Unknown target group",
_ => TB("Unknown target group"),
};
}
@@ -2,14 +2,16 @@ namespace AIStudio.Tools.PluginSystem;
public static class PluginTypeExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(PluginTypeExtensions).Namespace, nameof(PluginTypeExtensions));
public static string GetName(this PluginType type) => type switch
{
PluginType.LANGUAGE => "Language plugin",
PluginType.ASSISTANT => "Assistant plugin",
PluginType.CONFIGURATION => "Configuration plugin",
PluginType.THEME => "Theme plugin",
PluginType.LANGUAGE => TB("Language plugin"),
PluginType.ASSISTANT => TB("Assistant plugin"),
PluginType.CONFIGURATION => TB("Configuration plugin"),
PluginType.THEME => TB("Theme plugin"),
_ => "Unknown plugin type",
_ => TB("Unknown plugin type"),
};
public static string GetDirectory(this PluginType type) => type switch
@@ -4,21 +4,24 @@ using AIStudio.Agents;
using AIStudio.Chat;
using AIStudio.Provider;
using AIStudio.Settings;
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools.RAG.AugmentationProcesses;
public sealed class AugmentationOne : IAugmentationProcess
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(AugmentationOne).Namespace, nameof(AugmentationOne));
#region Implementation of IAugmentationProcess
/// <inheritdoc />
public string TechnicalName => "AugmentationOne";
/// <inheritdoc />
public string UIName => "Standard augmentation process";
public string UIName => TB("Standard augmentation process");
/// <inheritdoc />
public string Description => "This is the standard augmentation process, which uses all retrieval contexts to augment the chat thread.";
public string Description => TB("This is the standard augmentation process, which uses all retrieval contexts to augment the chat thread.");
/// <inheritdoc />
public async Task<ChatThread> ProcessAsync(IProvider provider, IContent lastPrompt, ChatThread chatThread, IReadOnlyList<IRetrievalContext> retrievalContexts, CancellationToken token = default)
@@ -3,21 +3,24 @@ using AIStudio.Chat;
using AIStudio.Components;
using AIStudio.Provider;
using AIStudio.Settings;
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools.RAG.DataSourceSelectionProcesses;
public class AgenticSrcSelWithDynHeur : IDataSourceSelectionProcess
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(AgenticSrcSelWithDynHeur).Namespace, nameof(AgenticSrcSelWithDynHeur));
#region Implementation of IDataSourceSelectionProcess
/// <inheritdoc />
public string TechnicalName => "AgenticSrcSelWithDynHeur";
/// <inheritdoc />
public string UIName => "Automatic AI data source selection with heuristik source reduction";
public string UIName => TB("Automatic AI data source selection with heuristik source reduction");
/// <inheritdoc />
public string Description => "Automatically selects the appropriate data sources based on the last prompt. Applies a heuristic reduction at the end to reduce the number of data sources.";
public string Description => TB("Automatically selects the appropriate data sources based on the last prompt. Applies a heuristic reduction at the end to reduce the number of data sources.");
/// <inheritdoc />
public async Task<DataSelectionResult> SelectDataSourcesAsync(IProvider provider, IContent lastPrompt, ChatThread chatThread, AllowedSelectedDataSources dataSources, CancellationToken token = default)
@@ -2,6 +2,7 @@ using AIStudio.Chat;
using AIStudio.Provider;
using AIStudio.Settings;
using AIStudio.Settings.DataModel;
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.RAG.AugmentationProcesses;
using AIStudio.Tools.RAG.DataSourceSelectionProcesses;
using AIStudio.Tools.Services;
@@ -10,16 +11,18 @@ namespace AIStudio.Tools.RAG.RAGProcesses;
public sealed class AISrcSelWithRetCtxVal : IRagProcess
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(AISrcSelWithRetCtxVal).Namespace, nameof(AISrcSelWithRetCtxVal));
#region Implementation of IRagProcess
/// <inheritdoc />
public string TechnicalName => "AISrcSelWithRetCtxVal";
/// <inheritdoc />
public string UIName => "AI source selection with AI retrieval context validation";
public string UIName => TB("AI source selection with AI retrieval context validation");
/// <inheritdoc />
public string Description => "This RAG process filters data sources, automatically selects appropriate sources, optionally allows manual source selection, retrieves data, and automatically validates the retrieval context.";
public string Description => TB("This RAG process filters data sources, automatically selects appropriate sources, optionally allows manual source selection, retrieves data, and automatically validates the retrieval context.");
/// <inheritdoc />
public async Task<ChatThread> ProcessAsync(IProvider provider, IContent lastPrompt, ChatThread chatThread, CancellationToken token = default)
@@ -1,4 +1,7 @@
// ReSharper disable NotAccessedPositionalProperty.Global
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools.Rust;
/// <summary>
@@ -8,11 +11,13 @@ namespace AIStudio.Tools.Rust;
/// <param name="FilterExtensions">The file extensions associated with the filter.</param>
public readonly record struct FileTypeFilter(string FilterName, string[] FilterExtensions)
{
public static FileTypeFilter PDF => new("PDF Files", ["pdf"]);
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(FileTypeFilter).Namespace, nameof(FileTypeFilter));
public static FileTypeFilter Text => new("Text Files", ["txt", "md"]);
public static FileTypeFilter PDF => new(TB("PDF Files"), ["pdf"]);
public static FileTypeFilter AllOffice => new("All Office Files", ["docx", "xlsx", "pptx", "doc", "xls", "ppt", "pdf"]);
public static FileTypeFilter Text => new(TB("Text Files"), ["txt", "md"]);
public static FileTypeFilter AllImages => new("All Image Files", ["jpg", "jpeg", "png", "gif", "bmp", "tiff"]);
public static FileTypeFilter AllOffice => new(TB("All Office Files"), ["docx", "xlsx", "pptx", "doc", "xls", "ppt", "pdf"]);
public static FileTypeFilter AllImages => new(TB("All Image Files"), ["jpg", "jpeg", "png", "gif", "bmp", "tiff"]);
}
@@ -1,9 +1,12 @@
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Rust;
namespace AIStudio.Tools.Services;
public sealed partial class RustService
{
private static string TB_APIKeys(string fallbackEN) => I18N.I.T(fallbackEN, typeof(RustService).Namespace, $"{nameof(RustService)}.APIKeys");
/// <summary>
/// Try to get the API key for the given secret ID.
/// </summary>
@@ -12,13 +15,15 @@ public sealed partial class RustService
/// <returns>The requested secret.</returns>
public async Task<RequestedSecret> GetAPIKey(ISecretId secretId, bool isTrying = false)
{
static string TB(string fallbackEN) => TB_APIKeys(fallbackEN);
var secretRequest = new SelectSecretRequest($"provider::{secretId.SecretId}::{secretId.SecretName}::api_key", Environment.UserName, isTrying);
var result = await this.http.PostAsJsonAsync("/secrets/get", secretRequest, this.jsonRustSerializerOptions);
if (!result.IsSuccessStatusCode)
{
if(!isTrying)
this.logger!.LogError($"Failed to get the API key for secret ID '{secretId.SecretId}' due to an API issue: '{result.StatusCode}'");
return new RequestedSecret(false, new EncryptedText(string.Empty), "Failed to get the API key due to an API issue.");
return new RequestedSecret(false, new EncryptedText(string.Empty), TB("Failed to get the API key due to an API issue."));
}
var secret = await result.Content.ReadFromJsonAsync<RequestedSecret>(this.jsonRustSerializerOptions);
@@ -36,13 +41,15 @@ public sealed partial class RustService
/// <returns>The store secret response.</returns>
public async Task<StoreSecretResponse> SetAPIKey(ISecretId secretId, string key)
{
static string TB(string fallbackEN) => TB_APIKeys(fallbackEN);
var encryptedKey = await this.encryptor!.Encrypt(key);
var request = new StoreSecretRequest($"provider::{secretId.SecretId}::{secretId.SecretName}::api_key", Environment.UserName, encryptedKey);
var result = await this.http.PostAsJsonAsync("/secrets/store", request, this.jsonRustSerializerOptions);
if (!result.IsSuccessStatusCode)
{
this.logger!.LogError($"Failed to store the API key for secret ID '{secretId.SecretId}' due to an API issue: '{result.StatusCode}'");
return new StoreSecretResponse(false, "Failed to get the API key due to an API issue.");
return new StoreSecretResponse(false, TB("Failed to get the API key due to an API issue."));
}
var state = await result.Content.ReadFromJsonAsync<StoreSecretResponse>(this.jsonRustSerializerOptions);
@@ -59,12 +66,14 @@ public sealed partial class RustService
/// <returns>The delete secret response.</returns>
public async Task<DeleteSecretResponse> DeleteAPIKey(ISecretId secretId)
{
static string TB(string fallbackEN) => TB_APIKeys(fallbackEN);
var request = new SelectSecretRequest($"provider::{secretId.SecretId}::{secretId.SecretName}::api_key", Environment.UserName, false);
var result = await this.http.PostAsJsonAsync("/secrets/delete", request, this.jsonRustSerializerOptions);
if (!result.IsSuccessStatusCode)
{
this.logger!.LogError($"Failed to delete the API key for secret ID '{secretId.SecretId}' due to an API issue: '{result.StatusCode}'");
return new DeleteSecretResponse{Success = false, WasEntryFound = false, Issue = "Failed to delete the API key due to an API issue."};
return new DeleteSecretResponse{Success = false, WasEntryFound = false, Issue = TB("Failed to delete the API key due to an API issue.")};
}
var state = await result.Content.ReadFromJsonAsync<DeleteSecretResponse>(this.jsonRustSerializerOptions);
@@ -1,9 +1,12 @@
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Rust;
namespace AIStudio.Tools.Services;
public sealed partial class RustService
{
private static string TB_Clipboard(string fallbackEN) => I18N.I.T(fallbackEN, typeof(RustService).Namespace, $"{nameof(RustService)}.Clipboard");
/// <summary>
/// Tries to copy the given text to the clipboard.
/// </summary>
@@ -11,7 +14,9 @@ public sealed partial class RustService
/// <param name="text">The text to copy to the clipboard.</param>
public async Task CopyText2Clipboard(ISnackbar snackbar, string text)
{
var message = "Successfully copied the text to your clipboard";
static string TB(string fallbackEN) => TB_Clipboard(fallbackEN);
var message = TB("Successfully copied the text to your clipboard");
var iconColor = Color.Error;
var severity = Severity.Error;
try
@@ -21,7 +26,7 @@ public sealed partial class RustService
if (!response.IsSuccessStatusCode)
{
this.logger!.LogError($"Failed to copy the text to the clipboard due to an network error: '{response.StatusCode}'");
message = "Failed to copy the text to your clipboard.";
message = TB("Failed to copy the text to your clipboard.");
return;
}
@@ -29,7 +34,7 @@ public sealed partial class RustService
if (!state.Success)
{
this.logger!.LogError("Failed to copy the text to the clipboard.");
message = "Failed to copy the text to your clipboard.";
message = TB("Failed to copy the text to your clipboard.");
return;
}
@@ -1,9 +1,12 @@
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Rust;
namespace AIStudio.Tools.Services;
public sealed partial class RustService
{
private static string TB_Secrets(string fallbackEN) => I18N.I.T(fallbackEN, typeof(RustService).Namespace, $"{nameof(RustService)}.Secrets");
/// <summary>
/// Try to get the secret data for the given secret ID.
/// </summary>
@@ -12,13 +15,15 @@ public sealed partial class RustService
/// <returns>The requested secret.</returns>
public async Task<RequestedSecret> GetSecret(ISecretId secretId, bool isTrying = false)
{
static string TB(string fallbackEN) => TB_Secrets(fallbackEN);
var secretRequest = new SelectSecretRequest($"secret::{secretId.SecretId}::{secretId.SecretName}", Environment.UserName, isTrying);
var result = await this.http.PostAsJsonAsync("/secrets/get", secretRequest, this.jsonRustSerializerOptions);
if (!result.IsSuccessStatusCode)
{
if(!isTrying)
this.logger!.LogError($"Failed to get the secret data for secret ID '{secretId.SecretId}' due to an API issue: '{result.StatusCode}'");
return new RequestedSecret(false, new EncryptedText(string.Empty), "Failed to get the secret data due to an API issue.");
return new RequestedSecret(false, new EncryptedText(string.Empty), TB("Failed to get the secret data due to an API issue."));
}
var secret = await result.Content.ReadFromJsonAsync<RequestedSecret>(this.jsonRustSerializerOptions);
@@ -36,13 +41,15 @@ public sealed partial class RustService
/// <returns>The store secret response.</returns>
public async Task<StoreSecretResponse> SetSecret(ISecretId secretId, string secretData)
{
static string TB(string fallbackEN) => TB_Secrets(fallbackEN);
var encryptedSecret = await this.encryptor!.Encrypt(secretData);
var request = new StoreSecretRequest($"secret::{secretId.SecretId}::{secretId.SecretName}", Environment.UserName, encryptedSecret);
var result = await this.http.PostAsJsonAsync("/secrets/store", request, this.jsonRustSerializerOptions);
if (!result.IsSuccessStatusCode)
{
this.logger!.LogError($"Failed to store the secret data for secret ID '{secretId.SecretId}' due to an API issue: '{result.StatusCode}'");
return new StoreSecretResponse(false, "Failed to get the secret data due to an API issue.");
return new StoreSecretResponse(false, TB("Failed to get the secret data due to an API issue."));
}
var state = await result.Content.ReadFromJsonAsync<StoreSecretResponse>(this.jsonRustSerializerOptions);
@@ -59,12 +66,14 @@ public sealed partial class RustService
/// <returns>The delete secret response.</returns>
public async Task<DeleteSecretResponse> DeleteSecret(ISecretId secretId)
{
static string TB(string fallbackEN) => TB_Secrets(fallbackEN);
var request = new SelectSecretRequest($"secret::{secretId.SecretId}::{secretId.SecretName}", Environment.UserName, false);
var result = await this.http.PostAsJsonAsync("/secrets/delete", request, this.jsonRustSerializerOptions);
if (!result.IsSuccessStatusCode)
{
this.logger!.LogError($"Failed to delete the secret data for secret ID '{secretId.SecretId}' due to an API issue: '{result.StatusCode}'");
return new DeleteSecretResponse{Success = false, WasEntryFound = false, Issue = "Failed to delete the secret data due to an API issue."};
return new DeleteSecretResponse{Success = false, WasEntryFound = false, Issue = TB("Failed to delete the secret data due to an API issue.")};
}
var state = await result.Content.ReadFromJsonAsync<DeleteSecretResponse>(this.jsonRustSerializerOptions);
@@ -1,5 +1,6 @@
using AIStudio.Settings;
using AIStudio.Settings.DataModel;
using AIStudio.Tools.PluginSystem;
using Microsoft.AspNetCore.Components;
@@ -7,6 +8,8 @@ namespace AIStudio.Tools.Services;
public sealed class UpdateService : BackgroundService, IMessageBusReceiver
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(UpdateService).Namespace, nameof(UpdateService));
private static bool IS_INITIALIZED;
private static ISnackbar? SNACKBAR;
@@ -118,7 +121,7 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
{
if (notifyUserWhenNoUpdate)
{
SNACKBAR!.Add("No update found.", Severity.Normal, config =>
SNACKBAR!.Add(TB("No update found."), Severity.Normal, config =>
{
config.Icon = Icons.Material.Filled.Update;
config.IconSize = Size.Large;
@@ -1,10 +1,13 @@
using AIStudio.Settings.DataModel;
using AIStudio.Tools.ERIClient.DataModel;
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools.Validation;
public sealed class DataSourceValidation
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(DataSourceValidation).Namespace, nameof(DataSourceValidation));
public Func<string> GetSecretStorageIssue { get; init; } = () => string.Empty;
public Func<string> GetPreviousDataSourceName { get; init; } = () => string.Empty;
@@ -26,13 +29,13 @@ public sealed class DataSourceValidation
public string? ValidatingHostname(string hostname)
{
if(string.IsNullOrWhiteSpace(hostname))
return "Please enter a hostname, e.g., http://localhost";
return TB("Please enter a hostname, e.g., http://localhost");
if(!hostname.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) && !hostname.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
return "The hostname must start with either http:// or https://";
return TB("The hostname must start with either http:// or https://");
if(!Uri.TryCreate(hostname, UriKind.Absolute, out _))
return "The hostname is not a valid HTTP(S) URL.";
return TB("The hostname is not a valid HTTP(S) URL.");
return null;
}
@@ -40,7 +43,7 @@ public sealed class DataSourceValidation
public string? ValidatePort(int port)
{
if(port is < 1 or > 65535)
return "The port must be between 1 and 65535.";
return TB("The port must be between 1 and 65535.");
return null;
}
@@ -48,14 +51,14 @@ public sealed class DataSourceValidation
public string? ValidateSecurityPolicy(DataSourceSecurity securityPolicy)
{
if(securityPolicy is DataSourceSecurity.NOT_SPECIFIED)
return "Please select your security policy.";
return TB("Please select your security policy.");
var dataSourceSecurity = this.GetSecurityRequirements();
if (dataSourceSecurity is null)
return null;
if(dataSourceSecurity.Value.AllowedProviderType is ProviderType.SELF_HOSTED && securityPolicy is not DataSourceSecurity.SELF_HOSTED)
return "This data source can only be used with a self-hosted LLM provider. Please change the security policy.";
return TB("This data source can only be used with a self-hosted LLM provider. Please change the security policy.");
return null;
}
@@ -66,7 +69,7 @@ public sealed class DataSourceValidation
return null;
if(string.IsNullOrWhiteSpace(username))
return "The username must not be empty.";
return TB("The username must not be empty.");
return null;
}
@@ -84,10 +87,10 @@ public sealed class DataSourceValidation
if (string.IsNullOrWhiteSpace(secret))
return authMethod switch
{
AuthMethod.TOKEN => "Please enter your secure access token.",
AuthMethod.USERNAME_PASSWORD => "Please enter your password.",
AuthMethod.TOKEN => TB("Please enter your secure access token."),
AuthMethod.USERNAME_PASSWORD => TB("Please enter your password."),
_ => "Please enter the secret necessary for authentication."
_ => TB("Please enter the secret necessary for authentication.")
};
return null;
@@ -96,7 +99,7 @@ public sealed class DataSourceValidation
public string? ValidateRetrievalProcess(RetrievalInfo retrievalInfo)
{
if(retrievalInfo == default)
return "Please select one retrieval process.";
return TB("Please select one retrieval process.");
return null;
}
@@ -104,14 +107,14 @@ public sealed class DataSourceValidation
public string? ValidatingName(string dataSourceName)
{
if(string.IsNullOrWhiteSpace(dataSourceName))
return "The name must not be empty.";
return TB("The name must not be empty.");
if (dataSourceName.Length > 40)
return "The name must not exceed 40 characters.";
return TB("The name must not exceed 40 characters.");
var lowerName = dataSourceName.ToLowerInvariant();
if(lowerName != this.GetPreviousDataSourceName() && this.GetUsedDataSourceNames().Contains(lowerName))
return "The name is already used by another data source. Please choose a different name.";
return TB("The name is already used by another data source. Please choose a different name.");
return null;
}
@@ -119,10 +122,10 @@ public sealed class DataSourceValidation
public string? ValidatePath(string path)
{
if(string.IsNullOrWhiteSpace(path))
return "The path must not be empty. Please select a directory.";
return TB("The path must not be empty. Please select a directory.");
if(!Directory.Exists(path))
return "The path does not exist. Please select a valid directory.";
return TB("The path does not exist. Please select a valid directory.");
return null;
}
@@ -130,10 +133,10 @@ public sealed class DataSourceValidation
public string? ValidateFilePath(string filePath)
{
if(string.IsNullOrWhiteSpace(filePath))
return "The file path must not be empty. Please select a file.";
return TB("The file path must not be empty. Please select a file.");
if(!File.Exists(filePath))
return "The file does not exist. Please select a valid file.";
return TB("The file does not exist. Please select a valid file.");
return null;
}
@@ -141,7 +144,7 @@ public sealed class DataSourceValidation
public string? ValidateEmbeddingId(string embeddingId)
{
if(string.IsNullOrWhiteSpace(embeddingId))
return "Please select an embedding provider.";
return TB("Please select an embedding provider.");
return null;
}
@@ -149,7 +152,7 @@ public sealed class DataSourceValidation
public string? ValidateUserAcknowledgedCloudEmbedding(bool value)
{
if(this.GetSelectedCloudEmbedding() && !value)
return "Please acknowledge that you are aware of the cloud embedding implications.";
return TB("Please acknowledge that you are aware of the cloud embedding implications.");
return null;
}
@@ -157,10 +160,10 @@ public sealed class DataSourceValidation
public string? ValidateTestedConnection()
{
if(!this.GetTestedConnection())
return "Please test the connection before saving.";
return TB("Please test the connection before saving.");
if(!this.GetTestedConnectionResult())
return "The connection test failed. Please check the connection settings.";
return TB("The connection test failed. Please check the connection settings.");
return null;
}
@@ -168,7 +171,7 @@ public sealed class DataSourceValidation
public string? ValidateAuthMethod(AuthMethod authMethod)
{
if(!this.GetAvailableAuthMethods().Contains(authMethod))
return "Please select one valid authentication method.";
return TB("Please select one valid authentication method.");
return null;
}
@@ -1,11 +1,15 @@
using AIStudio.Provider;
using AIStudio.Provider.HuggingFace;
using AIStudio.Tools.PluginSystem;
using Host = AIStudio.Provider.SelfHosted.Host;
namespace AIStudio.Tools.Validation;
public sealed class ProviderValidation
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ProviderValidation).Namespace, nameof(ProviderValidation));
public Func<LLMProviders> GetProvider { get; init; } = () => LLMProviders.NONE;
public Func<string> GetAPIKeyStorageIssue { get; init; } = () => string.Empty;
@@ -22,13 +26,13 @@ public sealed class ProviderValidation
return null;
if(string.IsNullOrWhiteSpace(hostname))
return "Please enter a hostname, e.g., http://localhost:1234";
return TB("Please enter a hostname, e.g., http://localhost:1234");
if(!hostname.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) && !hostname.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
return "The hostname must start with either http:// or https://";
return TB("The hostname must start with either http:// or https://");
if(!Uri.TryCreate(hostname, UriKind.Absolute, out _))
return "The hostname is not a valid HTTP(S) URL.";
return TB("The hostname is not a valid HTTP(S) URL.");
return null;
}
@@ -43,7 +47,7 @@ public sealed class ProviderValidation
return apiKeyStorageIssue;
if(string.IsNullOrWhiteSpace(apiKey))
return "Please enter an API key.";
return TB("Please enter an API key.");
return null;
}
@@ -51,15 +55,15 @@ public sealed class ProviderValidation
public string? ValidatingInstanceName(string instanceName)
{
if (string.IsNullOrWhiteSpace(instanceName))
return "Please enter an instance name.";
return TB("Please enter an instance name.");
if (instanceName.Length > 40)
return "The instance name must not exceed 40 characters.";
return TB("The instance name must not exceed 40 characters.");
// The instance name must be unique:
var lowerInstanceName = instanceName.ToLowerInvariant();
if (lowerInstanceName != this.GetPreviousInstanceName() && this.GetUsedInstanceNames().Contains(lowerInstanceName))
return "The instance name must be unique; the chosen name is already in use.";
return TB("The instance name must be unique; the chosen name is already in use.");
return null;
}
@@ -70,7 +74,7 @@ public sealed class ProviderValidation
return null;
if (model == default)
return "Please select a model.";
return TB("Please select a model.");
return null;
}
@@ -78,7 +82,7 @@ public sealed class ProviderValidation
public string? ValidatingProvider(LLMProviders llmProvider)
{
if (llmProvider == LLMProviders.NONE)
return "Please select a provider.";
return TB("Please select a provider.");
return null;
}
@@ -89,7 +93,7 @@ public sealed class ProviderValidation
return null;
if (host == Host.NONE)
return "Please select a host.";
return TB("Please select a host.");
return null;
}
@@ -100,7 +104,7 @@ public sealed class ProviderValidation
return null;
if (inferenceProvider is HFInferenceProvider.NONE)
return "Please select an Hugging Face inference provider.";
return TB("Please select an Hugging Face inference provider.");
return null;
}
@@ -5,11 +5,14 @@ using System.Text.Json.Serialization;
using AIStudio.Chat;
using AIStudio.Dialogs;
using AIStudio.Settings;
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Tools;
public static class WorkspaceBehaviour
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(WorkspaceBehaviour).Namespace, nameof(WorkspaceBehaviour));
public static readonly JsonSerializerOptions JSON_OPTIONS = new()
{
WriteIndented = true,
@@ -97,13 +100,13 @@ public static class WorkspaceBehaviour
{
"Message", (chat.WorkspaceId == Guid.Empty) switch
{
true => $"Are you sure you want to delete the temporary chat '{chat.Name}'?",
false => $"Are you sure you want to delete the chat '{chat.Name}' in the workspace '{workspaceName}'?",
true => TB($"Are you sure you want to delete the temporary chat '{chat.Name}'?"),
false => TB($"Are you sure you want to delete the chat '{chat.Name}' in the workspace '{workspaceName}'?"),
}
},
};
var dialogReference = await dialogService.ShowAsync<ConfirmDialog>("Delete Chat", dialogParameters, Dialogs.DialogOptions.FULLSCREEN);
var dialogReference = await dialogService.ShowAsync<ConfirmDialog>(TB("Delete Chat"), dialogParameters, Dialogs.DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult is null || dialogResult.Canceled)
return;