import { tr } from '../lib/i18n'; import { useState } from 'react'; import { Btn, ErrorNotice, Icon } from './ui'; import { useStore, runtimeModelAction, pushToast } from '../lib/store'; import { deviceLabel } from '../lib/runtime-models'; import { modelFamilyIcon } from '../lib/model-icons'; /** Shared instance list; device measurements remain owned by the host. */ export function RunningModels({ onSelect, selected, controls = false }: { onSelect?: (id: string) => void; selected?: string; controls?: boolean; }) { const runtime = useStore(s => s.runtime), hardware = useStore(s => s.hardware), serving = useStore(s => s.serving), connected = useStore(s => s.connection === 'live'); const [pending, setPending] = useState(''), [error, setError] = useState(''); if (!runtime?.instances.length) return null; async function act(id: string, action: 'unload' | 'default') { setPending(id); setError(''); try { await runtimeModelAction(id, action); pushToast('success', action === 'unload' ? 'Model unloaded' : 'Chat model changed'); } catch (e) { setError(e instanceof Error ? e.message : String(e)); } finally { setPending(''); } } return

{tr("Loaded models ")}{tr(runtime.instances.length)}

{tr(runtime.instances.map(i => { const log = serving?.requests.filter(r => r.instanceId === i.id) ?? []; const active = log.filter(r => r.state === 'generating').length, queued = log.filter(r => r.state === 'queued').length; return
{tr(onSelect ? : {tr(i.family)})}{tr(i.name)} · {tr(i.memory.context / 1024)}{tr("K \u00B7 ")}{tr(deviceLabel(i.gpuIds, hardware))}{tr(runtime.defaultId === i.id ? ' · Chat default' : '')}
0}>{tr(active ? `${active} active` : queued ? 'Queued' : 'Idle')}{tr(queued ? ` · ${queued} queued` : '')} {tr(controls ?
{tr(runtime.defaultId !== i.id ? void act(i.id, 'default')}>{tr("Use in chat")} : null)} 0 || queued > 0 || !connected} onClick={() => void act(i.id, 'unload')}>{tr(pending === i.id ? 'Updating…' : 'Unload')}
: null)}
; }))}
{tr(error ? : null)}
; }