From 01eb99096e0a0d7c3fc65c3c3d9b99962cbbfee2 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 29 Mar 2025 18:55:30 +0100 Subject: [PATCH 1/3] Added a function to load a text file --- app/MindWork AI Studio/Pages/Writer.razor | 3 +++ app/MindWork AI Studio/Pages/Writer.razor.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/MindWork AI Studio/Pages/Writer.razor b/app/MindWork AI Studio/Pages/Writer.razor index 790e3e07..4832de7c 100644 --- a/app/MindWork AI Studio/Pages/Writer.razor +++ b/app/MindWork AI Studio/Pages/Writer.razor @@ -8,6 +8,9 @@ + + Load a text file + Logger { get; init; } = null!; + [Inject] + private RustService RustService { get; init; } = null!; + private static readonly Dictionary USER_INPUT_ATTRIBUTES = new(); private readonly Timer typeTimer = new(TimeSpan.FromMilliseconds(1_500)); @@ -56,6 +62,19 @@ public partial class Writer : MSGComponentBase, IAsyncDisposable #endregion private bool IsProviderSelected => this.providerSettings.UsedLLMProvider != LLMProviders.NONE; + + private async Task LoadTextFile() + { + var result = await this.RustService.SelectFile("Load a text file"); + if(result.UserCancelled) + return; + + if(!File.Exists(result.SelectedFilePath)) + return; + + var text = await File.ReadAllTextAsync(result.SelectedFilePath, Encoding.UTF8); + this.userInput = text; + } private async Task InputKeyEvent(KeyboardEventArgs keyEvent) { From 6e253db69f5dc4127494623e58eb218830f6bb3c Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 29 Mar 2025 19:18:43 +0100 Subject: [PATCH 2/3] Removed previous UI elements --- app/MindWork AI Studio/Pages/Writer.razor | 38 +---------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/app/MindWork AI Studio/Pages/Writer.razor b/app/MindWork AI Studio/Pages/Writer.razor index 4832de7c..1dba9895 100644 --- a/app/MindWork AI Studio/Pages/Writer.razor +++ b/app/MindWork AI Studio/Pages/Writer.razor @@ -13,49 +13,13 @@ - - - + @if (this.isStreaming) { } - \ No newline at end of file From a682302b6b263b637411392da33a8ff41d1ca620 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 29 Mar 2025 21:07:17 +0100 Subject: [PATCH 3/3] Implemented text chunks --- app/MindWork AI Studio/Pages/Writer.razor | 7 ++++++- app/MindWork AI Studio/Pages/Writer.razor.cs | 21 +++++++++++++++++++ app/MindWork AI Studio/Tools/WriterChunk.cs | 10 +++++++++ app/MindWork AI Studio/wwwroot/app.css | 22 ++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 app/MindWork AI Studio/Tools/WriterChunk.cs diff --git a/app/MindWork AI Studio/Pages/Writer.razor b/app/MindWork AI Studio/Pages/Writer.razor index 1dba9895..2941a9c3 100644 --- a/app/MindWork AI Studio/Pages/Writer.razor +++ b/app/MindWork AI Studio/Pages/Writer.razor @@ -13,7 +13,12 @@ - + @foreach (var chunk in this.chunks) + { + + @chunk.Content + + } @if (this.isStreaming) diff --git a/app/MindWork AI Studio/Pages/Writer.razor.cs b/app/MindWork AI Studio/Pages/Writer.razor.cs index 543286fc..8864bec8 100644 --- a/app/MindWork AI Studio/Pages/Writer.razor.cs +++ b/app/MindWork AI Studio/Pages/Writer.razor.cs @@ -28,6 +28,7 @@ public partial class Writer : MSGComponentBase, IAsyncDisposable private ChatThread? chatThread; private bool isStreaming; private string userInput = string.Empty; + private List chunks = new(); private string userDirection = string.Empty; private string suggestion = string.Empty; @@ -74,6 +75,26 @@ public partial class Writer : MSGComponentBase, IAsyncDisposable var text = await File.ReadAllTextAsync(result.SelectedFilePath, Encoding.UTF8); this.userInput = text; + this.ChunkText(); + } + + private void ChunkText() + { + this.chunks.Clear(); + var startIndex = 0; + var contentSpan = this.userInput.AsSpan(); + for (var index = 0; index < contentSpan.Length; index++) + { + if (contentSpan[index] is '\n') + { + var endIndex = index; + var lineMemory = this.userInput.AsMemory(startIndex..endIndex); + this.chunks.Add(new WriterChunk(lineMemory, false, false)); + startIndex = endIndex + 1; + } + } + + this.StateHasChanged(); } private async Task InputKeyEvent(KeyboardEventArgs keyEvent) diff --git a/app/MindWork AI Studio/Tools/WriterChunk.cs b/app/MindWork AI Studio/Tools/WriterChunk.cs new file mode 100644 index 00000000..d8031e3c --- /dev/null +++ b/app/MindWork AI Studio/Tools/WriterChunk.cs @@ -0,0 +1,10 @@ +namespace AIStudio.Tools; + +public sealed class WriterChunk(ReadOnlyMemory content, bool isSelected, bool isProcessing) +{ + public ReadOnlyMemory Content = content; + + public bool IsSelected = isSelected; + + public bool IsProcessing = isProcessing; +} \ No newline at end of file diff --git a/app/MindWork AI Studio/wwwroot/app.css b/app/MindWork AI Studio/wwwroot/app.css index af0e139a..9d9195ce 100644 --- a/app/MindWork AI Studio/wwwroot/app.css +++ b/app/MindWork AI Studio/wwwroot/app.css @@ -35,6 +35,28 @@ margin-top: 4px; } +.write-mode-chunk { + font-size: large; + padding-left: 1.5em; + position: relative; +} + +.write-mode-chunk::before { + content: ""; + position: absolute; + left: 0; + top: 10%; + height: 80%; + width: 0.8em; + background-color: transparent; + border-radius: 0.4em; + transition: background-color 0.5s ease; +} + +.write-mode-chunk:hover::before { + background-color: #5894f3; /* Balkenfarbe im hover-Zustand */ +} + .plugin-icon-container { width: var(--mud-icon-size-large); height: var(--mud-icon-size-large);