mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-24 09:53:38 +00:00
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
92 lines
3.3 KiB
C#
92 lines
3.3 KiB
C#
using AIStudio.Settings;
|
|
using AIStudio.Tools.ToolCallingSystem;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AIStudio.Components;
|
|
|
|
/// <summary>
|
|
/// Picks the tools of a run as an ordinary form field, next to the settings they belong to.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The counterpart to the tool selection in the footer, which floats above a whole chat or
|
|
/// assistant. Where the tools belong to one specific setting — the instructions of a batch job,
|
|
/// say — they are easier to grasp right there, and a read-only field is the honest way to show
|
|
/// tools somebody else decided on.
|
|
/// </remarks>
|
|
public partial class ToolSelectionField : MSGComponentBase
|
|
{
|
|
[Parameter]
|
|
public AIStudio.Tools.Components Component { get; set; } = AIStudio.Tools.Components.CHAT;
|
|
|
|
[Parameter]
|
|
public HashSet<string> SelectedToolIds { get; set; } = [];
|
|
|
|
[Parameter]
|
|
public EventCallback<HashSet<string>> SelectedToolIdsChanged { get; set; }
|
|
|
|
/// <summary>
|
|
/// Shows the tools without letting the user change them.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// For tools that were decided elsewhere, such as by a document analysis policy. The user
|
|
/// still gets to see what the run will do.
|
|
/// </remarks>
|
|
[Parameter]
|
|
public bool ReadOnly { get; set; }
|
|
|
|
[Parameter]
|
|
public bool Disabled { get; set; }
|
|
|
|
[Parameter]
|
|
public string Label { get; set; } = string.Empty;
|
|
|
|
[Parameter]
|
|
public string Help { get; set; } = string.Empty;
|
|
|
|
[Inject]
|
|
private ToolRegistry ToolRegistry { get; init; } = null!;
|
|
|
|
private List<ConfigurationSelectData<string>> availableTools = [];
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
// Like ToolSelection, the field shows the tools which will actually run, also when the
|
|
// selection is read-only. See ToolSelectionRules.NormalizeSelection:
|
|
this.SelectedToolIds = ToolSelectionRules.NormalizeSelection(this.SelectedToolIds);
|
|
base.OnParametersSet();
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
this.availableTools = (await this.ToolRegistry.GetCatalogAsync(this.Component))
|
|
.Select(x => new ConfigurationSelectData<string>(x.Implementation.GetDisplayName(), x.Definition.Id))
|
|
.ToList();
|
|
|
|
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
private bool IsToolLocked(string toolId) => !this.SettingsManager.IsToolActive(toolId);
|
|
|
|
private async Task OptionChangedAsync(HashSet<string> updatedToolIds)
|
|
{
|
|
this.SelectedToolIds = ToolSelectionRules.NormalizeSelection(updatedToolIds);
|
|
await this.SelectedToolIdsChanged.InvokeAsync(this.SelectedToolIds);
|
|
}
|
|
|
|
protected override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
|
|
{
|
|
switch (triggeredEvent)
|
|
{
|
|
case Event.CONFIGURATION_CHANGED:
|
|
this.availableTools = (await this.ToolRegistry.GetCatalogAsync(this.Component))
|
|
.Select(x => new ConfigurationSelectData<string>(x.Implementation.GetDisplayName(), x.Definition.Id))
|
|
.ToList();
|
|
|
|
await this.InvokeAsync(this.StateHasChanged);
|
|
break;
|
|
}
|
|
}
|
|
}
|