Files
AI-Studio/app/MindWork AI Studio/Components/ManagedToolsWarning.razor.cs
T
Thorsten Sommer c4400c0ff6
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-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 / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
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 }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Added mailboxes as local data sources (#1022)
2026-10-04 12:26:26 +02:00

113 lines
4.5 KiB
C#

using AIStudio.Provider;
using AIStudio.Tools.ToolCallingSystem;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
/// <summary>
/// Says when tools an assistant was told to use cannot reach the selected provider.
/// </summary>
/// <remarks>
/// Whoever named these tools — a document analysis policy, an assistant plugin — did so without
/// knowing which provider the user would pick. The user cannot switch a blocked tool on either,
/// because there is no selection to switch. Saying nothing would let the run quietly proceed
/// without them, which is why this belongs next to the provider selection: choosing another
/// provider is what resolves it.
/// </remarks>
public partial class ManagedToolsWarning : MSGComponentBase
{
[Parameter]
public AIStudio.Tools.Components Component { get; set; } = AIStudio.Tools.Components.CHAT;
/// <summary>
/// The tools of this run, as named by the assistant's own rules.
/// </summary>
[Parameter]
public IReadOnlySet<string> ToolIds { get; set; } = new HashSet<string>();
[Parameter]
public AIStudio.Settings.Provider ProviderSettings { get; set; } = AIStudio.Settings.Provider.NONE;
[Parameter]
public string Class { get; set; } = "mb-3";
[Inject]
private ToolRegistry ToolRegistry { get; init; } = null!;
private IReadOnlyList<ToolCatalogItem> availableTools = [];
/// <summary>
/// Whether this run expects tools while the selected provider cannot call any.
/// </summary>
private bool NeedsToolCallingProvider => this.ToolIds.Count > 0 && this.SettingsManager.AreToolsEnabled() && !this.ProviderSettings.GetToolCallingAvailability().IsAvailable;
/// <summary>
/// The tools of this run whose settings are incomplete, so they cannot run at all.
/// </summary>
/// <remarks>
/// Unlike the confidence case, no provider resolves this: the tool itself is missing something,
/// such as the web search without a server address. Tools an organization switched off are left
/// out, because completing their settings would not bring them back either.
/// </remarks>
private IReadOnlyList<string> ToolsNeedingConfiguration
{
get
{
if (this.ToolIds.Count is 0 || !this.SettingsManager.AreToolsEnabled())
return [];
var collectionIds = this.ToolRegistry.NormalizeSelection(this.ToolIds);
return this.availableTools
.Where(x => collectionIds.Contains(x.Id) && x.IsActive && !x.ConfigurationState.IsConfigured)
.Select(x => x.DisplayName)
.ToList();
}
}
/// <summary>
/// The tools of this run which the selected provider is not trusted enough to receive.
/// </summary>
/// <remarks>
/// Tools switched off in the settings are not counted: choosing another provider would not
/// bring them back, so naming them here would send the user after the wrong fix.
/// </remarks>
private IReadOnlyList<string> ToolsBeyondProviderConfidence
{
get
{
if (this.ToolIds.Count is 0 || !this.SettingsManager.AreToolsEnabled())
return [];
var providerConfidence = this.ProviderSettings == AIStudio.Settings.Provider.NONE
? ConfidenceLevel.NONE
: this.ProviderSettings.UsedLLMProvider.GetConfidence(this.SettingsManager).Level;
var collectionIds = this.ToolRegistry.NormalizeSelection(this.ToolIds);
return this.availableTools
.Where(x => collectionIds.Contains(x.Id) && x.IsActive)
.Where(x => !ToolSelectionRules.IsProviderConfidenceAllowed(providerConfidence, x.MinimumProviderConfidence))
.Select(x => x.DisplayName)
.ToList();
}
}
protected override async Task OnInitializedAsync()
{
this.availableTools = await this.ToolRegistry.GetCatalogAsync(this.Component);
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
await base.OnInitializedAsync();
}
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);
await this.InvokeAsync(this.StateHasChanged);
break;
}
}
}