Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

feat(chat): name the picked model by its catalog label on closed pickers (#2967)

Call White1ac84546c370
diff --git a/ui/src/components/workbench/AgentRoutePicker.test.tsx b/ui/src/components/workbench/AgentRoutePicker.test.tsx
index 154f21727..24807dd4c 100644
--- a/ui/src/components/workbench/AgentRoutePicker.test.tsx
+++ b/ui/src/components/workbench/AgentRoutePicker.test.tsx
@@ -44,6 +44,7 @@ vi.mock('../../context/ApiContext', async (importOriginal) => ({
// does — and an empty default keeps the backend fallback in play.
let catalogReasoning: Record<string, { value: string; label: string }[]> = {};
let catalogMenus: Record<string, { omitted: string[]; not_on: Record<string, string[]> }> = {};
+let catalogLabels: Record<string, string> = {};
// How many catalog reads were made, and whether the next ones wait to be answered.
let catalogReads = 0;
let deferReads = false;
@@ -68,7 +69,7 @@ vi.mock('../../lib/backendModels', async (importOriginal) => ({
catalogReads += 1;
const answer = () => onLoaded({
models: ['sonnet', 'opus'],
- modelLabels: {},
+ modelLabels: catalogLabels,
reasoningOptions: catalogReasoning,
// As the real loader answers: only a Hub catalog carries effort menus.
...(hubUnread ? { hubUnread: true as const } : hubMode === 'hub' ? { effortMenus: catalogMenus } : {}),
@@ -193,6 +194,8 @@ describe('AgentRoutePicker', () => {
cleanup();
catalogReasoning = {};
catalogMenus = {};
+ catalogLabels = {};
+ window.localStorage.clear();
sourceNames = null;
hubMode = 'direct';
hubUnread = false;
@@ -452,6 +455,18 @@ describe('AgentRoutePicker', () => {
expect(catalogReads).toBe(2);
});
+ it('names the model on the closed trigger by the label the catalog gave it', async () => {
+ catalogLabels = { sonnet: 'Sonnet 5.5' };
+ const user = userEvent.setup();
+ render(<OptimisticOwner onWrite={vi.fn()} />);
+ await openMenu(user);
+ await user.keyboard('{Escape}');
+
+ const name = within(screen.getByRole('button', { name: /claude/ })).getByText('Sonnet 5.5');
+ // The stored id stays one hover away.
+ expect(name.getAttribute('title')).toBe('sonnet');
+ });
+
it('highlights the pick while the owner write is still in flight', async () => {
const user = userEvent.setup();
const onWrite = vi.fn();
diff --git a/ui/src/components/workbench/AgentRoutePicker.tsx b/ui/src/components/workbench/AgentRoutePicker.tsx
index 1e70905f7..ba0af1e72 100644
--- a/ui/src/components/workbench/AgentRoutePicker.tsx
+++ b/ui/src/components/workbench/AgentRoutePicker.tsx
@@ -11,6 +11,7 @@ import type { EffortMenu } from '../settings/models/types';
import { loadBackendModelsWithRefresh, modelOptionLabel, supersedesHubAnswer, useAddModelExit } from '../../lib/backendModels';
import { isEffortSupported, refusedSavedEffort, resolveEffortOptions } from '../../lib/effortOptions';
import { useSourceNames } from '../../lib/useSourceNames';
+import { rememberModelLabels, useRememberedModelLabel } from '../../lib/modelLabelMemory';
import { useRouteSurfaceActive } from '../../lib/routeSurfaceActivity';
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
import { ResponsiveMenu } from '../ui/responsive-menu';
@@ -175,6 +176,9 @@ export const AgentRoutePicker: React.FC<AgentRoutePickerProps> = ({
const currentAgent = displayValue.agent_name;
const currentModel = displayValue.model;
const currentEffort = displayValue.reasoning_effort;
+ // The closed trigger names the model as the menu does, from labels remembered
+ // across pickers and loads; the raw id stays one hover away.
+ const currentModelLabel = useRememberedModelLabel(backend, currentModel) ?? currentModel;
const currentAgentLabel = displayedAgent?.display_name || currentAgent;
const triggerLabel = (routeIsDefault && defaultLabel) || currentAgentLabel || defaultLabel || t('chat.pickAgent');
const agentLabel = currentAgentLabel || defaultLabel || t('chat.pickAgent');
@@ -266,6 +270,8 @@ export const AgentRoutePicker: React.FC<AgentRoutePickerProps> = ({
setEffortMenusByBackend((prev) => ({ ...prev, [backend]: effortMenus ?? {} }));
setModelsByBackend((prev) => ({ ...prev, [backend]: models }));
setModelLabelsByBackend((prev) => ({ ...prev, [backend]: modelLabels ?? {} }));
+ // Closed pickers anywhere name their model from this answer.
+ rememberModelLabels(backend, modelLabels ?? {});
},
() => {
loadedBackends.delete(backend);
@@ -447,8 +453,11 @@ export const AgentRoutePicker: React.FC<AgentRoutePickerProps> = ({
{currentModel && (
<>
<span className="text-muted">·</span>
- <span className="truncate font-mono text-[10px] text-muted">
- {currentModel}
+ <span
+ className="truncate font-mono text-[10px] text-muted"
+ title={currentModelLabel !== currentModel ? currentModel : undefined}
+ >
+ {currentModelLabel}
</span>
</>
)}
diff --git a/ui/src/lib/backendModels.ts b/ui/src/lib/backendModels.ts
index a9cca770c..59ff576e5 100644
--- a/ui/src/lib/backendModels.ts
+++ b/ui/src/lib/backendModels.ts
@@ -132,6 +132,22 @@ export async function fetchBackendModels(
return agent === null ? { ...native, hubUnread: true } : native;
}
+/**
+ * Just the display labels of a backend's models, for a closed picker that names
+ * the current model. Reads only what is already on disk: Model Hub's persisted
+ * catalog, or Claude/Codex's cached catalog snapshot. OpenCode's live list is
+ * never read here — it may start OpenCode, and it carries no labels anyway.
+ */
+export async function fetchBackendModelLabels(
+ api: ApiContextType,
+ backend: string,
+): Promise<Record<string, string>> {
+ const hub = hubCatalogModels(await api.readModelHubAgentCatalogForModelPicker(backend), backend);
+ if (hub) return hub.modelLabels ?? {};
+ if (backend !== 'claude' && backend !== 'codex') return {};
+ return (await nativeBackendModels(api, backend)).modelLabels ?? {};
+}
+
async function nativeBackendModels(api: ApiContextType, backend: string): Promise<BackendModels> {
if (!getBackendUiMeta(backend).capabilities.supports_cli) return { models: [] };
if (backend === 'claude') {
diff --git a/ui/src/lib/modelLabelMemory.test.ts b/ui/src/lib/modelLabelMemory.test.ts
new file mode 100644
index 000000000..d9564a5e9
--- /dev/null
+++ b/ui/src/lib/modelLabelMemory.test.ts
@@ -0,0 +1,91 @@
+/* @vitest-environment jsdom */
+
+// A closed picker names its model ("Opus 5.5") instead of the stored id. The
+// cost contract: a label this browser has seen costs no request, a miss costs
+// one read per backend per load of what is already on disk, and OpenCode's live
+// list — which may start OpenCode — is never read for a label.
+
+import { renderHook, waitFor } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const api = {
+ readModelHubAgentCatalogForModelPicker: vi.fn(),
+ claudeModels: vi.fn(),
+ codexModels: vi.fn(),
+ readOpencodeOptionsForModelPicker: vi.fn(),
+};
+vi.mock('../context/ApiContext', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('../context/ApiContext')>()),
+ useApi: () => api,
+}));
+
+const STORAGE_KEY = 'avibe.model-labels.v1';
+
+// The memory is page-load state: each case loads a fresh module, as a reload would.
+const freshMemory = async () => {
+ vi.resetModules();
+ return import('./modelLabelMemory');
+};
+
+beforeEach(() => {
+ window.localStorage.clear();
+ for (const fn of Object.values(api)) fn.mockReset();
+ api.readModelHubAgentCatalogForModelPicker.mockResolvedValue(null);
+ api.claudeModels.mockResolvedValue({
+ ok: true,
+ models: ['claude-opus-5-5', 'claude-sonnet-5-5'],
+ model_labels: { 'claude-opus-5-5': 'Opus 5.5', 'claude-sonnet-5-5': 'Sonnet 5.5' },
+ });
+});
+
+describe('remembered model labels', () => {
+ it('names a model seen in an earlier load from the first render, without a request', async () => {
+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify({ claude: { 'claude-opus-5-5': 'Opus 5.5' } }));
+ const { useRememberedModelLabel } = await freshMemory();
+
+ const { result } = renderHook(() => useRememberedModelLabel('claude', 'claude-opus-5-5'));
+
+ expect(result.current).toBe('Opus 5.5');
+ expect(api.readModelHubAgentCatalogForModelPicker).not.toHaveBeenCalled();
+ expect(api.claudeModels).not.toHaveBeenCalled();
+ });
+
+ it('reads a backend once per load on a miss, then names every model of it', async () => {
+ const { useRememberedModelLabel } = await freshMemory();
+
+ const opus = renderHook(() => useRememberedModelLabel('claude', 'claude-opus-5-5'));
+ const sonnet = renderHook(() => useRememberedModelLabel('claude', 'claude-sonnet-5-5'));
+ // A model the catalog has no label for keeps its id, and asks nothing more.
+ const custom = renderHook(() => useRememberedModelLabel('claude', 'my-custom-model'));
+
+ await waitFor(() => expect(opus.result.current).toBe('Opus 5.5'));
+ expect(sonnet.result.current).toBe('Sonnet 5.5');
+ expect(custom.result.current).toBeNull();
+ expect(api.readModelHubAgentCatalogForModelPicker).toHaveBeenCalledTimes(1);
+ expect(api.claudeModels).toHaveBeenCalledTimes(1);
+ // ...and the next load names them without asking.
+ expect(JSON.parse(window.localStorage.getItem(STORAGE_KEY) ?? '{}').claude['claude-opus-5-5']).toBe('Opus 5.5');
+ });
+
+ it('takes a Model Hub catalog\'s display names, and never reads OpenCode\'s live list', async () => {
+ api.readModelHubAgentCatalogForModelPicker.mockImplementation(async (backend: string) =>
+ backend === 'codex'
+ ? {
+ backend: 'codex',
+ mode: 'hub',
+ catalog_models: [{ id: 'gpt-6.1', display_name: 'GPT-6.1', routeable: true, reasoning_efforts: [], supports_reasoning: true }],
+ }
+ : null,
+ );
+ const { useRememberedModelLabel } = await freshMemory();
+
+ const codex = renderHook(() => useRememberedModelLabel('codex', 'gpt-6.1'));
+ const opencode = renderHook(() => useRememberedModelLabel('opencode', 'anthropic/claude-opus-5-5'));
+
+ await waitFor(() => expect(codex.result.current).toBe('GPT-6.1'));
+ await waitFor(() => expect(api.readModelHubAgentCatalogForModelPicker).toHaveBeenCalledWith('opencode'));
+ expect(opencode.result.current).toBeNull();
+ expect(api.codexModels).not.toHaveBeenCalled();
+ expect(api.readOpencodeOptionsForModelPicker).not.toHaveBeenCalled();
+ });
+});
diff --git a/ui/src/lib/modelLabelMemory.ts b/ui/src/lib/modelLabelMemory.ts
new file mode 100644
index 000000000..9b477b2ab
--- /dev/null
+++ b/ui/src/lib/modelLabelMemory.ts
@@ -0,0 +1,84 @@
+import { useEffect, useSyncExternalStore } from 'react';
+
+import { useApi } from '../context/ApiContext';
+import { fetchBackendModelLabels } from './backendModels';
+
+// Friendly model names ("Opus 5.5") for closed pickers, which otherwise only
+// know the raw id the route stores. Every catalog answer a picker already reads
+// is remembered here and in localStorage, so a trigger normally names its model
+// from the first paint without a request. Only a model this browser has never
+// seen a label for costs one read — per backend per page load, of what is
+// already on disk (see fetchBackendModelLabels) — and a model with no label
+// simply keeps its id.
+
+const STORAGE_KEY = 'avibe.model-labels.v1';
+
+type LabelsByBackend = Record<string, Record<string, string>>;
+
+const isLabelMap = (value: unknown): value is Record<string, string> =>
+ Boolean(value) && typeof value === 'object' && !Array.isArray(value)
+ && Object.values(value as Record<string, unknown>).every((label) => typeof label === 'string');
+
+function readStored(): LabelsByBackend {
+ try {
+ const raw = typeof window !== 'undefined' ? window.localStorage.getItem(STORAGE_KEY) : null;
+ const parsed = raw ? (JSON.parse(raw) as unknown) : null;
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
+ const out = Object.create(null) as LabelsByBackend;
+ for (const [backend, labels] of Object.entries(parsed as Record<string, unknown>)) {
+ if (isLabelMap(labels)) out[backend] = Object.assign(Object.create(null), labels);
+ }
+ return out;
+ } catch {
+ return {};
+ }
+}
+
+let labelsByBackend: LabelsByBackend | null = null;
+const listeners = new Set<() => void>();
+// Backends whose labels were read (or are being read) this page load.
+const readThisLoad = new Set<string>();
+
+const current = (): LabelsByBackend => (labelsByBackend ??= readStored());
+
+/** Record a backend's complete label answer, replacing what was known for it. */
+export function rememberModelLabels(backend: string, labels: Record<string, string>): void {
+ if (!backend) return;
+ readThisLoad.add(backend);
+ const next = Object.assign(Object.create(null), current()) as LabelsByBackend;
+ next[backend] = Object.assign(Object.create(null), labels);
+ labelsByBackend = next;
+ try {
+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
+ } catch {
+ // Storage full or unavailable: the in-memory answer still serves this load.
+ }
+ for (const listener of listeners) listener();
+}
+
+const subscribe = (listener: () => void) => {
+ listeners.add(listener);
+ return () => listeners.delete(listener);
+};
+
+const labelOf = (backend: string, model: string): string | null => {
+ const labels = current()[backend];
+ return labels && Object.prototype.hasOwnProperty.call(labels, model) ? labels[model] : null;
+};
+
+/** The remembered label for `model`, reading the backend's labels once if this
+ * browser has none for it. Null keeps the caller on the raw id. */
+export function useRememberedModelLabel(backend: string, model: string | null | undefined): string | null {
+ const api = useApi();
+ const label = useSyncExternalStore(subscribe, () => (backend && model ? labelOf(backend, model) : null));
+ useEffect(() => {
+ if (!backend || !model || label !== null || readThisLoad.has(backend)) return;
+ readThisLoad.add(backend);
+ fetchBackendModelLabels(api, backend).then(
+ (labels) => rememberModelLabels(backend, labels),
+ // No answer this load; the open menu still reads the full list.
+ () => undefined,
+ );
+ }, [api, backend, model, label]);
+ return label;
+}