feat: 拆分 CLI 与网页宿主,并在无有效城市时暂停等人确认
将原单体 MAF1 拆成 MAF1(控制台工作流)和 MAF1.Web(可视化编排)。 抽城市失败时暂停:网页弹确认、CLI 控制台询问,超时采用默认结束查询; 也可改填城市后继续。共享决策模型放在 MAF1.Core。
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using MAF1.Decisions;
|
||||
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));
|
||||
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));
|
||||
|
||||
Console.WriteLine("可视化编排: http://127.0.0.1:5288");
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user