docs: 为 CLI、网页编排器和插件协议补充学习向注释
在核心类型、图执行器、stdio 插件和前端入口写清职责与对照路径,不改运行行为。
This commit is contained in:
@@ -4,8 +4,13 @@ using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace MAF1.PluginContract;
|
||||
|
||||
/// <summary>
|
||||
/// 进程外插件的 stdio 协议:宿主把 PluginRequest JSON 写入 stdin,插件把输出 JSON 写到 stdout。
|
||||
/// 学习时对照 PluginProcessRunner:那边启动进程、写 stdin、读 stdout。
|
||||
/// </summary>
|
||||
public static class PluginStdio
|
||||
{
|
||||
/// <summary>插件入口第一步:读完 stdin 再干活。宿主写完会关闭 stdin。</summary>
|
||||
public static async Task<PluginRequest> ReadRequestAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
using Stream stdin = Console.OpenStandardInput();
|
||||
@@ -20,6 +25,7 @@ public static class PluginStdio
|
||||
return request ?? new PluginRequest();
|
||||
}
|
||||
|
||||
/// <summary>把 Outputs 写成一行 JSON。不要往 stdout 打日志,日志请走 stderr。</summary>
|
||||
public static async Task WriteOutputsAsync(Dictionary<string, object?> outputs, CancellationToken cancellationToken = default)
|
||||
{
|
||||
string json = JsonSerializer.Serialize(outputs, PluginJson.Options);
|
||||
@@ -27,6 +33,7 @@ public static class PluginStdio
|
||||
await Console.Out.FlushAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>把宿主注入的 LLM 凭据写进环境变量,这样 AgentFactory.Load 能读到 Key。</summary>
|
||||
public static void ApplyCredentialsToEnvironment(IReadOnlyDictionary<string, PluginCredentialPayload> credentials)
|
||||
{
|
||||
foreach (KeyValuePair<string, PluginCredentialPayload> pair in credentials)
|
||||
@@ -49,6 +56,9 @@ public static class PluginStdio
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插件自己读天气等配置时用。优先 MAF1_CONTENT_ROOT(宿主 exe 目录),否则向上找 appsettings.json。
|
||||
/// </summary>
|
||||
public static IConfiguration LoadHostConfiguration()
|
||||
{
|
||||
string contentRoot = Environment.GetEnvironmentVariable("MAF1_CONTENT_ROOT");
|
||||
|
||||
Reference in New Issue
Block a user