using MAF1.PluginContract; namespace MAF1.Web.Web; /// 画布上一个端口的元数据,前端用来渲染圆点和检查器文案。 public sealed class PortInfo { public string Name { get; init; } = ""; public string Type { get; init; } = ""; public string Description { get; init; } = ""; public bool Required { get; init; } } /// /// 一种可放到画布上的节点类型。Origin=system 走进程内 Handler;Origin=plugin 走独立进程。 /// public sealed class AgentTypeInfo { public string Type { get; init; } = ""; public string Name { get; init; } = ""; public string Description { get; init; } = ""; public string Origin { get; set; } = "system"; public string Version { get; init; } = ""; public string Folder { get; init; } = ""; public bool Overridden { get; set; } /// /// 进程内实现。系统节点必填;插件节点为 None,走独立进程。 /// public SystemHandler Handler { get; init; } public IReadOnlyList Inputs { get; init; } = []; public IReadOnlyList Outputs { get; init; } = []; public IReadOnlyList Credentials { get; init; } = []; } /// 系统节点绑定到哪个 C# 实现。插件节点 Handler 保持 None。 public enum SystemHandler { None = 0, FileCity, Weather, } /// /// 写死在宿主里的两种系统节点。插件 id 若与 Type 冲突,运行时优先插件进程。 /// public static class AgentCatalog { public static AgentTypeInfo? FindSystem(string type) => SystemNodes.FirstOrDefault(item => item.Type.Equals(type, StringComparison.OrdinalIgnoreCase)); public static IReadOnlyList SystemNodes { get; } = [ new() { Type = "fileCity-system", Name = "FileCityAgent-System", Description = "读取指定文本文件,判断并抽出有效城市名(系统内置实现)。", Origin = "system", Handler = SystemHandler.FileCity, Inputs = [ new PortInfo { Name = "filePath", Type = "string", Description = "本地文件路径,例如 Data/cities.txt", Required = true }, ], Outputs = [ new PortInfo { Name = "hasValidCities", Type = "bool", Description = "是否存在有效城市" }, new PortInfo { Name = "cities", Type = "string[]", Description = "有效城市名列表" }, new PortInfo { Name = "reason", Type = "string", Description = "判断说明" }, new PortInfo { Name = "raw", Type = "string", Description = "Agent 原始文本" }, ], Credentials = [ new PluginCredentialNeed { Name = "llm", Type = "openai-compatible", Required = true, Description = "OpenAI 兼容接口:endpoint + apiKey + model", }, ], }, new() { Type = "weather-system", Name = "WeatherAgent-System", Description = "按城市列表查询天气并汇总(系统内置实现)。", Origin = "system", Handler = SystemHandler.Weather, Inputs = [ new PortInfo { Name = "cities", Type = "string[]", Description = "要查询的城市名列表", Required = true }, ], Outputs = [ new PortInfo { Name = "summary", Type = "string", Description = "天气汇总文本" }, ], Credentials = [ new PluginCredentialNeed { Name = "llm", Type = "openai-compatible", Required = true, Description = "OpenAI 兼容接口:endpoint + apiKey + model", }, ], }, ]; }