112 lines
4.0 KiB
C#
112 lines
4.0 KiB
C#
using MAF1.PluginContract;
|
||
|
||
namespace MAF1.Web;
|
||
|
||
/// <summary>画布上一个端口的元数据,前端用来渲染圆点和检查器文案。</summary>
|
||
public sealed class PortInfo
|
||
{
|
||
public string Name { get; init; } = "";
|
||
public string Type { get; init; } = "";
|
||
public string Description { get; init; } = "";
|
||
public bool Required { get; init; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 一种可放到画布上的节点类型。Origin=system 走进程内 Handler;Origin=plugin 走独立进程。
|
||
/// </summary>
|
||
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; }
|
||
|
||
/// <summary>
|
||
/// 进程内实现。系统节点必填;插件节点为 None,走独立进程。
|
||
/// </summary>
|
||
public SystemHandler Handler { get; init; }
|
||
|
||
public IReadOnlyList<PortInfo> Inputs { get; init; } = [];
|
||
public IReadOnlyList<PortInfo> Outputs { get; init; } = [];
|
||
public IReadOnlyList<PluginCredentialNeed> Credentials { get; init; } = [];
|
||
}
|
||
|
||
/// <summary>系统节点绑定到哪个 C# 实现。插件节点 Handler 保持 None。</summary>
|
||
public enum SystemHandler
|
||
{
|
||
None = 0,
|
||
FileCity,
|
||
Weather,
|
||
}
|
||
|
||
/// <summary>
|
||
/// 写死在宿主里的两种系统节点。插件 id 若与 Type 冲突,运行时优先插件进程。
|
||
/// </summary>
|
||
public static class AgentCatalog
|
||
{
|
||
public static AgentTypeInfo? FindSystem(string type)
|
||
=> SystemNodes.FirstOrDefault(item => item.Type.Equals(type, StringComparison.OrdinalIgnoreCase));
|
||
|
||
public static IReadOnlyList<AgentTypeInfo> 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",
|
||
},
|
||
],
|
||
},
|
||
];
|
||
}
|