Assistant send result (#75)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2024-08-18 12:32:18 +02:00
1 parent ea0ead58f8
commit 909fbe89bb
36 files changed
+400 -63

No files matched your search

+4 -1
View File
@@ -1,3 +1,6 @@
namespace AIStudio.Tools;
public readonly record struct ButtonData(string Text, string Icon, Color Color, string Tooltip, Func<Task> AsyncAction);
public readonly record struct ButtonData(string Text, string Icon, Color Color, string Tooltip, Func<Task> AsyncAction) : IButtonData
{
public ButtonTypes Type => ButtonTypes.BUTTON;
}
@@ -0,0 +1,7 @@
namespace AIStudio.Tools;
public enum ButtonTypes
{
BUTTON = 0,
SEND_TO,
}
+9
View File
@@ -15,4 +15,13 @@ public enum Event
// Chat events:
HAS_CHAT_UNSAVED_CHANGES,
RESET_CHAT_STATE,
// Send assistant events:
SEND_TO_GRAMMAR_SPELLING_ASSISTANT,
SEND_TO_ICON_FINDER_ASSISTANT,
SEND_TO_REWRITE_ASSISTANT,
SEND_TO_TRANSLATION_ASSISTANT,
SEND_TO_AGENDA_ASSISTANT,
SEND_TO_CODING_ASSISTANT,
SEND_TO_TEXT_SUMMARIZER_ASSISTANT,
}
@@ -0,0 +1,6 @@
namespace AIStudio.Tools;
public interface IButtonData
{
public ButtonTypes Type { get; }
}
@@ -11,6 +11,7 @@ public sealed class MessageBus
private readonly ConcurrentDictionary<IMessageBusReceiver, ComponentBase[]> componentFilters = new();
private readonly ConcurrentDictionary<IMessageBusReceiver, Event[]> componentEvents = new();
private readonly ConcurrentDictionary<Event, ConcurrentQueue<Message>> deferredMessages = new();
private readonly ConcurrentQueue<Message> messageQueue = new();
private readonly SemaphoreSlim sendingSemaphore = new(1, 1);
@@ -65,6 +66,24 @@ public sealed class MessageBus
}
}
public void DeferMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data = default)
{
if (this.deferredMessages.TryGetValue(triggeredEvent, out var queue))
queue.Enqueue(new Message(sendingComponent, triggeredEvent, data));
else
{
this.deferredMessages[triggeredEvent] = new();
this.deferredMessages[triggeredEvent].Enqueue(new Message(sendingComponent, triggeredEvent, data));
}
}
public IEnumerable<T?> CheckDeferredMessages<T>(Event triggeredEvent)
{
if (this.deferredMessages.TryGetValue(triggeredEvent, out var queue))
while (queue.TryDequeue(out var message))
yield return message.Data is T data ? data : default;
}
public async Task<TResult?> SendMessageUseFirstResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data = default)
{
foreach (var (receiver, componentFilter) in this.componentFilters)
@@ -0,0 +1,15 @@
using AIStudio.Components.Pages;
namespace AIStudio.Tools;
public readonly record struct SendToButton() : IButtonData
{
public ButtonTypes Type => ButtonTypes.SEND_TO;
public Func<string> GetData { get; init; } = () => string.Empty;
public bool UseResultingContentBlockData { get; init; } = true;
public SendToAssistant Self { get; init; } = SendToAssistant.NONE;
}