Add Luna.Configuration with TOML-based agent and provider config
Implement configuration system with embedded TOML resources for agent and provider definitions, custom IConfigurationSource/Provider for agent and provider options, and DI extension methods. Includes config models for agents, providers, sessions, and Telegram integration.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Luna.Configuration.Services.Providers;
|
||||
|
||||
internal class ProviderOptionsConfigurationProvider(IEnumerable<(string Name, ProviderOptions Options)> providerOptions)
|
||||
: ConfigurationProvider
|
||||
{
|
||||
public override void Load()
|
||||
{
|
||||
foreach (var (name, options) in providerOptions)
|
||||
{
|
||||
var keyPrefix = $"Providers:{name}";
|
||||
|
||||
foreach (var property in options.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
|
||||
{
|
||||
var value = property.GetValue(options);
|
||||
|
||||
if (value is string[] array)
|
||||
{
|
||||
for (var i = 0; i < array.Length; i++)
|
||||
Data[$"{keyPrefix}:{property.Name}:{i}"] = array[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
Data[$"{keyPrefix}:{property.Name}"] = value?.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user