fix(web): find a keyless primary's provider from the model id (UF-054, UF-055)
A provider without its key lists no models, so Model Pilot could not tell the primary needed a key, and it compared a prefixed active id with a bare one. The provider now also comes from the id's prefix or family name, and prefixed and bare ids count as the same model. The account row's fallback initial is A for Account, not W.
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
|||||||
import type { Provider } from '@/hooks/useProviders';
|
import type { Provider } from '@/hooks/useProviders';
|
||||||
import { HintTooltip } from '@/components/ui/hint-tooltip';
|
import { HintTooltip } from '@/components/ui/hint-tooltip';
|
||||||
import { formatModelLabel } from '@/lib/model-label';
|
import { formatModelLabel } from '@/lib/model-label';
|
||||||
|
import { providerForModel, sameModel } from '@/lib/model-provider';
|
||||||
|
|
||||||
interface ModelPilotCardProps {
|
interface ModelPilotCardProps {
|
||||||
defaultModel: string;
|
defaultModel: string;
|
||||||
@@ -187,10 +188,11 @@ const LaneDropdown = ({
|
|||||||
const resolveModelName = (modelId: string | null, providers: Provider[]): string =>
|
const resolveModelName = (modelId: string | null, providers: Provider[]): string =>
|
||||||
modelId ? formatModelLabel(modelId, providers) : 'Not set';
|
modelId ? formatModelLabel(modelId, providers) : 'Not set';
|
||||||
|
|
||||||
/** True when the model's provider needs an API key that the vault lacks. */
|
/** True when the model's provider needs an API key that the vault lacks. A
|
||||||
|
* keyless provider lists no models, so the provider comes from the id. */
|
||||||
const needsKey = (modelId: string | null, providers: Provider[]): boolean => {
|
const needsKey = (modelId: string | null, providers: Provider[]): boolean => {
|
||||||
if (!modelId) return false;
|
if (!modelId) return false;
|
||||||
const provider = providers.find(p => p.models.some(m => m.id === modelId));
|
const provider = providerForModel(modelId, providers);
|
||||||
return !!provider && provider.requiresKey && !provider.hasKey;
|
return !!provider && provider.requiresKey && !provider.hasKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -296,7 +298,7 @@ const ModelPilotCard = ({
|
|||||||
// usable model instead, which the status bar shows. Say so here, or the two
|
// usable model instead, which the status bar shows. Say so here, or the two
|
||||||
// screens name different "default" models (UF-054).
|
// screens name different "default" models (UF-054).
|
||||||
const primaryNote = needsKey(defaultModel || null, providers)
|
const primaryNote = needsKey(defaultModel || null, providers)
|
||||||
? activeModel && activeModel !== defaultModel
|
? activeModel && !sameModel(activeModel, defaultModel)
|
||||||
? `Needs an API key. New chats use ${formatModelLabel(activeModel, providers)} until you add one.`
|
? `Needs an API key. New chats use ${formatModelLabel(activeModel, providers)} until you add one.`
|
||||||
: 'Needs an API key before it can answer.'
|
: 'Needs an API key before it can answer.'
|
||||||
: null;
|
: null;
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ const Sidebar = ({
|
|||||||
className="mt-1.5 flex items-center justify-center gap-2.5 border-t border-[var(--line-soft)] px-2.5 pb-0 pt-3.5 text-left lg:justify-start"
|
className="mt-1.5 flex items-center justify-center gap-2.5 border-t border-[var(--line-soft)] px-2.5 pb-0 pt-3.5 text-left lg:justify-start"
|
||||||
>
|
>
|
||||||
<span className="grid h-7 w-7 shrink-0 place-items-center rounded-full bg-[var(--honey)] text-[11px] font-bold text-[#1a1407]">
|
<span className="grid h-7 w-7 shrink-0 place-items-center rounded-full bg-[var(--honey)] text-[11px] font-bold text-[#1a1407]">
|
||||||
{initialOf(userName, "W")}
|
{initialOf(userName, "A")}
|
||||||
</span>
|
</span>
|
||||||
<span className="hidden min-w-0 flex-1 lg:block">
|
<span className="hidden min-w-0 flex-1 lg:block">
|
||||||
<span className="block truncate text-[13px] font-semibold">
|
<span className="block truncate text-[13px] font-semibold">
|
||||||
|
|||||||
26
apps/web/src/lib/model-provider.test.ts
Normal file
26
apps/web/src/lib/model-provider.test.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import type { Provider } from '@/hooks/useProviders';
|
||||||
|
import { bareModelId, providerForModel, sameModel } from './model-provider';
|
||||||
|
|
||||||
|
const provider = (id: string, models: string[] = []): Provider => ({
|
||||||
|
id, name: id, hasKey: false, badge: null, keyUrl: null, requiresKey: true,
|
||||||
|
models: models.map(m => ({ id: m, name: m, cost: '$', speed: 'fast' })),
|
||||||
|
});
|
||||||
|
|
||||||
|
const providers = [provider('anthropic'), provider('openai'), provider('ollama', ['ollama/llama3.1:8b'])];
|
||||||
|
|
||||||
|
describe('model-provider', () => {
|
||||||
|
it('strips the router prefix and compares bare ids', () => {
|
||||||
|
expect(bareModelId('anthropic/claude-sonnet-4-6')).toBe('claude-sonnet-4-6');
|
||||||
|
expect(sameModel('anthropic/claude-sonnet-4-6', 'claude-sonnet-4-6')).toBe(true);
|
||||||
|
expect(sameModel('ollama/llama3.1:8b', 'claude-sonnet-4-6')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('finds the provider from the catalog, the prefix or the family name', () => {
|
||||||
|
expect(providerForModel('ollama/llama3.1:8b', providers)?.id).toBe('ollama');
|
||||||
|
expect(providerForModel('anthropic/claude-sonnet-4-6', providers)?.id).toBe('anthropic');
|
||||||
|
expect(providerForModel('claude-sonnet-4-6', providers)?.id).toBe('anthropic');
|
||||||
|
expect(providerForModel('gpt-5', providers)?.id).toBe('openai');
|
||||||
|
expect(providerForModel('mystery-model', providers)).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
40
apps/web/src/lib/model-provider.ts
Normal file
40
apps/web/src/lib/model-provider.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import type { Provider } from '@/hooks/useProviders';
|
||||||
|
|
||||||
|
/** A model id without its router prefix: "anthropic/claude-sonnet-4-6" → "claude-sonnet-4-6". */
|
||||||
|
export function bareModelId(id: string): string {
|
||||||
|
const slash = id.indexOf('/');
|
||||||
|
return (slash > 0 ? id.slice(slash + 1) : id).trim().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether two ids name the same model, with or without a provider prefix. */
|
||||||
|
export function sameModel(a: string, b: string): boolean {
|
||||||
|
return bareModelId(a) === bareModelId(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model families by name, for providers whose catalog is empty until a key is
|
||||||
|
// added. Mirrors providerForModel in packages/server/src/local/model-availability.ts.
|
||||||
|
const FAMILY_PROVIDERS: Array<[RegExp, string]> = [
|
||||||
|
[/^claude-/, 'anthropic'],
|
||||||
|
[/^(gpt-|o\d)/, 'openai'],
|
||||||
|
[/^gemini-/, 'google'],
|
||||||
|
[/^deepseek-/, 'deepseek'],
|
||||||
|
[/^grok-/, 'xai'],
|
||||||
|
[/^(mistral-|codestral-)/, 'mistral'],
|
||||||
|
[/^qwen/, 'alibaba'],
|
||||||
|
[/^minimax-/, 'minimax'],
|
||||||
|
[/^glm-/, 'zhipu'],
|
||||||
|
];
|
||||||
|
|
||||||
|
/** The provider a model belongs to: its catalog entry, its prefix, or its family name. */
|
||||||
|
export function providerForModel(modelId: string, providers: Provider[]): Provider | null {
|
||||||
|
const listed = providers.find(p => p.models.some(m => m.id === modelId));
|
||||||
|
if (listed) return listed;
|
||||||
|
const id = modelId.trim().toLowerCase();
|
||||||
|
const slash = id.indexOf('/');
|
||||||
|
if (slash > 0) {
|
||||||
|
const byPrefix = providers.find(p => p.id === id.slice(0, slash));
|
||||||
|
if (byPrefix) return byPrefix;
|
||||||
|
}
|
||||||
|
const family = FAMILY_PROVIDERS.find(([pattern]) => pattern.test(bareModelId(id)));
|
||||||
|
return family ? providers.find(p => p.id === family[1]) ?? null : null;
|
||||||
|
}
|
||||||
@@ -15,7 +15,8 @@ function providers(anthropicHasKey: boolean): Provider[] {
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
id: 'anthropic', name: 'Anthropic', hasKey: anthropicHasKey, badge: null, keyUrl: null, requiresKey: true,
|
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' }],
|
// Like the server: a provider without its key lists no models.
|
||||||
|
models: anthropicHasKey ? [{ 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,
|
id: 'ollama', name: 'Ollama', hasKey: false, badge: null, keyUrl: null, requiresKey: false,
|
||||||
@@ -54,6 +55,11 @@ describe('Model Pilot primary note (UF-054)', () => {
|
|||||||
expect(screen.getByTestId('model-pilot-primary-note')).toHaveTextContent('Needs an API key before it can answer.');
|
expect(screen.getByTestId('model-pilot-primary-note')).toHaveTextContent('Needs an API key before it can answer.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('treats a prefixed id of the same model as the primary itself', () => {
|
||||||
|
renderCard(false, 'anthropic/claude-sonnet-4-6');
|
||||||
|
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', () => {
|
it('says nothing when the primary has its key', () => {
|
||||||
renderCard(true, 'claude-sonnet-4-6');
|
renderCard(true, 'claude-sonnet-4-6');
|
||||||
expect(screen.queryByTestId('model-pilot-primary-note')).not.toBeInTheDocument();
|
expect(screen.queryByTestId('model-pilot-primary-note')).not.toBeInTheDocument();
|
||||||
|
|||||||
@@ -546,7 +546,7 @@ Entries UF-010 to UF-019 come from the UI audit `anti-slop/audit-001-2026-10-14.
|
|||||||
- Where: at commit `b20b138`, `apps/web/src/components/os/ModelPilotCard.tsx:361` (the Primary lane) and `apps/web/src/components/os/StatusBar.tsx:160` ("Default model:")
|
- Where: at commit `b20b138`, `apps/web/src/components/os/ModelPilotCard.tsx:361` (the Primary lane) and `apps/web/src/components/os/StatusBar.tsx:160` ("Default model:")
|
||||||
- Symptom: Settings → Models shows Claude Sonnet 4.6 as the primary model, while the status bar says "Default model: Llama3.1 (8b)".
|
- Symptom: Settings → Models shows Claude Sonnet 4.6 as the primary model, while the status bar says "Default model: Llama3.1 (8b)".
|
||||||
- Cause: both are true. The primary has no API key, so the server's usable-model check routes new chats to the local model, and the status bar shows that model. Model Pilot only shows the configured primary and never says it cannot answer.
|
- Cause: both are true. The primary has no API key, so the server's usable-model check routes new chats to the local model, and the status bar shows that model. Model Pilot only shows the configured primary and never says it cannot answer.
|
||||||
- What we did: when the primary's provider needs a key the vault lacks, Model Pilot says so under Primary and names the model new chats use until a key is added. Settings reads that model from the server. A test covers the keyless, unknown and keyed cases.
|
- What we did: when the primary's provider needs a key the vault lacks, Model Pilot says so under Primary and names the model new chats use until a key is added. A keyless provider lists no models, so the provider comes from the model id (prefix or family name), and ids with and without the provider prefix count as the same model. Settings reads the active model from the server. Tests cover the keyless, prefixed, unknown and keyed cases.
|
||||||
- Recommendation: apply the same change in the main project.
|
- Recommendation: apply the same change in the main project.
|
||||||
|
|
||||||
### UF-055. Home greets the user by the assistant's name
|
### UF-055. Home greets the user by the assistant's name
|
||||||
@@ -555,7 +555,7 @@ Entries UF-010 to UF-019 come from the UI audit `anti-slop/audit-001-2026-10-14.
|
|||||||
- Where: at commit `b20b138`, `packages/server/src/local/routes/home.ts:265` (the greeting name) and `apps/web/src/components/os/AppShell.tsx:206` (the sidebar account row); the default comes from `packages/agent/src/auto-identity.ts`
|
- Where: at commit `b20b138`, `packages/server/src/local/routes/home.ts:265` (the greeting name) and `apps/web/src/components/os/AppShell.tsx:206` (the sidebar account row); the default comes from `packages/agent/src/auto-identity.ts`
|
||||||
- Symptom: a user who left their name empty during onboarding sees "Welcome, Waggle" on Home and "Waggle" as the account name in the sidebar.
|
- Symptom: a user who left their name empty during onboarding sees "Welcome, Waggle" on Home and "Waggle" as the account name in the sidebar.
|
||||||
- Cause: both read the name from the identity row. At startup the sidecar fills that row with the assistant's own identity, named "Waggle", and onboarding only overwrites it when the user types a name.
|
- Cause: both read the name from the identity row. At startup the sidecar fills that row with the assistant's own identity, named "Waggle", and onboarding only overwrites it when the user types a name.
|
||||||
- What we did: the name comes from profile.json, which the user states. The identity row is a fallback and its default assistant name is ignored, so with no name the greeting has none and the account row reads "Account". The agent package exports the default name as `DEFAULT_AGENT_NAME`. Server and web tests cover a profile name, a real identity name and the default.
|
- What we did: the name comes from profile.json, which the user states. The identity row is a fallback and its default assistant name is ignored, so with no name the greeting has none and the account row reads "Account" with the initial A. The agent package exports the default name as `DEFAULT_AGENT_NAME`. Server and web tests cover a profile name, a real identity name and the default.
|
||||||
- Recommendation: apply the same change in the main project, and keep the assistant's identity apart from the user's.
|
- Recommendation: apply the same change in the main project, and keep the assistant's identity apart from the user's.
|
||||||
|
|
||||||
### UF-056. Home calls the last 24 hours "While you slept"
|
### UF-056. Home calls the last 24 hours "While you slept"
|
||||||
|
|||||||
Reference in New Issue
Block a user