diff --git a/app/MindWork AI Studio/Chat/ChatThread.cs b/app/MindWork AI Studio/Chat/ChatThread.cs index b66ad1d..4e89206 100644 --- a/app/MindWork AI Studio/Chat/ChatThread.cs +++ b/app/MindWork AI Studio/Chat/ChatThread.cs @@ -97,4 +97,17 @@ public sealed record ChatThread logger.LogInformation(logMessage); return systemPromptText; } + + /// + /// Removes a content block from this chat thread. + /// + /// The content block to remove. + public void Remove(IContent content) + { + var block = this.Blocks.FirstOrDefault(x => x.Content == content); + if(block is null) + return; + + this.Blocks.Remove(block); + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor index aeafa48..51dd8f1 100644 --- a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor +++ b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor @@ -12,7 +12,15 @@ @this.Role.ToName() (@this.Time) - + @if (this.RemoveBlockFunc is not null) + { + + + + } + + + diff --git a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs index ab3caab..898c577 100644 --- a/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs +++ b/app/MindWork AI Studio/Chat/ContentBlockComponent.razor.cs @@ -40,6 +40,9 @@ public partial class ContentBlockComponent : ComponentBase /// [Parameter] public string Class { get; set; } = string.Empty; + + [Parameter] + public Func? RemoveBlockFunc { get; set; } [Inject] private RustService RustService { get; init; } = null!; @@ -49,6 +52,9 @@ public partial class ContentBlockComponent : ComponentBase [Inject] private SettingsManager SettingsManager { get; init; } = null!; + + [Inject] + private IDialogService DialogService { get; init; } = null!; private bool HideContent { get; set; } @@ -122,4 +128,19 @@ public partial class ContentBlockComponent : ComponentBase private string CardClasses => $"my-2 rounded-lg {this.Class}"; private CodeBlockTheme CodeColorPalette => this.SettingsManager.IsDarkMode ? CodeBlockTheme.Dark : CodeBlockTheme.Default; + + private async Task RemoveBlock() + { + if (this.RemoveBlockFunc is null) + return; + + var remove = await this.DialogService.ShowMessageBox( + "Remove Message", + "Do you really want to remove this message?", + "Yes, remove it", + "No, keep it"); + + if (remove.HasValue && remove.Value) + await this.RemoveBlockFunc(this.Content); + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ChatComponent.razor b/app/MindWork AI Studio/Components/ChatComponent.razor index 961d65c..9fd6f38 100644 --- a/app/MindWork AI Studio/Components/ChatComponent.razor +++ b/app/MindWork AI Studio/Components/ChatComponent.razor @@ -11,7 +11,7 @@ { @if (!block.HideFromUser) { - + } } } diff --git a/app/MindWork AI Studio/Components/ChatComponent.razor.cs b/app/MindWork AI Studio/Components/ChatComponent.razor.cs index f324114..4b9a469 100644 --- a/app/MindWork AI Studio/Components/ChatComponent.razor.cs +++ b/app/MindWork AI Studio/Components/ChatComponent.razor.cs @@ -571,6 +571,17 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable await MessageBus.INSTANCE.SendMessage(this, Event.WORKSPACE_TOGGLE_OVERLAY); } + private async Task RemoveBlock(IContent block) + { + if(this.ChatThread is null) + return; + + this.ChatThread.Remove(block); + this.hasUnsavedChanges = true; + await this.SaveThread(); + this.StateHasChanged(); + } + #region Overrides of MSGComponentBase public override async Task ProcessIncomingMessage(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default diff --git a/app/MindWork AI Studio/wwwroot/changelog/v0.9.24.md b/app/MindWork AI Studio/wwwroot/changelog/v0.9.24.md new file mode 100644 index 0000000..03d2545 --- /dev/null +++ b/app/MindWork AI Studio/wwwroot/changelog/v0.9.24.md @@ -0,0 +1,2 @@ +# v0.9.24, build 199 (2025-01-xx xx:xx UTC) +- Added a button to remove a message from the chat thread. \ No newline at end of file