// Copyright (c) Microsoft. All rights reserved. using Microsoft.Agents.AI.AGUI; using Microsoft.Extensions.AI; namespace AGUIDojoClient.Components.Shared; /// /// Service for managing demo scenarios and creating chat clients for each scenario. /// public sealed class DemoService { private readonly IHttpClientFactory _httpClientFactory; private readonly List _scenarios; /// /// Initializes a new instance of the class. /// /// Factory for creating HTTP clients. public DemoService(IHttpClientFactory httpClientFactory) { this._httpClientFactory = httpClientFactory; this._scenarios = InitializeScenarios(); } /// /// Gets all available demo scenarios. /// public IEnumerable AllScenarios => this._scenarios; /// /// Gets a specific scenario by its ID. /// /// The scenario identifier. /// The scenario if found; otherwise, null. public DemoScenario? GetScenario(string id) => this._scenarios.FirstOrDefault(s => s.Id.Equals(id, StringComparison.OrdinalIgnoreCase)); /// /// Creates a chat client for the specified endpoint. /// /// The AG-UI endpoint path. /// A configured chat client. public IChatClient CreateChatClient(string endpoint) { HttpClient httpClient = this._httpClientFactory.CreateClient("aguiserver"); return new AGUIChatClient(httpClient, endpoint); } private static List InitializeScenarios() { return [ new DemoScenario( Id: "agentic_chat", Title: "Agentic Chat", Description: "Chat with your Copilot and call frontend tools", Tags: ["Chat", "Tools", "Streaming"], Endpoint: "/agentic_chat", Icon: "💬" ), new DemoScenario( Id: "backend_tool_rendering", Title: "Backend Tool Rendering", Description: "Render and stream your backend tools to the frontend", Tags: ["Agent State", "Collaborating"], Endpoint: "/backend_tool_rendering", Icon: "🛠️" ), new DemoScenario( Id: "human_in_the_loop", Title: "Human in the Loop", Description: "Plan a task together and direct the Copilot to take the right steps", Tags: ["HITL", "Interactivity"], Endpoint: "/human_in_the_loop", Icon: "👤" ), new DemoScenario( Id: "agentic_generative_ui", Title: "Agentic Generative UI", Description: "Assign a long running task to your Copilot and see how it performs!", Tags: ["Generative UI (agent)", "Long running task"], Endpoint: "/agentic_generative_ui", Icon: "🤖" ), new DemoScenario( Id: "tool_based_generative_ui", Title: "Tool Based Generative UI", Description: "Haiku generator that uses tool based generative UI", Tags: ["Generative UI (action)", "Tools"], Endpoint: "/tool_based_generative_ui", Icon: "🎨" ), new DemoScenario( Id: "shared_state", Title: "Shared State between Agent and UI", Description: "A recipe Copilot which reads and updates collaboratively", Tags: ["Agent State", "Collaborating"], Endpoint: "/shared_state", Icon: "🍳" ), new DemoScenario( Id: "predictive_state_updates", Title: "Predictive State Updates", Description: "Use collaboration to edit a document in real time with your Copilot", Tags: ["State", "Streaming", "Tools"], Endpoint: "/predictive_state_updates", Icon: "📝" ) ]; } }