The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(settings): correct role assignment in search panel
Steven Enamakel30e34e972d1a
diff --git a/app/src/components/settings/panels/SearchPanelRoles.tsx b/app/src/components/settings/panels/SearchPanelRoles.tsxnew file mode 100644index 0000000000..a26147ebcc--- /dev/null+++ b/app/src/components/settings/panels/SearchPanelRoles.tsx@@ -0,0 +1,196 @@+import { ChevronDownIcon, ChevronUpIcon, PlusIcon, XIcon } from 'lucide-react';++import type {+ SearchProviderInfo,+ SearchRole,+ SearchSettings,+ SearchSettingsUpdate,+} from '../../../utils/tauriCommands/config';+import Badge from '../../ui/Badge';+import Button from '../../ui/Button';++type Translate = (key: string) => string;++/** The roles the core exposes, in display order. */+export const SEARCH_ROLES: readonly SearchRole[] = ['search', 'answer', 'contents'];++const withProvider = (text: string, provider: string) => text.replace('{provider}', provider);++function roleTitle(role: SearchRole, t: Translate): string {+ if (role === 'answer') return t('settings.search.roleAnswer');+ if (role === 'contents') return t('settings.search.roleContents');+ return t('settings.search.roleSearch');+}++function roleDescription(role: SearchRole, t: Translate): string {+ if (role === 'answer') return t('settings.search.roleAnswerDesc');+ if (role === 'contents') return t('settings.search.roleContentsDesc');+ return t('settings.search.roleSearchDesc');+}++/** Move `order[index]` by `delta` places, returning a new array. */+export function moveProvider(order: string[], index: number, delta: -1 | 1): string[] {+ const target = index + delta;+ if (target < 0 || target >= order.length) return order;+ const next = [...order];+ [next[index], next[target]] = [next[target], next[index]];+ return next;+}++interface RowProps {+ role: SearchRole;+ settings: SearchSettings;+ saving: boolean;+ persist: (update: SearchSettingsUpdate) => Promise<boolean>;+ t: Translate;+}++/**+ * One role: its explanation, which provider serves it now, and the ordered+ * provider list the user can reorder, trim and reset. The list is built from+ * `settings.roles[role]`; providers that can serve the role but are not in the+ * list are offered as "add" buttons.+ */+const SearchRoleRow = ({ role, settings, saving, persist, t }: RowProps) => {+ const byId = new Map<string, SearchProviderInfo>(settings.providers.map(p => [p.id, p]));+ const order = (settings.roles[role] ?? []).filter(id => byId.get(id)?.roles.includes(role));+ const effective = settings.effective_roles[role] ?? [];+ const serving = effective[0] ? byId.get(effective[0]) : undefined;+ const addable = settings.providers.filter(p => p.roles.includes(role) && !order.includes(p.id));+ const testId = `search-role-${role}`;++ const saveOrder = (next: string[]) => void persist({ roles: { [role]: next } });++ return (+ <div data-testid={testId} className="rounded-xl border border-line bg-surface p-3 space-y-2">+ <div className="flex items-start justify-between gap-2">+ <div className="min-w-0">+ <p className="text-sm font-medium text-content">{roleTitle(role, t)}</p>+ <p className="text-xs text-content-muted">{roleDescription(role, t)}</p>+ </div>+ <Button+ type="button"+ variant="tertiary"+ size="xs"+ data-testid={`${testId}-reset`}+ disabled={saving}+ onClick={() => saveOrder([])}>+ {t('settings.search.roleReset')}+ </Button>+ </div>++ <p+ data-testid={`${testId}-serving`}+ className={+ serving+ ? 'text-[11px] text-content-secondary'+ : 'text-[11px] text-amber-700 dark:text-amber-300'+ }>+ {serving+ ? withProvider(t('settings.search.roleServedBy'), serving.label)+ : t('settings.search.roleNoProvider')}+ </p>++ <ol className="divide-y divide-line-subtle rounded-lg border border-line-subtle">+ {order.map((id, index) => {+ const provider = byId.get(id);+ if (!provider) return null;+ const usable = effective.includes(id);+ return (+ <li+ key={id}+ data-testid={`${testId}-provider-${id}`}+ data-serving={serving?.id === id ? 'true' : undefined}+ className="flex items-center gap-2 px-2.5 py-1.5">+ <span className="w-4 text-[11px] tabular-nums text-content-muted">{index + 1}</span>+ <span className="flex-1 min-w-0 truncate text-xs text-content">{provider.label}</span>+ {!usable && <Badge variant="neutral">{t('settings.search.roleUnavailable')}</Badge>}+ <Button+ type="button"+ variant="tertiary"+ size="xs"+ iconOnly+ aria-label={withProvider(t('settings.search.roleMoveUp'), provider.label)}+ disabled={saving || index === 0}+ onClick={() => saveOrder(moveProvider(order, index, -1))}>+ <ChevronUpIcon className="size-3.5" aria-hidden="true" />+ </Button>+ <Button+ type="button"+ variant="tertiary"+ size="xs"+ iconOnly+ aria-label={withProvider(t('settings.search.roleMoveDown'), provider.label)}+ disabled={saving || index === order.length - 1}+ onClick={() => saveOrder(moveProvider(order, index, 1))}>+ <ChevronDownIcon className="size-3.5" aria-hidden="true" />+ </Button>+ <Button+ type="button"+ variant="tertiary"+ tone="danger"+ size="xs"+ iconOnly+ aria-label={withProvider(t('settings.search.roleRemove'), provider.label)}+ disabled={saving || order.length <= 1}+ onClick={() => saveOrder(order.filter(other => other !== id))}>+ <XIcon className="size-3.5" aria-hidden="true" />+ </Button>+ </li>+ );+ })}+ </ol>++ {addable.length > 0 && (+ <div className="flex flex-wrap gap-1.5">+ {addable.map(provider => (+ <Button+ key={provider.id}+ type="button"+ variant="secondary"+ size="xs"+ data-testid={`${testId}-add-${provider.id}`}+ disabled={saving}+ onClick={() => saveOrder([...order, provider.id])}>+ <PlusIcon className="size-3" aria-hidden="true" />+ {withProvider(t('settings.search.roleAdd'), provider.label)}+ </Button>+ ))}+ </div>+ )}+ </div>+ );+};++interface Props {+ settings: SearchSettings;+ saving: boolean;+ persist: (update: SearchSettingsUpdate) => Promise<boolean>;+ t: Translate;+}++/** The Roles section: one row per capability role (Search, Answer, Contents). */+const SearchPanelRoles = ({ settings, saving, persist, t }: Props) => (+ <section className="space-y-2" aria-labelledby="search-roles-heading">+ <div>+ <h3 id="search-roles-heading" className="text-xs font-semibold text-content-secondary">+ {t('settings.search.rolesTitle')}+ </h3>+ <p className="text-[11px] text-content-muted leading-relaxed">+ {t('settings.search.rolesDesc')}+ </p>+ </div>+ {SEARCH_ROLES.map(role => (+ <SearchRoleRow+ key={role}+ role={role}+ settings={settings}+ saving={saving}+ persist={persist}+ t={t}+ />+ ))}+ </section>+);++export default SearchPanelRoles;