Files
MAF1/MAF1.Web/Web/AgentCatalog.cs
T
admin777 950d09ddb0 docs: 为 CLI、网页编排器和插件协议补充学习向注释
在核心类型、图执行器、stdio 插件和前端入口写清职责与对照路径,不改运行行为。
2026-08-28 11:51:48 +08:00

112 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 走进程内 HandlerOrigin=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",
},
],
},
];
}