diff --git a/src/A2A.Client/A2A.Client.csproj b/src/A2A.Client/A2A.Client.csproj index e290ae8..ad3d354 100644 --- a/src/A2A.Client/A2A.Client.csproj +++ b/src/A2A.Client/A2A.Client.csproj @@ -25,6 +25,7 @@ https://github.com/neuroglia-io/a2a git embedded + $(NoWarn);Undefined diff --git a/tools/A2A.ClientConsole/Program.cs b/tools/A2A.ClientConsole/Program.cs index 334a931..a083f74 100644 --- a/tools/A2A.ClientConsole/Program.cs +++ b/tools/A2A.ClientConsole/Program.cs @@ -1,7 +1,6 @@ using A2A; using A2A.Client; using A2A.Models; -using Microsoft.AspNetCore.Components.Routing; using Microsoft.Extensions.DependencyInjection; using Spectre.Console; using Spectre.Console.Rendering; @@ -246,9 +245,15 @@ async Task RunInteractionLoopAsync() async Task ChatAsync() { DisplayNewPage(); + var contextId = Guid.NewGuid().ToString("N"); + var taskId = (string?)null; + CollectInput: + AnsiConsole.WriteLine(); var userInput = AnsiConsole.Ask("[bold blue]You:[/]"); var userMessage = new Message { + ContextId = contextId, + TaskId = taskId, Role = Role.User, Parts = [new TextPart { Text = userInput }] }; @@ -256,12 +261,11 @@ async Task ChatAsync() { Message = userMessage }; - try { var cancellationTokenSource = new CancellationTokenSource(); var supportsStreaming = agentCard!.Capabilities?.Streaming == true; - var currentTaskId = (string?)null; + var loop = false; if (supportsStreaming) { var responseText = new StringBuilder(); @@ -272,8 +276,8 @@ async Task ChatAsync() { if (streamResponse.Task != null) { - currentTaskId = streamResponse.Task.Id; - AnsiConsole.MarkupLine($"\n[blue]Agent:[/] [dim]Task started: {currentTaskId}[/]"); + taskId = streamResponse.Task.Id; + AnsiConsole.MarkupLine($"\n[blue]Agent:[/] [dim]Task started: {taskId}[/]"); AnsiConsole.MarkupLine("[blue]Agent:[/] [dim]Status: {0}[/]", streamResponse.Task.Status?.State ?? "unknown"); if (streamResponse.Task.Artifacts != null) { @@ -285,7 +289,7 @@ async Task ChatAsync() if (part is TextPart textPart) { responseText.Append(textPart.Text); - AnsiConsole.Markup(textPart.Text); + AnsiConsole.Write(textPart.Text); } } } @@ -298,13 +302,32 @@ async Task ChatAsync() if (part is TextPart textPart) { responseText.Append(textPart.Text); - AnsiConsole.Markup(textPart.Text); + AnsiConsole.Write(textPart.Text); } } + AnsiConsole.WriteLine(); } else if (streamResponse.StatusUpdate != null) { AnsiConsole.MarkupLine($"\n[blue]Agent:[/] [dim]Task status: {streamResponse.StatusUpdate.Status?.State}[/]"); + if (streamResponse.StatusUpdate.Status?.Message is not null) + { + foreach (var part in streamResponse.StatusUpdate.Status.Message.Parts) + { + switch (part) + { + case TextPart textPart: + AnsiConsole.Write(textPart.Text); + break; + } + } + AnsiConsole.WriteLine(); + } + if (streamResponse.StatusUpdate.Status?.State == TaskState.InputRequired) + { + loop = true; + break; + } } else if (streamResponse.ArtifactUpdate != null) { @@ -314,7 +337,7 @@ async Task ChatAsync() switch (part) { case TextPart textPart: - AnsiConsole.Markup(textPart.Text); + AnsiConsole.Write(textPart.Text); break; } } @@ -326,11 +349,11 @@ async Task ChatAsync() { if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.C) { - if (currentTaskId != null) + if (taskId != null) { try { - await client!.CancelTaskAsync(currentTaskId); + await client!.CancelTaskAsync(taskId); AnsiConsole.MarkupLine("\n[yellow]Task cancelled.[/]"); } catch (Exception ex) @@ -350,15 +373,7 @@ async Task ChatAsync() { AnsiConsole.MarkupLine("\n[yellow]Operation cancelled.[/]"); } - - if (responseText.Length > 0) - { - var agentMessage = new Message - { - Role = Role.Agent, - Parts = [new TextPart { Text = responseText.ToString() }] - }; - } + if (loop) goto CollectInput; } else { @@ -378,8 +393,8 @@ async Task ChatAsync() } else if (response is A2A.Models.Task task) { - currentTaskId = task.Id; - AnsiConsole.MarkupLine($"[yellow]⚙ Task created: {currentTaskId}[/]"); + taskId = task.Id; + AnsiConsole.MarkupLine($"[yellow]⚙ Task created: {taskId}[/]"); AnsiConsole.MarkupLine($"[dim]Status: {task.Status?.State ?? "unknown"}[/]"); } }