Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/MindWork AI Studio/Assistants/I18N/allTexts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25030,6 +25030,30 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::TOOLCALLINGSYSTEM::TOOLSETTINGSSERVICE::T40310
-- The file path is null or empty and the file therefore can not be loaded.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::USERFILE::T932243993"] = "The file path is null or empty and the file therefore can not be loaded."

-- The API key for '{0}' contains a character which an API key cannot contain, such as a line break or an invisible character. Please enter the key again in the settings. If your organization provides the key, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3169974238"] = "The API key for '{0}' contains a character which an API key cannot contain, such as a line break or an invisible character. Please enter the key again in the settings. If your organization provides the key, please contact your IT department."

-- The API key for '{0}' contains a character which an API key cannot contain, such as a line break or an invisible character. Please enter the key again in the settings. If your organization provides the key, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3169974238::INFORMAL"] = "The API key for '{0}' contains a character which an API key cannot contain, such as a line break or an invisible character. Please enter the key again in the settings. If your organization provides the key, please contact your IT department."

-- The API key contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the key and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3476635333"] = "The API key contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the key and enter it again."

-- The API key contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the key and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3476635333::INFORMAL"] = "The API key contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the key and enter it again."

-- The API key contains the character '{0}', which an API key cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the key.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3728920309"] = "The API key contains the character '{0}', which an API key cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the key."

-- The API key contains the character '{0}', which an API key cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the key.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3728920309::INFORMAL"] = "The API key contains the character '{0}', which an API key cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the key."

-- The API key contains a space or a line break, which an API key cannot contain. Please check whether you copied more than the key.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T839628124"] = "The API key contains a space or a line break, which an API key cannot contain. Please check whether you copied more than the key."

-- The API key contains a space or a line break, which an API key cannot contain. Please check whether you copied more than the key.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T839628124::INFORMAL"] = "The API key contains a space or a line break, which an API key cannot contain. Please check whether you copied more than the key."

-- The hostname is not a valid HTTP(S) URL.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T1013354736"] = "The hostname is not a valid HTTP(S) URL."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public abstract partial class ConfigurationBase : MSGComponentBase

protected bool IsDisabled => this.Disabled() || this.IsLocked();

private string Classes => $"{this.GetClassForBase} {JUSTIFIED_HELP_CLASS} {this.MarginClass}";
private string Classes => $"{this.GetClassForBase} {this.MarginClass}";

/// <summary>
/// The bottom margin of the option. Options inside settings panels need the default
Expand All @@ -66,8 +66,6 @@ public abstract partial class ConfigurationBase : MSGComponentBase

private protected virtual RenderFragment? Body => null;

private const string JUSTIFIED_HELP_CLASS = "configuration-help-justified";

private const string MARGIN_CLASS = "mb-6";

protected static readonly Dictionary<string, object?> SPELLCHECK_ATTRIBUTES = new();
Expand Down
2 changes: 1 addition & 1 deletion app/MindWork AI Studio/Components/Issues.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@foreach (var issue in this.IssuesData)
{
<MudListItem Icon="@AppIcons.WARNING" IconColor="Color.Error">
@issue
<MudJustifiedText Typo="Typo.body1">@issue</MudJustifiedText>
</MudListItem>
}
</MudList>
Expand Down
8 changes: 4 additions & 4 deletions app/MindWork AI Studio/Components/UserAPIKeyPrompt.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
}
else
{
<MudText Typo="Typo.body1" Class="mb-3">
<MudJustifiedText Typo="Typo.body1" Class="mb-3">
@TA("Your organization has set up AI providers for you. To use them, AI Studio needs your personal API key. Please enter it below.")
</MudText>
</MudJustifiedText>
}

<SecretInputField Secret="@this.apiKey" SecretChanged="@(value => this.apiKey = value)" Label="@T("API key")"/>
<SecretInputField Secret="@this.apiKey" SecretChanged="@(value => this.apiKey = value)" Label="@T("API key")" Validation="@ValidateAPIKey"/>

@if (!string.IsNullOrWhiteSpace(this.issue))
{
Expand All @@ -22,7 +22,7 @@
}

<MudStack Row="@true" AlignItems="AlignItems.Center">
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@AppIcons.SAVE" Disabled="@(this.isBusy || string.IsNullOrWhiteSpace(this.apiKey))" OnClick="@this.StoreAPIKeyAsync">
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@AppIcons.SAVE" Disabled="@(!this.CanStoreAPIKey)" OnClick="@this.StoreAPIKeyAsync">
@T("Check and save API key")
</MudButton>
@if (this.isBusy)
Expand Down
13 changes: 11 additions & 2 deletions app/MindWork AI Studio/Components/UserAPIKeyPrompt.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AIStudio.Tools.Services;
using AIStudio.Tools.UserAPIKeys;
using AIStudio.Tools.Validation;

using Microsoft.AspNetCore.Components;

Expand Down Expand Up @@ -42,12 +43,20 @@ public partial class UserAPIKeyPrompt : MSGComponentBase

private string Title => string.IsNullOrWhiteSpace(this.Group.Prompt?.Title) ? TA("Your API key is missing") : this.Group.Prompt.Title;

/// <summary>
/// Whether the entered key can be checked and stored: it is there, and it can be sent.
/// </summary>
private bool CanStoreAPIKey => !this.isBusy && !string.IsNullOrWhiteSpace(this.apiKey) && !APIKeyValidation.Check(this.apiKey).IsProblem;

private static string? ValidateAPIKey(string apiKey) => APIKeyValidation.Validate(apiKey);

private async Task StoreAPIKeyAsync()
{
var enteredAPIKey = this.apiKey.Trim();
if (this.isBusy || string.IsNullOrWhiteSpace(enteredAPIKey))
if (!this.CanStoreAPIKey)
return;

var enteredAPIKey = APIKeyValidation.Normalize(this.apiKey);

this.isBusy = true;
this.issue = string.Empty;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
var fieldOptions = field.GetOptions();
if (fieldOptions.Count > 0)
{
<MudSelect T="string" Label="@GetFieldLabel(toolSection, fieldName, field)" Value="@GetValue(toolSection, fieldName)" ValueChanged="@(value => this.UpdateValue(toolSection, fieldName, value))" Variant="Variant.Outlined" Margin="Margin.Dense" HelperText="@this.GetFieldDescription(toolSection, fieldName, field)" Placeholder="@GetFieldPlaceholder(toolSection, fieldName, field)" Class="mb-3 configuration-help-justified" Disabled="@this.IsFieldDisabled(toolSection, fieldName)">
<MudSelect T="string" Label="@GetFieldLabel(toolSection, fieldName, field)" Value="@GetValue(toolSection, fieldName)" ValueChanged="@(value => this.UpdateValue(toolSection, fieldName, value))" Variant="Variant.Outlined" Margin="Margin.Dense" HelperText="@this.GetFieldDescription(toolSection, fieldName, field)" Placeholder="@GetFieldPlaceholder(toolSection, fieldName, field)" Class="mb-3" Disabled="@this.IsFieldDisabled(toolSection, fieldName)">
@if (!toolSection.Definition.SettingsSchema.Required.Contains(fieldName))
{
<MudSelectItem T="string" Value="@string.Empty">@T("Not set")</MudSelectItem>
Expand All @@ -85,7 +85,7 @@
}
else
{
<MudTextField T="string" Label="@GetFieldLabel(toolSection, fieldName, field)" Value="@GetValue(toolSection, fieldName)" ValueChanged="@(value => this.UpdateValue(toolSection, fieldName, value))" Variant="Variant.Outlined" Margin="Margin.Dense" Class="mb-3 configuration-help-justified" HelperText="@this.GetFieldDescription(toolSection, fieldName, field)" Placeholder="@GetFieldPlaceholder(toolSection, fieldName, field)" InputType="@(field.Secret ? InputType.Password : InputType.Text)" Disabled="@this.IsFieldDisabled(toolSection, fieldName)" />
<MudTextField T="string" Label="@GetFieldLabel(toolSection, fieldName, field)" Value="@GetValue(toolSection, fieldName)" ValueChanged="@(value => this.UpdateValue(toolSection, fieldName, value))" Variant="Variant.Outlined" Margin="Margin.Dense" Class="mb-3" HelperText="@this.GetFieldDescription(toolSection, fieldName, field)" Placeholder="@GetFieldPlaceholder(toolSection, fieldName, field)" InputType="@(field.Secret ? InputType.Password : InputType.Text)" Disabled="@this.IsFieldDisabled(toolSection, fieldName)" Validation="@GetFieldValidation(field)" DebounceInterval="@GetFieldDebounceInterval(field)" />
}
}
</MudPaper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using AIStudio.Components;
using AIStudio.Tools.ToolCallingSystem;
using AIStudio.Tools.Validation;

using Microsoft.AspNetCore.Components;

Expand Down Expand Up @@ -173,6 +175,50 @@ private string GetFieldDescription(ToolSection section, string fieldName, ToolSe

private bool IsFieldDisabled(ToolSection section, string fieldName) => this.ToolSettingsService.IsFieldLocked(section.Definition, fieldName);

/// <summary>
/// Checks an API key while the user types it, and leaves every other field alone.
/// </summary>
private static Func<string, string?>? GetFieldValidation(ToolSettingsFieldDefinition fieldDefinition) => fieldDefinition.IsAPIKey ? APIKeyValidation.Validate : null;

/// <summary>
/// Lets an API key field pass its text on while the user types, so that its check follows the typing.
/// </summary>
/// <remarks>
/// Every other field keeps passing its text on only when the user leaves it, as it always did.
/// </remarks>
private static double GetFieldDebounceInterval(ToolSettingsFieldDefinition fieldDefinition) => fieldDefinition.IsAPIKey ? TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS : 0;

/// <summary>
/// Finds the first API key the user entered which cannot be sent.
/// </summary>
/// <remarks>
/// Only a key the user can change stops the save. A key the organization locked is not theirs
/// to fix, and refusing to save would block every other setting of the collection as well.
/// </remarks>
/// <param name="message">The field and what is wrong with its key, or empty when every key can be sent.</param>
/// <returns>True when a key cannot be sent.</returns>
private bool TryFindAPIKeyIssue(out string message)
{
foreach (var section in this.sections)
{
foreach (var (fieldName, fieldDefinition) in section.Definition.SettingsSchema.Properties)
{
if (!fieldDefinition.IsAPIKey || this.IsFieldDisabled(section, fieldName))
continue;

var issue = APIKeyValidation.Validate(GetValue(section, fieldName));
if (issue is null)
continue;

message = $"{GetFieldLabel(section, fieldName, fieldDefinition)}: {issue}";
return true;
}
}

message = string.Empty;
return false;
}

private static string GetFieldPlaceholder(ToolSection section, string fieldName, ToolSettingsFieldDefinition fieldDefinition) =>
string.IsNullOrWhiteSpace(GetValue(section, fieldName)) ? GetFieldDefaultValue(section, fieldName, fieldDefinition) : string.Empty;

Expand All @@ -194,6 +240,12 @@ private async Task Save()
if (this.item is null)
return;

if (this.TryFindAPIKeyIssue(out var apiKeyIssue))
{
this.validationMessage = apiKeyIssue;
return;
}

foreach (var section in this.sections)
{
var validationState = await this.ToolSettingsService.ValidateSettingsAsync(section.Definition, section.Values, section.Implementation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25032,6 +25032,30 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::TOOLCALLINGSYSTEM::TOOLSETTINGSSERVICE::T40310
-- The file path is null or empty and the file therefore can not be loaded.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::USERFILE::T932243993"] = "Der Dateipfad ist leer, daher kann die Datei nicht geladen werden."

-- The API key for '{0}' contains a character which an API key cannot contain, such as a line break or an invisible character. Please enter the key again in the settings. If your organization provides the key, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3169974238"] = "Der API-Schlüssel für „{0}“ enthält ein Zeichen, das in einem API-Schlüssel nicht vorkommen kann, etwa einen Zeilenumbruch oder ein unsichtbares Zeichen. Bitte geben Sie den Schlüssel in den Einstellungen erneut ein. Wenn Ihre Organisation den Schlüssel bereitstellt, wenden Sie sich bitte an Ihre IT-Abteilung."

-- The API key for '{0}' contains a character which an API key cannot contain, such as a line break or an invisible character. Please enter the key again in the settings. If your organization provides the key, please contact your IT department.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3169974238::INFORMAL"] = "Der API-Schlüssel für „{0}“ enthält ein Zeichen, das in einem API-Schlüssel nicht vorkommen kann, etwa einen Zeilenumbruch oder ein unsichtbares Zeichen. Bitte gib den Schlüssel in den Einstellungen erneut ein. Wenn deine Organisation den Schlüssel bereitstellt, wende dich bitte an deine IT-Abteilung."

-- The API key contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the key and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3476635333"] = "Der API-Schlüssel enthält ein unsichtbares Zeichen. Solche Zeichen kommen oft mit, wenn Sie Text von einer Webseite oder aus einem Dokument kopieren. Bitte löschen Sie den Schlüssel und geben Sie ihn erneut ein."

-- The API key contains an invisible character, which often comes along when you copy text from a web page or a document. Please delete the key and enter it again.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3476635333::INFORMAL"] = "Der API-Schlüssel enthält ein unsichtbares Zeichen. Solche Zeichen kommen oft mit, wenn du Text von einer Webseite oder aus einem Dokument kopierst. Bitte lösche den Schlüssel und gib ihn erneut ein."

-- The API key contains the character '{0}', which an API key cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the key.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3728920309"] = "Der API-Schlüssel enthält das Zeichen „{0}“, das in einem API-Schlüssel nicht vorkommen kann. Textverarbeitungsprogramme machen zum Beispiel aus Anführungszeichen und Bindestrichen solche Zeichen. Bitte überprüfen Sie den Schlüssel."

-- The API key contains the character '{0}', which an API key cannot contain. Word processors, for example, turn quotation marks and dashes into such characters. Please check the key.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T3728920309::INFORMAL"] = "Der API-Schlüssel enthält das Zeichen „{0}“, das in einem API-Schlüssel nicht vorkommen kann. Textverarbeitungsprogramme machen zum Beispiel aus Anführungszeichen und Bindestrichen solche Zeichen. Bitte überprüfe den Schlüssel."

-- The API key contains a space or a line break, which an API key cannot contain. Please check whether you copied more than the key.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T839628124"] = "Der API-Schlüssel enthält ein Leerzeichen oder einen Zeilenumbruch. Beides kann in einem API-Schlüssel nicht vorkommen. Bitte überprüfen Sie, ob Sie mehr als nur den Schlüssel kopiert haben."

-- The API key contains a space or a line break, which an API key cannot contain. Please check whether you copied more than the key.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::APIKEYVALIDATION::T839628124::INFORMAL"] = "Der API-Schlüssel enthält ein Leerzeichen oder einen Zeilenumbruch. Beides kann in einem API-Schlüssel nicht vorkommen. Bitte überprüfe, ob du mehr als nur den Schlüssel kopiert hast."

-- The hostname is not a valid HTTP(S) URL.
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T1013354736"] = "Der Hostname ist keine gültige HTTP(S)-URL."

Expand Down
Loading
Loading