// Copyright (c) Microsoft. All rights reserved. using System.Diagnostics.CodeAnalysis; namespace Microsoft.Agents.AI.DevUI; /// /// Provides helper methods for configuring the Microsoft Agents AI DevUI in ASP.NET applications. /// public static class DevUIExtensions { /// /// Maps an endpoint that serves the DevUI from the '/devui' path. /// /// /// DevUI requires the OpenAI Responses and Conversations services to be registered with /// and /// , /// and the corresponding endpoints to be mapped using /// and /// . /// /// The to add the endpoint to. /// A that can be used to add authorization or other endpoint configuration. /// /// /// /// /// Thrown when is null. public static IEndpointConventionBuilder MapDevUI( this IEndpointRouteBuilder endpoints) { var group = endpoints.MapGroup(""); group.MapDevUI(pattern: "/devui"); group.MapMeta(); group.MapEntities(); return group; } /// /// Maps an endpoint that serves the DevUI. /// /// The to add the endpoint to. /// /// The route pattern for the endpoint (e.g., "/devui", "/agent-ui"). /// Defaults to "/devui" if not specified. This is the path where DevUI will be accessible. /// /// A that can be used to add authorization or other endpoint configuration. /// Thrown when is null. /// Thrown when is null or whitespace. internal static IEndpointConventionBuilder MapDevUI( this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern = "/devui") { ArgumentNullException.ThrowIfNull(endpoints); ArgumentException.ThrowIfNullOrWhiteSpace(pattern); // Ensure the pattern doesn't end with a slash for consistency var cleanPattern = pattern.TrimEnd('/'); // Create the DevUI handler var logger = endpoints.ServiceProvider.GetRequiredService>(); var devUIHandler = new DevUIMiddleware(logger, cleanPattern); return endpoints.MapGet($"{cleanPattern}/{{*path}}", devUIHandler.HandleRequestAsync) .WithName($"DevUI at {cleanPattern}") .WithDescription("Interactive developer interface for Microsoft Agent Framework"); } }