Fixed bugs related to the workspaces component (#228)

This commit is contained in:
Thorsten Sommer 2024-12-04 11:44:12 +01:00 committed by GitHub
parent 55d7895f58
commit 61f7a3dd72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 21 deletions

View File

@ -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;

View File

@ -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<ConfirmDialog>("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);
}
}

View File

@ -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.
- 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.