Files
meeting-assistant/MeetingAssistant/Workflow/WorkflowRulesEditorChatViewModel.cs
T
codex 693f52afee
PR and Push Build/Test / build-and-test (push) Successful in 7m0s
Add tray rules and identities editor
2026-05-28 01:28:16 +02:00

66 lines
1.8 KiB
C#

using System.Collections.ObjectModel;
namespace MeetingAssistant.Workflow;
public sealed class WorkflowRulesEditorChatViewModel
{
private readonly IWorkflowRulesEditorChatPipeline pipeline;
public WorkflowRulesEditorChatViewModel(IWorkflowRulesEditorChatPipeline pipeline)
{
this.pipeline = pipeline;
}
public ObservableCollection<WorkflowRulesEditorChatMessage> Messages { get; } = [];
public string Draft { get; set; } = "";
public bool IsThinking { get; private set; }
public event EventHandler? Changed;
public async Task SendAsync(CancellationToken cancellationToken = default)
{
var prompt = Draft.Trim();
if (string.IsNullOrWhiteSpace(prompt) || IsThinking)
{
return;
}
Draft = "";
var priorConversation = Messages.ToList();
Messages.Add(new WorkflowRulesEditorChatMessage(WorkflowRulesEditorChatRole.User, prompt));
IsThinking = true;
OnChanged();
try
{
var result = await pipeline.SendAsync(
priorConversation,
prompt,
cancellationToken);
Messages.Clear();
foreach (var message in result.Conversation)
{
Messages.Add(message);
}
}
catch (Exception exception) when (exception is not OperationCanceledException)
{
Messages.Add(new WorkflowRulesEditorChatMessage(
WorkflowRulesEditorChatRole.Agent,
$"Rules editor failed: {exception.Message}"));
}
finally
{
IsThinking = false;
OnChanged();
}
}
private void OnChanged()
{
Changed?.Invoke(this, EventArgs.Empty);
}
}