Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(model-hub): make source-detail standby and tiers readable on first use (#1729)
Maxcb8adaf7b8a9
diff --git a/docs/plans/model-hub-ui-spec.md b/docs/plans/model-hub-ui-spec.mdindex 97dc0e615..09071c5bc 100644--- a/docs/plans/model-hub-ui-spec.md+++ b/docs/plans/model-hub-ui-spec.md@@ -3680,8 +3680,8 @@ them do I actually want, and what reasoning tiers does each accept?* Nothing els| `myA8k` header | 型号 ID (250) · 录入 (84) · 推理强度 (470, with info) · fill spacer | static | no | — || `OM5PH` row | model id, entry-kind pill, tier chips, overflow icon | one model | tiers, overflow | Edit tiers / row menu || Retired discovered-row delta `[derived]` | same `OM5PH` chrome, muted ink, existing tag component with `sourceDetail.entry.retired`; never a new row component | `origin: discovered`, `retired: true` `[contract]` | no delete or reactivation action | Remains readable and non-supplying; refetch preserves it |-| `p2JwTz` tiers | chips, or 未设置档位 + `+ 添加档位` | `reasoning_efforts[]` `[contract]` FC-03 | yes | Enter edit mode |-| `eVavA` tiers (editing) | removable chips + text input + 回车添加 · 任意文本 | local edit → `PATCH /api/models/sources/<source_id>/models/<model_id>` `[contract]` | yes | Add / remove a tier |+| `p2JwTz` tiers | chips, or 未设置档位; `+ 添加档位` is drawn only while a pointer is on the row, in the box it reserves either way, and the row answers that hover with `--model-hub-wash-0a` fill and nothing else — no border, no height, no reflow; a write this row rolled back keeps its 重试 here `[derived]` | `reasoning_efforts[]` `[contract]` FC-03 | the whole cell, by pointer, focus or tap — the cell's box is the row band rather than the chips it happens to hold, so a device with no hover draws no pill and still has the same target | Enter edit mode; retry the rolled-back write |+| `eVavA` tiers (editing) | removable chips + text input + 回车添加 · 任意文本 + ghost suggestion chips derived from the source's proved protocol (the OpenAI protocols offer `low` `medium` `high` `xhigh`; Anthropic Messages names no tier vocabulary and offers none) + one muted line stating that tiers are sent as typed and that a model with none is still routable `[derived]` | local edit → `PATCH /api/models/sources/<source_id>/models/<model_id>` `[contract]`; suggestions are presentation only — never persisted, never pre-filled at discovery, never sent | yes; one row is in this state at a time, and the state ends when focus leaves the editor — Escape (which hands focus back to the row) or focus moving anywhere outside it, including another row's cell — so every control inside it is reachable by keyboard and by pointer alike; a rolled-back write is not held here, it stays with its row `p2JwTz` | Add / remove a tier; a suggestion adds through the same path typing it would take; retry a rolled-back write || `nN4TZ` manual row | editable id input, 手动添加 pill, tier affordance, 取消 / 添加 | local draft → `POST /api/models/sources/<source_id>/models` `[contract]` | yes | Commit or discard || `Q83BF` add row | 添加模型 + when to use it | — | yes | Append a manual draft row || `tF3Bh` footnote | scope of this page; that tiers are yours to type; that the interface type is confirmed at add time, shown, and not editable here | static | no | — |diff --git a/ui/src/components/settings/models/SourceDetailPanel.test.tsx b/ui/src/components/settings/models/SourceDetailPanel.test.tsxindex b520cdea3..af41c10a0 100644--- a/ui/src/components/settings/models/SourceDetailPanel.test.tsx+++ b/ui/src/components/settings/models/SourceDetailPanel.test.tsx@@ -22,13 +22,15 @@ import { GuardGapList } from './GuardGapList';import { REPAIR_DESTINATION, REPAIR_LABEL_KEY, repairAction, type RepairKind } from './repair';import { SourceDetailPanel } from './SourceDetailPanel';import { SourceMutationReport } from './SourceMutationReport';+import { TIER_SUGGESTIONS } from './tierSuggestions';import {COOLDOWN_DETAIL_KEYS,ERROR_DETAIL_KEYS,NEEDS_ACTION_DETAIL_KEYS,+ SOURCE_PROTOCOLS,SOURCE_STATUSES,} from './types';-import type { Source, SourceDetailKey, SourceKind, SupplyChannel } from './types';+import type { Source, SourceDetailKey, SourceKind, SourceProtocol, SupplyChannel } from './types';import { useSourceMutationReport } from './useSourceMutationReport';const source: Source = {@@ -165,6 +167,17 @@ const renderPanel = (adoptedBy: Source['adopted_by'] = undefined) => render(</ToastProvider>,);+const renderProtocol = (protocol: SourceProtocol, models: Source['models'] = source.models) => render(+ <ToastProvider>+ <I18nextProvider i18n={i18n}>+ <ReportOwnedPanel source={{ ...source, protocol, models }} trackMutation={immediateTrack} onReauth={noReauth} />+ </I18nextProvider>+ </ToastProvider>,+);+/** Read by the class the stylesheet owns: the ghost chip has no other identity. */+const suggestedTiers = () => Array.from(document.querySelectorAll('.model-hub-source-tier-suggest'))+ .map((chip) => chip.textContent?.trim() ?? '');+const EchoPanel: React.FC<{reconcile?: () => Promise<SourceMutationLanding['verdict'] | void> | SourceMutationLanding['verdict'] | void;scheduler?: MutationScheduler;@@ -1000,6 +1013,182 @@ describe('SourceDetailPanel', () => {await waitFor(() => expect(update).toHaveBeenCalledWith(source.id, 'model-a', []));});+ it('leaves a resting row to its model and the tiers it already carries', () => {+ renderProtocol('openai_responses');+ expect(suggestedTiers()).toEqual([]);+ expect(screen.queryByText(/sent exactly as typed|按你输入的原样发送/i)).toBeNull();+ // The add affordance is not absent from the row, only from what a resting row+ // draws — keeping the box it reserves is what lets revealing it move nothing.+ const cell = screen.getByRole('button', { name: /high/i });+ expect(cell.querySelector('.model-hub-source-tier-add.model-hub-source-tier-reveal')).toBeTruthy();+ });++ // The suggestion set is discovered from its total protocol Record, so a protocol+ // added later fails here until that table decides what it offers — and what it+ // decides is what the open editor draws, minus whatever the model already has.+ it('offers exactly the tiers its proved protocol names, and only while editing', async () => {+ for (const protocol of SOURCE_PROTOCOLS) {+ renderProtocol(protocol);+ expect(suggestedTiers()).toEqual([]);+ await userEvent.click(screen.getByRole('button', { name: /high/i }));+ expect(suggestedTiers()).toEqual(TIER_SUGGESTIONS[protocol].filter((tier) => tier !== 'high'));+ cleanup();+ }+ });++ it('adds a suggested tier through the same write typing it would take', async () => {+ const update = vi.spyOn(modelsApi, 'updateModelReasoningEfforts').mockResolvedValueOnce({+ ...source,+ models: [{ ...source.models[0], reasoning_efforts: ['high', 'low'] }],+ });+ renderProtocol('openai_responses');+ await userEvent.click(screen.getByRole('button', { name: /high/i }));+ await userEvent.click(screen.getByRole('button', { name: /^Add low$|^添加 low$/ }));++ await waitFor(() => expect(update).toHaveBeenCalledWith(source.id, 'model-a', ['high', 'low']));+ });++ it('keeps a suggestion out of the draft and off the wire until it is clicked', async () => {+ const update = vi.spyOn(modelsApi, 'updateModelReasoningEfforts');+ renderProtocol('openai_chat');+ await userEvent.click(screen.getByRole('button', { name: /high/i }));++ expect(suggestedTiers().length).toBeGreaterThan(0);+ expect((screen.getByPlaceholderText(/Enter to add|回车添加/i) as HTMLInputElement).value).toBe('');+ expect(update).not.toHaveBeenCalled();+ });++ it('collapses the editor on Escape and on a click elsewhere', async () => {+ renderProtocol('openai_responses');+ await userEvent.click(screen.getByRole('button', { name: /high/i }));+ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(screen.queryByPlaceholderText(/Enter to add|回车添加/i)).toBeNull());+ expect(suggestedTiers()).toEqual([]);++ await userEvent.click(screen.getByRole('button', { name: /high/i }));+ await userEvent.click(screen.getByRole('heading', { name: source.display_name as string }));+ await waitFor(() => expect(screen.queryByPlaceholderText(/Enter to add|回车添加/i)).toBeNull());+ });++ it('hands the editor to the row that was clicked instead of opening a second one', async () => {+ renderProtocol('openai_responses', [+ source.models[0],+ { id: 'model-b', display_name: null, origin: 'discovered', reasoning_efforts: [] },+ ]);+ await userEvent.click(screen.getByRole('button', { name: /high/i }));+ expect(screen.getAllByPlaceholderText(/Enter to add|回车添加/i)).toHaveLength(1);++ await userEvent.click(screen.getByRole('button', { name: /No tiers set|未设置档位/i }));++ const inputs = screen.getAllByPlaceholderText(/Enter to add|回车添加/i);+ expect(inputs).toHaveLength(1);+ expect(document.activeElement).toBe(inputs[0]);+ });++ // An editor is a place the keyboard moves around in, not only lands in. Keyed+ // to the input's own blur, the collapse made every control inside it+ // pointer-only: Tab left the field and took the editor with it.+ it('lets the keyboard reach a suggestion and stays open around the write', async () => {+ const update = vi.spyOn(modelsApi, 'updateModelReasoningEfforts').mockResolvedValueOnce({+ ...source,+ models: [{ ...source.models[0], reasoning_efforts: ['high', 'low'] }],+ });+ renderProtocol('openai_responses');+ await userEvent.click(screen.getByRole('button', { name: /high/i }));+ await userEvent.tab();+ const suggestion = screen.getByRole('button', { name: /^Add low$|^添加 low$/ });+ expect(document.activeElement).toBe(suggestion);++ await userEvent.keyboard('{Enter}');+ await waitFor(() => expect(update).toHaveBeenCalledWith(source.id, 'model-a', ['high', 'low']));+ // The chip it was standing on is gone; focus is back on the one control the+ // edit state cannot lose, not on the body with the editor closed behind it.+ const input = screen.getByPlaceholderText(/Enter to add|回车添加/i);+ expect(document.activeElement).toBe(input);+ });++ it('returns focus to the row it collapsed when Escape asked for it', async () => {+ renderProtocol('openai_responses');+ await userEvent.click(screen.getByRole('button', { name: /high/i }));+ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(screen.queryByPlaceholderText(/Enter to add|回车添加/i)).toBeNull());+ expect(document.activeElement).toBe(screen.getByRole('button', { name: /high/i }));+ });++ // A write that was rolled back is the row's unfinished business, and 重试 is+ // the only answer to it — so moving the editor elsewhere, which answers+ // nothing, cannot be what takes the answer away.+ it('keeps a failed write answerable after the editor moves to another row', async () => {+ const update = vi.spyOn(modelsApi, 'updateModelReasoningEfforts').mockRejectedValueOnce(new Error('write failed'));+ renderProtocol('openai_responses', [+ source.models[0],+ { id: 'model-b', display_name: null, origin: 'discovered', reasoning_efforts: [] },+ ]);+ await userEvent.click(screen.getByRole('button', { name: /high/i }));+ await userEvent.type(screen.getByPlaceholderText(/Enter to add|回车添加/i), 'low{Enter}');+ expect(await screen.findByText(/tier was not saved|档位没保存上/i)).toBeTruthy();++ await userEvent.click(screen.getByRole('button', { name: /No tiers set|未设置档位/i }));+ expect(screen.getAllByPlaceholderText(/Enter to add|回车添加/i)).toHaveLength(1);+ expect(screen.getByText(/tier was not saved|档位没保存上/i)).toBeTruthy();++ update.mockResolvedValueOnce({ ...source, models: [{ ...source.models[0], reasoning_efforts: ['high', 'low'] }] });+ await userEvent.click(screen.getByRole('button', { name: /^Try again$|^重试$/i }));+ await waitFor(() => expect(update).toHaveBeenLastCalledWith(source.id, 'model-a', ['high', 'low']));+ await waitFor(() => expect(screen.queryByText(/tier was not saved|档位没保存上/i)).toBeNull());+ });++ // Hover is a reveal, not a layout change, and the row answers it with fill+ // alone. Asserted against the stylesheet because jsdom resolves neither a media+ // query nor a hover state, and this half of the interaction is CSS-owned.+ it('reveals the add affordance on hover without moving the row', () => {+ const css = readFileSync(join(process.cwd(), 'src/components/settings/models/modelHubSurface.css'), 'utf8');+ const pointer = css.slice(css.indexOf('@media (hover: hover)'), css.indexOf('@media (hover: none)'));+ const touch = css.slice(css.indexOf('@media (hover: none)'));+ expect(pointer).toMatch(/\.model-hub-source-table-row:hover \{ background: var\(--model-hub-wash-0a\); \}/);+ expect(pointer).toMatch(/\.model-hub-source-tier-reveal \{ opacity: 0;/);+ expect(pointer).toMatch(/\.model-hub-source-table-row:hover \.model-hub-source-tier-reveal,[\s\S]*?opacity: 1;/);+ expect(pointer).not.toMatch(/display: none|height|padding|margin|border/);+ expect(touch).toMatch(/\.model-hub-source-tier-reveal \{ display: none; \}/);+ });++ // The reveal is a paint, so what a tap has to find cannot be part of it: the+ // cell owns the row's band whatever it is drawing, which is what lets the pill+ // be removed on touch and lets a model with no tiers still be a target at all.+ it('gives the tier cell the row band to be tapped in, whichever branch is drawing', () => {+ const css = readFileSync(join(process.cwd(), 'src/components/settings/models/modelHubSurface.css'), 'utf8');+ const base = css.slice(0, css.indexOf('@media (hover: hover)'));+ expect(base).toMatch(/\.model-hub-source-tier-cell \{\s*min-height: calc\(var\(--model-hub-source-table-row-height\) - 2 \* var\(--model-hub-source-table-padding-y\)\);\s*\}/);+ const pointer = css.slice(css.indexOf('@media (hover: hover)'), css.indexOf('@media (hover: none)'));+ const touch = css.slice(css.indexOf('@media (hover: none)'), css.indexOf('.model-hub-source-tier-empty'));+ for (const branch of [pointer, touch]) expect(branch).not.toMatch(/height/);++ // And the class is on the control the tap opens, for a model with tiers and+ // for one without — CSS nobody wears is not a hit area.+ renderProtocol('openai_responses', [+ source.models[0],+ { id: 'model-b', display_name: null, origin: 'discovered', reasoning_efforts: [] },+ ]);+ for (const name of [/high/i, /No tiers set|未设置档位/i]) {+ expect(screen.getByRole('button', { name }).className).toContain('model-hub-source-tier-cell');+ }+ });++ it('explains standby beside the label rather than in a place the reader must find', async () => {+ renderPanel([]);+ expect(screen.getByText(/^Standby$|^备用$/i)).toBeTruthy();++ // Reached by keyboard, not by hover alone: the sentence is the only thing on+ // the bar that says a just-added source is fine, so it cannot be pointer-only.+ const hint = screen.getByRole('button', { name: /What standby means|备用是什么意思/i });+ hint.focus();+ await userEvent.keyboard('{Enter}');+ expect(await screen.findByText(/serves a route through it|它就会显示为使用中/i)).toBeTruthy();++ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(screen.queryByText(/serves a route through it|它就会显示为使用中/i)).toBeNull());+ });+it('sends a manual-model removal before showing any guarded-change confirm', async () => {const remove = vi.spyOn(modelsApi, 'deleteCustomModel').mockResolvedValueOnce(source);renderPanel();diff --git a/ui/src/components/settings/models/SourceDetailPanel.tsx b/ui/src/components/settings/models/SourceDetailPanel.tsxindex f6210254d..abc104f3e 100644--- a/ui/src/components/settings/models/SourceDetailPanel.tsx+++ b/ui/src/components/settings/models/SourceDetailPanel.tsx@@ -14,6 +14,7 @@ import { PROTOCOL_COPY_KEYS } from './addApiKeyState';import { classifyModelHubFailure } from './asyncLifetime';import { Field } from './dialogFields';import { GuardImpact } from './GuardImpact';+import { ModelHubInfoHint } from './ModelHubInfoHint';import {assessSourceEdit,canEditSourceEndpoint,@@ -48,9 +49,17 @@ import { reconcileUnknownWrite } from './reconcileUnknownWrite';import { REPAIR_DESTINATION, REPAIR_LABEL_KEY, reauthBodyKey, reauthCost, repairAction } from './repair';import { sourceStatePresentation } from './sourceStatePresentation';import { tierMutationPayload, type TierMutationIntent } from './tierMutation';+import { TIER_SUGGESTIONS } from './tierSuggestions';import { useDeadlineClock } from './useDeadlineClock';import { ACCENT_ICON, ACCENT_TILE, isCustomEndpoint, sourceVisual } from './vendorMeta';-import type { RouteHopRef, Source, SourcePatch, SuppliedModel, SupplyGap } from './types';+import type {+ RouteHopRef,+ Source,+ SourcePatch,+ SourceProtocol,+ SuppliedModel,+ SupplyGap,+} from './types';const ManualModelMenu: React.FC<{model: SuppliedModel;@@ -148,20 +157,43 @@ const enteredHost = (source: Source): string | null => {const TierEditor: React.FC<{model: SuppliedModel;+ protocol: SourceProtocol;+ editing: boolean;+ onEdit: () => void;+ onClose: () => void;onMutating: () => void;trackMutation: TrackSourceMutation;-}> = ({ model, onMutating, trackMutation }) => {+}> = ({ model, protocol, editing, onEdit, onClose, onMutating, trackMutation }) => {const { t } = useTranslation();const [tiers, setTiers] = React.useState(model.reasoning_efforts ?? []);const [draft, setDraft] = React.useState('');- const [editing, setEditing] = React.useState(false);const [saving, setSaving] = React.useState(false);const [failedNext, setFailedNext] = React.useState<TierMutationIntent | null>(null);+ const [returnFocus, setReturnFocus] = React.useState(false);+ const inputRef = React.useRef<HTMLInputElement>(null);+ const cellRef = React.useRef<HTMLButtonElement>(null);React.useEffect(() => setTiers(model.reasoning_efforts ?? []), [model.reasoning_efforts]);+ // Which row is open belongs to the table, not to the row — that is what makes+ // "one editor at a time" structural rather than a convention every collapse+ // path has to remember. What the row drops on the way out is the uncommitted+ // draft, and only that: a rolled-back write is not a draft, so it stays with+ // the row that produced it (below) rather than with whoever holds the editor.+ React.useEffect(() => { if (!editing) setDraft(''); }, [editing]);+ // Escape is the one collapse the keyboard asks for, so it is the one that owes+ // a place to land; a click elsewhere already chose one.+ React.useEffect(() => {+ if (editing || !returnFocus) return;+ cellRef.current?.focus();+ setReturnFocus(false);+ }, [editing, returnFocus]);const commit = async (intent: TierMutationIntent): Promise<boolean> => {if (saving) return false;setSaving(true);+ // Every in-editor control is transient — a suggestion becomes a chip, a chip+ // disappears — so acting on one has to hand focus back to the field that+ // outlives them all, before the element holding it unmounts onto the body.+ (inputRef.current ?? cellRef.current)?.focus();try {return await trackMutation(async (latest, settlement) => {const payload = tierMutationPayload(latest, model.id, intent);@@ -202,46 +234,93 @@ const TierEditor: React.FC<{if (!failedNext) return;if (await commit(failedNext) && failedNext.kind === 'add' && draft.trim() === failedNext.tier) setDraft('');};+ // A rolled-back write is the row's own unfinished business: the tier list is+ // already back to what the server holds, and 重试 is the only way forward from+ // there. So the notice renders in whichever state the row is in and leaves only+ // through a write that lands — never because the editor closed or moved on.+ const failure = failedNext && (+ <span className="model-hub-source-tier inline-flex items-center gap-1.5 text-destructive-ink">+ {t('settings.models.sourceDetail.fail.tier')}+ <button type="button" disabled={saving} onClick={() => void retry()} className="font-semibold underline underline-offset-2 disabled:opacity-50">{t('settings.models.sourceDetail.retry')}</button>+ </span>+ );if (!editing) {+ // The whole cell is the edit entry, which is what lets the add affordance be+ // drawn only under a pointer: 20 rows each carrying a permanent 「+ 添加档位」+ // pill turn an inventory table into a wall of buttons. It stays in the box it+ // reserves rather than being removed from it, so revealing it moves nothing.return (- <button- type="button"- className="flex min-w-0 flex-wrap items-center gap-1.5 text-left"- onClick={() => { setFailedNext(null); setEditing(true); }}- >- {tiers.length > 0 ? tiers.map((tier) => (- <span key={tier} className="model-hub-source-tier model-hub-source-tier-chip inline-flex rounded-full border border-border font-mono text-foreground">{tier}</span>- )) : <span className="model-hub-source-tier-empty">{t('settings.models.sourceDetail.tiers.empty')}</span>}- <span className="model-hub-source-tier model-hub-source-tier-add inline-flex rounded-full border font-semibold">{t(tiers.length > 0 ? 'settings.models.sourceDetail.tiers.add' : 'settings.models.sourceDetail.tiers.addFirst')}</span>- </button>+ <div className="flex min-w-0 flex-col gap-1.5">+ <button+ ref={cellRef}+ type="button"+ className="model-hub-source-tier-cell flex min-w-0 flex-wrap items-center gap-1.5 text-left"+ onClick={onEdit}+ >+ {tiers.length > 0 ? tiers.map((tier) => (+ <span key={tier} className="model-hub-source-tier model-hub-source-tier-chip inline-flex rounded-full border border-border font-mono text-foreground">{tier}</span>+ )) : <span className="model-hub-source-tier-empty">{t('settings.models.sourceDetail.tiers.empty')}</span>}+ <span className="model-hub-source-tier model-hub-source-tier-add model-hub-source-tier-reveal inline-flex rounded-full border font-semibold">{t(tiers.length > 0 ? 'settings.models.sourceDetail.tiers.add' : 'settings.models.sourceDetail.tiers.addFirst')}</span>+ </button>+ {failure}+ </div>);}+ const suggestions = TIER_SUGGESTIONS[protocol].filter((tier) => !tiers.includes(tier));+ // The editor collapses when focus leaves the editor, not when the input alone+ // does. Keyed to the input, every control inside had to defend itself against+ // its own focus — which a pointer can fake by refusing it and a keyboard+ // cannot, so Tab closed the row before it could reach a suggestion at all.+ // Containment is that same rule stated once, at the boundary it is about.return (- <div className="flex min-w-0 flex-wrap items-center gap-1.5">- {tiers.map((tier) => (- <span key={tier} className="model-hub-source-tier model-hub-source-tier-chip inline-flex items-center gap-1 rounded-full border border-border font-mono text-foreground">- {tier}- <button type="button" disabled={saving} onMouseDown={(event) => event.preventDefault()} onClick={() => void commit({ kind: 'remove', tier })} aria-label={t('settings.models.sourceDetail.tiers.remove', { tier }) as string} className="text-muted hover:text-foreground disabled:opacity-50">- <X className="size-2.5" />+ <div+ className="flex min-w-0 flex-col gap-1.5"+ onBlur={(event) => { if (!event.currentTarget.contains(event.relatedTarget)) onClose(); }}+ onKeyDown={(event) => {+ if (event.key !== 'Escape') return;+ event.preventDefault();+ setDraft('');+ setReturnFocus(true);+ onClose();+ }}+ >+ <div className="flex min-w-0 flex-wrap items-center gap-1.5">+ {tiers.map((tier) => (+ <span key={tier} className="model-hub-source-tier model-hub-source-tier-chip inline-flex items-center gap-1 rounded-full border border-border font-mono text-foreground">+ {tier}+ <button type="button" disabled={saving} onClick={() => void commit({ kind: 'remove', tier })} aria-label={t('settings.models.sourceDetail.tiers.remove', { tier }) as string} className="text-muted hover:text-foreground disabled:opacity-50">+ <X className="size-2.5" />+ </button>+ </span>+ ))}+ <Input+ ref={inputRef}+ autoFocus+ value={draft}+ onChange={(event) => setDraft(event.target.value)}+ onKeyDown={(event) => { if (event.key === 'Enter') { event.preventDefault(); void add(); } }}+ disabled={saving}+ placeholder={t('settings.models.sourceDetail.tiers.inputHint') as string}+ className="model-hub-source-tier h-7 w-28 rounded-full border-mint/40 px-2.5"+ />+ {/* A suggestion adds through the same path typing it would take. */}+ {suggestions.map((tier) => (+ <button+ key={tier}+ type="button"+ disabled={saving}+ onClick={() => void commit({ kind: 'add', tier })}+ aria-label={t('settings.models.sourceDetail.tiers.suggest', { tier }) as string}+ className="model-hub-source-tier model-hub-source-tier-suggest inline-flex rounded-full border font-mono disabled:opacity-50"+ >+ {tier}</button>- </span>- ))}- <Input- value={draft}- onChange={(event) => setDraft(event.target.value)}- onBlur={() => { if (!failedNext) { setDraft(''); setEditing(false); } }}- onKeyDown={(event) => {- if (event.key === 'Enter') { event.preventDefault(); void add(); }- if (event.key === 'Escape') { event.preventDefault(); setDraft(''); event.currentTarget.blur(); }- }}- disabled={saving}- placeholder={t('settings.models.sourceDetail.tiers.inputHint') as string}- className="model-hub-source-tier h-7 w-28 rounded-full border-mint/40 px-2.5"- />- {failedNext && <span className="model-hub-source-tier inline-flex items-center gap-1.5 text-destructive-ink">- {t('settings.models.sourceDetail.fail.tier')}- <button type="button" disabled={saving} onMouseDown={(event) => event.preventDefault()} onClick={() => void retry()} className="font-semibold underline underline-offset-2 disabled:opacity-50">{t('settings.models.sourceDetail.retry')}</button>- </span>}+ ))}+ {failure}+ </div>+ {/* The two questions a free-text field cannot answer by itself: whether+ anything validates what is typed, and what an empty row costs. */}+ <p className="model-hub-source-tier-note">{t('settings.models.sourceDetail.tiers.note')}</p></div>);};@@ -309,6 +388,7 @@ export const SourceDetailPanel: React.FC<{const [replacingKey, setReplacingKey] = React.useState(false);const [manageStage, dispatchManageStage] = React.useReducer(transitionManageStage, { kind: 'idle' });const [manualDraft, setManualDraft] = React.useState<{ modelId: string; tiers: string[]; failed: boolean; retryRead: boolean } | null>(null);+ const [editingTiers, setEditingTiers] = React.useState<string | null>(null);const [guard, setGuard] = React.useState<GuardedAction | null>(null);const [result, setResult] = React.useState<{ added: string[]; removed: string[] } | null>(null);const [refetchFailed, setRefetchFailed] = React.useState(false);@@ -777,7 +857,13 @@ export const SourceDetailPanel: React.FC<{<span className="model-hub-pill model-hub-source-interface-pill border" title={interfaceLabel}><span className="truncate">{interfaceLabel}</span></span>- {state.key && <span className="model-hub-source-state flex items-center gap-1.5"><span className={cn('size-[5px] shrink-0 rounded-full', state.dotClass)} />{t(state.key, state.values)}</span>}+ {/* 备用 is the first thing a just-added source says about itself, and+ on its own it reads as a failed add. The explanation sits on the+ label rather than in a subtitle line — the bar draws two lines and+ the copy register keeps explanations behind a compact info+ affordance — and the hint is a real control, so keyboard and touch+ reach the sentence hover alone would keep from them. */}+ {state.key && <span className="model-hub-source-state flex items-center gap-1.5"><span className={cn('size-[5px] shrink-0 rounded-full', state.dotClass)} />{t(state.key, state.values)}{state.hint && <ModelHubInfoHint label={t(state.hint.labelKey) as string} content={t(state.hint.bodyKey)} className="size-[13px]" />}</span>}{source.last_discovered_at && <span className="model-hub-source-age text-muted">{t('settings.models.sourceDetail.status.listUpdated', { time: formatRelativeTime(source.last_discovered_at, t) })}</span>}</div><p className="model-hub-source-summary truncate font-mono">{t(host ? 'settings.models.sourceDetail.summary' : 'settings.models.gateway.modelCount', { host, count: source.models.length })}</p>@@ -802,7 +888,18 @@ export const SourceDetailPanel: React.FC<{<div key={model.id} className="model-hub-source-table-row grid gap-3 border-b border-border last:border-b-0 md:items-center md:gap-y-0"><span className="flex min-w-0 items-center gap-2"><span className="model-hub-source-model truncate font-mono text-foreground" title={model.id}>{model.id}</span>{result?.added.includes(model.id) && <span className="model-hub-accent-pill--mint model-hub-source-pill rounded-full border px-2 py-0.5 font-semibold">{t('settings.models.sourceDetail.refetch.added')}</span>}</span><span className={cn('model-hub-source-pill model-hub-source-entry-pill w-fit rounded-full border font-semibold', model.origin !== 'discovered' && 'model-hub-source-entry-pill--manual')}>{t(`settings.models.sourceDetail.entry.${model.origin === 'discovered' ? 'auto' : 'manual'}`)}</span>- <TierEditor model={model} onMutating={() => { setResult(null); setRefetchFailed(false); }} trackMutation={trackMutation} />+ <TierEditor+ model={model}+ protocol={source.protocol}+ editing={editingTiers === model.id}+ onEdit={() => setEditingTiers(model.id)}+ // Guarded against the row it is closing: the outgoing editor's blur+ // lands after the incoming row's click, so an unguarded close would+ // collapse the editor the user just opened.+ onClose={() => setEditingTiers((current) => (current === model.id ? null : current))}+ onMutating={() => { setResult(null); setRefetchFailed(false); }}+ trackMutation={trackMutation}+ /><div className="flex items-center justify-end gap-2">{removeFailure?.modelId === model.id && <span className="model-hub-source-tier text-right text-destructive-ink">{t('settings.models.sourceDetail.fail.removeModel')} <button type="button" disabled={busy} onClick={() => {if (!removeFailure.retryRead) void remove(model);diff --git a/ui/src/components/settings/models/modelHubSurface.css b/ui/src/components/settings/models/modelHubSurface.cssindex f34090f07..16d6836bd 100644--- a/ui/src/components/settings/models/modelHubSurface.css+++ b/ui/src/components/settings/models/modelHubSurface.css@@ -1008,6 +1008,45 @@border-color: var(--model-hub-wash-24);color: var(--muted);}+/* A suggestion is a value this source has not declared, so it is drawn as the+ absence of one: the saved chip's box with a hairline outline instead of a+ fill. It is never a vocabulary — clicking one types it, and typing anything+ else remains equally valid. */+.model-hub-source-tier-suggest {+ padding: var(--model-hub-source-chip-padding-y) var(--model-hub-source-chip-padding-x);+ border-color: var(--model-hub-wash-24);+ border-style: dashed;+ color: var(--model-hub-ink-73);+}+.model-hub-source-tier-suggest:hover { border-color: var(--model-hub-wash-33); color: var(--foreground); }+.model-hub-source-tier-note {+ color: var(--model-hub-source-footnote-ink);+ font-size: var(--model-hub-source-tier-size);+ line-height: 15px;+}+/* The cell is the way into the editor, so its box is the row's band rather than+ whatever its contents happen to measure — a model with no tiers offers only a+ 10.5px caption, and a touch device is shown no pill at all. Owned here, once,+ outside both hover branches: the target a tap has to find cannot be decided by+ what the row is currently drawing. */+.model-hub-source-tier-cell {+ min-height: calc(var(--model-hub-source-table-row-height) - 2 * var(--model-hub-source-table-padding-y));+}+/* The row's add affordance is drawn only while a pointer is on the row. It keeps+ the box it reserves either way, so revealing it moves no chip and changes no+ row height — the row answers a hover with fill alone. A keyboard reaches the+ cell by focus and gets the same reveal; a touch device has no hover to answer+ with, so the pill is removed there rather than left as a blank gap, which the+ cell can afford because the tappable box is the cell's own, not the pill's. */+@media (hover: hover) {+ .model-hub-source-table-row:hover { background: var(--model-hub-wash-0a); }+ .model-hub-source-tier-reveal { opacity: 0; transition: opacity 120ms ease; }+ .model-hub-source-table-row:hover .model-hub-source-tier-reveal,+ .model-hub-source-tier-cell:focus-visible .model-hub-source-tier-reveal { opacity: 1; }+}+@media (hover: none) {+ .model-hub-source-tier-reveal { display: none; }+}.model-hub-source-tier-empty {color: var(--model-hub-ink-59);font-size: var(--model-hub-source-age-size);diff --git a/ui/src/components/settings/models/sourceStatePresentation.test.ts b/ui/src/components/settings/models/sourceStatePresentation.test.tsindex 2ce462c7e..72dc8bb0c 100644--- a/ui/src/components/settings/models/sourceStatePresentation.test.ts+++ b/ui/src/components/settings/models/sourceStatePresentation.test.ts@@ -1,7 +1,17 @@import { describe, expect, it } from 'vitest';-import { sourceStatePresentation } from './sourceStatePresentation';-import type { SourceState, SourceStatus } from './types';+import { sourceStatePresentation, type SourceStateSurface } from './sourceStatePresentation';+import { SOURCE_STATUSES } from './types';+import type { SourceState, SourceStatus, SupplyChannel } from './types';++/**+ * How each supply channel reaches the `native` flag both callers pass — stated as+ * a total Record so a channel added later has to say which reading it takes.+ */+const CHANNEL_IS_NATIVE: Readonly<Record<SupplyChannel, boolean>> = {+ native_cli: true,+ hub: false,+};const state = (status: SourceStatus, over: Partial<SourceState> = {}): SourceState => ({status,@@ -60,6 +70,57 @@ describe('sourceStatePresentation', () => {).key).toBe('settings.models.upstream.state.unavailableDue');});+ // The explanation belongs to the reading, not to one surface: every path that+ // produces 备用 carries it and no other state borrows it. Stated over the whole+ // status union and both surfaces so a status added later has to decide rather+ // than inherit silence, and so a surface cannot quietly drop the sentence.+ it('explains the standby reading wherever it is produced, and nothing else', () => {+ const surfaces: SourceStateSurface[] = ['card', 'detail'];+ const adoptions = [+ undefined,+ { known: true, backends: [], native: false },+ { known: true, backends: ['Claude Code'], native: false },+ ];+ const readings = SOURCE_STATUSES.flatMap((status) => surfaces.flatMap((surface) => adoptions.map(+ (adoption) => sourceStatePresentation(state(status), surface, 'en', 0, adoption),+ )));++ for (const reading of readings) {+ expect(Boolean(reading.hint)).toBe(reading.key === 'settings.models.upstream.state.standby');+ }+ expect(readings.filter((reading) => reading.hint).length).toBeGreaterThan(0);+ expect(sourceStatePresentation(state('standby'), 'detail', 'en', 0).hint).toEqual({+ labelKey: 'settings.models.sourceDetail.status.standbyHintLabel',+ bodyKey: 'settings.models.sourceDetail.status.standbyHint',+ });+ });++ // The hint promises one transition, so it is honest only if every supply+ // channel can make it — and both can, for the same reason: adoption is read off+ // route hops, and a source of either channel is a route candidate exactly while+ // its agent is in Gateway mode. 「Supplying … (native)」 is that transition's own+ // landing state, which is why naming the mode is what keeps the sentence true+ // for a native source rather than what excludes it.+ it('promises a transition every supply channel can make', () => {+ for (const native of Object.values(CHANNEL_IS_NATIVE)) {+ expect(sourceStatePresentation(state('standby'), 'detail', 'en', 0, {+ known: true,+ backends: [],+ native,+ }).hint).toBeTruthy();++ const adopted = sourceStatePresentation(state('active'), 'card', 'en', 0, {+ known: true,+ backends: ['Claude Code'],+ native,+ });+ expect(adopted.key).toBe(native+ ? 'settings.models.upstream.state.supplyingNative'+ : 'settings.models.upstream.state.supplying');+ expect(adopted.hint).toBeUndefined();+ }+ });+it('maps each needs-action cause to the copy register', () => {expect(sourceStatePresentation(state('needs_action', {detail_key: 'models.source.needs_action.balance_exhausted',diff --git a/ui/src/components/settings/models/sourceStatePresentation.ts b/ui/src/components/settings/models/sourceStatePresentation.tsindex 35e5a2932..6521b352a 100644--- a/ui/src/components/settings/models/sourceStatePresentation.ts+++ b/ui/src/components/settings/models/sourceStatePresentation.ts@@ -5,10 +5,36 @@ export type SourceStateSurface = 'card' | 'detail';export type SourceStatePresentation = {key: string | null;values?: Record<string, string>;+ /**+ * Copy that explains the label in place, for a reading whose plain meaning is+ * not the meaning a first-time user takes from it. Both halves are named here+ * because the affordance carrying them is a control: the body is what it says+ * and the label is what it is called, and neither is a string a consumer may+ * invent at the keyboard.+ */+ hint?: { labelKey: string; bodyKey: string };textClass: string;dotClass: string;};+/**+ * A healthy source that no route currently reaches. It is the state a source+ * lands in the moment it is added, and 备用 next to a key just created reads as+ * "the add failed" — so the authority that names the state also names the+ * sentence that explains it, and every surface rendering the label can reach+ * the same one. `active` without an adopting backend is the same reading and+ * shares this presentation rather than restating it.+ */+const STANDBY: SourceStatePresentation = {+ key: 'settings.models.upstream.state.standby',+ hint: {+ labelKey: 'settings.models.sourceDetail.status.standbyHintLabel',+ bodyKey: 'settings.models.sourceDetail.status.standbyHint',+ },+ textClass: 'text-muted',+ dotClass: 'bg-muted',+};+const NEEDS_ACTION_KEY: Readonly<Record<NeedsActionDetailKey, string>> = {'models.source.needs_action.oauth_expired': 'settings.models.sourceDetail.status.needsAction.oauthExpired','models.source.needs_action.balance_exhausted': 'settings.models.sourceDetail.status.needsAction.balanceExhausted',@@ -19,16 +45,8 @@ const NEEDS_ACTION_KEY: Readonly<Record<NeedsActionDetailKey, string>> = {type Rule = (state: SourceState, surface: SourceStateSurface, locale: string, now: number) => SourceStatePresentation;const STATUS_RULES: Readonly<Record<SourceStatus, Rule>> = {- active: () => ({- key: 'settings.models.upstream.state.standby',- textClass: 'text-muted',- dotClass: 'bg-muted',- }),- standby: () => ({- key: 'settings.models.upstream.state.standby',- textClass: 'text-muted',- dotClass: 'bg-muted',- }),+ active: () => STANDBY,+ standby: () => STANDBY,cooldown: (state, _surface, locale, now) => {const retryAt = state.retry_at ? new Date(state.retry_at).getTime() : Number.NaN;const remainingMinutes = Math.ceil((retryAt - now) / 60_000);diff --git a/ui/src/components/settings/models/tierSuggestions.ts b/ui/src/components/settings/models/tierSuggestions.tsnew file mode 100644index 000000000..cbcfc4c14--- /dev/null+++ b/ui/src/components/settings/models/tierSuggestions.ts@@ -0,0 +1,23 @@+import type { SourceProtocol } from './types';++/**+ * What the tier editor offers as ghost chips, derived from the protocol this+ * source was proved to speak. The OpenAI protocols name a fixed effort+ * vocabulary, so those four are worth offering; the Anthropic Messages protocol+ * expresses reasoning as a thinking budget rather than a named tier, so there is+ * nothing protocol-derived to suggest and that source stays pure free text.+ *+ * These are suggestions, never a vocabulary: `reasoning_efforts` is an+ * arbitrary-string capability declaration passed to the upstream verbatim, and a+ * relay may accept tiers no protocol ever named. Nothing here is persisted,+ * pre-filled at discovery, or sent to the API — a suggestion becomes data only+ * when the user clicks it, through the same add path typing it would take.+ * `lib/effortOptions.ts` is the sibling table for the OTHER axis — which efforts+ * an agent BACKEND offers — and is deliberately not reused: it answers a+ * different question and carries values (`minimal`, `max`) this one does not.+ */+export const TIER_SUGGESTIONS: Readonly<Record<SourceProtocol, readonly string[]>> = {+ anthropic: [],+ openai_responses: ['low', 'medium', 'high', 'xhigh'],+ openai_chat: ['low', 'medium', 'high', 'xhigh'],+};diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 3f04e1e4c..199091812 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -1451,6 +1451,8 @@"accountBanned": "Account restricted"},"error": "Error",+ "standbyHintLabel": "What standby means",+ "standbyHint": "This source is healthy. It reads as in use once a backend in Gateway mode serves a route through it.","listUpdated": "· model list updated {{time}}"},"summary_one": "{{host}} · {{count}} model",@@ -1536,7 +1538,9 @@"addFirst": "+ Add tier","add": "+ Tier","inputHint": "Enter to add · any text",- "remove": "Remove {{tier}}"+ "remove": "Remove {{tier}}",+ "suggest": "Add {{tier}}",+ "note": "Tiers are sent exactly as typed. A model with no tiers is still routable — its requests are sent without the effort parameter."},"addRow": {"hint": "Use this when a model is not discoverable, or when you only want one of them"diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex 842807538..3dd5e540d 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -1451,6 +1451,8 @@"accountBanned": "账号被限制"},"error": "异常",+ "standbyHintLabel": "备用是什么意思",+ "standbyHint": "这个来源是健康的。当网关模式下的某个后端通过它供给一条路由时,它就会显示为使用中。","listUpdated": "· 型号列表更新于 {{time}}"},"summary_one": "{{host}} · {{count}} 个型号",@@ -1536,7 +1538,9 @@"addFirst": "+ 添加档位","add": "+ 档位","inputHint": "回车添加 · 任意文本",- "remove": "移除 {{tier}}"+ "remove": "移除 {{tier}}",+ "suggest": "添加 {{tier}}",+ "note": "档位按你输入的原样发送。没有档位的型号照样可以路由,只是请求不带 effort 参数。"},"addRow": {"hint": "拉取不到、或只想接入其中一个时用"