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:
@@ -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>
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user