diff --git a/app/MindWork AI Studio/Pages/Chat.razor.cs b/app/MindWork AI Studio/Pages/Chat.razor.cs index 8db196a..fd87a0b 100644 --- a/app/MindWork AI Studio/Pages/Chat.razor.cs +++ b/app/MindWork AI Studio/Pages/Chat.razor.cs @@ -381,19 +381,18 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable return; } - if (this.chatThread is not null && this.workspaces is not null && deletePreviousChat) + if (this.chatThread is not null && deletePreviousChat) { string chatPath; if (this.chatThread.WorkspaceId == Guid.Empty) - { chatPath = Path.Join(SettingsManager.DataDirectory, "tempChats", this.chatThread.ChatId.ToString()); - } else - { chatPath = Path.Join(SettingsManager.DataDirectory, "workspaces", this.chatThread.WorkspaceId.ToString(), this.chatThread.ChatId.ToString()); - } - - await this.workspaces.DeleteChat(chatPath, askForConfirmation: false, unloadChat: true); + + if(this.workspaces is null) + await WorkspaceBehaviour.DeleteChat(this.DialogService, this.chatThread.WorkspaceId, this.chatThread.ChatId, askForConfirmation: false); + else + await this.workspaces.DeleteChat(chatPath, askForConfirmation: false, unloadChat: true); } this.isStreaming = false; @@ -445,9 +444,6 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable if(this.chatThread is null) return; - if(this.workspaces is null) - return; - if (this.SettingsManager.ConfigurationData.Workspace.StorageBehavior is WorkspaceStorageBehavior.STORE_CHATS_MANUALLY && this.hasUnsavedChanges) { var confirmationDialogParameters = new DialogParameters @@ -478,16 +474,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable return; // Delete the chat from the current workspace or the temporary storage: - if (this.chatThread!.WorkspaceId == Guid.Empty) - { - // Case: The chat is stored in the temporary storage: - await this.workspaces.DeleteChat(Path.Join(SettingsManager.DataDirectory, "tempChats", this.chatThread.ChatId.ToString()), askForConfirmation: false, unloadChat: false); - } - else - { - // Case: The chat is stored in a workspace. - await this.workspaces.DeleteChat(Path.Join(SettingsManager.DataDirectory, "workspaces", this.chatThread.WorkspaceId.ToString(), this.chatThread.ChatId.ToString()), askForConfirmation: false, unloadChat: false); - } + await WorkspaceBehaviour.DeleteChat(this.DialogService, this.chatThread!.WorkspaceId, this.chatThread.ChatId, askForConfirmation: false); this.chatThread!.WorkspaceId = workspaceId; await this.SaveThread(); @@ -498,6 +485,10 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable private async Task LoadedChatChanged() { + // + // It should not happen that the workspace component is not loaded + // because the workspace component is calling this method. + // if(this.workspaces is null) return; diff --git a/app/MindWork AI Studio/Tools/WorkspaceBehaviour.cs b/app/MindWork AI Studio/Tools/WorkspaceBehaviour.cs index 269768a..942374a 100644 --- a/app/MindWork AI Studio/Tools/WorkspaceBehaviour.cs +++ b/app/MindWork AI Studio/Tools/WorkspaceBehaviour.cs @@ -3,6 +3,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using AIStudio.Chat; +using AIStudio.Dialogs; using AIStudio.Settings; namespace AIStudio.Tools; @@ -81,4 +82,39 @@ public static class WorkspaceBehaviour var workspaceNamePath = Path.Join(workspacePath, "name"); return await File.ReadAllTextAsync(workspaceNamePath, Encoding.UTF8); } + + public static async Task DeleteChat(IDialogService dialogService, Guid workspaceId, Guid chatId, bool askForConfirmation = true) + { + var chat = await LoadChat(new(workspaceId, chatId)); + if (chat is null) + return; + + if (askForConfirmation) + { + var workspaceName = await LoadWorkspaceName(chat.WorkspaceId); + var dialogParameters = new DialogParameters + { + { + "Message", (chat.WorkspaceId == Guid.Empty) switch + { + true => $"Are you sure you want to delete the temporary chat '{chat.Name}'?", + false => $"Are you sure you want to delete the chat '{chat.Name}' in the workspace '{workspaceName}'?", + } + }, + }; + + var dialogReference = await dialogService.ShowAsync("Delete Chat", dialogParameters, Dialogs.DialogOptions.FULLSCREEN); + var dialogResult = await dialogReference.Result; + if (dialogResult is null || dialogResult.Canceled) + return; + } + + string chatDirectory; + if (chat.WorkspaceId == Guid.Empty) + chatDirectory = Path.Join(SettingsManager.DataDirectory, "tempChats", chat.ChatId.ToString()); + else + chatDirectory = Path.Join(SettingsManager.DataDirectory, "workspaces", chat.WorkspaceId.ToString(), chat.ChatId.ToString()); + + Directory.Delete(chatDirectory, true); + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/wwwroot/changelog/v0.9.22.md b/app/MindWork AI Studio/wwwroot/changelog/v0.9.22.md index 2120b7a..98f26e5 100644 --- a/app/MindWork AI Studio/wwwroot/changelog/v0.9.22.md +++ b/app/MindWork AI Studio/wwwroot/changelog/v0.9.22.md @@ -2,4 +2,6 @@ - Added the possibility to configure preview feature visibility in the app settings. This is useful for users who want to test new features before they are officially released. - Added the possibility to configure embedding providers in the app settings as a prototype preview feature. Embeddings are necessary in order to integrate local data and files. - Added the writer mode as an experimental preview feature. This feature is just an experiment as we explore how to implement long text support in AI Studio. -- Improved self-hosted LLM provider configuration by filtering embedding models. \ No newline at end of file +- Improved self-hosted LLM provider configuration by filtering embedding models. +- Fixed a bug where you couldn't move a chat to (another) workspace when the workspaces were docked to the left side and were collapsed. +- Fixed a bug when you replaced a chat with a new chat, and the workspaces were docked to the left and were collapsed; then, the previous chat was not removed from the workspace. \ No newline at end of file