From 01bca867c42fd4648c97bbed3595a7c32b9a749e Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Fri, 18 Sep 2026 15:57:36 +0200 Subject: [PATCH] Ask in the data source dialogs as well --- .../DataSourceLocalDirectoryDialog.razor.cs | 22 +++++++++++++++++-- .../DataSourceLocalFileDialog.razor.cs | 22 +++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/app/MindWork AI Studio/Dialogs/DataSourceLocalDirectoryDialog.razor.cs b/app/MindWork AI Studio/Dialogs/DataSourceLocalDirectoryDialog.razor.cs index 996bf28c..56c6c7d5 100644 --- a/app/MindWork AI Studio/Dialogs/DataSourceLocalDirectoryDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/DataSourceLocalDirectoryDialog.razor.cs @@ -25,7 +25,13 @@ public partial class DataSourceLocalDirectoryDialog : MSGComponentBase [Parameter] public IReadOnlyList> AvailableEmbeddings { get; set; } = []; - + + [Inject] + private IDialogService DialogService { get; init; } = null!; + + [Inject] + private DataSourceEmbeddingService DataSourceEmbeddingService { get; init; } = null!; + private static readonly Dictionary SPELLCHECK_ATTRIBUTES = new(); private readonly DataSourceValidation dataSourceValidation; @@ -171,8 +177,20 @@ public partial class DataSourceLocalDirectoryDialog : MSGComponentBase // When the data is not valid, we don't store it: if (!this.dataIsValid) return; - + var addedDataSource = this.CreateDataSource(); + + // + // Ask while the dialog is still open, so a token limit which would have cost the prepared + // documents can be corrected right away. Asking in DataSourceManagement instead would have + // to be written once per data source kind, and by then the numbers are out of reach. + // + // Only when editing: while adding, DataSource is still default -- both local data sources + // are record structs -- and nothing has been prepared for a source which does not exist yet. + // + if (this.IsEditing && !await DataSourceReindexWarning.ConfirmDataSourceChangeAsync(this.DialogService, this.SettingsManager, this.DataSourceEmbeddingService, this.DataSource, addedDataSource)) + return; + this.MudDialog.Close(DialogResult.Ok(addedDataSource)); } diff --git a/app/MindWork AI Studio/Dialogs/DataSourceLocalFileDialog.razor.cs b/app/MindWork AI Studio/Dialogs/DataSourceLocalFileDialog.razor.cs index 698652dc..278db390 100644 --- a/app/MindWork AI Studio/Dialogs/DataSourceLocalFileDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/DataSourceLocalFileDialog.razor.cs @@ -25,7 +25,13 @@ public partial class DataSourceLocalFileDialog : MSGComponentBase [Parameter] public IReadOnlyList> AvailableEmbeddings { get; set; } = []; - + + [Inject] + private IDialogService DialogService { get; init; } = null!; + + [Inject] + private DataSourceEmbeddingService DataSourceEmbeddingService { get; init; } = null!; + private static readonly Dictionary SPELLCHECK_ATTRIBUTES = new(); private readonly DataSourceValidation dataSourceValidation; @@ -171,8 +177,20 @@ public partial class DataSourceLocalFileDialog : MSGComponentBase // When the data is not valid, we don't store it: if (!this.dataIsValid) return; - + var addedDataSource = this.CreateDataSource(); + + // + // Ask while the dialog is still open, so a token limit which would have cost the prepared + // documents can be corrected right away. Asking in DataSourceManagement instead would have + // to be written once per data source kind, and by then the numbers are out of reach. + // + // Only when editing: while adding, DataSource is still default -- both local data sources + // are record structs -- and nothing has been prepared for a source which does not exist yet. + // + if (this.IsEditing && !await DataSourceReindexWarning.ConfirmDataSourceChangeAsync(this.DialogService, this.SettingsManager, this.DataSourceEmbeddingService, this.DataSource, addedDataSource)) + return; + this.MudDialog.Close(DialogResult.Ok(addedDataSource)); }