From 152eed65420b83ab40fa2406a193c9462089a205 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Fri, 12 Jul 2024 22:03:46 +0200 Subject: [PATCH] Added option to delete current & start new chat --- .../Components/Pages/Chat.razor | 7 ++++++ .../Components/Pages/Chat.razor.cs | 23 +++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/MindWork AI Studio/Components/Pages/Chat.razor b/app/MindWork AI Studio/Components/Pages/Chat.razor index dabe31cc..0017303b 100644 --- a/app/MindWork AI Studio/Components/Pages/Chat.razor +++ b/app/MindWork AI Studio/Components/Pages/Chat.razor @@ -62,6 +62,13 @@ } + + @if (this.SettingsManager.ConfigurationData.WorkspaceStorageBehavior is WorkspaceStorageBehavior.STORE_CHATS_AUTOMATICALLY) + { + + + + } @if (this.SettingsManager.ConfigurationData.WorkspaceStorageBehavior is not WorkspaceStorageBehavior.DISABLE_WORKSPACES) { diff --git a/app/MindWork AI Studio/Components/Pages/Chat.razor.cs b/app/MindWork AI Studio/Components/Pages/Chat.razor.cs index 49cde7d2..0820b8de 100644 --- a/app/MindWork AI Studio/Components/Pages/Chat.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/Chat.razor.cs @@ -224,9 +224,9 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable return threadName; } - private async Task StartNewChat(bool useSameWorkspace = false) + private async Task StartNewChat(bool useSameWorkspace = false, bool deletePreviousChat = false) { - if (this.hasUnsavedChanges) + if (this.SettingsManager.ConfigurationData.WorkspaceStorageBehavior is WorkspaceStorageBehavior.STORE_CHATS_MANUALLY && this.hasUnsavedChanges) { var dialogParameters = new DialogParameters { @@ -238,7 +238,22 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable if (dialogResult.Canceled) return; } - + + if (this.chatThread is not null && this.workspaces 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); + } + this.isStreaming = false; this.hasUnsavedChanges = false; this.userInput = string.Empty; @@ -273,7 +288,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable if(this.workspaces is null) return; - if (this.hasUnsavedChanges) + if (this.SettingsManager.ConfigurationData.WorkspaceStorageBehavior is WorkspaceStorageBehavior.STORE_CHATS_MANUALLY && this.hasUnsavedChanges) { var confirmationDialogParameters = new DialogParameters {