2026-09-11 10:46:52 +08:00
|
|
|
// 进程外 Weather 插件。stdio 适配 + 复用 MAF1.Core 的 WeatherAgent。
|
|
|
|
|
// LLM / OpenWeather Key 只来自宿主注入的环境变量;天气站点配置读本插件目录的 appsettings.json。
|
2026-08-26 18:06:02 +08:00
|
|
|
using MAF1.Agents.Weather;
|
|
|
|
|
using MAF1.PluginContract;
|
|
|
|
|
using MAF1.Tools;
|
|
|
|
|
using MAF1.Utils;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
|
|
|
|
PluginRequest request = await PluginStdio.ReadRequestAsync();
|
|
|
|
|
PluginStdio.ApplyCredentialsToEnvironment(request.Credentials);
|
|
|
|
|
|
2026-09-11 10:46:52 +08:00
|
|
|
IConfiguration config = PluginStdio.LoadPluginConfiguration();
|
2026-08-26 18:06:02 +08:00
|
|
|
AgentFactory factory = new(AgentFactory.Load(config));
|
|
|
|
|
WeatherOptions weatherOptions = config.GetSection("Weather").Get<WeatherOptions>() ?? new WeatherOptions();
|
2026-09-11 10:46:52 +08:00
|
|
|
string? openWeatherKey = Environment.GetEnvironmentVariable("OPENWEATHER_API_KEY");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(openWeatherKey))
|
|
|
|
|
{
|
|
|
|
|
weatherOptions.OpenWeather.ApiKey = openWeatherKey;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-26 18:06:02 +08:00
|
|
|
using HttpClient http = WeatherTools.CreateHttpClient();
|
|
|
|
|
var result = await WeatherAgent.RunAsync(
|
|
|
|
|
WeatherAgent.Create(factory, new WeatherTools(weatherOptions, http)),
|
|
|
|
|
request.Inputs);
|
|
|
|
|
await PluginStdio.WriteOutputsAsync(result.Outputs);
|
|
|
|
|
return 0;
|