2025-03-12 10:31:01 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2025-03-12 17:05:27 +00:00
|
|
|
|
2025-03-12 10:31:01 +00:00
|
|
|
using AIStudio.Settings;
|
2025-03-16 13:03:43 +00:00
|
|
|
using AIStudio.Tools.Services;
|
2025-03-12 10:31:01 +00:00
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
namespace AIStudio.Dialogs.Settings;
|
|
|
|
|
2025-03-16 20:05:33 +00:00
|
|
|
public abstract class SettingsDialogBase : ComponentBase, IMessageBusReceiver, IDisposable
|
2025-03-12 10:31:01 +00:00
|
|
|
{
|
|
|
|
[CascadingParameter]
|
2025-03-12 18:12:56 +00:00
|
|
|
protected IMudDialogInstance MudDialog { get; set; } = null!;
|
2025-03-12 10:31:01 +00:00
|
|
|
|
|
|
|
[Inject]
|
|
|
|
protected SettingsManager SettingsManager { get; init; } = null!;
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
protected IDialogService DialogService { get; init; } = null!;
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
protected MessageBus MessageBus { get; init; } = null!;
|
|
|
|
|
2025-03-16 13:03:43 +00:00
|
|
|
[Inject]
|
|
|
|
protected RustService RustService { get; init; } = null!;
|
|
|
|
|
|
|
|
protected readonly List<ConfigurationSelectData<string>> availableLLMProviders = new();
|
|
|
|
protected readonly List<ConfigurationSelectData<string>> availableEmbeddingProviders = new();
|
2025-03-12 10:31:01 +00:00
|
|
|
|
|
|
|
#region Overrides of ComponentBase
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2025-03-16 20:05:33 +00:00
|
|
|
protected override async Task OnInitializedAsync()
|
2025-03-12 10:31:01 +00:00
|
|
|
{
|
2025-03-16 20:05:33 +00:00
|
|
|
// Register this component with the message bus:
|
|
|
|
this.MessageBus.RegisterComponent(this);
|
|
|
|
this.MessageBus.ApplyFilters(this, [], [ Event.CONFIGURATION_CHANGED ]);
|
|
|
|
|
2025-03-12 10:31:01 +00:00
|
|
|
this.UpdateProviders();
|
2025-03-16 13:03:43 +00:00
|
|
|
this.UpdateEmbeddingProviders();
|
2025-03-16 20:05:33 +00:00
|
|
|
await base.OnInitializedAsync();
|
2025-03-12 10:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
protected void Close() => this.MudDialog.Cancel();
|
|
|
|
|
|
|
|
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
|
|
|
|
private void UpdateProviders()
|
|
|
|
{
|
2025-03-16 13:03:43 +00:00
|
|
|
this.availableLLMProviders.Clear();
|
2025-03-12 10:31:01 +00:00
|
|
|
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
|
2025-03-16 13:03:43 +00:00
|
|
|
this.availableLLMProviders.Add(new (provider.InstanceName, provider.Id));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateEmbeddingProviders()
|
|
|
|
{
|
|
|
|
this.availableEmbeddingProviders.Clear();
|
|
|
|
foreach (var provider in this.SettingsManager.ConfigurationData.EmbeddingProviders)
|
|
|
|
this.availableEmbeddingProviders.Add(new (provider.Name, provider.Id));
|
2025-03-12 10:31:01 +00:00
|
|
|
}
|
2025-03-16 20:05:33 +00:00
|
|
|
|
|
|
|
#region Implementation of IMessageBusReceiver
|
|
|
|
|
|
|
|
public string ComponentName => nameof(Settings);
|
|
|
|
|
|
|
|
public Task ProcessMessage<TMsg>(ComponentBase? sendingComponent, Event triggeredEvent, TMsg? data)
|
|
|
|
{
|
|
|
|
switch (triggeredEvent)
|
|
|
|
{
|
|
|
|
case Event.CONFIGURATION_CHANGED:
|
|
|
|
this.StateHasChanged();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
|
|
|
{
|
|
|
|
return Task.FromResult<TResult?>(default);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Implementation of IDisposable
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
this.MessageBus.Unregister(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2025-03-12 10:31:01 +00:00
|
|
|
}
|