using Microsoft.Extensions.DependencyInjection; namespace Luna.Configuration.Extensions; public static class ServiceCollectionExtensions { extension(IServiceCollection services) { public IServiceCollection AddProviderOptions(string? name) { services.AddOptions(name) .BindConfiguration($"Providers:{name}") .Validate( options => !string.IsNullOrWhiteSpace(options.ApiKey), $"{name} options missing ApiKey") .Validate( options => !string.IsNullOrWhiteSpace(options.ApiUrl), $"{name} options missing ApiUrl") .Validate( options => options.Models is { Length: > 0 }, $"{name} options missing Model definitions") .ValidateOnStart(); return services; } public IServiceCollection AddAgentOptions(string? name) { services.AddOptions(name) .BindConfiguration($"Agents:{name}") .Validate( options => !string.IsNullOrWhiteSpace(options.Provider), $"{name} options missing Provider") .Validate( options => !string.IsNullOrWhiteSpace(options.ModelId), $"{name} options missing ModelId") .Validate( options => !string.IsNullOrWhiteSpace(options.Instructions), $"{name} options missing Instructions") .Validate( options => options.MaxContextTokens > 0, $"{name} options must have MaxContextTokens greater than 0") .ValidateOnStart(); return services; } public IServiceCollection AddSessionOptions() { services.AddOptions() .BindConfiguration("Session") .Validate( options => options.ContextTokenThreshold > 0, "Session options must have ContextTokenThreshold greater than 0") .ValidateOnStart(); return services; } public IServiceCollection AddTelegramOptions() { services.AddOptions() .BindConfiguration("Channels:Telegram") .Validate( options => !string.IsNullOrWhiteSpace(options.BotToken), "Telegram options missing BotToken") .ValidateOnStart(); return services; } } }