AI-Studio/app/MindWork AI Studio/Dialogs/Settings/ToolSettingsDialog.razor.cs

42 lines
1.3 KiB
C#
Raw Normal View History

using AIStudio.Tools.ToolCallingSystem;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Dialogs.Settings;
public partial class ToolSettingsDialog : SettingsDialogBase
{
[Parameter]
public string ToolId { get; set; } = string.Empty;
[Inject]
private ToolRegistry ToolRegistry { get; init; } = null!;
[Inject]
private ToolSettingsService ToolSettingsService { get; init; } = null!;
private ToolDefinition? toolDefinition;
private Dictionary<string, string> values = new(StringComparer.Ordinal);
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
this.toolDefinition = this.ToolRegistry.GetDefinition(this.ToolId);
if (this.toolDefinition is not null)
this.values = await this.ToolSettingsService.GetSettingsAsync(this.toolDefinition);
}
private string GetValue(string fieldName) => this.values.GetValueOrDefault(fieldName, string.Empty);
private void UpdateValue(string fieldName, string? value) => this.values[fieldName] = value ?? string.Empty;
private async Task Save()
{
if (this.toolDefinition is null)
return;
await this.ToolSettingsService.SaveSettingsAsync(this.toolDefinition, this.values);
this.MudDialog.Close();
}
}