2026-08-28 10:43:57 +08:00
|
|
|
using MAF1.Decisions;
|
2026-08-26 18:06:02 +08:00
|
|
|
using MAF1.Utils;
|
|
|
|
|
using MAF1.Web;
|
|
|
|
|
|
|
|
|
|
WindowsConsole.EnableUtf8();
|
|
|
|
|
|
|
|
|
|
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));
|
2026-08-28 10:43:57 +08:00
|
|
|
app.MapGet("/api/run/{runId}", (string runId, AgentRuntime runtime) =>
|
|
|
|
|
{
|
|
|
|
|
WorkflowRunResult? result = runtime.Runner.Get(runId);
|
|
|
|
|
return result is null
|
|
|
|
|
? Results.NotFound(new WorkflowRunResult { Ok = false, Status = WorkflowRunStatus.Failed, Error = "找不到这次运行。" })
|
|
|
|
|
: Results.Ok(result);
|
|
|
|
|
});
|
|
|
|
|
app.MapPost("/api/run/{runId}/decide", (string runId, DecisionAnswer answer, AgentRuntime runtime, CancellationToken cancellationToken)
|
|
|
|
|
=> runtime.Runner.DecideAsync(runId, answer, cancellationToken));
|
2026-08-26 18:06:02 +08:00
|
|
|
|
|
|
|
|
Console.WriteLine("可视化编排: http://127.0.0.1:5288");
|
|
|
|
|
app.Run();
|