@using AIStudio.Tools.ToolCallingSystem @inherits MSGComponentBase
@T("Tool Selection") @T("Tools allow the LLM to perform targeted additional actions such as web searches or reading web pages.") @if (!this.SupportsTools) { @this.UnsupportedToolsMessage } else if (this.Disabled) { @T("Tool changes are locked while a response is running. Your current selection is shown below and applies again from the next message once the run is finished.") } else if (this.catalog.Count == 0) { @T("No tools are available in this context.") } @if (this.SupportsTools && this.catalog.Count > 0) { var itemsShownFirst = this.GetItemsShownFirst(); var unavailableItems = this.GetUnavailableItems(); @* Each list has a wrapper of its own, which gives its rows their compact padding: the rows share their parent with nothing else, neither the introduction nor the button between both lists. *@ @if (itemsShownFirst.Count > 0) {
@foreach (var item in itemsShownFirst) { @this.RenderRow(item) }
} else { @T("No tool can be selected right now.") } @if (unavailableItems.Count > 0) { @this.GetUnavailableToolsButtonText(unavailableItems)
@foreach (var item in unavailableItems) { @this.RenderRow(item) }
@T("You can switch off tools you never need in the app settings, under Tool Settings. They then no longer appear here.")
} }
@T("Close")
@code { /// /// One row of the selection, in either list. /// /// /// Both lists show the same row, so it is written once. It stays in this component, which keeps /// the translations of its texts: a component of its own would give each of them a new key. /// private RenderFragment RenderRow(ToolCatalogItem item) => @
@* Everything but the settings button switches the tool, so aiming for the small switch is optional. The button spans that part of the row, which keeps the settings button outside of it without any event plumbing. *@ @* A checkbox rather than a switch, because this row is one entry of a set the user picks from, not a setting of its own -- the same question the data source selection next to it asks, and it should not look like a different one. The checkbox only shows the state; the surrounding button does the switching. It therefore takes no pointer events at all: its label reaches past the visible box and would otherwise swallow the clicks landing in that strip. *@ @if (!item.IsActive) { } @item.DisplayName @if (this.GetWarningText(item) is var warningText && !string.IsNullOrWhiteSpace(warningText)) { @* A caption renders as an inline span by default, and an inline element cannot be justified. The div makes it a block of its own. *@ @warningText }
; }