using Avalonia.Controls; using System.Collections.Generic; using System.Text.Json; using VisionAsist.SDK; namespace ModuleWeather; public class WeatherModule : IModule { public string Name => "WeatherModule"; public string Description => "Модуль для получения данных о погоде"; public void Settings(object[] args) { // args[0] — это родительское окно из Ядра var parentWindow = args != null && args.Length > 0 ? args[0] as Window : null; var win = new Window { Title = "Настройки", Content = new WeatherView(), // Вставляем наш контрол Width = 350, Height = 250, WindowStartupLocation = WindowStartupLocation.CenterOwner }; if (parentWindow != null) win.Show(parentWindow); else win.Show(); } public List GetTools() { return new List { new ToolDefinition { Name = "get_weather", Description = "Получает текущую погоду для указанного города", ParametersSchema = JsonSerializer.Serialize(new { type = "object", properties = new { city = new { type = "string", description = "Название города на русском языке" } }, required = new[] { "city" } }) }, new ToolDefinition { Name = "get_qnh", Description = "Получает текущее давление над уровнем моря для указанного города", ParametersSchema = JsonSerializer.Serialize(new { type = "object", properties = new { city = new { type = "string", description = "Название города на русском языке" } }, required = new[] { "city" } }) } }; } public string Execute(string toolName, string argumentsJson) { if (toolName == "get_weather") { try { var args = JsonDocument.Parse(argumentsJson); if (args.RootElement.TryGetProperty("city", out var cityElement)) { string city = cityElement.GetString() ?? "неизвестном городе"; return $"Погода в {city} сейчас отличная, солнечно, +25 градусов!"; } } catch { return "Ошибка при обработке аргументов погоды"; } } else if (toolName == "get_qnh") { try { var args = JsonDocument.Parse(argumentsJson); if (args.RootElement.TryGetProperty("city", out var cityElement)) { string city = cityElement.GetString() ?? "неизвестном городе"; return $"Давление над уровнем моря в {city} сейчас 1020 мм рт. ст!"; } } catch (Exception e) { Console.WriteLine(e); throw; } } return "Инструмент не найден"; } }