Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
feat(web): chat model picker lists every local Ollama model
Frank Arena4b3ae2e3f7b5
diff --git a/src/core/agent.ts b/src/core/agent.tsindex 7cd64cd9..f18bbb0c 100644--- a/src/core/agent.ts+++ b/src/core/agent.ts@@ -2000,7 +2000,11 @@ export class Agent {}/** Public wrapper for web API model switching. */- async switchProvider(providerName: string): Promise<{ ok: boolean; message: string }> {+ async switchProvider(providerName: string, model?: string): Promise<{ ok: boolean; message: string }> {+ // Providers like Ollama Local serve many models; pin the requested one+ // before the registry is rebuilt from config.+ const pc = (this.config.providers as Record<string, unknown>)[providerName] as { model?: string } | undefined;+ if (model && pc && typeof pc === 'object') pc.model = model;return this.switchSessionProvider(providerName);}diff --git a/src/index.ts b/src/index.tsindex 16c9a293..c61d4b05 100644--- a/src/index.ts+++ b/src/index.ts@@ -3408,7 +3408,7 @@ async function runAgent(isDaemon: boolean = false): Promise<void> {setWebSessionSyncEnabled(() => agent.isSessionSyncEnabled());setWebProgrammingMode(agent.programmingMode);setWebBgTasks(agent.backgroundTasks);- setWebModelSwitch((provider) => agent.switchProvider(provider));+ setWebModelSwitch((provider, model) => agent.switchProvider(provider, model));setWebCurrentProvider(() => agent.getCurrentProvider());// IDE provider registry powers features like commit message generation.// It does not require a supervisor, so wire it up unconditionally.diff --git a/src/web/api/chat.ts b/src/web/api/chat.tsindex 38a3253a..2ce4bdbc 100644--- a/src/web/api/chat.ts+++ b/src/web/api/chat.ts@@ -8,7 +8,7 @@ import type { SessionRepository } from '../../sessions/index.js';let webChannel: WebChannel | null = null;let programmingMode: ProgrammingMode | null = null;-let modelSwitchFn: ((provider: string) => Promise<{ ok: boolean; message: string }>) | null = null;+let modelSwitchFn: ((provider: string, model?: string) => Promise<{ ok: boolean; message: string }>) | null = null;let currentProviderFn: (() => { name: string; model: string }) | null = null;let sessions: SessionRepository | null = null;let sessionSyncEnabledFn: (() => boolean) | null = null;@@ -45,7 +45,7 @@ export function setProgrammingMode(pm: ProgrammingMode): void {programmingMode = pm;}-export function setModelSwitchCallback(fn: (provider: string) => Promise<{ ok: boolean; message: string }>): void {+export function setModelSwitchCallback(fn: (provider: string, model?: string) => Promise<{ ok: boolean; message: string }>): void {modelSwitchFn = fn;}@@ -214,29 +214,49 @@ chat.post('/api/chat/permission/:id', async (c) => {// ─── Models / Provider Switching ─────────────────────────────-chat.get('/api/chat/models', (c) => {+/** Every model the local Ollama server has pulled (empty if unreachable). */+async function listOllamaModels(baseUrl: string): Promise<string[]> {+ try {+ const root = baseUrl.replace(/\/+$/, '').replace(/\/(v1|api)$/, '');+ const res = await fetch(`${root}/api/tags`, { signal: AbortSignal.timeout(3000) });+ if (!res.ok) return [];+ const data = (await res.json()) as { models?: { name?: string }[] };+ return (data.models ?? []).map((m) => m.name ?? '').filter(Boolean).sort();+ } catch {+ return [];+ }+}++chat.get('/api/chat/models', async (c) => {const config = loadConfig();const active = getActiveProviders(config);const current = currentProviderFn ? currentProviderFn() : { name: config.providers.default || '', model: '' };- return c.json({- current: current,- providers: active.map(p => ({- name: p.name,- model: p.model,- isCurrent: p.name === current.name,- })),- });+ const entries: { name: string; model: string; available: boolean; isCurrent: boolean }[] = [];+ for (const p of active) {+ // Ollama Local hosts many models behind one provider: list each one.+ const models = p.name === 'ollamaLocal' ? await listOllamaModels(p.baseUrl) : [];+ if (models.length && !models.includes(p.model)) models.unshift(p.model);+ for (const model of models.length ? models : [p.model]) {+ entries.push({+ name: p.name,+ model,+ available: true,+ isCurrent: p.name === current.name && model === current.model,+ });+ }+ }+ return c.json({ current, providers: entries });});chat.post('/api/chat/models/switch', async (c) => {if (!modelSwitchFn) {return c.json({ error: 'Model switching not available' }, 503);}- const body = await c.req.json<{ provider: string }>();+ const body = await c.req.json<{ provider: string; model?: string }>();if (!body.provider) {return c.json({ error: 'provider is required' }, 400);}- const result = await modelSwitchFn(body.provider);+ const result = await modelSwitchFn(body.provider, body.model?.trim() || undefined);return c.json(result);});diff --git a/ui/src/components/chat/ModelSwitcher.tsx b/ui/src/components/chat/ModelSwitcher.tsxindex 75519a1d..4af25d6d 100644--- a/ui/src/components/chat/ModelSwitcher.tsx+++ b/ui/src/components/chat/ModelSwitcher.tsx@@ -30,8 +30,8 @@ export function ModelSwitcher({const setModel = useChatStore((s) => s.setModel);const loadModels = useCallback(async () => {- if (models) return;- setLoading(true);+ // Always refetch: the Ollama model list changes as models are pulled.+ setLoading(!models);try {const data = await api.chat.models.list();setModels(data);@@ -42,20 +42,16 @@ export function ModelSwitcher({}}, [models]);- async function handleSwitch(providerName: string) {- setSwitching(providerName);+ async function handleSwitch(providerName: string, model: string) {+ setSwitching(`${providerName}::${model}`);try {- await api.chat.models.switch(providerName);+ const res = await api.chat.models.switch(providerName, model);+ if (!res.ok) return;// Refresh model list to get new currentconst data = await api.chat.models.list();setModels(data);-- // Find the provider to get the model name- const p = data.providers.find((pr) => pr.name === providerName);- if (p) {- setProvider(p.name);- setModel(p.model);- }+ setProvider(data.current?.name || providerName);+ setModel(data.current?.model || model);setOpen(false);} catch {// silently fail@@ -89,7 +85,7 @@ export function ModelSwitcher({</PopoverTrigger><PopoverContent align="start" className="w-72 p-2"><p className="px-2 pb-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider">- Providers+ Models</p>{loading ? (@@ -97,16 +93,17 @@ export function ModelSwitcher({<Loader2 className="h-4 w-4 animate-spin text-primary" /></div>) : models ? (- <div className="flex flex-col gap-0.5">+ <div className="flex max-h-[60vh] flex-col gap-0.5 overflow-y-auto">{models.providers.map((p) => {- const isActive = p.name === currentProvider;- const isSwitching = switching === p.name;+ const key = `${p.name}::${p.model}`;+ const isActive = p.name === currentProvider && p.model === currentModel;+ const isSwitching = switching === key;return (<button- key={p.name}+ key={key}disabled={!p.available || isSwitching}onClick={() => {- if (!isActive && p.available) handleSwitch(p.name);+ if (!isActive && p.available) handleSwitch(p.name, p.model);}}className={cn("flex items-center gap-2 rounded-md px-2 py-2 text-left text-sm transition-colors",@@ -118,15 +115,15 @@ export function ModelSwitcher({><div className="min-w-0 flex-1"><div className="flex items-center gap-1.5">- <span className="font-medium text-foreground">- {p.name}+ <span className="truncate font-medium text-foreground">+ {p.model}</span>{isActive && (- <Check className="h-3.5 w-3.5 text-primary" />+ <Check className="h-3.5 w-3.5 shrink-0 text-primary" />)}</div><p className="truncate text-xs text-muted-foreground">- {p.model}+ {p.name}</p></div>{isSwitching ? (diff --git a/ui/src/lib/api.ts b/ui/src/lib/api.tsindex bddaab29..844a7162 100644--- a/ui/src/lib/api.ts+++ b/ui/src/lib/api.ts@@ -117,9 +117,10 @@ export const chat = {post<{ resolved: boolean }>(`/api/chat/permission/${id}`, { action }),models: {list: () => get<ModelsResponse>("/api/chat/models"),- switch: (provider: string) =>+ switch: (provider: string, model?: string) =>post<{ ok: boolean; message: string }>("/api/chat/models/switch", {provider,+ model,}),},threads: {@@ -483,8 +484,8 @@ export interface ToolStep {}export interface ModelsResponse {- current: string;- providers: { name: string; model: string; available: boolean }[];+ current: { name: string; model: string };+ providers: { name: string; model: string; available: boolean; isCurrent?: boolean }[];}export interface CodeStatus {