diff --git a/app/MindWork AI Studio/Components/Blocks/ITreeItem.cs b/app/MindWork AI Studio/Components/Blocks/ITreeItem.cs index b33c178d..ad718e71 100644 --- a/app/MindWork AI Studio/Components/Blocks/ITreeItem.cs +++ b/app/MindWork AI Studio/Components/Blocks/ITreeItem.cs @@ -1,3 +1,3 @@ namespace AIStudio.Components.Blocks; -public interface ITreeItem; \ No newline at end of file +public interface ITreeItem; \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/TreeButton.cs b/app/MindWork AI Studio/Components/Blocks/TreeButton.cs index ff21b8d8..f7e3a858 100644 --- a/app/MindWork AI Studio/Components/Blocks/TreeButton.cs +++ b/app/MindWork AI Studio/Components/Blocks/TreeButton.cs @@ -1,3 +1,3 @@ namespace AIStudio.Components.Blocks; -public readonly record struct TreeButton(WorkspaceBranch Branch, int Depth, string Text, string Icon) : ITreeItem; \ No newline at end of file +public readonly record struct TreeButton(WorkspaceBranch Branch, int Depth, string Text, string Icon) : ITreeItem; \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/TreeDivider.cs b/app/MindWork AI Studio/Components/Blocks/TreeDivider.cs index c4a6d9f6..6c311272 100644 --- a/app/MindWork AI Studio/Components/Blocks/TreeDivider.cs +++ b/app/MindWork AI Studio/Components/Blocks/TreeDivider.cs @@ -1,3 +1,3 @@ namespace AIStudio.Components.Blocks; -public readonly record struct TreeDivider : ITreeItem; \ No newline at end of file +public readonly record struct TreeDivider : ITreeItem; \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs b/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs index ac5e0384..aef9e065 100644 --- a/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs +++ b/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs @@ -1,6 +1,6 @@ namespace AIStudio.Components.Blocks; -public class TreeItemData : ITreeItem +public class TreeItemData : ITreeItem { public WorkspaceBranch Branch { get; init; } = WorkspaceBranch.NONE; @@ -12,9 +12,9 @@ public class TreeItemData : ITreeItem public bool IsChat { get; init; } - public T? Value { get; init; } + public string Path { get; init; } = string.Empty; public bool Expandable { get; init; } = true; - public HashSet> Children { get; init; } = []; + public HashSet Children { get; init; } = []; } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor index 9eff4701..6673a7d9 100644 --- a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor +++ b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor @@ -1,17 +1,17 @@ - + @switch (item) { - case TreeDivider: + case TreeDivider:
  • break; - case TreeItemData treeItem: + case TreeItemData treeItem: @if (treeItem.IsChat) { - +
    @treeItem.Text @@ -25,7 +25,7 @@ } else { - +
    @treeItem.Text @@ -35,7 +35,7 @@ } break; - case TreeButton treeButton: + case TreeButton treeButton:
  • diff --git a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs index 965585b7..3884989e 100644 --- a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs +++ b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs @@ -33,7 +33,7 @@ public partial class Workspaces : ComponentBase } }; - private readonly HashSet> treeItems = new(); + private readonly HashSet treeItems = new(); #region Overrides of ComponentBase @@ -55,33 +55,33 @@ public partial class Workspaces : ComponentBase private async Task LoadTreeItems() { this.treeItems.Clear(); - this.treeItems.Add(new TreeItemData + this.treeItems.Add(new TreeItemData { Depth = 0, Branch = WorkspaceBranch.WORKSPACES, Text = "Workspaces", Icon = Icons.Material.Filled.Folder, Expandable = true, - Value = "root", + Path = "root", Children = await this.LoadWorkspaces(), }); - this.treeItems.Add(new TreeDivider()); - this.treeItems.Add(new TreeItemData + this.treeItems.Add(new TreeDivider()); + this.treeItems.Add(new TreeItemData { Depth = 0, Branch = WorkspaceBranch.TEMPORARY_CHATS, Text = "Temporary chats", Icon = Icons.Material.Filled.Timer, Expandable = true, - Value = "temp", + Path = "temp", Children = await this.LoadTemporaryChats(), }); } - private async Task>> LoadTemporaryChats() + private async Task> LoadTemporaryChats() { - var tempChildren = new HashSet>(); + var tempChildren = new HashSet(); // // Search for workspace folders in the data directory: @@ -100,7 +100,7 @@ public partial class Workspaces : ComponentBase var chatNamePath = Path.Join(tempChatDirPath, "name"); var chatName = await File.ReadAllTextAsync(chatNamePath, Encoding.UTF8); - tempChildren.Add(new TreeItemData + tempChildren.Add(new TreeItemData { IsChat = true, Depth = 1, @@ -108,7 +108,7 @@ public partial class Workspaces : ComponentBase Text = chatName, Icon = Icons.Material.Filled.Timer, Expandable = false, - Value = tempChatDirPath, + Path = tempChatDirPath, }); } @@ -117,7 +117,7 @@ public partial class Workspaces : ComponentBase private async Task>> LoadWorkspaces() { - var workspaces = new HashSet>(); + var workspaces = new HashSet(); // // Search for workspace folders in the data directory: @@ -136,7 +136,7 @@ public partial class Workspaces : ComponentBase var workspaceNamePath = Path.Join(workspaceDirPath, "name"); var workspaceName = await File.ReadAllTextAsync(workspaceNamePath, Encoding.UTF8); - workspaces.Add(new TreeItemData + workspaces.Add(new TreeItemData { IsChat = false, Depth = 1, @@ -144,18 +144,18 @@ public partial class Workspaces : ComponentBase Text = workspaceName, Icon = Icons.Material.Filled.Description, Expandable = true, - Value = workspaceDirPath, + Path = workspaceDirPath, Children = await this.LoadWorkspaceChats(workspaceDirPath), }); } - workspaces.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 1, "Add workspace",Icons.Material.Filled.Add)); + workspaces.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 1, "Add workspace",Icons.Material.Filled.Add)); return workspaces; } - private async Task>> LoadWorkspaceChats(string workspacePath) + private async Task> LoadWorkspaceChats(string workspacePath) { - var workspaceChats = new HashSet>(); + var workspaceChats = new HashSet(); // Enumerate the workspace directory: foreach (var chatPath in Directory.EnumerateDirectories(workspacePath)) @@ -164,7 +164,7 @@ public partial class Workspaces : ComponentBase var chatNamePath = Path.Join(chatPath, "name"); var chatName = await File.ReadAllTextAsync(chatNamePath, Encoding.UTF8); - workspaceChats.Add(new TreeItemData + workspaceChats.Add(new TreeItemData { IsChat = true, Depth = 2, @@ -172,32 +172,32 @@ public partial class Workspaces : ComponentBase Text = chatName, Icon = Icons.Material.Filled.Chat, Expandable = false, - Value = chatPath, + Path = chatPath, }); } - workspaceChats.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 2, "Add chat",Icons.Material.Filled.Add)); + workspaceChats.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 2, "Add chat",Icons.Material.Filled.Add)); return workspaceChats; } - public async Task StoreChat(ChatThread thread) + public async Task StoreChat(ChatThread chat) { string chatDirectory; - if (thread.WorkspaceId == Guid.Empty) - chatDirectory = Path.Join(SettingsManager.DataDirectory, "tempChats", thread.ChatId.ToString()); + if (chat.WorkspaceId == Guid.Empty) + chatDirectory = Path.Join(SettingsManager.DataDirectory, "tempChats", chat.ChatId.ToString()); else - chatDirectory = Path.Join(SettingsManager.DataDirectory, "workspaces", thread.WorkspaceId.ToString(), thread.ChatId.ToString()); + chatDirectory = Path.Join(SettingsManager.DataDirectory, "workspaces", chat.WorkspaceId.ToString(), chat.ChatId.ToString()); // Ensure the directory exists: Directory.CreateDirectory(chatDirectory); // Save the chat name: var chatNamePath = Path.Join(chatDirectory, "name"); - await File.WriteAllTextAsync(chatNamePath, thread.Name); + await File.WriteAllTextAsync(chatNamePath, chat.Name); // Save the thread as thread.json: var chatPath = Path.Join(chatDirectory, "thread.json"); - await File.WriteAllTextAsync(chatPath, JsonSerializer.Serialize(thread, JSON_OPTIONS), Encoding.UTF8); + await File.WriteAllTextAsync(chatPath, JsonSerializer.Serialize(chat, JSON_OPTIONS), Encoding.UTF8); // Reload the tree items: await this.LoadTreeItems();