using AIStudio.Provider; namespace AIStudio.Tools.ToolCallingSystem.Harness; /// /// One event of a streamed round of a tool calling conversation. /// /// /// Text arrives while the round is still running, its outcome only at the end. A round which ends /// without a ROUND_COMPLETED event has failed: that is how a failed request or a truncated stream /// is told apart from a round which simply had nothing to say. The adapter has already told the /// user what went wrong in that case, so the loop ends without a message of its own. /// /// What this event carries. /// The piece of text, set for TEXT_DELTA events only. /// The round's outcome, set for ROUND_COMPLETED events only. public sealed record ToolCallingStreamEvent(ToolCallingStreamEventKind Kind, ContentStreamChunk? Delta, ToolCallingRound? Round) { /// /// Creates an event for a piece of text, along with the sources it brought. /// /// The chunk to show. public static ToolCallingStreamEvent TextDelta(ContentStreamChunk delta) => new(ToolCallingStreamEventKind.TEXT_DELTA, delta, null); /// /// Creates an event for a piece of text without any sources. /// /// The text to show. public static ToolCallingStreamEvent TextDelta(string text) => new(ToolCallingStreamEventKind.TEXT_DELTA, new ContentStreamChunk(text, []), null); /// /// Creates the event which ends a round. /// /// The round's outcome. public static ToolCallingStreamEvent RoundCompleted(ToolCallingRound round) => new(ToolCallingStreamEventKind.ROUND_COMPLETED, null, round); }