diff --git a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs index 42717705..8adfeb3b 100644 --- a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs +++ b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs @@ -215,7 +215,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore p.Id == this.selectedPolicy.Id); + + if (!stillExists) + { + // Policy was removed, select a new one: + this.selectedPolicy = this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies.FirstOrDefault(); + } + else + { + // Policy still exists, update the reference to the potentially updated version: + this.selectedPolicy = this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies + .First(p => p.Id == this.selectedPolicy.Id); + } + } + else + { + // No policy was selected, select the first one if available: + this.selectedPolicy = this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies.FirstOrDefault(); + } + + // Update form values to reflect the current policy: + this.ResetForm(); + + // Update the expansion state based on the policy protection: + this.policyDefinitionExpanded = !this.selectedPolicy?.IsProtected ?? true; + + // Update available providers: + this.UpdateProviders(); + + // Apply policy preselection: + this.ApplyPolicyPreselection(preferPolicyPreselection: true); + + // Reset validation state: + this.form?.ResetValidation(); + this.ClearInputIssues(); + } private string? ValidatePolicyDescription(string description) {