2024-10-02 11:42:27 -07:00
|
|
|
using System.Diagnostics;
|
2024-07-25 00:06:06 -07:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
2024-10-08 10:02:48 -07:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
2024-06-28 08:03:42 -07:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-07-25 00:06:06 -07:00
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
2024-10-02 11:42:27 -07:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2024-06-28 08:03:42 -07:00
|
|
|
|
2024-10-16 20:09:39 -07:00
|
|
|
namespace Microsoft.AutoGen.Runtime;
|
2024-06-28 08:03:42 -07:00
|
|
|
|
|
|
|
public static class AgentWorkerHostingExtensions
|
|
|
|
{
|
2024-10-28 17:28:36 -07:00
|
|
|
public static WebApplicationBuilder AddAgentService(this WebApplicationBuilder builder, bool local = false)
|
2024-06-28 08:03:42 -07:00
|
|
|
{
|
2024-10-28 17:28:36 -07:00
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
//TODO: make configuration more flexible
|
|
|
|
builder.WebHost.ConfigureKestrel(serverOptions =>
|
|
|
|
{
|
|
|
|
serverOptions.ListenLocalhost(5001, listenOptions =>
|
|
|
|
{
|
|
|
|
listenOptions.Protocols = HttpProtocols.Http2;
|
|
|
|
listenOptions.UseHttps();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-06-28 08:03:42 -07:00
|
|
|
builder.Services.AddGrpc();
|
2024-10-28 17:28:36 -07:00
|
|
|
builder.AddOrleans(local);
|
2024-07-25 00:06:06 -07:00
|
|
|
builder.Services.TryAddSingleton(DistributedContextPropagator.Current);
|
2024-06-28 08:03:42 -07:00
|
|
|
builder.Services.AddSingleton<WorkerGateway>();
|
|
|
|
builder.Services.AddSingleton<IHostedService>(sp => sp.GetRequiredService<WorkerGateway>());
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2024-10-08 10:02:48 -07:00
|
|
|
public static WebApplicationBuilder AddLocalAgentService(this WebApplicationBuilder builder)
|
|
|
|
{
|
2024-10-28 17:28:36 -07:00
|
|
|
builder.AddAgentService(local: true);
|
2024-10-08 10:02:48 -07:00
|
|
|
return builder;
|
|
|
|
}
|
2024-06-28 08:03:42 -07:00
|
|
|
public static WebApplication MapAgentService(this WebApplication app)
|
|
|
|
{
|
|
|
|
app.MapGrpcService<WorkerGatewayService>();
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
}
|