Skip to content

Build and run agents you can see, understand and trust.

fix(ui): distinguish credentials by name in TTS and fallback model selectors (#2169)

qbcb504127f23d2
diff --git a/examples/web_ui/frontend/src/components/popover/ModelParametersPopover.tsx b/examples/web_ui/frontend/src/components/popover/ModelParametersPopover.tsx
index 4b99360cc..7c5fabe49 100644
--- a/examples/web_ui/frontend/src/components/popover/ModelParametersPopover.tsx
+++ b/examples/web_ui/frontend/src/components/popover/ModelParametersPopover.tsx
@@ -1,14 +1,22 @@
-import { ChevronDown, SlidersHorizontal } from 'lucide-react';
+import { Check, ChevronDown, SlidersHorizontal } from 'lucide-react';
import { useCallback, useEffect, useState } from 'react';
-import type { ChatModelConfig, ModelCard, TTSModelCard, TTSModelConfig } from '@/api';
+import type {
+ ChatModelConfig,
+ CredentialView,
+ ModelCard,
+ TTSModelCard,
+ TTSModelConfig,
+} from '@/api';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
+ DropdownMenuGroup,
DropdownMenuLabel,
+ DropdownMenuPortal,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
@@ -24,6 +32,8 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip
import { useAvailableModels } from '@/hooks/useAvailableModels';
import { useAvailableTTSModels } from '@/hooks/useAvailableTTSModels';
import { useTranslation } from '@/i18n/useI18n';
+import { cn } from '@/lib/utils';
+import { credentialLabel } from '@/utils/common';
interface ParameterProperty {
type?: string;
@@ -68,6 +78,17 @@ function resolveType(prop: ParameterProperty): ResolvedType {
return { type: 'string', enumValues: null };
}
+/** Extract default values from a TTS model card's parameter schema. */
+function extractDefaults(schema: ParameterSchema | undefined): Record<string, unknown> {
+ const defaults: Record<string, unknown> = {};
+ if (schema?.properties) {
+ for (const [k, p] of Object.entries(schema.properties)) {
+ if (p.default !== undefined) defaults[k] = p.default;
+ }
+ }
+ return defaults;
+}
+
// ---------------------------------------------------------------------------
// Field components
// ---------------------------------------------------------------------------
@@ -273,7 +294,15 @@ export function ModelParametersPopover({
};
const disabled = locked || !selectedModel;
- const hasFallbackOptions = Object.keys(groups).length > 0;
+ // Credentials whose model list failed to load come back with an empty
+ // `models` array; drop them so they don't render empty submenus
+ const fallbackGroups = Object.entries(groups)
+ .map(([type, items]) => [type, items.filter((i) => i.models.length > 0)] as const)
+ .filter(([, usable]) => usable.length > 0);
+ const ttsGroupEntries = Object.entries(ttsGroups)
+ .map(([type, items]) => [type, items.filter((i) => i.models.length > 0)] as const)
+ .filter(([, usable]) => usable.length > 0);
+ const hasFallbackOptions = fallbackGroups.length > 0;
return (
<DropdownMenu>
@@ -301,41 +330,84 @@ export function ModelParametersPopover({
<p>{t('llm-select.empty.title')}</p>
</div>
) : (
- Object.entries(groups).map(([type, items], idx) => (
- <div key={type}>
- {idx > 0 && <DropdownMenuSeparator />}
- <DropdownMenuLabel>
- {type.replace(/_credential$/, '')}
- </DropdownMenuLabel>
- {items.flatMap(({ credential, models }) =>
- models.map((m) => {
- const isSelected =
- selectedFallbackModel?.credential_id ===
- credential.id &&
- selectedFallbackModel?.model === m.name;
- return (
- <DropdownMenuCheckboxItem
- key={`${credential.id}-${m.name}`}
- checked={isSelected}
- onCheckedChange={(checked) => {
- if (checked) {
- handleSelectFallback(
- type,
- credential.id,
+ fallbackGroups.map(([type, usable], idx) => {
+ const isSingle = usable.length === 1;
+
+ const renderFallbackItems = (
+ credential: CredentialView,
+ models: ModelCard[],
+ ) =>
+ models.map((m) => {
+ const isSelected =
+ selectedFallbackModel?.credential_id ===
+ credential.id &&
+ selectedFallbackModel?.model === m.name;
+ return (
+ <DropdownMenuCheckboxItem
+ key={`${credential.id}-${m.name}`}
+ checked={isSelected}
+ onCheckedChange={(checked) => {
+ if (checked) {
+ handleSelectFallback(
+ type,
+ credential.id,
+ m.name,
+ );
+ } else {
+ onFallbackChange(null);
+ }
+ }}
+ >
+ {m.label}
+ </DropdownMenuCheckboxItem>
+ );
+ });
+
+ return (
+ <DropdownMenuGroup key={type}>
+ {idx > 0 && <DropdownMenuSeparator />}
+ <DropdownMenuLabel>
+ {type.replace(/_credential$/, '')}
+ </DropdownMenuLabel>
+ {isSingle
+ ? renderFallbackItems(
+ usable[0].credential,
+ usable[0].models,
+ )
+ : usable.map(({ credential, models }) => {
+ const hasSelected = models.some(
+ (m) =>
+ selectedFallbackModel?.credential_id ===
+ credential.id &&
+ selectedFallbackModel?.model ===
m.name,
- );
- } else {
- onFallbackChange(null);
- }
- }}
- >
- {m.label}
- </DropdownMenuCheckboxItem>
- );
- }),
- )}
- </div>
- ))
+ );
+ return (
+ <DropdownMenuSub key={credential.id}>
+ <DropdownMenuSubTrigger>
+ <Check
+ className={cn(
+ 'size-4 mr-1.5 shrink-0',
+ !hasSelected &&
+ 'invisible',
+ )}
+ />
+ {credentialLabel(credential)}
+ </DropdownMenuSubTrigger>
+ <DropdownMenuPortal>
+ <DropdownMenuSubContent className="max-h-60 overflow-y-auto">
+ {renderFallbackItems(
+ credential,
+ models,
+ )}
+ </DropdownMenuSubContent>
+ </DropdownMenuPortal>
+ </DropdownMenuSub>
+ );
+ })}
+ </DropdownMenuGroup>
+ );
+ })
)}
<DropdownMenuSeparator />
<DropdownMenuCheckboxItem
@@ -426,69 +498,98 @@ export function ModelParametersPopover({
<span className="truncate">{t('model-parameters.ttsLabel')}</span>
</DropdownMenuSubTrigger>
<DropdownMenuSubContent className="max-h-96 overflow-y-auto">
- {Object.keys(ttsGroups).length === 0 ? (
+ {ttsGroupEntries.length === 0 ? (
<div className="px-2 py-3 text-center text-sm text-muted-foreground">
<p>{t('model-parameters.ttsEmpty')}</p>
</div>
) : (
- Object.entries(ttsGroups).map(([type, items], idx) => (
- <div key={type}>
- {idx > 0 && <DropdownMenuSeparator />}
- <DropdownMenuLabel>
- {type.replace(/_credential$/, '')}
- </DropdownMenuLabel>
- {items.flatMap(({ credential, models }) =>
- models.map((m) => {
- const isSelected =
- selectedTTSModel?.credential_id ===
- credential.id &&
- selectedTTSModel?.model === m.name;
- return (
- <DropdownMenuCheckboxItem
- key={`${credential.id}-${m.name}`}
- checked={isSelected}
- onSelect={(e) => e.preventDefault()}
- onCheckedChange={(checked) => {
- if (!checked) return;
- const schema = m.parameter_schema as
- | ParameterSchema
- | undefined;
- const defaults: Record<
- string,
- unknown
- > = {};
- if (schema?.properties) {
- for (const [k, p] of Object.entries(
- schema.properties,
- )) {
- if (p.default !== undefined) {
- defaults[k] = p.default;
- }
- }
- }
- onTTSChange({
- type,
- credential_id: credential.id,
- model: m.name,
- parameters: defaults,
- });
- }}
- >
- {m.label}
- {m.realtime && (
- <Badge
- variant="outline"
- className="ml-1.5 text-[10px] px-1 py-0"
- >
- Realtime
- </Badge>
- )}
- </DropdownMenuCheckboxItem>
- );
- }),
- )}
- </div>
- ))
+ ttsGroupEntries.map(([type, usable], idx) => {
+ const isSingle = usable.length === 1;
+
+ const renderTTSItems = (
+ credential: CredentialView,
+ models: TTSModelCard[],
+ ) =>
+ models.map((m) => {
+ const isSelected =
+ selectedTTSModel?.credential_id === credential.id &&
+ selectedTTSModel?.model === m.name;
+ return (
+ <DropdownMenuCheckboxItem
+ key={`${credential.id}-${m.name}`}
+ checked={isSelected}
+ onSelect={(e) => e.preventDefault()}
+ onCheckedChange={(checked) => {
+ if (!checked) return;
+ onTTSChange({
+ type,
+ credential_id: credential.id,
+ model: m.name,
+ parameters: extractDefaults(
+ m.parameter_schema as
+ | ParameterSchema
+ | undefined,
+ ),
+ });
+ }}
+ >
+ {m.label}
+ {m.realtime && (
+ <Badge
+ variant="outline"
+ className="ml-1.5 text-[10px] px-1 py-0"
+ >
+ Realtime
+ </Badge>
+ )}
+ </DropdownMenuCheckboxItem>
+ );
+ });
+
+ return (
+ <DropdownMenuGroup key={type}>
+ {idx > 0 && <DropdownMenuSeparator />}
+ <DropdownMenuLabel>
+ {type.replace(/_credential$/, '')}
+ </DropdownMenuLabel>
+ {isSingle
+ ? renderTTSItems(
+ usable[0].credential,
+ usable[0].models,
+ )
+ : usable.map(({ credential, models }) => {
+ const hasSelected = models.some(
+ (m) =>
+ selectedTTSModel?.credential_id ===
+ credential.id &&
+ selectedTTSModel?.model === m.name,
+ );
+ return (
+ <DropdownMenuSub key={credential.id}>
+ <DropdownMenuSubTrigger>
+ <Check
+ className={cn(
+ 'size-4 mr-1.5 shrink-0',
+ !hasSelected &&
+ 'invisible',
+ )}
+ />
+ {credentialLabel(credential)}
+ </DropdownMenuSubTrigger>
+ <DropdownMenuPortal>
+ <DropdownMenuSubContent className="max-h-60 overflow-y-auto">
+ {renderTTSItems(
+ credential,
+ models,
+ )}
+ </DropdownMenuSubContent>
+ </DropdownMenuPortal>
+ </DropdownMenuSub>
+ );
+ })}
+ </DropdownMenuGroup>
+ );
+ })
)}
{/* TTS parameters sub-panel (hover to expand right) */}
diff --git a/examples/web_ui/frontend/src/components/select/EmbeddingSelect.tsx b/examples/web_ui/frontend/src/components/select/EmbeddingSelect.tsx
index 93c4331f1..1da2e1556 100644
--- a/examples/web_ui/frontend/src/components/select/EmbeddingSelect.tsx
+++ b/examples/web_ui/frontend/src/components/select/EmbeddingSelect.tsx
@@ -8,6 +8,7 @@ import {
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
+ DropdownMenuPortal,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
@@ -15,6 +16,7 @@ import {
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { useTranslation } from '@/i18n/useI18n.ts';
+import { credentialLabel } from '@/utils/common';
interface SelectedEmbedding {
type: string;
@@ -53,6 +55,7 @@ export function EmbeddingSelect({
// (provider type → credential → models).
const groups: Record<string, KbEmbeddingProvider[]> = {};
for (const provider of providers) {
+ if (provider.models.length === 0) continue;
const type = (provider.credential.data.type as string) ?? 'unknown';
if (!groups[type]) groups[type] = [];
groups[type].push(provider);
@@ -103,15 +106,12 @@ export function EmbeddingSelect({
{m.label}
</DropdownMenuItem>
))
- : items.map(({ credential, models }) => {
- const credName =
- (credential.data.name as string) ||
- credential.id.slice(0, 8);
- return (
- <DropdownMenuSub key={credential.id}>
- <DropdownMenuSubTrigger>
- {credName}
- </DropdownMenuSubTrigger>
+ : items.map(({ credential, models }) => (
+ <DropdownMenuSub key={credential.id}>
+ <DropdownMenuSubTrigger>
+ {credentialLabel(credential)}
+ </DropdownMenuSubTrigger>
+ <DropdownMenuPortal>
<DropdownMenuSubContent className="max-h-60 overflow-y-auto">
{models.map((m) => (
<DropdownMenuItem
@@ -128,9 +128,9 @@ export function EmbeddingSelect({
</DropdownMenuItem>
))}
</DropdownMenuSubContent>
- </DropdownMenuSub>
- );
- })}
+ </DropdownMenuPortal>
+ </DropdownMenuSub>
+ ))}
</DropdownMenuGroup>
);
})
diff --git a/examples/web_ui/frontend/src/components/select/LlmSelect.tsx b/examples/web_ui/frontend/src/components/select/LlmSelect.tsx
index 837a39bf2..4ff680f3c 100644
--- a/examples/web_ui/frontend/src/components/select/LlmSelect.tsx
+++ b/examples/web_ui/frontend/src/components/select/LlmSelect.tsx
@@ -9,6 +9,7 @@ import {
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
+ DropdownMenuPortal,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
@@ -18,6 +19,7 @@ import {
import { useAvailableModels } from '@/hooks/useAvailableModels';
import { useTranslation } from '@/i18n/useI18n.ts';
import { cn } from '@/lib/utils';
+import { credentialLabel } from '@/utils/common';
interface Props extends Omit<React.ComponentPropsWithoutRef<typeof Button>, 'onChange' | 'value'> {
value?: ChatModelConfig | null;
@@ -52,7 +54,12 @@ export function LlmSelect({
}: Props) {
const { groups, loading, refetch } = useAvailableModels();
const { t } = useTranslation();
- const hasOptions = Object.keys(groups).length > 0;
+ // Credentials whose model list failed to load come back with an empty
+ // `models` array; drop them so they don't render empty submenus
+ const groupEntries = Object.entries(groups)
+ .map(([type, items]) => [type, items.filter((i) => i.models.length > 0)] as const)
+ .filter(([, usable]) => usable.length > 0);
+ const hasOptions = groupEntries.length > 0;
useEffect(() => {
if (refetchTrigger !== undefined && refetchTrigger > 0) refetch();
@@ -88,8 +95,8 @@ export function LlmSelect({
<p className="text-xs mt-1">{t('llm-select.empty.description')}</p>
</div>
) : (
- Object.entries(groups).map(([type, items], idx) => {
- const isSingle = items.length === 1;
+ groupEntries.map(([type, usable], idx) => {
+ const isSingle = usable.length === 1;
return (
<DropdownMenuGroup key={type}>
{idx > 0 && <DropdownMenuSeparator />}
@@ -97,13 +104,13 @@ export function LlmSelect({
{type.replace(/_credential$/, '')}
</DropdownMenuLabel>
{isSingle
- ? items[0].models.map((m) => (
+ ? usable[0].models.map((m) => (
<DropdownMenuItem
key={m.name}
onSelect={() =>
handleSelect(
type,
- items[0].credential.id,
+ usable[0].credential.id,
m.name,
)
}
@@ -111,15 +118,12 @@ export function LlmSelect({
{m.name}
</DropdownMenuItem>
))
- : items.map(({ credential, models }) => {
- const credName =
- (credential.data.name as string) ||
- credential.id.slice(0, 8);
- return (
- <DropdownMenuSub key={credential.id}>
- <DropdownMenuSubTrigger>
- {credName}
- </DropdownMenuSubTrigger>
+ : usable.map(({ credential, models }) => (
+ <DropdownMenuSub key={credential.id}>
+ <DropdownMenuSubTrigger>
+ {credentialLabel(credential)}
+ </DropdownMenuSubTrigger>
+ <DropdownMenuPortal>
<DropdownMenuSubContent className="max-h-60 overflow-y-auto">
{models.map((m) => (
<DropdownMenuItem
@@ -136,9 +140,9 @@ export function LlmSelect({
</DropdownMenuItem>
))}
</DropdownMenuSubContent>
- </DropdownMenuSub>
- );
- })}
+ </DropdownMenuPortal>
+ </DropdownMenuSub>
+ ))}
</DropdownMenuGroup>
);
})
diff --git a/examples/web_ui/frontend/src/utils/common.ts b/examples/web_ui/frontend/src/utils/common.ts
index e0db38d8d..b7bc3e42c 100644
--- a/examples/web_ui/frontend/src/utils/common.ts
+++ b/examples/web_ui/frontend/src/utils/common.ts
@@ -1,3 +1,10 @@
+import type { CredentialView } from '@/api';
+
+/** Display label for a credential: its user-facing name, or a short id prefix. */
+export function credentialLabel(credential: CredentialView): string {
+ return (credential.data.name as string) || credential.id.slice(0, 8);
+}
+
/**
* Copy a string to the system clipboard.
*