2026-04-09 13:37:53 +00:00
|
|
|
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;
|
2026-04-10 08:43:13 +00:00
|
|
|
private IToolImplementation? implementation;
|
2026-04-09 13:37:53 +00:00
|
|
|
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)
|
2026-04-10 08:43:13 +00:00
|
|
|
{
|
|
|
|
|
this.implementation = this.ToolRegistry.GetImplementation(this.toolDefinition.ImplementationKey);
|
2026-04-09 13:37:53 +00:00
|
|
|
this.values = await this.ToolSettingsService.GetSettingsAsync(this.toolDefinition);
|
2026-04-10 08:43:13 +00:00
|
|
|
}
|
2026-04-09 13:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetValue(string fieldName) => this.values.GetValueOrDefault(fieldName, string.Empty);
|
|
|
|
|
|
2026-04-10 08:43:13 +00:00
|
|
|
private string GetFieldLabel(string fieldName, ToolSettingsFieldDefinition fieldDefinition) =>
|
|
|
|
|
this.implementation?.GetSettingsFieldLabel(fieldName, fieldDefinition) ?? fieldDefinition.Title;
|
|
|
|
|
|
|
|
|
|
private string GetFieldDescription(string fieldName, ToolSettingsFieldDefinition fieldDefinition) =>
|
|
|
|
|
this.implementation?.GetSettingsFieldDescription(fieldName, fieldDefinition) ?? fieldDefinition.Description;
|
|
|
|
|
|
2026-04-09 13:37:53 +00:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|