diff --git a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor index 24d7f699..c14b910c 100644 --- a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor +++ b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor @@ -14,7 +14,16 @@
- @treeItem.Text + + @if (string.IsNullOrWhiteSpace(treeItem.Text)) + { + @("Empty chat") + } + else + { + @treeItem.Text + } +
diff --git a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs index f858338d..89fa1d57 100644 --- a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs +++ b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs @@ -20,12 +20,18 @@ public partial class Workspaces : ComponentBase [Inject] private IDialogService DialogService { get; set; } = null!; + [Inject] + public Random RNG { get; set; } = null!; + [Parameter] public ChatThread? CurrentChatThread { get; set; } [Parameter] public EventCallback CurrentChatThreadChanged { get; set; } + [Parameter] + public Func LoadedChatWasChanged { get; set; } = () => Task.CompletedTask; + private const Placement WORKSPACE_ITEM_TOOLTIP_PLACEMENT = Placement.Bottom; private static readonly JsonSerializerOptions JSON_OPTIONS = new() @@ -123,7 +129,7 @@ public partial class Workspaces : ComponentBase return tempChildren; } - private async Task LoadWorkspaceName(Guid workspaceId) + public async Task LoadWorkspaceName(Guid workspaceId) { if(workspaceId == Guid.Empty) return string.Empty; @@ -238,6 +244,7 @@ public partial class Workspaces : ComponentBase { this.CurrentChatThread = chat; await this.CurrentChatThreadChanged.InvokeAsync(this.CurrentChatThread); + await this.LoadedChatWasChanged(); } return chat; @@ -289,6 +296,7 @@ public partial class Workspaces : ComponentBase { this.CurrentChatThread = null; await this.CurrentChatThreadChanged.InvokeAsync(this.CurrentChatThread); + await this.LoadedChatWasChanged(); } } @@ -429,11 +437,12 @@ public partial class Workspaces : ComponentBase // Update the chat's workspace: chat.WorkspaceId = workspaceId; - // Handle the case, where the chat is the active chat: + // Handle the case where the chat is the active chat: if (this.CurrentChatThread?.ChatId == chat.ChatId) { this.CurrentChatThread = chat; await this.CurrentChatThreadChanged.InvokeAsync(this.CurrentChatThread); + await this.LoadedChatWasChanged(); } await this.StoreChat(chat); @@ -441,6 +450,21 @@ public partial class Workspaces : ComponentBase private async Task AddChat(string workspacePath) { + var workspaceId = Guid.Parse(Path.GetFileName(workspacePath)); + var chat = new ChatThread + { + WorkspaceId = workspaceId, + ChatId = Guid.NewGuid(), + Name = string.Empty, + Seed = this.RNG.Next(), + SystemPrompt = "You are a helpful assistant!", + Blocks = [], + }; + var chatPath = Path.Join(workspacePath, chat.ChatId.ToString()); + + await this.StoreChat(chat); + await this.LoadChat(chatPath, switchToChat: true); + await this.LoadTreeItems(); } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/Chat.razor b/app/MindWork AI Studio/Components/Pages/Chat.razor index a9f1aea1..ee454273 100644 --- a/app/MindWork AI Studio/Components/Pages/Chat.razor +++ b/app/MindWork AI Studio/Components/Pages/Chat.razor @@ -3,7 +3,14 @@ @using AIStudio.Settings - Chats + @if (this.chatThread is not null && this.chatThread.WorkspaceId != Guid.Empty) + { + @($"Chat in Workspace \"{this.currentWorkspaceName}\"") + } + else + { + @("Temporary Chat") + } @@ -67,7 +74,7 @@ - + } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/Chat.razor.cs b/app/MindWork AI Studio/Components/Pages/Chat.razor.cs index 17a9173d..1569a905 100644 --- a/app/MindWork AI Studio/Components/Pages/Chat.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/Chat.razor.cs @@ -36,6 +36,7 @@ public partial class Chat : ComponentBase, IAsyncDisposable private bool hasUnsavedChanges; private bool isStreaming; private string userInput = string.Empty; + private string currentWorkspaceName = string.Empty; private bool workspacesVisible; private Workspaces? workspaces; @@ -71,15 +72,25 @@ public partial class Chat : ComponentBase, IAsyncDisposable // Create a new chat thread if necessary: var threadName = this.ExtractThreadName(this.userInput); - this.chatThread ??= new() + + if (this.chatThread is null) { - WorkspaceId = Guid.Empty, - ChatId = Guid.NewGuid(), - Name = threadName, - Seed = this.RNG.Next(), - SystemPrompt = "You are a helpful assistant!", - Blocks = [], - }; + this.chatThread = new() + { + WorkspaceId = Guid.Empty, + ChatId = Guid.NewGuid(), + Name = threadName, + Seed = this.RNG.Next(), + SystemPrompt = "You are a helpful assistant!", + Blocks = [], + }; + } + else + { + // Set the thread name if it is empty: + if (string.IsNullOrWhiteSpace(this.chatThread.Name)) + this.chatThread.Name = threadName; + } // // Add the user message to the thread: @@ -226,6 +237,7 @@ public partial class Chat : ComponentBase, IAsyncDisposable this.isStreaming = false; this.hasUnsavedChanges = false; this.userInput = string.Empty; + this.currentWorkspaceName = string.Empty; await this.inputField.Clear(); } @@ -267,6 +279,21 @@ public partial class Chat : ComponentBase, IAsyncDisposable this.chatThread!.WorkspaceId = workspaceId; await this.SaveThread(); + + this.currentWorkspaceName = await this.workspaces.LoadWorkspaceName(this.chatThread.WorkspaceId); + } + + private async Task LoadedChatChanged() + { + if(this.workspaces is null) + return; + + this.isStreaming = false; + this.hasUnsavedChanges = false; + this.userInput = string.Empty; + this.currentWorkspaceName = this.chatThread is null ? string.Empty : await this.workspaces.LoadWorkspaceName(this.chatThread.WorkspaceId); + + await this.inputField.Clear(); } #region Implementation of IAsyncDisposable