webui: fix tool selector toggle/counter, key tools by stable identity (#24065)

* webui: fix tool selector toggle/counter, key tools by stable identity

Key the disabled set, counts and toggles by a stable per-tool key
instead of bare function name, deduped from one canonical list. Per-tool
checkboxes become presentational (single row handler, no nested button),
category checkboxes drop the tristate (n/total carries partial). One
getEnabledToolsForLLM keeps normalized MCP schemas and dedupes by name.

* ui: use SvelteSet and SvelteMap for local tool collections to satisfy svelte/prefer-svelte-reactivity
This commit is contained in:
Pascal
2026-06-04 13:09:49 +02:00
committed by GitHub
parent 4d742877b2
commit 4586479852
7 changed files with 203 additions and 240 deletions
@@ -62,13 +62,11 @@
<span class="w-20 shrink-0 text-center">Always allow</span>
</div>
{#each group.tools as tool (tool.function.name)}
{@const toolName = tool.function.name}
{@const isEnabled = toolsStore.isToolEnabled(toolName)}
{@const permissionKey = toolsStore.getPermissionKey(toolName)}
{@const isAlwaysAllowed = permissionKey
? permissionsStore.hasTool(permissionKey)
: false}
{#each group.tools as entry (entry.key)}
{@const toolName = entry.definition.function.name}
{@const isEnabled = toolsStore.isToolEnabled(entry.key)}
{@const permissionKey = entry.key}
{@const isAlwaysAllowed = permissionsStore.hasTool(permissionKey)}
<div class="flex items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50">
<TruncatedText text={toolName} class="flex-1" showTooltip={true} />
@@ -76,7 +74,7 @@
<div class="flex w-16 shrink-0 justify-center">
<Checkbox
checked={isEnabled}
onCheckedChange={() => toolsStore.toggleTool(toolName)}
onCheckedChange={() => toolsStore.toggleTool(entry.key)}
class="h-4 w-4"
/>
</div>
@@ -86,9 +84,9 @@
checked={isAlwaysAllowed}
onCheckedChange={() => {
if (isAlwaysAllowed) {
permissionsStore.revokeTool(permissionKey!);
permissionsStore.revokeTool(permissionKey);
} else {
permissionsStore.allowTool(permissionKey!);
permissionsStore.allowTool(permissionKey);
}
}}
class="h-4 w-4"