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
fix(model-hub): preserve OpenCode menu authority
cyhf36bd18bccc5
diff --git a/docs/plans/model-hub-ui-spec.md b/docs/plans/model-hub-ui-spec.mdindex 276b6029c..d04b884b1 100644--- a/docs/plans/model-hub-ui-spec.md+++ b/docs/plans/model-hub-ui-spec.md@@ -1488,6 +1488,7 @@ unable to outlive its surface, which is the cheaper answer wherever it is availa| `gateway.menu.search` `[derived]` | 搜索模型或供应商 | Search models or sources || `gateway.menu.selected` `[derived]` | 已选 {{selected}} / {{total}} | {{selected}} of {{total}} selected || `gateway.menu.empty` `[derived]` | 没有可供 OpenCode 选择的模型 | No eligible source models are available |+| `gateway.menu.inventoryUnavailable` `[derived]` | 暂时无法读取模型清单,请先重试供应商列表,再编辑此选择。 | Model inventory is unavailable. Retry the source list before editing this selection. || `gateway.menu.noMatch` `[derived]` | 没有匹配的模型 | No models match this search || `gateway.menu.save` `[derived]` | 保存选择 | Save selection || `gateway.menu.saving` `[derived]` | 正在保存… | Saving… |@@ -1856,8 +1857,10 @@ backend has selected models and nothing can serve them* — the fix is a source「这个后端没有可用型号」 is reserved for a fixed backend whose catalog is genuinely empty.OpenCode with `menu.checked == []` instead says 「尚未选择模型」: the eligible Sourceinventory may be full, but none of it belongs to OpenCode's explicit menu until the user-chooses it. The group keeps its header and its `<mode> · <status>` line in every branch;-only the row area differs.+chooses it. A persisted Route left behind after a model is unchecked is dormant: it does+not keep a row visible or trigger a chain read, and becomes visible with its saved mapping+if that model is selected again. The group keeps its header and its `<mode> · <status>`+line in every branch; only the row area differs.**The OpenCode empty branch offers the exact fix in place** `[derived]`. **Manage models**is present both in the group head and beside 「尚未选择模型」. It opens a dialog populated@@ -1866,7 +1869,10 @@ OpenCode identifier. Saving performs `PUT /api/models/agents/opencode/menu`; a smodel with no Route then appears as an ordinary row whose current-text slot reads`gateway.group.status.unconfigured`, and that row opens frame 02. The dialog preservesthe saved menu view, blocks dismissal while its write is outstanding, and retains the-draft after a failed save.+draft after a failed save. The Source inventory must be an authoritative ready read before+the dialog enables search, selection, or save. An unread or failed inventory preserves the+stored `menu.checked` values, shows `gateway.menu.inventoryUnavailable`, and cannot issue+the menu `PUT`; stale or absent inventory is never interpreted as an empty selection.**Extreme data**diff --git a/ui/src/components/settings/models/AgentCard.test.tsx b/ui/src/components/settings/models/AgentCard.test.tsxindex c1d504bd4..1dd437de9 100644--- a/ui/src/components/settings/models/AgentCard.test.tsx+++ b/ui/src/components/settings/models/AgentCard.test.tsx@@ -74,15 +74,22 @@ afterEach(cleanup);describe('AgentCard', () => {it('renders an empty OpenCode selection as configurable rather than as missing backend supply', async () => {const onOpenModels = vi.fn();- render(<I18nextProvider i18n={localeInstance('zh')}><AgentCard agents={[openCodeAgent]} sources={[]} chains={{}} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenModels={onOpenModels} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);+ const retainedModelId = 'openai/gpt-5.6-luna';+ const agentWithRetainedRoute = {+ ...openCodeAgent,+ routes: { [retainedModelId]: { hops: [{ source_id: 'src_a', model_id: 'gpt-5.6-luna' }] } },+ model_supply: [{ model_id: retainedModelId, chain_length: 1, has_runnable_hop: true }],+ };+ render(<I18nextProvider i18n={localeInstance('zh')}><AgentCard agents={[agentWithRetainedRoute]} sources={[]} chains={{}} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenModels={onOpenModels} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);expect(screen.getByText('网关 · 未配置模型路由')).toBeTruthy();expect(screen.getByText('已选 0 个模型')).toBeTruthy();expect(screen.getByText('尚未选择模型')).toBeTruthy();+ expect(screen.queryByText(retainedModelId)).toBeNull();expect(screen.queryByText('这个后端没有可用模型')).toBeNull();await userEvent.click(screen.getAllByRole('button', { name: '管理模型' })[0]);- expect(onOpenModels).toHaveBeenCalledWith(openCodeAgent);+ expect(onOpenModels).toHaveBeenCalledWith(agentWithRetainedRoute);});it('labels a selected OpenCode model with an empty route as unconfigured', () => {diff --git a/ui/src/components/settings/models/AgentCard.tsx b/ui/src/components/settings/models/AgentCard.tsxindex e99b21a1d..89193a449 100644--- a/ui/src/components/settings/models/AgentCard.tsx+++ b/ui/src/components/settings/models/AgentCard.tsx@@ -6,7 +6,7 @@ import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { ResponsiveMenu } from '@/components/ui/responsive-menu';import { cn } from '@/lib/utils';-import { collapsedModelRows, listedModelIds, modelChainKey, modelSupplyState, type ModelChainIndex, type ModelChainRead } from './modelRows';+import { collapsedModelRows, modelChainKey, modelSupplyState, visibleModelIds, type ModelChainIndex, type ModelChainRead } from './modelRows';import { foldRegionRead } from './regionRead';import { agentGroupStatus } from './supply';import { agentHasLiveChainProjection, type FreshRuntimeProjection } from './runtimeLifecycle';@@ -116,7 +116,7 @@ const AgentModelCard: React.FC<{const { Icon, accent } = backendVisual(agent.backend);const [expanded, setExpanded] = React.useState(false);const [modeMenuOpen, setModeMenuOpen] = React.useState(false);- const allModels = listedModelIds(agent);+ const allModels = visibleModelIds(agent);const hasOpenMenu = agent.menu_kind === 'open';const displayedModelCount = hasOpenMenu ? agent.menu?.checked.length ?? 0 : allModels.length;const chainProjectionLive = agentHasLiveChainProjection(runtime, agent);diff --git a/ui/src/components/settings/models/OpenCodeMenuDialog.test.tsx b/ui/src/components/settings/models/OpenCodeMenuDialog.test.tsxindex 5f0c11023..6aba3677d 100644--- a/ui/src/components/settings/models/OpenCodeMenuDialog.test.tsx+++ b/ui/src/components/settings/models/OpenCodeMenuDialog.test.tsx@@ -82,6 +82,7 @@ describe('OpenCodeMenuDialog', () => {openagent={agent}sources={sources}+ inventoryReadyonClose={onClose}onSaved={onSaved}menuWrite={{ pending: false, track: async (work) => work() }}@@ -113,6 +114,7 @@ describe('OpenCodeMenuDialog', () => {openagent={{ ...agent, menu: { view: 'full', checked: ['openai/gpt-5.6-sol'] } }}sources={sources}+ inventoryReadyonClose={vi.fn()}onSaved={vi.fn()}menuWrite={{ pending: false, track: async (work) => work() }}@@ -135,6 +137,7 @@ describe('OpenCodeMenuDialog', () => {openagent={{ ...agent, menu: { view: 'featured', checked: ['openai/missing-model'] } }}sources={sources}+ inventoryReadyonClose={vi.fn()}onSaved={vi.fn()}menuWrite={{ pending: false, track: async (work) => work() }}@@ -146,4 +149,29 @@ describe('OpenCodeMenuDialog', () => {await user.click(screen.getByRole('button', { name: 'Save selection' }));await waitFor(() => expect(putMenu).toHaveBeenCalledWith({ view: 'featured', checked: [] }));});++ it('keeps the saved menu immutable while source inventory is unread', async () => {+ const user = userEvent.setup();+ const putMenu = vi.spyOn(modelsApi, 'putMenu');+ render(+ <I18nextProvider i18n={i18n}>+ <OpenCodeMenuDialog+ open+ agent={{ ...agent, menu: { view: 'featured', checked: ['openai/gpt-5.6-luna'] } }}+ sources={[]}+ inventoryReady={false}+ onClose={vi.fn()}+ onSaved={vi.fn()}+ menuWrite={{ pending: false, track: async (work) => work() }}+ />+ </I18nextProvider>,+ );++ expect(screen.getByText('1 selected')).toBeTruthy();+ expect(screen.getByText('Model inventory is unavailable. Retry the source list before editing this selection.')).toBeTruthy();+ const save = screen.getByRole('button', { name: 'Save selection' });+ expect(save.hasAttribute('disabled')).toBe(true);+ await user.click(save);+ expect(putMenu).not.toHaveBeenCalled();+ });});diff --git a/ui/src/components/settings/models/OpenCodeMenuDialog.tsx b/ui/src/components/settings/models/OpenCodeMenuDialog.tsxindex 670368b1a..8095b36f2 100644--- a/ui/src/components/settings/models/OpenCodeMenuDialog.tsx+++ b/ui/src/components/settings/models/OpenCodeMenuDialog.tsx@@ -39,33 +39,38 @@ export const OpenCodeMenuDialog: React.FC<{open: boolean;agent: AgentSupply;sources: Source[];+ inventoryReady: boolean;onClose: () => void;onSaved: (echoed: AgentSupply) => void | Promise<void>;menuWrite: PendingWrite;-}> = ({ open, agent, sources, onClose, onSaved, menuWrite }) => {+}> = ({ open, agent, sources, inventoryReady, onClose, onSaved, menuWrite }) => {const { t } = useTranslation();const models = React.useMemo(() => selectableModels(agent, sources), [agent, sources]);const availableIds = React.useMemo(() => new Set(models.map((model) => model.id)), [models]);const rawChecked = React.useMemo(() => agent.menu?.checked ?? [], [agent.menu?.checked]);const savedChecked = React.useMemo(- () => (agent.menu?.checked ?? []).filter((id) => availableIds.has(id)),- [agent.menu?.checked, availableIds],+ () => inventoryReady ? rawChecked.filter((id) => availableIds.has(id)) : rawChecked,+ [availableIds, inventoryReady, rawChecked],);const [selected, setSelected] = React.useState<Set<string>>(() => new Set(savedChecked));const [query, setQuery] = React.useState('');const [saveFailed, setSaveFailed] = React.useState(false);const seed = React.useRef(initialSeedState);- const authoritative = savedMenuKey(agent.menu);+ const inventoryKey = React.useMemo(() => JSON.stringify(models.map((model) => model.id)), [models]);+ const [lastReadyInventory, setLastReadyInventory] = React.useState<string | null>(() => inventoryReady ? inventoryKey : null);+ const inventoryAuthority = inventoryReady ? inventoryKey : lastReadyInventory ?? 'unread';+ const authoritative = JSON.stringify([savedMenuKey(agent.menu), inventoryAuthority]);React.useEffect(() => {if (!open) return;+ if (inventoryReady && lastReadyInventory !== inventoryKey) setLastReadyInventory(inventoryKey);const step = seedStep(seed.current, authoritative);seed.current = step.state;if (!step.reseed) return;setSelected(new Set(savedChecked));setQuery('');setSaveFailed(false);- }, [open, authoritative, savedChecked]);+ }, [open, authoritative, inventoryKey, inventoryReady, lastReadyInventory, savedChecked]);const normalizedQuery = query.trim().toLocaleLowerCase();const visibleModels = normalizedQuery@@ -75,7 +80,7 @@ export const OpenCodeMenuDialog: React.FC<{const dirty = selected.size !== savedSet.size || [...selected].some((id) => !savedSet.has(id));const toggle = (id: string) => {- if (menuWrite.pending) return;+ if (!inventoryReady || menuWrite.pending) return;setSaveFailed(false);setSelected((previous) => {const next = new Set(previous);@@ -86,7 +91,7 @@ export const OpenCodeMenuDialog: React.FC<{};const save = () => {- if (!dirty || menuWrite.pending) return;+ if (!inventoryReady || !dirty || menuWrite.pending) return;setSaveFailed(false);void menuWrite.track(async () => {let echoed: AgentSupply;@@ -130,14 +135,20 @@ export const OpenCodeMenuDialog: React.FC<{placeholder={t('settings.models.gateway.menu.search') as string}aria-label={t('settings.models.gateway.menu.search') as string}className="min-w-0 flex-1 text-[12.5px]"- disabled={menuWrite.pending}+ disabled={!inventoryReady || menuWrite.pending}/></div>- <span className="shrink-0 text-[11px] font-semibold text-muted">{t('settings.models.gateway.menu.selected', { selected: selected.size, total: models.length })}</span>+ <span className="shrink-0 text-[11px] font-semibold text-muted">+ {inventoryReady+ ? t('settings.models.gateway.menu.selected', { selected: selected.size, total: models.length })+ : t('settings.models.gateway.selectedModelCount', { count: selected.size })}+ </span></div><div className="min-h-0 flex-1 overflow-y-auto rounded-md border border-border bg-background p-1.5">- {models.length === 0 ? (+ {!inventoryReady ? (+ <p className="px-4 py-10 text-center text-[12.5px] text-muted">{t('settings.models.gateway.menu.inventoryUnavailable')}</p>+ ) : models.length === 0 ? (<p className="px-4 py-10 text-center text-[12.5px] text-muted">{t('settings.models.gateway.menu.empty')}</p>) : visibleModels.length === 0 ? (<p className="px-4 py-10 text-center text-[12.5px] text-muted">{t('settings.models.gateway.menu.noMatch')}</p>@@ -151,7 +162,7 @@ export const OpenCodeMenuDialog: React.FC<{type="button"role="checkbox"aria-checked={checked}- disabled={menuWrite.pending}+ disabled={!inventoryReady || menuWrite.pending}onClick={() => toggle(model.id)}className={cn('flex min-h-11 w-full min-w-0 items-center gap-3 rounded-md px-3 py-2 text-left transition-colors hover:bg-surface-2 disabled:opacity-50',@@ -174,7 +185,7 @@ export const OpenCodeMenuDialog: React.FC<{<div className="min-h-5 text-[11px] font-semibold text-destructive-ink" role="status">{saveFailed ? t('settings.models.gateway.menu.saveFailed') : null}</div><div className="flex w-full flex-col-reverse gap-2 sm:w-auto sm:flex-row"><Button type="button" variant="outline" onClick={onClose} disabled={menuWrite.pending}>{t('settings.models.gateway.menu.cancel')}</Button>- <Button type="button" onClick={save} disabled={!dirty || menuWrite.pending}>+ <Button type="button" onClick={save} disabled={!inventoryReady || !dirty || menuWrite.pending}>{menuWrite.pending && <LoaderCircle className="animate-spin" aria-hidden="true" />}{t(menuWrite.pending ? 'settings.models.gateway.menu.saving' : 'settings.models.gateway.menu.save')}</Button>diff --git a/ui/src/components/settings/models/SettingsModelsPage.tsx b/ui/src/components/settings/models/SettingsModelsPage.tsxindex 8ab5a8995..82b67446a 100644--- a/ui/src/components/settings/models/SettingsModelsPage.tsx+++ b/ui/src/components/settings/models/SettingsModelsPage.tsx@@ -1383,7 +1383,7 @@ export const SettingsModelsPage: React.FC = () => {/>)}{orderAgent && <SourceOrderDrawer open agent={orderAgent} sources={sources} sourceReads={sourceCollectionReads} onClose={() => setOrderBackend(null)} onSaved={agentSaved} orderWrite={{ pending: agentWrites.has(orderAgent.backend), track: (work) => agentWriteRegistry.track(orderAgent.backend, work) }} />}- {menuAgent && <OpenCodeMenuDialog open agent={menuAgent} sources={sources} onClose={() => setMenuBackend(null)} onSaved={agentSaved} menuWrite={{ pending: agentWrites.has(menuAgent.backend), track: (work) => agentWriteRegistry.track(menuAgent.backend, work) }} />}+ {menuAgent && <OpenCodeMenuDialog open agent={menuAgent} sources={sources} inventoryReady={sourcesRead.kind === 'ready'} onClose={() => setMenuBackend(null)} onSaved={agentSaved} menuWrite={{ pending: agentWrites.has(menuAgent.backend), track: (work) => agentWriteRegistry.track(menuAgent.backend, work) }} />}<RouteChainDialogselection={routeSelection}sources={sources}diff --git a/ui/src/components/settings/models/modelRows.test.ts b/ui/src/components/settings/models/modelRows.test.tsindex 9eb995ee1..626fd601e 100644--- a/ui/src/components/settings/models/modelRows.test.ts+++ b/ui/src/components/settings/models/modelRows.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest';-import { COLLAPSED_MODEL_LIMIT, collapsedModelRows, listedModelIds, modelChainKey, modelChainRequests, modelSupplyState } from './modelRows';+import { COLLAPSED_MODEL_LIMIT, collapsedModelRows, listedModelIds, modelChainKey, modelChainRequests, modelSupplyState, visibleModelIds } from './modelRows';import type { AgentSupply } from './types';const agent: AgentSupply = {@@ -22,6 +22,15 @@ describe('modelRows', () => {expect(modelChainKey('claude', 'builtin')).toBe('claude\u0000builtin');});+ it('keeps dormant OpenCode routes hidden until their model is selected again', () => {+ const open = { ...agent, backend: 'opencode' as const, menu_kind: 'open' as const, builtin_models: null, menu: { view: 'featured' as const, checked: [] } };++ expect(visibleModelIds(open)).toEqual([]);+ expect(collapsedModelRows(open)).toEqual({ visible: [], hidden: [] });+ expect(modelChainRequests([open])).toEqual([]);+ expect(visibleModelIds({ ...open, menu: { view: 'featured', checked: ['route-only'] } })).toEqual(['route-only']);+ });+});describe('collapsedModelRows', () => {diff --git a/ui/src/components/settings/models/modelRows.ts b/ui/src/components/settings/models/modelRows.tsindex a3d37e911..4c27e097f 100644--- a/ui/src/components/settings/models/modelRows.ts+++ b/ui/src/components/settings/models/modelRows.ts@@ -71,6 +71,12 @@ export function listedModelIds(agent: AgentSupply): string[] {});}+/** OpenCode rows are its saved menu, not dormant routes left behind by an earlier selection. */+export function visibleModelIds(agent: AgentSupply): string[] {+ if (agent.menu_kind !== 'open') return listedModelIds(agent);+ return [...new Set(agent.menu?.checked ?? [])].filter(Boolean);+}+export const COLLAPSED_MODEL_LIMIT = 6;export type CollapsedModelRows = {@@ -90,7 +96,7 @@ export function modelSupplyState(agent: AgentSupply, modelId: string): ModelSupp/** Keep the backend menu order stable while bounding each collapsed group. */export function collapsedModelRows(agent: AgentSupply, expanded = false): CollapsedModelRows {- const models = listedModelIds(agent);+ const models = visibleModelIds(agent);if (expanded) return { visible: models, hidden: [] };return {visible: models.slice(0, COLLAPSED_MODEL_LIMIT),@@ -103,7 +109,7 @@ export function modelChainRequests(agents: AgentSupply[]): ModelChainRequest[] {const requests = new Map<string, ModelChainRequest>();for (const agent of agents) {if (agent.mode !== 'hub') continue;- for (const modelId of listedModelIds(agent)) {+ for (const modelId of visibleModelIds(agent)) {const key = modelChainKey(agent.backend, modelId);if (!requests.has(key)) requests.set(key, { backend: agent.backend, modelId });}diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex ce6690d18..209caedf1 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -946,6 +946,7 @@"search": "Search models or sources","selected": "{{selected}} of {{total}} selected","empty": "No eligible source models are available",+ "inventoryUnavailable": "Model inventory is unavailable. Retry the source list before editing this selection.","noMatch": "No models match this search","save": "Save selection","saving": "Saving…",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex 33c568a85..14bbde198 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -946,6 +946,7 @@"search": "搜索模型或供应商","selected": "已选 {{selected}} / {{total}}","empty": "没有可供 OpenCode 选择的模型",+ "inventoryUnavailable": "暂时无法读取模型清单,请先重试供应商列表,再编辑此选择。","noMatch": "没有匹配的模型","save": "保存选择","saving": "正在保存…",