diff --git a/app/AGENTS.md b/app/AGENTS.md index 70e9ffcd6..a83bf886e 100644 --- a/app/AGENTS.md +++ b/app/AGENTS.md @@ -39,6 +39,7 @@ Key structure: - **JSON contracts** - The contracts of all JSON which AI Studio reads or writes are generated while compiling. Each kind of options names the `JsonSerializerContext` which knows its types, with `GenerationMode = Metadata`, as its `TypeInfoResolver` and ends with `.AsReadOnly()`; only `VisualBriefingJson.Canonical` leaves that out, see MWAIS0010. A new JSON type goes into the context of the options it is read or written with, and into `JsonTestRoots` in `app/Tests/Serialization/`, whose contract, defaults, and coverage tests then check it. Give JSON types `set` instead of `init`, because the source generator of .NET 10 drops the initializer of an `init` property which the JSON leaves out, and write a record or a `JsonObject` instead of an anonymous type. Never call System.Text.Json without options, nor with `JsonSerializerOptions.Default`, `.Web`, or a `DefaultJsonTypeInfoResolver`: each of them builds the contracts by reflection, whose code a published build may lack. MWAIS0015 refuses them while compiling, `JsonOptionsResolverTests` checks the resolvers of all options of the app, and the trim smoke test of `dotnet run verify` builds the contract of every type of their contexts in a trimmed build. Reflection itself stays switched on, because Blazor Server needs it for JSON of its own, see `Trimming.props`. - **Long menus** - MudBlazor keeps a `MudSelect` inside the window by itself, but never a `MudMenu`: a menu taller than the window runs past its edge, and its lower entries cannot be reached. Give every `MudMenu` whose entries come from data, such as the assistants or the profiles, `MaxHeight="@MenuDefaults.MAX_HEIGHT"`, so that it scrolls. - **Growing popovers** - Since version 9, MudBlazor places an open popover again whenever its content changes size. Content which unfolds later, such as a `MudCollapse` or an `ExpansionPanel` inside a `MudPopover`, therefore stays inside the window and needs no code of its own. +- **Validated text fields** - Without `Immediate` or a `DebounceInterval`, a `MudTextField` passes its text on only when the user leaves it, so an issue stays visible while the user types the text which resolves it. Give every `MudTextField` with a `Validation` which takes typing `DebounceInterval="@TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS"` and bind its `Value`, not its `Text`: bound by its text, the field also delays the texts its parent sets, e.g., by a reset, and checks them although nobody touched it. `Immediate="@true"` works as well, but renders the parent with every keystroke. `ValidatedTextFieldTests` checks this rule. - **Encryption** - Initialized before Rust service is marked ready - **Access to the app server** - Only the app window gets into the Blazor server. `AppAccessMiddleware` runs first in `Program.cs`, right after the host filter, and refuses every request without the session cookie of the window or with an origin other than the app's own. Add no exception for any path, not even for static files: `AppAccessPipelineTests` checks the order in `Program.cs`. Since nothing but the window holds the cookie, the app never sends a request to its own server: read files below `wwwroot/` through `WebRootFiles`. The system browser gets no cookie either, so never open a URL of the app server there; offer a save dialog through `RustService` instead, as the ERI Server assistant does for its specification. `runtime/AGENTS.md` describes the runtime side. - **Debug environment** - Reads `startup.env` file with IPC credentials diff --git a/app/MindWork AI Studio/Assistants/Agenda/AssistantAgenda.razor b/app/MindWork AI Studio/Assistants/Agenda/AssistantAgenda.razor index de67bc57c..4d4dd9492 100644 --- a/app/MindWork AI Studio/Assistants/Agenda/AssistantAgenda.razor +++ b/app/MindWork AI Studio/Assistants/Agenda/AssistantAgenda.razor @@ -1,8 +1,8 @@ @attribute [Route(Routes.ASSISTANT_AGENDA)] @inherits AssistantBaseCore - - + + @@ -29,10 +29,10 @@ } - - - - + + + + @@ -41,7 +41,7 @@ @if (!this.isMeetingVirtual) { - + diff --git a/app/MindWork AI Studio/Assistants/BeyondFactsLab/BflStepForm.razor b/app/MindWork AI Studio/Assistants/BeyondFactsLab/BflStepForm.razor index b102609b0..c4d0daca3 100644 --- a/app/MindWork AI Studio/Assistants/BeyondFactsLab/BflStepForm.razor +++ b/app/MindWork AI Studio/Assistants/BeyondFactsLab/BflStepForm.razor @@ -57,6 +57,7 @@ else if (this.HasPublicDetails) HelperText="@field.Hint" MaxLength="@field.Kind.MaxLength" Validation="@this.ValidationOf(field)" + DebounceInterval="@TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS" Disabled="@this.Disabled" Adornment="@AdornmentOf(field)" AdornmentIcon="@PUBLIC_DETAIL_ICON" diff --git a/app/MindWork AI Studio/Assistants/BeyondFactsLab/BflValueCardSort.razor b/app/MindWork AI Studio/Assistants/BeyondFactsLab/BflValueCardSort.razor index 23439a3d7..31df93587 100644 --- a/app/MindWork AI Studio/Assistants/BeyondFactsLab/BflValueCardSort.razor +++ b/app/MindWork AI Studio/Assistants/BeyondFactsLab/BflValueCardSort.razor @@ -59,6 +59,7 @@ Label="@T("Value")" MaxLength="@BflCardSort.MAX_NAME_LENGTH" Validation="@this.NameValidation" + DebounceInterval="@TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS" Disabled="@this.Disabled" Variant="Variant.Outlined" Style="flex: 1 1 0;"/> diff --git a/app/MindWork AI Studio/Assistants/Builder/AssistantBuilder.razor b/app/MindWork AI Studio/Assistants/Builder/AssistantBuilder.razor index 28dd56b24..0c3024afd 100644 --- a/app/MindWork AI Studio/Assistants/Builder/AssistantBuilder.razor +++ b/app/MindWork AI Studio/Assistants/Builder/AssistantBuilder.razor @@ -9,7 +9,7 @@ @if (this.step is BuilderStep.DESCRIBE) { - + @* This switch chooses between the two kinds of assistant the Builder can create, so it stays outside the advanced options. Its fields are required, and a collapsed panel would hide diff --git a/app/MindWork AI Studio/Assistants/Coding/AssistantCoding.razor b/app/MindWork AI Studio/Assistants/Coding/AssistantCoding.razor index 878583c24..73d023636 100644 --- a/app/MindWork AI Studio/Assistants/Coding/AssistantCoding.razor +++ b/app/MindWork AI Studio/Assistants/Coding/AssistantCoding.razor @@ -13,9 +13,9 @@ @if (this.provideCompilerMessages) { - + } - + diff --git a/app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor b/app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor index 3a2ece2ae..107f8fac4 100644 --- a/app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor +++ b/app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor @@ -5,7 +5,7 @@ @if (this.provideHistory) { - + } diff --git a/app/MindWork AI Studio/Assistants/ERI/AssistantERI.razor b/app/MindWork AI Studio/Assistants/ERI/AssistantERI.razor index 632cb2dd1..aa8841386 100644 --- a/app/MindWork AI Studio/Assistants/ERI/AssistantERI.razor +++ b/app/MindWork AI Studio/Assistants/ERI/AssistantERI.razor @@ -103,7 +103,7 @@ else @if (this.selectedProgrammingLanguage is ProgrammingLanguages.OTHER) { - + } @@ -136,20 +136,20 @@ else @if (this.selectedDataSource is DataSources.CUSTOM) { - + } @if(this.selectedDataSource > DataSources.FILE_SYSTEM) { - + } @if (this.NeedHostnamePort()) {
- + @if (this.dataSourcePort < 1024) @@ -185,7 +185,7 @@ else } - + @if (this.selectedAuthenticationMethods.Contains(Auth.KERBEROS)) diff --git a/app/MindWork AI Studio/Assistants/GrammarSpelling/AssistantGrammarSpelling.razor b/app/MindWork AI Studio/Assistants/GrammarSpelling/AssistantGrammarSpelling.razor index ec0cb75a6..d966d3b02 100644 --- a/app/MindWork AI Studio/Assistants/GrammarSpelling/AssistantGrammarSpelling.razor +++ b/app/MindWork AI Studio/Assistants/GrammarSpelling/AssistantGrammarSpelling.razor @@ -2,6 +2,6 @@ @inherits AssistantBaseCore - + \ No newline at end of file diff --git a/app/MindWork AI Studio/Assistants/IconFinder/AssistantIconFinder.razor b/app/MindWork AI Studio/Assistants/IconFinder/AssistantIconFinder.razor index 43bb5f4fd..45345105d 100644 --- a/app/MindWork AI Studio/Assistants/IconFinder/AssistantIconFinder.razor +++ b/app/MindWork AI Studio/Assistants/IconFinder/AssistantIconFinder.razor @@ -1,7 +1,7 @@ @attribute [Route(Routes.ASSISTANT_ICON_FINDER)] @inherits AssistantBaseCore - + diff --git a/app/MindWork AI Studio/Assistants/JobPosting/AssistantJobPostings.razor b/app/MindWork AI Studio/Assistants/JobPosting/AssistantJobPostings.razor index 68ef83986..6e4262fb3 100644 --- a/app/MindWork AI Studio/Assistants/JobPosting/AssistantJobPostings.razor +++ b/app/MindWork AI Studio/Assistants/JobPosting/AssistantJobPostings.razor @@ -2,12 +2,12 @@ @inherits AssistantBaseCore - + @* Four zones, so no default target: every drop has to be aimed at the field it belongs to. *@ - + diff --git a/app/MindWork AI Studio/Assistants/LegalCheck/AssistantLegalCheck.razor b/app/MindWork AI Studio/Assistants/LegalCheck/AssistantLegalCheck.razor index f4fd95d0a..dae13ce9f 100644 --- a/app/MindWork AI Studio/Assistants/LegalCheck/AssistantLegalCheck.razor +++ b/app/MindWork AI Studio/Assistants/LegalCheck/AssistantLegalCheck.razor @@ -8,8 +8,8 @@ @* Two zones, so no default target: the user has to aim at the one they mean. *@ - + - + \ No newline at end of file diff --git a/app/MindWork AI Studio/Assistants/ModelComparison/AssistantModelComparison.razor b/app/MindWork AI Studio/Assistants/ModelComparison/AssistantModelComparison.razor index 7451f2d13..8b2420c99 100644 --- a/app/MindWork AI Studio/Assistants/ModelComparison/AssistantModelComparison.razor +++ b/app/MindWork AI Studio/Assistants/ModelComparison/AssistantModelComparison.razor @@ -69,7 +69,7 @@ @ModelComparisonTexts.WhatTheModelsReceive - + @T("Material (optional)") diff --git a/app/MindWork AI Studio/Assistants/MyTasks/AssistantMyTasks.razor b/app/MindWork AI Studio/Assistants/MyTasks/AssistantMyTasks.razor index 74bc16e6a..86505d983 100644 --- a/app/MindWork AI Studio/Assistants/MyTasks/AssistantMyTasks.razor +++ b/app/MindWork AI Studio/Assistants/MyTasks/AssistantMyTasks.razor @@ -2,7 +2,7 @@ @inherits AssistantBaseCore - + @T("Attach documents") @TA("You can enter text, attach one or more documents, or use both. At least one input is required.") diff --git a/app/MindWork AI Studio/Assistants/PromptOptimizer/AssistantPromptOptimizer.razor b/app/MindWork AI Studio/Assistants/PromptOptimizer/AssistantPromptOptimizer.razor index 6b363bc87..5c5268728 100644 --- a/app/MindWork AI Studio/Assistants/PromptOptimizer/AssistantPromptOptimizer.razor +++ b/app/MindWork AI Studio/Assistants/PromptOptimizer/AssistantPromptOptimizer.razor @@ -5,8 +5,9 @@ to be aimed at the one it belongs to. *@ - + diff --git a/app/MindWork AI Studio/Assistants/SWOTAnalysis/AssistantSWOTAnalysis.razor b/app/MindWork AI Studio/Assistants/SWOTAnalysis/AssistantSWOTAnalysis.razor index 1c63603a4..4b7d63cb1 100644 --- a/app/MindWork AI Studio/Assistants/SWOTAnalysis/AssistantSWOTAnalysis.razor +++ b/app/MindWork AI Studio/Assistants/SWOTAnalysis/AssistantSWOTAnalysis.razor @@ -14,13 +14,13 @@ @T("Input") - + @T("Analysis Options") - + diff --git a/app/MindWork AI Studio/Assistants/SlideBuilder/SlideAssistant.razor b/app/MindWork AI Studio/Assistants/SlideBuilder/SlideAssistant.razor index 752e033a4..69304a57f 100644 --- a/app/MindWork AI Studio/Assistants/SlideBuilder/SlideAssistant.razor +++ b/app/MindWork AI Studio/Assistants/SlideBuilder/SlideAssistant.razor @@ -8,7 +8,7 @@ @TA("You can enter text, use one or more documents or images, or use both. At least one of these options is required.") - + @* Side by side where the window is wide enough; each column ends with its zone, so both zones line up below explanations of different length: *@ @@ -54,7 +54,7 @@ @TA("Please enter a title for the presentation. This will help the LLM to select more relevant content.") - + @T("Important Aspects") diff --git a/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor b/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor index 6c293fcd4..9c80b374e 100644 --- a/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor +++ b/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor @@ -1,7 +1,7 @@ @attribute [Route(Routes.ASSISTANT_SYNONYMS)] @inherits AssistantBaseCore - + diff --git a/app/MindWork AI Studio/Assistants/TextSummarizer/AssistantTextSummarizer.razor b/app/MindWork AI Studio/Assistants/TextSummarizer/AssistantTextSummarizer.razor index 51f6e5607..61f75ba22 100644 --- a/app/MindWork AI Studio/Assistants/TextSummarizer/AssistantTextSummarizer.razor +++ b/app/MindWork AI Studio/Assistants/TextSummarizer/AssistantTextSummarizer.razor @@ -7,7 +7,7 @@ } - + diff --git a/app/MindWork AI Studio/Assistants/Translation/AssistantTranslation.razor b/app/MindWork AI Studio/Assistants/Translation/AssistantTranslation.razor index 06178f115..10d9870b5 100644 --- a/app/MindWork AI Studio/Assistants/Translation/AssistantTranslation.razor +++ b/app/MindWork AI Studio/Assistants/Translation/AssistantTranslation.razor @@ -15,8 +15,8 @@ } else { - @* Bound by its value, the field shows no issue before you type, also when you switch the live translation off: *@ - + @* Bound by its value, the field shows no issue before you type, also when you switch the live translation off. It checks your text again shortly after you stop typing, see TextFieldDefaults: *@ + } diff --git a/app/MindWork AI Studio/Components/TextFieldDefaults.cs b/app/MindWork AI Studio/Components/TextFieldDefaults.cs new file mode 100644 index 000000000..f32acd3ba --- /dev/null +++ b/app/MindWork AI Studio/Components/TextFieldDefaults.cs @@ -0,0 +1,18 @@ +namespace AIStudio.Components; + +/// +/// Settings every text field of AI Studio shares. +/// +public static class TextFieldDefaults +{ + /// + /// The time in milliseconds after the last keystroke when a text field with a validation checks its text again. + /// + /// + /// Without Immediate or a DebounceInterval, a MudTextField passes its text on only when the user leaves it, so an + /// issue stays visible while the user types the text which resolves it. A text field with a validation therefore + /// sets DebounceInterval to this value and binds its Value, not its Text: bound by its text, the field would delay + /// the texts its parent sets as well, e.g., by a reset, and check them without having been touched. + /// + public const double VALIDATION_DEBOUNCE_MILLISECONDS = 500; +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Dialogs/DirectChatLauncherSettingsDialog.razor b/app/MindWork AI Studio/Dialogs/DirectChatLauncherSettingsDialog.razor index 28d147087..3854b4318 100644 --- a/app/MindWork AI Studio/Dialogs/DirectChatLauncherSettingsDialog.razor +++ b/app/MindWork AI Studio/Dialogs/DirectChatLauncherSettingsDialog.razor @@ -24,9 +24,9 @@ @* The dashed frame shows that these fields belong together: they describe one chat the launcher tile opens. *@ - - - + + + } @@ -194,11 +195,12 @@ } @@ -104,13 +105,14 @@ @@ -322,11 +324,12 @@ } diff --git a/app/MindWork AI Studio/wwwroot/changelog/v26.11.2.md b/app/MindWork AI Studio/wwwroot/changelog/v26.11.2.md index 868b37705..3df6ede5c 100644 --- a/app/MindWork AI Studio/wwwroot/changelog/v26.11.2.md +++ b/app/MindWork AI Studio/wwwroot/changelog/v26.11.2.md @@ -20,4 +20,5 @@ - Fixed the Assistant Builder, which ignored the category you chose for your assistant. You can now also name a category of your own. - Fixed assistant plugins which wrote numbers and dates according to the region settings of your computer. Plugins now show them the same way on every computer: a decimal number such as `12.5` keeps its point, and the `DateTime` helper writes the names of months in English. - Fixed the translation, agenda, and e-mail assistants checking your input again and again in the background, about once a second, even while you weren't typing. -- Fixed the translation assistant complaining about a missing text before you had typed anything, e.g., right after you switched the live translation on or off. \ No newline at end of file +- Fixed the translation assistant complaining about a missing text before you had typed anything, e.g., right after you switched the live translation on or off. +- Fixed text fields in assistants and dialogs which kept showing a missing or invalid input while you typed, until you left the field. They now check your input again half a second after you stop typing. \ No newline at end of file diff --git a/app/Tests/Components/ValidatedTextFieldTests.cs b/app/Tests/Components/ValidatedTextFieldTests.cs new file mode 100644 index 000000000..016893faf --- /dev/null +++ b/app/Tests/Components/ValidatedTextFieldTests.cs @@ -0,0 +1,174 @@ +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; + +using AIStudio.Components; + +namespace AIStudio.Tests.Components; + +/// +/// Checks that every text field with a validation checks its text again while the user types. +/// +/// +/// Without Immediate or a DebounceInterval, a MudTextField passes its text on only when the user leaves it, so an +/// issue stays visible while the user types the text which resolves it. A field with a DebounceInterval binds its +/// Value, not its Text: bound by its text, it would delay the texts its parent sets as well, e.g., by a reset, and +/// check them without having been touched, see TextFieldDefaults. A read-only field takes no typing and needs neither. +/// +[TestFixture] +public sealed partial class ValidatedTextFieldTests +{ + private const string CHECKS_ON_LEAVING = "checks its text only when the user leaves it"; + private const string DEBOUNCED_BY_TEXT = "binds its text, so it delays and checks the texts its parent sets as well"; + + [TestCase("""""", ExpectedResult = "")] + [TestCase("""""", ExpectedResult = "")] + [TestCase("""""", ExpectedResult = "")] + [TestCase("""""", ExpectedResult = "")] + [TestCase("""""", ExpectedResult = "1: " + CHECKS_ON_LEAVING)] + [TestCase("""""", ExpectedResult = "1: " + CHECKS_ON_LEAVING)] + [TestCase("""""", ExpectedResult = "1: " + DEBOUNCED_BY_TEXT)] + [TestCase("""""", ExpectedResult = "1: " + DEBOUNCED_BY_TEXT)] + [TestCase(""" b)")" Validation="@this.Validate"/>""", ExpectedResult = "1: " + CHECKS_ON_LEAVING)] + [TestCase(""" + + + + """, ExpectedResult = "6: " + CHECKS_ON_LEAVING)] + public string AValidatedTextFieldIsJudgedByHowItChecksWhileTheUserTypes(string razor) => string.Join(" | ", ValidatedTextFields(razor).SelectMany(field => IssuesOf(field).Select(issue => $"{field.Line}: {issue}"))); + + [Test] + public void EveryValidatedTextFieldChecksWhileTheUserTypes() + { + var appDirectory = AppSourceDirectory(); + var fields = 0; + var issues = new List(); + foreach (var file in RazorFiles(appDirectory)) + { + foreach (var field in ValidatedTextFields(File.ReadAllText(file))) + { + fields++; + issues.AddRange(IssuesOf(field).Select(issue => $"{Path.GetRelativePath(appDirectory, file)}:{field.Line}: {issue}")); + } + } + + Assert.That(fields, Is.GreaterThan(50), "The test found too few text fields with a validation, so it probably misreads the Razor files."); + Assert.That(issues, Is.Empty, $"Give these text fields DebounceInterval=\"@{nameof(TextFieldDefaults)}.{nameof(TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS)}\" and bind their Value:\n{string.Join('\n', issues)}"); + } + + /// + /// A MudTextField of a Razor source, from its opening angle bracket to its closing one. + /// + /// The line on which the field starts, counted from 1. + /// The markup of the field. + private sealed record TextFieldTag(int Line, string Source); + + /// + /// Finds every MudTextField with a validation which takes typing, i.e., which is not read-only. + /// + private static IEnumerable ValidatedTextFields(string razor) + { + foreach (Match start in TextFieldStartRegex().Matches(razor)) + { + var tag = razor[start.Index..(TagEnd(razor, start.Index + start.Length) + 1)]; + if (!ValidationRegex().IsMatch(tag) || ReadOnlyRegex().IsMatch(tag)) + continue; + + yield return new TextFieldTag(razor[..start.Index].Count(character => character == '\n') + 1, tag); + } + } + + private static IEnumerable IssuesOf(TextFieldTag field) + { + var isDebounced = DebounceRegex().IsMatch(field.Source); + if (!isDebounced && !ImmediateRegex().IsMatch(field.Source)) + yield return CHECKS_ON_LEAVING; + + if (isDebounced && TextBindingRegex().IsMatch(field.Source)) + yield return DEBOUNCED_BY_TEXT; + } + + /// + /// Finds the angle bracket which closes a tag. + /// + /// + /// An attribute value may hold an angle bracket of its own, e.g., in a lambda or a comparison, and the C# code + /// inside its parentheses may hold strings with quotes, as @T("…") does. So the search skips attribute values, + /// counts parentheses, and skips the strings inside them. + /// + private static int TagEnd(string razor, int position) + { + var depth = 0; + var isInsideValue = false; + for (; position < razor.Length; position++) + { + var character = razor[position]; + if (depth > 0 && character == '"') + { + position = StringEnd(razor, position); + continue; + } + + switch (character) + { + case '(' or '[' or '{': + depth++; + break; + + case ')' or ']' or '}': + depth--; + break; + + case '"' when depth == 0: + isInsideValue = !isInsideValue; + break; + + case '>' when depth == 0 && !isInsideValue: + return position; + } + } + + throw new InvalidOperationException("A MudTextField has no end."); + } + + /// + /// Finds the quote which closes a C# string, skipping escaped characters. + /// + private static int StringEnd(string razor, int openingQuote) + { + for (var position = openingQuote + 1; position < razor.Length; position++) + { + if (razor[position] == '\\') + position++; + else if (razor[position] == '"') + return position; + } + + throw new InvalidOperationException("A string inside a MudTextField has no end."); + } + + private static IEnumerable RazorFiles(string appDirectory) => Directory.EnumerateFiles(appDirectory, "*.razor", SearchOption.AllDirectories) + .Where(path => Path.GetRelativePath(appDirectory, path).Split(Path.DirectorySeparatorChar)[0] is not ("bin" or "obj" or "wwwroot")); + + [GeneratedRegex(@" Path.GetFullPath(Path.Combine(Path.GetDirectoryName(sourceFilePath)!, "..", "..", "MindWork AI Studio")); +} \ No newline at end of file