fix(web): say when the primary model has no key and which model chats use (UF-054)

Settings showed the configured primary while the status bar showed the
model new chats fall back to, so the two screens disagreed. Model Pilot now
says the primary needs a key and names the model in use.
This commit is contained in:
shumeiko.it
2026-10-27 14:20:05 +01:00
parent 97b2c984d8
commit c2998f1a6b
4 changed files with 107 additions and 0 deletions

View File

@@ -22,6 +22,9 @@ interface ModelPilotCardProps {
budgetThreshold: number;
dailyBudget: number | null;
providers: Provider[];
/** The model new chats actually run on (the server falls back from a primary
* it cannot use). Shown when it differs from an unusable primary. */
activeModel?: string | null;
onUpdate: (fields: {
defaultModel?: string;
fallbackModel?: string | null;
@@ -184,6 +187,13 @@ const LaneDropdown = ({
const resolveModelName = (modelId: string | null, providers: Provider[]): string =>
modelId ? formatModelLabel(modelId, providers) : 'Not set';
/** True when the model's provider needs an API key that the vault lacks. */
const needsKey = (modelId: string | null, providers: Provider[]): boolean => {
if (!modelId) return false;
const provider = providers.find(p => p.models.some(m => m.id === modelId));
return !!provider && provider.requiresKey && !provider.hasKey;
};
/** Resolve cost tier for a model id */
const resolveModelCost = (modelId: string | null, providers: Provider[]): string | null => {
if (!modelId) return null;
@@ -240,6 +250,7 @@ const ModelPilotCard = ({
budgetThreshold,
dailyBudget,
providers,
activeModel = null,
onUpdate,
}: ModelPilotCardProps) => {
const [singleMode, setSingleMode] = useState(false);
@@ -281,6 +292,15 @@ const ModelPilotCard = ({
const visibleLanes = singleMode ? LANES.slice(0, 1) : LANES;
// A primary without its key never answers: the server routes new chats to a
// usable model instead, which the status bar shows. Say so here, or the two
// screens name different "default" models (UF-054).
const primaryNote = needsKey(defaultModel || null, providers)
? activeModel && activeModel !== defaultModel
? `Needs an API key. New chats use ${formatModelLabel(activeModel, providers)} until you add one.`
: 'Needs an API key before it can answer.'
: null;
// kw (Wave S): when the fallback can never fire (== primary), offer a
// one-click switch to a strictly-cheaper usable model — only if one really
// exists in the catalog. Null hides the suggestion (no invented models).
@@ -359,6 +379,11 @@ const ModelPilotCard = ({
{lane.label}
</p>
<p className="text-[11px] text-muted-foreground truncate">{lane.description}</p>
{lane.key === 'primary' && primaryNote && (
<p className="mt-0.5 text-[11px] text-[var(--attention)]" data-testid="model-pilot-primary-note">
{primaryNote}
</p>
)}
</div>
</div>

View File

@@ -72,6 +72,16 @@ const SettingsApp = () => {
const [fallbackModel, setFallbackModel] = useState<string | null>(null);
const [budgetModel, setBudgetModel] = useState<string | null>(null);
const [budgetThreshold, setBudgetThreshold] = useState(0.8);
// The model new chats run on after the server's usable-model fallback.
const [activeModel, setActiveModel] = useState<string | null>(null);
useEffect(() => {
let cancelled = false;
Promise.resolve()
.then(() => adapter.getModel())
.then(model => { if (!cancelled) setActiveModel(model || null); })
.catch(() => { /* the note under Primary is optional */ });
return () => { cancelled = true; };
}, [defaultModel]);
const [dailyBudget, setDailyBudget] = useState<string>('');
const [saving, setSaving] = useState(false);
const [saveMsg, setSaveMsg] = useState('');
@@ -602,6 +612,7 @@ const SettingsApp = () => {
budgetThreshold={budgetThreshold}
dailyBudget={dailyBudget ? parseFloat(dailyBudget) : null}
providers={providers}
activeModel={activeModel}
onUpdate={(fields) => {
if (fields.defaultModel !== undefined) setDefaultModel(fields.defaultModel);
if (fields.fallbackModel !== undefined) setFallbackModel(fields.fallbackModel);

View File

@@ -0,0 +1,61 @@
/**
* UF-054: Settings named Claude Sonnet as the primary model while the status bar
* said new chats use Llama. Both were true: the primary had no key, so the
* server fell back to a usable model. Model Pilot now says so under Primary.
*/
import { describe, it, expect, afterEach } from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import ModelPilotCard from '@/components/os/ModelPilotCard';
import { TooltipProvider } from '@/components/ui/tooltip';
import type { Provider } from '@/hooks/useProviders';
afterEach(cleanup);
function providers(anthropicHasKey: boolean): Provider[] {
return [
{
id: 'anthropic', name: 'Anthropic', hasKey: anthropicHasKey, badge: null, keyUrl: null, requiresKey: true,
models: [{ id: 'claude-sonnet-4-6', name: 'Claude Sonnet 4.6', cost: '$$', speed: 'fast' }],
},
{
id: 'ollama', name: 'Ollama', hasKey: false, badge: null, keyUrl: null, requiresKey: false,
models: [{ id: 'ollama/llama3.1:8b', name: 'Llama3.1 (8b)', cost: 'FREE', speed: 'medium' }],
},
];
}
function renderCard(anthropicHasKey: boolean, activeModel: string | null) {
render(
<TooltipProvider>
<ModelPilotCard
defaultModel="claude-sonnet-4-6"
fallbackModel={null}
budgetModel={null}
budgetThreshold={0.8}
dailyBudget={null}
providers={providers(anthropicHasKey)}
activeModel={activeModel}
onUpdate={() => {}}
/>
</TooltipProvider>,
);
}
describe('Model Pilot primary note (UF-054)', () => {
it('names the model new chats use when the primary has no key', () => {
renderCard(false, 'ollama/llama3.1:8b');
expect(screen.getByTestId('model-pilot-primary-note')).toHaveTextContent(
'Needs an API key. New chats use Llama3.1 (8b) until you add one.',
);
});
it('still flags a keyless primary when the active model is unknown', () => {
renderCard(false, null);
expect(screen.getByTestId('model-pilot-primary-note')).toHaveTextContent('Needs an API key before it can answer.');
});
it('says nothing when the primary has its key', () => {
renderCard(true, 'claude-sonnet-4-6');
expect(screen.queryByTestId('model-pilot-primary-note')).not.toBeInTheDocument();
});
});