48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using MAF1;
|
|
using MAF1.Utils;
|
|
using MAF1.Web;
|
|
|
|
WindowsConsole.EnableUtf8();
|
|
|
|
if (args.Length > 0 && args[0] is "node" or "edge" or "--cli" or "-h" or "--help")
|
|
{
|
|
await CliHost.RunAsync(args);
|
|
return;
|
|
}
|
|
|
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
|
builder.WebHost.UseUrls("http://127.0.0.1:5288");
|
|
builder.Services.ConfigureHttpJsonOptions(options =>
|
|
{
|
|
options.SerializerOptions.PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase;
|
|
});
|
|
builder.Services.AddSingleton<AgentRuntime>();
|
|
|
|
WebApplication app = builder.Build();
|
|
app.UseDefaultFiles();
|
|
app.UseStaticFiles();
|
|
|
|
app.MapGet("/api/catalog", (AgentRuntime runtime) =>
|
|
{
|
|
var snapshot = runtime.Catalog.Load();
|
|
return new
|
|
{
|
|
pluginsRoot = snapshot.PluginsRoot,
|
|
system = snapshot.System,
|
|
plugins = snapshot.Plugins,
|
|
nodes = snapshot.Nodes,
|
|
issues = snapshot.Issues,
|
|
};
|
|
});
|
|
app.MapGet("/api/credentials", (AgentRuntime runtime) => runtime.Credentials.ListPublic());
|
|
app.MapGet("/api/status", (AgentRuntime runtime) => new
|
|
{
|
|
weatherProvider = runtime.WeatherProvider,
|
|
pluginsRoot = runtime.PluginsRoot,
|
|
});
|
|
app.MapPost("/api/run", (WorkflowGraph graph, AgentRuntime runtime, CancellationToken cancellationToken)
|
|
=> runtime.Runner.RunAsync(graph, cancellationToken));
|
|
|
|
Console.WriteLine("可视化编排: http://127.0.0.1:5288");
|
|
app.Run();
|