using System.Text.Json; using Elsa.Studio.Dashboard.Extensions; using Elsa.Studio.Shell; using Elsa.Studio.Shell.Extensions; using Elsa.Studio.Workflows.Extensions; using Elsa.Studio.Contracts; using Elsa.Studio.Core.BlazorWasm.Extensions; using Elsa.Studio.Extensions; using Elsa.Studio.Login.BlazorWasm.Extensions; using Elsa.Studio.Login.HttpMessageHandlers; using Elsa.Studio.Models; using Elsa.Studio.Options; using Elsa.Studio.Workflows.Designer.Extensions; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.Options; using Microsoft.JSInterop; // Build the host. var builder = WebAssemblyHostBuilder.CreateDefault(args); // Register root components. builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); builder.RootComponents.RegisterCustomElsaStudioElements(); // Register shell services and modules. var backendApiConfig = new BackendApiConfig { ConfigureBackendOptions = options => builder.Configuration.GetSection("Backend").Bind(options), ConfigureHttpClientBuilder = options => options.AuthenticationHandler = typeof(AuthenticatingApiHttpMessageHandler) }; builder.Services.AddCore(); builder.Services.AddShell(); builder.Services.AddRemoteBackend(backendApiConfig); builder.Services.AddLoginModule(); builder.Services.AddDashboardModule(); builder.Services.AddWorkflowsModule(); builder.Services.AddAgentsModule(backendApiConfig); // Build the application. var app = builder.Build(); // Apply client config. var js = app.Services.GetRequiredService(); var clientConfig = await js.InvokeAsync("getClientConfig"); var apiUrl = clientConfig.GetProperty("apiUrl").GetString()!; app.Services.GetRequiredService>().Value.Url = new Uri(apiUrl); // Run each startup task. var startupTaskRunner = app.Services.GetRequiredService(); await startupTaskRunner.RunStartupTasksAsync(); // Run the application. await app.RunAsync();