mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-10 22:27:21 +00:00
Turned getter-like extension methods into extension properties (#1157)
This commit is contained in:
1 parent
0375318b1b
commit
f649febf88
286 files changed
+1379
-1109
No files matched your search
@@ -4,7 +4,7 @@ public static class BiasCategoryExtensions
|
||||
{
|
||||
extension(BiasCategory biasCategory)
|
||||
{
|
||||
public string ToName() => biasCategory switch
|
||||
public string Name => biasCategory switch
|
||||
{
|
||||
BiasCategory.WHAT_SHOULD_WE_REMEMBER => "What should we remember?",
|
||||
BiasCategory.TOO_MUCH_INFORMATION => "Too much information",
|
||||
@@ -14,7 +14,7 @@ public static class BiasCategoryExtensions
|
||||
_ => "Unknown category",
|
||||
};
|
||||
|
||||
public string GetThoughts() => biasCategory switch
|
||||
public string Thoughts => biasCategory switch
|
||||
{
|
||||
BiasCategory.WHAT_SHOULD_WE_REMEMBER =>
|
||||
"""
|
||||
|
||||
@@ -56,7 +56,7 @@ public sealed class DataBatchProcessing(Expression<Func<Data, DataBatchProcessin
|
||||
/// The file format of the individual result files, one per processed document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only formats which hold an entire answer, see FileExportFormatExtensions.ANSWER_FORMATS.
|
||||
/// Only formats which hold an entire answer, see FileExportFormat.AnswerFormats.
|
||||
/// The tabular formats belong to the output mode TABLE_ONLY, which writes one table for the
|
||||
/// whole run instead of one file per document.
|
||||
/// </remarks>
|
||||
@@ -70,7 +70,7 @@ public sealed class DataBatchProcessing(Expression<Func<Data, DataBatchProcessin
|
||||
/// any format, a table or code for example, and the result files would then end up without an
|
||||
/// extension.
|
||||
/// </remarks>
|
||||
public static bool IsValidResultFileFormat(FileExportFormat format) => FileExportFormatExtensions.ANSWER_FORMATS.Contains(format);
|
||||
public static bool IsValidResultFileFormat(FileExportFormat format) => FileExportFormat.AnswerFormats.Contains(format);
|
||||
|
||||
public string CsvFileName { get; set; } = ManagedConfiguration.Register(configSelection, value => value.CsvFileName, string.Empty);
|
||||
|
||||
|
||||
@@ -94,13 +94,13 @@ public sealed record DataMailboxProvider : ILivePluginContent
|
||||
}
|
||||
|
||||
var transportSecurity = MailboxTransportSecurity.SSL_ON_CONNECT;
|
||||
if (table.TryGetValue("TransportSecurity", out var transportSecurityValue) && (!transportSecurityValue.TryRead<string>(out var transportSecurityText) || !EnumNames.TryParse(transportSecurityText, out transportSecurity) || transportSecurity is MailboxTransportSecurity.UNKNOWN))
|
||||
if (table.TryGetValue("TransportSecurity", out var transportSecurityValue) && (!transportSecurityValue.TryRead<string>(out var transportSecurityText) || !MailboxTransportSecurity.TryParseName(transportSecurityText, out transportSecurity) || transportSecurity is MailboxTransportSecurity.UNKNOWN))
|
||||
{
|
||||
logger.LogWarning("The configured mailbox provider {ProviderIndex} does not contain a valid TransportSecurity field. Allowed values are SSL_ON_CONNECT and STARTTLS.", index);
|
||||
return false;
|
||||
}
|
||||
|
||||
var port = transportSecurity.GetUsualPort() ?? MailboxTransportSecurityExtensions.SSL_ON_CONNECT_PORT;
|
||||
var port = transportSecurity.UsualPort ?? MailboxTransportSecurityExtensions.SSL_ON_CONNECT_PORT;
|
||||
if (table.TryGetValue("Port", out var portValue) && (!portValue.TryRead(out port) || port is < 1 or > 65535))
|
||||
{
|
||||
logger.LogWarning("The configured mailbox provider {ProviderIndex} does not contain a valid Port field. The port must be a number from 1 to 65535.", index);
|
||||
|
||||
@@ -170,7 +170,7 @@ public record struct DataSourceERI_V1: IERIDataSource
|
||||
Path = eriContext.Path ?? string.Empty,
|
||||
Type = eriContext.ToRetrievalContentType(),
|
||||
Links = eriContext.Links ?? [],
|
||||
Category = eriContext.Type.ToRetrievalContentCategory(),
|
||||
Category = eriContext.Type.RetrievalContentCategory,
|
||||
SourceCategory = eriContext.Category ?? string.Empty,
|
||||
MatchedText = eriContext.MatchedContent ?? string.Empty,
|
||||
DataSourceName = eriContext.Name ?? string.Empty,
|
||||
@@ -185,7 +185,7 @@ public record struct DataSourceERI_V1: IERIDataSource
|
||||
Type = eriContext.ToRetrievalContentType(),
|
||||
Links = eriContext.Links ?? [],
|
||||
Source = eriContext.MatchedContent ?? string.Empty,
|
||||
Category = eriContext.Type.ToRetrievalContentCategory(),
|
||||
Category = eriContext.Type.RetrievalContentCategory,
|
||||
SourceCategory = eriContext.Category ?? string.Empty,
|
||||
SourceType = ContentImageSource.BASE64,
|
||||
DataSourceName = eriContext.Name ?? string.Empty,
|
||||
@@ -275,7 +275,7 @@ public record struct DataSourceERI_V1: IERIDataSource
|
||||
// its passages reach a chat, see DataSourceOutboundDataExtensions.GetEffectiveOutboundDataRestriction.
|
||||
//
|
||||
var outboundDataRestriction = DataSourceOutboundDataExtensions.DEFAULT_OUTBOUND_DATA_RESTRICTION;
|
||||
if (table.TryGetValue("OutboundDataRestriction", out var outboundDataRestrictionValue) && !(outboundDataRestrictionValue.TryRead<string>(out var outboundDataRestrictionText) && EnumNames.TryParse(outboundDataRestrictionText, out outboundDataRestriction)))
|
||||
if (table.TryGetValue("OutboundDataRestriction", out var outboundDataRestrictionValue) && !(outboundDataRestrictionValue.TryRead<string>(out var outboundDataRestrictionText) && OutboundDataRestriction.TryParseName(outboundDataRestrictionText, out outboundDataRestriction)))
|
||||
{
|
||||
LOGGER.LogWarning($"The configured data source {idx} does not contain a valid outbound data restriction, so the strictest one applies. (Plugin ID: {configPluginId})");
|
||||
outboundDataRestriction = OutboundDataRestriction.ONLY_CONFIGURED_SERVICES;
|
||||
|
||||
@@ -8,7 +8,7 @@ public static class DataSourceSecurityExtensions
|
||||
|
||||
extension(DataSourceSecurity security)
|
||||
{
|
||||
public string ToSelectionText() => security switch
|
||||
public string SelectionText => security switch
|
||||
{
|
||||
DataSourceSecurity.NOT_SPECIFIED => TB("Please select a security policy"),
|
||||
|
||||
@@ -18,7 +18,7 @@ public static class DataSourceSecurityExtensions
|
||||
_ => TB("Unknown security policy")
|
||||
};
|
||||
|
||||
public string ToInfoText() => security switch
|
||||
public string InfoText => security switch
|
||||
{
|
||||
DataSourceSecurity.NOT_SPECIFIED => TB("The security of the data source is not specified yet. You cannot use this data source until you specify a security policy."),
|
||||
|
||||
@@ -28,7 +28,7 @@ public static class DataSourceSecurityExtensions
|
||||
_ => TB("Unknown security policy")
|
||||
};
|
||||
|
||||
public TextColor GetColor() => security switch
|
||||
public TextColor Color => security switch
|
||||
{
|
||||
DataSourceSecurity.ALLOW_ANY => TextColor.WARN,
|
||||
DataSourceSecurity.SELF_HOSTED => TextColor.SUCCESS,
|
||||
|
||||
@@ -15,8 +15,8 @@ public static class DataSourceTypeExtension
|
||||
/// <summary>
|
||||
/// Get the display name of the data source type.
|
||||
/// </summary>
|
||||
/// <returns>The display name of the data source type.</returns>
|
||||
public string GetDisplayName() => type switch
|
||||
/// <value>The display name of the data source type.</value>
|
||||
public string DisplayName => type switch
|
||||
{
|
||||
DataSourceType.LOCAL_FILE => TB("Local File"),
|
||||
DataSourceType.LOCAL_DIRECTORY => TB("Local Directory"),
|
||||
|
||||
@@ -8,7 +8,7 @@ public static class LangBehaviorExtensions
|
||||
|
||||
extension(LangBehavior langBehavior)
|
||||
{
|
||||
public string Name() => langBehavior switch
|
||||
public string Name => langBehavior switch
|
||||
{
|
||||
LangBehavior.AUTO => TB("Choose the language automatically, based on your system language."),
|
||||
LangBehavior.MANUAL => TB("Choose the language manually."),
|
||||
|
||||
@@ -9,7 +9,7 @@ public static class MailboxMaxAgeExtensions
|
||||
/// <param name="maxAge">The period.</param>
|
||||
extension(MailboxMaxAge maxAge)
|
||||
{
|
||||
public string GetName() => maxAge switch
|
||||
public string Name => maxAge switch
|
||||
{
|
||||
MailboxMaxAge.LAST_3_MONTHS => TB("The last 3 months"),
|
||||
MailboxMaxAge.LAST_6_MONTHS => TB("The last 6 months"),
|
||||
|
||||
@@ -18,7 +18,7 @@ public static class MailboxTransportSecurityExtensions
|
||||
|
||||
extension(MailboxTransportSecurity transportSecurity)
|
||||
{
|
||||
public string GetName() => transportSecurity switch
|
||||
public string Name => transportSecurity switch
|
||||
{
|
||||
MailboxTransportSecurity.SSL_ON_CONNECT => TB("TLS from the start (usually port 993)"),
|
||||
MailboxTransportSecurity.STARTTLS => TB("STARTTLS (usually port 143)"),
|
||||
@@ -29,8 +29,8 @@ public static class MailboxTransportSecurityExtensions
|
||||
/// <summary>
|
||||
/// The port the encryption usually comes with.
|
||||
/// </summary>
|
||||
/// <returns>The port, or null when there is no usual one.</returns>
|
||||
public int? GetUsualPort() => transportSecurity switch
|
||||
/// <value>The port, or null when there is no usual one.</value>
|
||||
public int? UsualPort => transportSecurity switch
|
||||
{
|
||||
MailboxTransportSecurity.SSL_ON_CONNECT => SSL_ON_CONNECT_PORT,
|
||||
MailboxTransportSecurity.STARTTLS => STARTTLS_PORT,
|
||||
|
||||
@@ -25,13 +25,13 @@ public static class OutboundDataRequirementExtensions
|
||||
public string GetToolBlockedMessage(Data settings) => requirement.Origin switch
|
||||
{
|
||||
OutboundDataOrigin.MAILBOX => GetMailboxBlockedMessage(requirement, settings.Mailboxes),
|
||||
OutboundDataOrigin.CONFLUENCE_WIKI => string.Format(TB("This chat holds content from your Confluence wiki, found while the setting 'Where a chat may send data after reading internal pages' of the tool 'Read Web Page' was '{0}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Restriction.GetName()),
|
||||
OutboundDataOrigin.INTERNAL_WEB_PAGE => string.Format(TB("This chat holds content from an internal web page on '{0}', read while the setting 'Where a chat may send data after reading internal pages' of the tool 'Read Web Page' was '{1}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Reference, requirement.Restriction.GetName()),
|
||||
OutboundDataOrigin.CONFLUENCE_WIKI => string.Format(TB("This chat holds content from your Confluence wiki, found while the setting 'Where a chat may send data after reading internal pages' of the tool 'Read Web Page' was '{0}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Restriction.Name),
|
||||
OutboundDataOrigin.INTERNAL_WEB_PAGE => string.Format(TB("This chat holds content from an internal web page on '{0}', read while the setting 'Where a chat may send data after reading internal pages' of the tool 'Read Web Page' was '{1}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Reference, requirement.Restriction.Name),
|
||||
OutboundDataOrigin.DATA_SOURCE => GetDataSourceBlockedMessage(requirement, settings.DataSources),
|
||||
|
||||
// NONE keeps no tool from running, since nothing restricts such a chat. What is left is an
|
||||
// origin this version does not know:
|
||||
_ => string.Format(TB("This chat holds internal content, read while a chat was restricted to '{0}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Restriction.GetName()),
|
||||
_ => string.Format(TB("This chat holds internal content, read while a chat was restricted to '{0}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Restriction.Name),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ public static class OutboundDataRequirementExtensions
|
||||
.FirstOrDefault();
|
||||
|
||||
return string.IsNullOrWhiteSpace(mailboxName)
|
||||
? string.Format(TB("This chat holds content from a mailbox which has been removed since, read while its setting 'Where a chat may send data after reading mails' was '{0}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Restriction.GetName())
|
||||
: string.Format(TB("This chat holds content from the mailbox '{0}', read while its setting 'Where a chat may send data after reading mails' was '{1}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), mailboxName, requirement.Restriction.GetName());
|
||||
? string.Format(TB("This chat holds content from a mailbox which has been removed since, read while its setting 'Where a chat may send data after reading mails' was '{0}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Restriction.Name)
|
||||
: string.Format(TB("This chat holds content from the mailbox '{0}', read while its setting 'Where a chat may send data after reading mails' was '{1}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), mailboxName, requirement.Restriction.Name);
|
||||
}
|
||||
|
||||
private static string GetDataSourceBlockedMessage(OutboundDataRequirement requirement, IEnumerable<IDataSource> dataSources)
|
||||
@@ -55,7 +55,7 @@ public static class OutboundDataRequirementExtensions
|
||||
.FirstOrDefault();
|
||||
|
||||
return string.IsNullOrWhiteSpace(dataSourceName)
|
||||
? string.Format(TB("This chat holds content from a data source which has been removed since, found while its setting 'Where a chat may send data after reading this data source' was '{0}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Restriction.GetName())
|
||||
: string.Format(TB("This chat holds content from the data source '{0}', found while its setting 'Where a chat may send data after reading this data source' was '{1}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), dataSourceName, requirement.Restriction.GetName());
|
||||
? string.Format(TB("This chat holds content from a data source which has been removed since, found while its setting 'Where a chat may send data after reading this data source' was '{0}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), requirement.Restriction.Name)
|
||||
: string.Format(TB("This chat holds content from the data source '{0}', found while its setting 'Where a chat may send data after reading this data source' was '{1}'. This tool would send data beyond that, so it is not available in this chat. A new chat without this content can use it again."), dataSourceName, requirement.Restriction.Name);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public static class OutboundDataRestrictionExtensions
|
||||
/// <returns>The restriction itself, or the strictest one when this version does not know it.</returns>
|
||||
public OutboundDataRestriction OrStrictestWhenUnknown() => Enum.IsDefined(restriction) ? restriction : OutboundDataRestriction.ONLY_CONFIGURED_SERVICES;
|
||||
|
||||
public string GetName() => restriction switch
|
||||
public string Name => restriction switch
|
||||
{
|
||||
OutboundDataRestriction.ONLY_CONFIGURED_SERVICES => TB("Only services configured in AI Studio"),
|
||||
OutboundDataRestriction.ONLY_LINKS_FROM_CHAT => TB("Configured services and addresses from the chat"),
|
||||
@@ -47,7 +47,7 @@ public static class OutboundDataRestrictionExtensions
|
||||
/// <summary>
|
||||
/// What a chat may still do on this level, once internal content entered it.
|
||||
/// </summary>
|
||||
public string GetDescription() => restriction switch
|
||||
public string Description => restriction switch
|
||||
{
|
||||
OutboundDataRestriction.ONLY_CONFIGURED_SERVICES => TB("The chat may only use services configured in AI Studio: your mailboxes, your data sources, your Confluence wiki, and the allowed private hosts of the tool 'Read Web Page'. It reads no other web pages, and it does not search the web."),
|
||||
OutboundDataRestriction.ONLY_LINKS_FROM_CHAT => TB("The chat may also read web pages whose addresses stand in the chat, written by you or returned by a tool, exactly as they stand there. It does not search the web, and the AI cannot choose addresses of its own outside the services configured in AI Studio."),
|
||||
|
||||
@@ -9,7 +9,7 @@ public static class PreviewFeaturesExtensions
|
||||
/// <param name="feature">The preview feature to check.</param>
|
||||
extension(PreviewFeatures feature)
|
||||
{
|
||||
public string GetPreviewDescription() => feature switch
|
||||
public string PreviewDescription => feature switch
|
||||
{
|
||||
PreviewFeatures.PRE_WRITER_MODE_2024 => TB("Writer Mode: Experiments about how to write long texts using AI"),
|
||||
PreviewFeatures.PRE_RAG_2024 => TB("RAG: Preview of our RAG implementation where you can refer your files or integrate enterprise data within your company"),
|
||||
@@ -32,8 +32,8 @@ public static class PreviewFeaturesExtensions
|
||||
/// This metadata is necessary because we cannot remove the enum values from the list.
|
||||
/// Otherwise, we could not deserialize old settings files that may contain these values.
|
||||
/// </remarks>
|
||||
/// <returns>True when the preview feature is released, false otherwise.</returns>
|
||||
public bool IsReleased() => feature switch
|
||||
/// <value>True when the preview feature is released, false otherwise.</value>
|
||||
public bool IsReleased => feature switch
|
||||
{
|
||||
PreviewFeatures.PRE_READ_PDF_2025 => true,
|
||||
PreviewFeatures.PRE_PLUGINS_2025 => true,
|
||||
@@ -45,7 +45,7 @@ public static class PreviewFeaturesExtensions
|
||||
|
||||
public bool IsEnabled(SettingsManager settingsManager)
|
||||
{
|
||||
if(feature.IsReleased())
|
||||
if(feature.IsReleased)
|
||||
return true;
|
||||
|
||||
return settingsManager.ConfigurationData.App.EnabledPreviewFeatures.Contains(feature);
|
||||
|
||||
@@ -8,7 +8,7 @@ public static class SendToChatDataSourceBehaviorExtensions
|
||||
|
||||
extension(SendToChatDataSourceBehavior behavior)
|
||||
{
|
||||
public string Description() => behavior switch
|
||||
public string Description => behavior switch
|
||||
{
|
||||
SendToChatDataSourceBehavior.NO_DATA_SOURCES => TB("Use no data sources, when sending an assistant result to a chat"),
|
||||
SendToChatDataSourceBehavior.APPLY_STANDARD_CHAT_DATA_SOURCE_OPTIONS => TB("Apply standard chat data source options, when sending an assistant result to a chat"),
|
||||
|
||||
@@ -4,7 +4,7 @@ public static class StartPageExtensions
|
||||
{
|
||||
extension(StartPage startPage)
|
||||
{
|
||||
public string ToRoute() => startPage switch
|
||||
public string Route => startPage switch
|
||||
{
|
||||
StartPage.HOME => string.Empty,
|
||||
StartPage.CHAT => Routes.CHAT,
|
||||
|
||||
@@ -8,7 +8,7 @@ public static class ThemesExtensions
|
||||
|
||||
extension(Themes theme)
|
||||
{
|
||||
public string GetName() => theme switch
|
||||
public string Name => theme switch
|
||||
{
|
||||
Themes.SYSTEM => TB("Synchronized with the operating system settings"),
|
||||
Themes.LIGHT => TB("Always use light theme"),
|
||||
|
||||
@@ -8,7 +8,7 @@ public static class TranscriptionOpusBitrateExtensions
|
||||
|
||||
extension(TranscriptionOpusBitrate bitrate)
|
||||
{
|
||||
public string GetName() => bitrate switch
|
||||
public string Name => bitrate switch
|
||||
{
|
||||
TranscriptionOpusBitrate.KBPS_32 => TB("32 kbps (smallest upload, lowest accuracy)"),
|
||||
TranscriptionOpusBitrate.KBPS_64 => TB("64 kbps"),
|
||||
@@ -17,7 +17,7 @@ public static class TranscriptionOpusBitrateExtensions
|
||||
_ => TB("Unknown"),
|
||||
};
|
||||
|
||||
public uint GetBitsPerSecond() => bitrate switch
|
||||
public uint BitsPerSecond => bitrate switch
|
||||
{
|
||||
TranscriptionOpusBitrate.KBPS_32 => 32_000,
|
||||
TranscriptionOpusBitrate.KBPS_64 => 64_000,
|
||||
|
||||
Reference in new issue
Block a user