feat: 将插件 stdin 协议定为 v1,并按声明注入凭据
进程外插件改为只读环境变量和自身配置,避免读宿主 appsettings;宿主按 plugin.json 声明注入 LLM / OpenWeather 等凭据。
This commit is contained in:
@@ -12,6 +12,10 @@ public sealed class PluginManifest
|
||||
public string Name { get; set; } = "";
|
||||
public string Description { get; set; } = "";
|
||||
public string Version { get; set; } = "1.0.0";
|
||||
|
||||
/// <summary>stdin/stdout 协议主版本。缺省或 0 视为 1。宿主拒绝大于 <see cref="PluginProtocol.Current"/> 的值。</summary>
|
||||
public int ProtocolVersion { get; set; }
|
||||
|
||||
public PluginLaunch Launch { get; set; } = new();
|
||||
public int TimeoutSeconds { get; set; }
|
||||
public Dictionary<string, string> Env { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
@@ -45,9 +49,51 @@ public sealed class PluginCredentialNeed
|
||||
public string Description { get; set; } = "";
|
||||
}
|
||||
|
||||
/// <summary>stdin/stdout JSON 协议版本。缺省字段按 1 处理,便于旧 plugin.json 继续用。</summary>
|
||||
public static class PluginProtocol
|
||||
{
|
||||
public const int Current = 1;
|
||||
|
||||
public static int Normalize(int version) => version <= 0 ? 1 : version;
|
||||
|
||||
public static bool IsSupported(int version)
|
||||
{
|
||||
int normalized = Normalize(version);
|
||||
return normalized >= 1 && normalized <= Current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>凭据 type 约定。宿主按类型注入环境变量,未知类型只传 stdin Extra。</summary>
|
||||
public static class PluginCredentialTypes
|
||||
{
|
||||
public const string OpenAiCompatible = "openai-compatible";
|
||||
public const string Llm = "llm";
|
||||
public const string OpenWeather = "openweather";
|
||||
|
||||
public static bool IsLlm(string? type)
|
||||
=> type is OpenAiCompatible or Llm
|
||||
|| string.Equals(type, "openai-compatible", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(type, "llm", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public static bool IsOpenWeather(string? type)
|
||||
=> string.Equals(type, OpenWeather, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public static bool Matches(string? declaredType, string? recordType)
|
||||
{
|
||||
if (IsLlm(declaredType) && IsLlm(recordType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return string.Equals(declaredType, recordType, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>宿主写入插件 stdin 的整包请求:业务输入 + 凭据。</summary>
|
||||
public sealed class PluginRequest
|
||||
{
|
||||
public int ProtocolVersion { get; set; } = PluginProtocol.Current;
|
||||
|
||||
public Dictionary<string, object?> Inputs { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
[JsonPropertyName("credentials")]
|
||||
|
||||
Reference in New Issue
Block a user