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.

fix(model-hub): reveal newly saved models (#1829)

Call Whiteaa6d4d99e3a3
diff --git a/ui/src/components/settings/models/AgentCard.test.tsx b/ui/src/components/settings/models/AgentCard.test.tsx
index 386752fa4..963a322ea 100644
--- a/ui/src/components/settings/models/AgentCard.test.tsx
+++ b/ui/src/components/settings/models/AgentCard.test.tsx
@@ -349,6 +349,37 @@ describe('AgentCard', () => {
expect(screen.getByText(/^Supply paused$|^等待供应商恢复$/i)).toBeTruthy();
});
+ it('reveals a newly saved model that lands beyond the collapsed limit', async () => {
+ const models = Array.from({ length: COLLAPSED_MODEL_LIMIT }, (_, index) => `model-${index + 1}`);
+ const addedModel = 'newly-added-model';
+ const catalogued = (ids: string[]): AgentSupply => ({
+ ...hubAgent,
+ routes: {},
+ model_supply: ids.map((modelId) => ({ model_id: modelId, chain_length: 0, has_runnable_hop: false })),
+ catalog_models: ids.map((id) => ({
+ id, display_name: null, origin: 'manual', models_dev_id: null, context_window: null, max_output_tokens: null,
+ input_modalities: ['text'], output_modalities: ['text'], supports_tools: true, supports_reasoning: false,
+ reasoning_efforts: [], locked: false, routeable: true,
+ })),
+ });
+ const props = {
+ sources: [], chains: {}, pendingBackends: new Set<string>(), switchFailures: new Set<string>(), connectingBackend: null,
+ onConnectHub: vi.fn(), onSwitchDirect: vi.fn(), onOpenOrder: vi.fn(), onOpenRoute: vi.fn(), onProbeSettled: vi.fn(),
+ };
+ const { rerender } = render(
+ <I18nextProvider i18n={i18n}><AgentCard agents={[catalogued(models)]} {...props} /></I18nextProvider>,
+ );
+
+ expect(screen.queryByText(addedModel)).toBeNull();
+ rerender(
+ <I18nextProvider i18n={i18n}><AgentCard agents={[catalogued([...models, addedModel])]} {...props} /></I18nextProvider>,
+ );
+
+ expect(screen.getByText(addedModel)).toBeTruthy();
+ await userEvent.click(screen.getByRole('button', { name: /^Collapse$|^收起$/i }));
+ expect(screen.queryByText(addedModel)).toBeNull();
+ });
+
it('keeps a chain reread reachable when a short group is unresolved', async () => {
const onProbeSettled = vi.fn();
const key = modelChainKey('claude', 'claude-opus-4-6');
diff --git a/ui/src/components/settings/models/AgentCard.tsx b/ui/src/components/settings/models/AgentCard.tsx
index d310a384b..e1ef9cafb 100644
--- a/ui/src/components/settings/models/AgentCard.tsx
+++ b/ui/src/components/settings/models/AgentCard.tsx
@@ -7,7 +7,7 @@ import { Button } from '@/components/ui/button';
import { ResponsiveMenu } from '@/components/ui/responsive-menu';
import { cn } from '@/lib/utils';
import { catalogModelIds } from './backendCatalog';
-import { collapsedModelRows, modelChainKey, modelSupplyState, type ModelChainIndex, type ModelChainRead } from './modelRows';
+import { COLLAPSED_MODEL_LIMIT, collapsedModelRows, modelChainKey, modelSupplyState, type ModelChainIndex, type ModelChainRead } from './modelRows';
import { foldRegionRead } from './regionRead';
import { agentGroupStatus } from './supply';
import { agentHasLiveChainProjection, type FreshRuntimeProjection } from './runtimeLifecycle';
@@ -137,7 +137,15 @@ const AgentModelCard: React.FC<{
const { Icon, accent } = backendVisual(agent.backend);
const [expanded, setExpanded] = React.useState(false);
const [modeMenuOpen, setModeMenuOpen] = React.useState(false);
- const allModels = catalogModelIds(agent);
+ const allModels = React.useMemo(() => catalogModelIds(agent), [agent]);
+ const previousModelsRef = React.useRef(allModels);
+ React.useEffect(() => {
+ const previousModels = new Set(previousModelsRef.current);
+ if (allModels.slice(COLLAPSED_MODEL_LIMIT).some((modelId) => !previousModels.has(modelId))) {
+ setExpanded(true);
+ }
+ previousModelsRef.current = allModels;
+ }, [allModels]);
const chainProjectionLive = agentHasLiveChainProjection(runtime, agent);
const collapsed = collapsedModelRows(agent, expanded);
const collapsedAtRest = collapsedModelRows(agent);
diff --git a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
index 7c4ac4e76..5843a6419 100644
--- a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
+++ b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
@@ -13,7 +13,7 @@ import type { ModelsSurfaceKind } from './modelHubSurfaceState';
import { modelsApi } from './modelsApi';
import { SOURCE_MUTATION_REPORT_PROJECTIONS } from './mutationSettlement';
import { SettingsModelsPage } from './SettingsModelsPage';
-import { CONTRACT_VERSION, type AgentBackend, type AgentChain, type AgentSupply, type RuntimeDependency, type Source, type UsageSummary } from './types';
+import { CONTRACT_VERSION, type AgentBackend, type AgentChain, type AgentSupply, type BackendModel, type RuntimeDependency, type Source, type UsageSummary } from './types';
const directAgent = (backend: AgentBackend): AgentSupply => ({
backend,
@@ -154,6 +154,51 @@ afterEach(() => {
});
describe('SettingsModelsPage surface branches', () => {
+ it('acknowledges a catalog save and reveals a new model beyond the collapsed limit', async () => {
+ const ids = Array.from({ length: 6 }, (_, index) => `catalog-model-${index + 1}`);
+ const addedId = 'catalog-model-added';
+ const model = (id: string): BackendModel => ({
+ id, display_name: null, origin: 'manual', models_dev_id: null, context_window: null, max_output_tokens: null,
+ input_modalities: ['text'], output_modalities: ['text'], supports_tools: true, supports_reasoning: false,
+ reasoning_efforts: [], locked: false, routeable: true,
+ });
+ const agent = (modelIds: string[]): AgentSupply => ({
+ ...takeoverAgent,
+ selected_model_id: modelIds[0] ?? null,
+ routes: {},
+ model_supply: modelIds.map((modelId) => ({ model_id: modelId, chain_length: 0, has_runnable_hop: false })),
+ builtin_models: modelIds,
+ catalog_models: modelIds.map(model),
+ });
+ const initial = agent(ids);
+ const saved = agent([...ids, addedId]);
+ vi.spyOn(modelsApi, 'listSources').mockResolvedValue([]);
+ vi.spyOn(modelsApi, 'listAgents').mockResolvedValueOnce([initial]).mockResolvedValue([saved]);
+ vi.spyOn(modelsApi, 'getRuntimeStatus').mockResolvedValue(runtime);
+ vi.spyOn(modelsApi, 'listEvents').mockResolvedValue([]);
+ vi.spyOn(modelsApi, 'getAgentSources').mockResolvedValue(initial);
+ vi.spyOn(modelsApi, 'putAgentModels').mockResolvedValue(saved);
+
+ render(
+ <ToastProvider>
+ <I18nextProvider i18n={i18n}>
+ <SettingsModelsPage />
+ </I18nextProvider>
+ </ToastProvider>,
+ );
+
+ await userEvent.click(await screen.findByRole('button', { name: /^Manage models$|^管理模型$/i }));
+ await userEvent.click(await screen.findByRole('button', { name: /^Add model$|^添加模型$/i }));
+ await userEvent.type(screen.getByLabelText(/^Backend model ID$|^后端模型 ID$/i), addedId);
+ await userEvent.click(screen.getByRole('button', { name: /^Add model$|^添加模型$/i }));
+ await userEvent.click(screen.getByRole('button', { name: /^Save$|^保存$/i }));
+
+ expect(await screen.findByText(/^Model list saved\.$|^模型列表已保存。$/i)).toBeTruthy();
+ expect(screen.getByText(addedId)).toBeTruthy();
+ await userEvent.click(screen.getByRole('button', { name: /^Collapse$|^收起$/i }));
+ expect(screen.queryByText(addedId)).toBeNull();
+ });
+
it('coalesces the OAuth success landing with its trailing stale-row notification', () => {
const page = readFileSync(join(process.cwd(), 'src/components/settings/models/SettingsModelsPage.tsx'), 'utf8');
const start = page.indexOf('const subscriptionAdded');
diff --git a/ui/src/components/settings/models/SettingsModelsPage.tsx b/ui/src/components/settings/models/SettingsModelsPage.tsx
index 31e96ca3e..f5bb0067a 100644
--- a/ui/src/components/settings/models/SettingsModelsPage.tsx
+++ b/ui/src/components/settings/models/SettingsModelsPage.tsx
@@ -787,6 +787,10 @@ export const SettingsModelsPage: React.FC = () => {
reconcile: refresh,
});
}, [applyAgentEcho, refresh]);
+ const catalogSaved = React.useCallback(async (echoed: AgentSupply) => {
+ await agentSaved(echoed);
+ if (aliveRef.current) showToast(t('settings.models.gateway.catalog.saved') as string, 'success');
+ }, [agentSaved, showToast, t]);
const switchToDirect = (agent: AgentSupply) => {
setSwitchFailures((previous) => {
const next = new Set(previous);
@@ -1383,7 +1387,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 && <BackendModelCatalogDialog open backend={menuAgent.backend} onClose={() => setMenuBackend(null)} onSaved={agentSaved} onObserved={applyAgentEcho} catalogWrite={{ pending: agentWrites.has(menuAgent.backend), track: (work) => agentWriteRegistry.track(menuAgent.backend, work) }} />}
+ {menuAgent && <BackendModelCatalogDialog open backend={menuAgent.backend} onClose={() => setMenuBackend(null)} onSaved={catalogSaved} onObserved={applyAgentEcho} catalogWrite={{ pending: agentWrites.has(menuAgent.backend), track: (work) => agentWriteRegistry.track(menuAgent.backend, work) }} />}
<RouteChainDialog
selection={routeSelection}
sources={sources}
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 1b7b0b3be..8f7de9a0b 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -963,6 +963,7 @@
"save": "Save",
"saving": "Saving…",
"cancel": "Cancel",
+ "saved": "Model list saved.",
"saveFailed": "The model list was not saved. It was re-read from the server; check it and try again.",
"saveNotApplied": "The list was stored, but this backend did not load it, so it is not in use yet. Save again once the backend is back.",
"saveRouted": "A model you removed still has a route. The list was re-read from the server; clear the route first, then remove it.",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 615127c0f..c7ce5e466 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -963,6 +963,7 @@
"save": "保存",
"saving": "正在保存…",
"cancel": "取消",
+ "saved": "模型列表已保存。",
"saveFailed": "模型列表未保存,已重新读取服务器上的列表,请确认后重试。",
"saveNotApplied": "列表已存下,但该后端没有加载它,因此尚未生效。等后端恢复后再保存一次。",
"saveRouted": "你移除的模型仍配置了路由。已重新读取服务器上的列表,请先清空该路由再移除。",