feat(webui): show persisted fallback preset on replies (NAN-133)

This commit is contained in:
Xubin Ren committed 2026-09-20 15:16:35 +08:00
1 parent db675a43b6
commit 8d0430c761
43 files changed
+919 -95

No files matched your search

@@ -92,7 +92,6 @@ interface ModelPresetBadgeProps {
providerLabel?: string | null;
needsSetup?: boolean;
attentionRequest?: number;
fallbackModelName?: string | null;
isHero: boolean;
onClick?: () => void;
}
@@ -109,7 +108,6 @@ export function ModelPresetBadge({
providerLabel,
needsSetup = false,
attentionRequest = 0,
fallbackModelName,
isHero,
onClick,
}: ModelPresetBadgeProps) {
@@ -128,22 +126,10 @@ export function ModelPresetBadge({
model: modelDetail ?? modelPresets[listedIndex]?.model,
provider: provider || modelPresets[listedIndex]?.provider,
};
const fallbackPreset = fallbackModelName
? modelPresets.find((preset) => preset.model?.trim() === fallbackModelName.trim())
: undefined;
const fallbackDisplayLabel = fallbackPreset?.name
|| fallbackModelName?.trim().split(/[/:]/).pop()
|| null;
const displayLabel = needsSetup ? label : fallbackDisplayLabel || label;
const displayModelDetail = fallbackPreset
? fallbackPreset.model
: fallbackModelName || modelDetail;
const displayProvider = fallbackPreset?.provider
|| (fallbackModelName ? inferProviderFromModelName(fallbackModelName) : provider);
const tooltipLabel = needsSetup ? label : [...new Set([
displayLabel,
displayModelDetail,
fallbackModelName ? null : providerLabel,
label,
modelDetail,
providerLabel,
].filter(Boolean))].join(" · ");
const presets = !activeName
? modelPresets
@@ -280,12 +266,11 @@ export function ModelPresetBadge({
const pill = (
<PresetPill
key={needsSetup ? attentionRequest : undefined}
label={displayLabel}
modelDetail={displayModelDetail}
provider={displayProvider}
label={label}
modelDetail={modelDetail}
provider={provider}
needsSetup={needsSetup}
needsAttention={needsSetup && attentionRequest > 0}
fallbackModelName={needsSetup ? null : fallbackModelName}
isHero={isHero}
/>
);
@@ -294,7 +279,7 @@ export function ModelPresetBadge({
const badge = !canSwitch ? (
<TooltipTrigger asChild>
<Container
aria-label={displayLabel}
aria-label={label}
tabIndex={opensSetup ? undefined : 0}
type={opensSetup ? "button" : undefined}
onClick={opensSetup ? onClick : undefined}
@@ -320,7 +305,7 @@ export function ModelPresetBadge({
<button
type="button"
data-switching={motion ? "true" : undefined}
aria-label={displayLabel}
aria-label={label}
aria-expanded={open}
onPointerDown={handlePointerDown}
onPointerMove={handlePointerMove}
@@ -510,7 +495,6 @@ function PresetPill({
provider,
needsSetup = false,
needsAttention = false,
fallbackModelName,
isHero,
offset,
scale,
@@ -520,7 +504,6 @@ function PresetPill({
provider?: string | null;
needsSetup?: boolean;
needsAttention?: boolean;
fallbackModelName?: string | null;
isHero: boolean;
offset?: number;
scale?: number;
@@ -543,7 +526,6 @@ function PresetPill({
return (
<span
data-fallback={fallbackModelName ? "true" : undefined}
data-needs-setup={needsSetup ? "true" : undefined}
data-preset-offset={offset}
className={cn(
@@ -205,7 +205,6 @@ interface ThreadComposerProps {
modelProvider?: string | null;
modelProviderLabel?: string | null;
modelNeedsSetup?: boolean;
fallbackModelName?: string | null;
onModelBadgeClick?: () => void;
onManageModels?: () => void;
contextUsage?: ComposerContextUsage | null;
@@ -907,7 +906,6 @@ export function ThreadComposer({
modelProvider = null,
modelProviderLabel = null,
modelNeedsSetup = false,
fallbackModelName = null,
onModelBadgeClick,
onManageModels,
contextUsage = null,
@@ -2274,7 +2272,6 @@ export function ThreadComposer({
providerLabel={modelProviderLabel}
needsSetup={modelNeedsSetup}
attentionRequest={modelSetupAttentionRequest}
fallbackModelName={fallbackModelName}
isHero={isHero && !compactControls}
onClick={modelNeedsSetup ? onModelBadgeClick : undefined}
/>
@@ -672,7 +672,6 @@ export function ThreadShell({
);
return typeof response.path === "string" ? response.path : null;
}, [client]);
const [fallbackModelName, setFallbackModelName] = useState<string | null>(null);
const [booting, setBooting] = useState(false);
const [slashCommands, setSlashCommands] = useState<SlashCommand[]>([]);
const cliApps = useInstalledSettingItems({
@@ -737,7 +736,6 @@ export function ThreadShell({
const handleTurnEnd = useCallback(() => {
if (chatId) activeViewportTurnByChatIdRef.current.delete(chatId);
setSubmittedViewportTurnId(null);
setFallbackModelName(null);
onTurnEnd?.();
}, [chatId, onTurnEnd]);
const {
@@ -1031,18 +1029,6 @@ export function ThreadShell({
});
}, [client, refreshModelSettings]);
useEffect(() => {
if (!chatId) {
setFallbackModelName(null);
return;
}
setFallbackModelName(null);
return client.onChat(chatId, (event) => {
if (event.event !== "turn_model_updated" || event.fallback !== true) return;
setFallbackModelName(event.model_name);
});
}, [chatId, client]);
useEffect(() => {
if (!historyKey || !chatId || loading) return;
const cached = messageCacheRef.current.get(chatId);
@@ -1421,7 +1407,6 @@ export function ThreadShell({
const handleThreadSend = useCallback(
(content: string, images?: SendAttachment[], options?: SendOptions) => {
setFallbackModelName(null);
const submitted = send(content, images, withWorkspaceScope(options));
if (
chatId
@@ -1570,7 +1555,6 @@ export function ThreadShell({
modelProvider={modelBadge.provider}
modelProviderLabel={modelBadge.providerLabel}
modelNeedsSetup={modelBadge.needsSetup}
fallbackModelName={fallbackModelName}
onModelBadgeClick={modelBadge.needsSetup ? onOpenModelSettings : undefined}
onManageModels={onOpenModelSettings}
contextUsage={composerContextUsage}
@@ -1620,7 +1604,6 @@ export function ThreadShell({
modelProvider={modelBadge.provider}
modelProviderLabel={modelBadge.providerLabel}
modelNeedsSetup={modelBadge.needsSetup}
fallbackModelName={fallbackModelName}
onModelBadgeClick={modelBadge.needsSetup ? onOpenModelSettings : undefined}
onManageModels={onOpenModelSettings}
contextUsage={composerContextUsage}