Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(ai): handle missing provider name in add provider dialog

Steven Enamakel13643a747208
diff --git a/app/src/components/settings/panels/ai/AddProviderDialog.tsx b/app/src/components/settings/panels/ai/AddProviderDialog.tsx
index 0fa53efc41..bd6032f530 100644
--- a/app/src/components/settings/panels/ai/AddProviderDialog.tsx
+++ b/app/src/components/settings/panels/ai/AddProviderDialog.tsx
@@ -1,30 +1,41 @@
/*
- * "Add a provider" — a modal holding one scrollable, grouped select box of
- * every provider that is NOT yet connected.
+ * "Add a provider" — a modal holding one rich select per provider category.
*
- * WHY A MODAL AND NOT AN INLINE LIST. There are ~15 providers and a user
- * connects one or two. Listing all fifteen inline spends the section on the
- * ones nobody chose and buries the ones actually configured, so the panel
- * lists only what is connected and this dialog owns the catalogue.
+ * WHY A MODAL. There are ~15 providers and a user connects one or two. Listing
+ * all fifteen inline spends the section on the ones nobody chose and buries the
+ * ones actually configured, so the panel lists only what is connected and this
+ * dialog owns the catalogue.
*
- * WHY ONE SCROLLING BOX AND NOT FOUR STACKED SECTIONS. Sections that each grow
- * to fit push the dialog past the viewport and hand the scroll to the page
- * behind it, so the group you were reading can leave the screen while its
- * heading stays. A single bounded listbox scrolls its own content, and the
- * group headings stick to the top edge while their own group is in view, so
- * "which category am I in" survives the scroll.
+ * WHY THREE SELECTS AND NOT ONE GROUPED LIST. The categories are not three
+ * slices of one decision, they are three different questions: a cloud provider
+ * wants an API key, a local runtime wants an endpoint on this machine, a CLI
+ * login wants nothing because another tool already holds the credential. One
+ * flat list makes the user infer that from the group heading alone; a select
+ * per category has a label and a line of helper text to say it outright, and
+ * each collapses to a single row when it has nothing to offer.
*
- * THE OPTIONS ARE `<button>`s IN A `<ul>`, NOT `role="listbox"`. This picks an
- * action and closes: the chosen provider hands off to its connect flow and
- * nothing stays selected. A real listbox would promise a selected value that
- * this component never holds, and would need roving focus to deliver what tab
- * order already gives us here.
+ * Custom is deliberately NOT a fourth select. It is one option, and a select
+ * over one option is a button wearing a costume.
+ *
+ * WHY THE POPUP LEAVES THE MODAL. Radix portals `SelectContent` to the body, so
+ * the list is not clipped by the dialog and a long cloud list is not squeezed
+ * into whatever height is left below its trigger. The dialog and the popup are
+ * both `z-50` from their own primitives and both portal to the body, which
+ * leaves paint order to DOM order — true today, but only incidentally. The
+ * explicit `z-[60]` makes the popup win by intent rather than by luck.
*/
-import { LuChevronRight } from 'react-icons/lu';
-
import { cn } from '../../../../lib/cn';
import { useT } from '../../../../lib/i18n/I18nContext';
+import Button from '../../../ui/Button';
+import Label from '../../../ui/Label';
import { ModalShell } from '../../../ui/ModalShell';
+import {
+ SelectContent,
+ SelectItem,
+ SelectRoot,
+ SelectTrigger,
+ SelectValue,
+} from '../../../ui/Select';
export interface ProviderOption {
slug: string;
@@ -36,63 +47,103 @@ export interface ProviderOption {
detail: string;
}
-export interface ProviderOptionGroup {
- /** Stable id, used for the React key so two groups may share a title. */
+export interface ProviderCategory {
id: string;
- /** Already-translated heading. */
+ /** Already-translated field label, placeholder and helper line. */
title: string;
+ placeholder: string;
+ helper: string;
+ /** Only what is NOT yet connected. The panel behind the dialog shows the
+ * rest, and offering to add something twice is how you get two rows for one
+ * provider. */
options: ProviderOption[];
}
-const ProviderOptionRow = ({
- option,
+const OptionSwatch = ({ label, tone, className }: { label: string; tone: string; className?: string }) => (
+ <span
+ aria-hidden
+ className={cn(
+ 'flex flex-shrink-0 items-center justify-center rounded-md font-semibold ring-1',
+ className,
+ tone
+ )}>
+ {label.trim().charAt(0).toUpperCase() || '?'}
+ </span>
+);
+
+const CategorySelect = ({
+ category,
onPick,
}: {
- option: ProviderOption;
+ category: ProviderCategory;
onPick: (slug: string) => void;
-}) => (
- <li>
- <button
- type="button"
- onClick={() => onPick(option.slug)}
- data-testid={`add-provider-option-${option.slug}`}
- className={cn(
- 'flex w-full items-center gap-3 px-3 py-2 text-left transition-colors',
- 'hover:bg-surface-hover focus:outline-none focus-visible:bg-surface-hover',
- 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500/40'
- )}>
- <span
- aria-hidden
- className={cn(
- 'flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs font-semibold ring-1',
- option.tone
- )}>
- {option.label.trim().charAt(0).toUpperCase() || '?'}
- </span>
- <span className="flex min-w-0 flex-1 flex-col gap-0.5">
- <span className="truncate text-sm font-medium text-content">{option.label}</span>
- <span className="truncate font-mono text-[11px] leading-4 text-content-muted">
- {option.detail}
- </span>
- </span>
- <LuChevronRight aria-hidden className="h-4 w-4 flex-shrink-0 text-content-faint" />
- </button>
- </li>
-);
+}) => {
+ const { t } = useT();
+ const empty = category.options.length === 0;
+ const triggerId = `add-provider-${category.id}`;
+
+ return (
+ <div className="flex flex-col gap-1.5">
+ <Label htmlFor={triggerId} className="text-xs text-content-secondary">
+ {category.title}
+ </Label>
+
+ {/* `value` is pinned to '' so the trigger always shows its placeholder:
+ choosing an item starts a connect flow and leaves nothing selected
+ here. A select that kept the last pick would claim a selection this
+ component does not own — the connection state lives in the panel. */}
+ <SelectRoot value="" onValueChange={onPick}>
+ <SelectTrigger
+ id={triggerId}
+ inputSize="sm"
+ disabled={empty}
+ data-testid={`add-provider-select-${category.id}`}>
+ <SelectValue
+ placeholder={
+ empty ? t('settings.ai.providers.categoryAllConnected') : category.placeholder
+ }
+ />
+ </SelectTrigger>
+ <SelectContent className="z-[60] w-[min(24rem,calc(100vw-2rem))]">
+ {category.options.map(option => (
+ <SelectItem
+ key={option.slug}
+ value={option.slug}
+ data-testid={`add-provider-option-${option.slug}`}>
+ <span className="flex min-w-0 items-center gap-2">
+ <OptionSwatch label={option.label} tone={option.tone} className="h-6 w-6 text-[10px]" />
+ <span className="flex min-w-0 flex-col">
+ <span className="truncate text-sm text-content">{option.label}</span>
+ <span className="truncate font-mono text-[10px] leading-3 text-content-muted">
+ {option.detail}
+ </span>
+ </span>
+ </span>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </SelectRoot>
+
+ <p className="text-[11px] leading-4 text-content-muted">{category.helper}</p>
+ </div>
+ );
+};
export const AddProviderDialog = ({
- groups,
+ categories,
onPick,
+ onAddCustom,
onClose,
}: {
- groups: ProviderOptionGroup[];
+ categories: ProviderCategory[];
/** Called with the chosen slug. The caller closes this dialog and starts the
* provider's own connect flow. */
onPick: (slug: string) => void;
+ /** Opens the full editor for a user-defined endpoint. */
+ onAddCustom: () => void;
onClose: () => void;
}) => {
const { t } = useT();
- const populated = groups.filter(group => group.options.length > 0);
return (
<ModalShell
@@ -100,31 +151,28 @@ export const AddProviderDialog = ({
titleId="add-provider-dialog-title"
subtitle={t('settings.ai.providers.addProviderSubtitle')}
onClose={onClose}
- maxWidthClassName="max-w-lg">
- {populated.length === 0 ? (
- <p className="py-6 text-center text-sm text-content-muted" data-testid="add-provider-empty">
- {t('settings.ai.providers.allConnected')}
- </p>
- ) : (
- /* The box owns the scroll. `overscroll-contain` stops a flick at the
- end of the list from continuing into the page behind the modal. */
- <div
- data-testid="add-provider-list"
- className="max-h-[22rem] w-full overflow-y-auto overscroll-contain rounded-xl border border-line bg-surface-subtle">
- {populated.map(group => (
- <section key={group.id}>
- <h3 className="sticky top-0 z-10 border-b border-line-subtle bg-surface-subtle/95 px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wide text-content-faint backdrop-blur">
- {group.title}
- </h3>
- <ul className="flex flex-col divide-y divide-line-subtle bg-surface">
- {group.options.map(option => (
- <ProviderOptionRow key={option.slug} option={option} onPick={onPick} />
- ))}
- </ul>
- </section>
- ))}
+ maxWidthClassName="max-w-md">
+ <div className="flex flex-col gap-4">
+ {categories.map(category => (
+ <CategorySelect key={category.id} category={category} onPick={onPick} />
+ ))}
+
+ {/* Not a fourth select: one option. */}
+ <div className="flex flex-col gap-1.5 border-t border-line-subtle pt-4">
+ <Button
+ type="button"
+ variant="secondary"
+ size="sm"
+ className="self-start"
+ onClick={onAddCustom}
+ data-testid="add-provider-custom">
+ {t('settings.ai.providers.addCustomAction')}
+ </Button>
+ <p className="text-[11px] leading-4 text-content-muted">
+ {t('settings.ai.providers.customDetail')}
+ </p>
</div>
- )}
+ </div>
</ModalShell>
);
};