AI-Studio/app/MindWork AI Studio/Components/ChatComposerState.cs
Thorsten Sommer d05ff26e62
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Fixed an issue with switching between chat threads while multiple chats are running (#779)
2026-05-25 20:48:26 +02:00

65 lines
1.9 KiB
C#

using AIStudio.Chat;
using AIStudio.Settings;
namespace AIStudio.Components;
public sealed class ChatComposerState
{
public string UserInput { get; private set; } = string.Empty;
public HashSet<FileAttachment> FileAttachments { get; } = [];
public bool HasUserDraft { get; private set; }
public bool HasComposerContent => !string.IsNullOrWhiteSpace(this.UserInput) || this.FileAttachments.Count > 0;
public bool HasVisibleUserDraft => this.HasUserDraft && (!string.IsNullOrWhiteSpace(this.UserInput) || this.FileAttachments.Count > 0);
public void ApplyTemplate(ChatTemplate chatTemplate)
{
this.UserInput = chatTemplate.PredefinedUserPrompt;
this.FileAttachments.Clear();
foreach (var attachment in chatTemplate.FileAttachments)
this.FileAttachments.Add(attachment.Normalize());
this.HasUserDraft = false;
}
public void SetUserInput(string? userInput)
{
this.UserInput = userInput ?? string.Empty;
this.HasUserDraft = !string.IsNullOrWhiteSpace(userInput);
}
public void SetSystemInput(string? userInput)
{
this.UserInput = userInput ?? string.Empty;
this.HasUserDraft = false;
}
public void MarkUserDraft()
{
this.HasUserDraft = true;
}
public void ReplaceFileAttachments(IEnumerable<FileAttachment> fileAttachments)
{
this.FileAttachments.Clear();
foreach (var attachment in fileAttachments)
this.FileAttachments.Add(attachment.Normalize());
}
public void Clear()
{
this.UserInput = string.Empty;
this.FileAttachments.Clear();
this.HasUserDraft = false;
}
public void RestoreFromTextBlock(ContentText textBlock)
{
this.UserInput = textBlock.Text;
this.ReplaceFileAttachments(textBlock.FileAttachments);
this.HasUserDraft = true;
}
}