Files

21 lines
1.1 KiB
C#

using Volcanic.AgenticCore.Abstractions.Extensions.Events;
using Volcanic.AgenticCore.Telegram.Inbound;
namespace Volcanic.AgenticCore.Telegram.Chats;
/// <summary>
/// Runs a prompt in a chat's session as a follow-up with the local-time header, never through the inbox (so it is never
/// debounced into a user's message and never answers a pending question). Idle: starts (or joins) a run and returns when
/// it settles. Busy: queued as a follow-up (never steering), returns when the run that took it settles.
/// </summary>
internal static class ChatFollowUps
{
public static async Task RunAsync(ChatContext chat, string prompt, TimeZoneInfo zone, TimeProvider time, CancellationToken cancellationToken)
{
var text = MessageContext.TimestampHeader(time.GetUtcNow(), zone) + "\n" + prompt;
var queued = chat.Session.IsStreaming;
await chat.Session.PromptAsync(text, null, StreamingBehavior.FollowUp, cancellationToken).ConfigureAwait(false);
if (queued) await chat.Session.WaitForIdleAsync(cancellationToken).ConfigureAwait(false);
}
}