refactor(webui): open models directly for first-run setup

This commit is contained in:
Xubin Ren committed 2026-09-02 16:25:07 +08:00
1 parent 1c1f746903
commit 05100b70ad
22 files changed
+75 -627

No files matched your search

@@ -1,128 +0,0 @@
import { useRef } from "react";
import { Check, Cloud, KeyRound, Laptop } from "lucide-react";
import { useTranslation } from "react-i18next";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { cn } from "@/lib/utils";
import type { ModelSetupAvailability, ModelSetupIntent } from "@/lib/model-setup";
const SETUP_OPTIONS = [
{
intent: "account",
icon: Cloud,
titleKey: "thread.composer.modelSetup.account.title",
title: "Connect an account",
descriptionKey: "thread.composer.modelSetup.account.description",
description: "Use a supported AI subscription.",
},
{
intent: "apiKey",
icon: KeyRound,
titleKey: "thread.composer.modelSetup.apiKey.title",
title: "Use an API key",
descriptionKey: "thread.composer.modelSetup.apiKey.description",
description: "Bring a key from your preferred provider.",
},
{
intent: "local",
icon: Laptop,
titleKey: "thread.composer.modelSetup.local.title",
title: "Run locally",
descriptionKey: "thread.composer.modelSetup.local.description",
description: "Connect Ollama, LM Studio, or vLLM.",
},
] as const;
export function ModelSetupDialog({
availability,
open,
onOpenChange,
onReturnFocus,
onSelect,
}: {
availability: ModelSetupAvailability;
open: boolean;
onOpenChange: (open: boolean) => void;
onReturnFocus: () => void;
onSelect: (intent: ModelSetupIntent) => void;
}) {
const { t } = useTranslation();
const selectedRef = useRef(false);
return (
<Dialog
open={open}
onOpenChange={(nextOpen) => {
if (nextOpen) selectedRef.current = false;
onOpenChange(nextOpen);
}}
>
<DialogContent
className="max-w-md gap-5 p-5 sm:p-6"
onCloseAutoFocus={(event) => {
event.preventDefault();
if (!selectedRef.current) onReturnFocus();
selectedRef.current = false;
}}
>
<DialogHeader className="pr-7">
<DialogTitle className="text-[18px] leading-6">
{t("thread.composer.modelSetup.title", { defaultValue: "Choose your AI" })}
</DialogTitle>
<DialogDescription className="leading-5">
{t("thread.composer.modelSetup.description", {
defaultValue: "Pick a starting point. You can change models at any time.",
})}
</DialogDescription>
</DialogHeader>
<div className="space-y-2">
{SETUP_OPTIONS.map((option) => {
const Icon = option.icon;
const ready = availability[option.intent];
return (
<button
key={option.intent}
type="button"
aria-label={t(option.titleKey, { defaultValue: option.title })}
onClick={() => {
selectedRef.current = true;
onSelect(option.intent);
}}
className={cn(
"group flex min-h-[68px] w-full items-center gap-3 rounded-control border border-border/55 bg-background px-3.5 py-3 text-left",
"transition-[background-color,border-color,transform] duration-150 ease-out hover:border-border hover:bg-muted/45 active:scale-[0.99]",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/45",
)}
>
<span className="grid h-9 w-9 shrink-0 place-items-center rounded-full bg-muted/70 text-foreground/75 transition-colors group-hover:bg-background">
<Icon className="h-[17px] w-[17px]" strokeWidth={1.8} aria-hidden />
</span>
<span className="min-w-0 flex-1">
<span className="block text-[14px] font-semibold leading-5 text-foreground">
{t(option.titleKey, { defaultValue: option.title })}
</span>
<span className="mt-0.5 block text-[12px] leading-[18px] text-muted-foreground">
{t(option.descriptionKey, { defaultValue: option.description })}
</span>
</span>
{ready ? (
<span className="inline-flex shrink-0 items-center gap-1 rounded-full bg-emerald-500/10 px-2 py-1 text-[11px] font-medium text-emerald-700 dark:text-emerald-300">
<Check className="h-3 w-3" strokeWidth={2.2} aria-hidden />
{t("thread.composer.modelSetup.ready", { defaultValue: "Ready" })}
</span>
) : null}
</button>
);
})}
</div>
</DialogContent>
</Dialog>
);
}
+6 -26
View File
@@ -70,7 +70,6 @@ import {
ModelPresetBadge,
type ModelPresetOption,
} from "@/components/thread/ModelPresetBadge";
import { ModelSetupDialog } from "@/components/thread/ModelSetupDialog";
import {
ACCEPT_ATTR,
MAX_ATTACHMENTS_PER_MESSAGE,
@@ -114,7 +113,6 @@ import {
} from "@/lib/session-drag";
import { formatQuotedUserMessage } from "@/lib/user-message-quote";
import { formatCompactTokenCount } from "@/lib/format";
import type { ModelSetupAvailability, ModelSetupIntent } from "@/lib/model-setup";
import { cn } from "@/lib/utils";
const VOICE_SHORTCUT_CODE = "KeyD";
@@ -300,9 +298,8 @@ interface ThreadComposerProps {
modelProvider?: string | null;
modelProviderLabel?: string | null;
modelNeedsSetup?: boolean;
modelSetupAvailability?: ModelSetupAvailability;
fallbackModelName?: string | null;
onModelBadgeClick?: (intent?: ModelSetupIntent) => void;
onModelBadgeClick?: () => void;
onManageModels?: () => void;
contextUsage?: ComposerContextUsage | null;
variant?: "thread" | "hero";
@@ -1000,7 +997,6 @@ export function ThreadComposer({
modelProvider = null,
modelProviderLabel = null,
modelNeedsSetup = false,
modelSetupAvailability = { account: false, apiKey: false, local: false },
fallbackModelName = null,
onModelBadgeClick,
onManageModels,
@@ -1040,7 +1036,6 @@ export function ThreadComposer({
} | null>(null);
const [inlineError, setInlineError] = useState<string | null>(null);
const [sendPending, setSendPending] = useState(false);
const [modelSetupOpen, setModelSetupOpen] = useState(false);
const interactionDisabled = !!disabled || sendPending;
const [voiceErrorFading, setVoiceErrorFading] = useState(false);
const [slashMenuDismissed, setSlashMenuDismissed] = useState(false);
@@ -2013,7 +2008,7 @@ export function ThreadComposer({
const submit = useCallback(() => {
if (modelNeedsSetup) {
setModelSetupOpen(true);
onModelBadgeClick?.();
return;
}
if (!canSend) return;
@@ -2121,6 +2116,7 @@ export function ThreadComposer({
isStreaming,
maxTextBytes,
modelNeedsSetup,
onModelBadgeClick,
onSend,
onStop,
onQuotedContextChange,
@@ -2131,15 +2127,6 @@ export function ThreadComposer({
value,
]);
const openModelSetup = useCallback(() => {
setModelSetupOpen(true);
}, []);
const continueModelSetup = useCallback((intent: ModelSetupIntent) => {
setModelSetupOpen(false);
onModelBadgeClick?.(intent);
}, [onModelBadgeClick]);
const onKeyDown = (e: ReactKeyboardEvent<HTMLTextAreaElement>) => {
if (showCliAppMenu) {
if (e.key === "ArrowDown") {
@@ -2561,7 +2548,7 @@ export function ThreadComposer({
needsSetup={modelNeedsSetup}
fallbackModelName={fallbackModelName}
isHero={isHero}
onClick={modelNeedsSetup ? openModelSetup : undefined}
onClick={modelNeedsSetup ? onModelBadgeClick : undefined}
/>
) : null}
{!voiceRecorder.isRecording ? <ComposerContextBadge usage={contextUsage} /> : null}
@@ -2620,10 +2607,10 @@ export function ThreadComposer({
showStopButton
? t("thread.composer.stop")
: modelNeedsSetup
? t("thread.composer.openModelSetup", { defaultValue: "Open AI setup" })
? t("thread.composer.configureModel", { defaultValue: "Configure model" })
: t("thread.composer.send")
}
onClick={showStopButton ? handleStop : modelNeedsSetup ? openModelSetup : undefined}
onClick={showStopButton ? handleStop : modelNeedsSetup ? onModelBadgeClick : undefined}
className={cn(
"thread-composer-action touch-target rounded-full transition-transform",
showStopButton
@@ -2669,13 +2656,6 @@ export function ThreadComposer({
</div>
) : null}
</div>
<ModelSetupDialog
availability={modelSetupAvailability}
open={modelSetupOpen}
onOpenChange={setModelSetupOpen}
onReturnFocus={() => textareaRef.current?.focus()}
onSelect={continueModelSetup}
/>
</form>
);
}
+2 -15
View File
@@ -39,10 +39,6 @@ import {
} from "@/lib/mcp-preset-events";
import type { CanonicalRunSnapshot, StreamError } from "@/lib/nanobot-client";
import { inferProviderFromModelName, providerDisplayLabel } from "@/lib/provider-brand";
import {
modelSetupAvailability,
type ModelSetupIntent,
} from "@/lib/model-setup";
import type {
ChatSummary,
SettingsPayload,
@@ -358,7 +354,6 @@ interface ThreadShellProps {
composerPortalTarget?: HTMLElement | null;
composerActive?: boolean;
composerInputAriaLabel?: string;
focusComposerRequest?: number;
emptyComposerVariant?: "hero" | "thread";
workspaceScope?: WorkspaceScopePayload | null;
workspaceDefaultScope?: WorkspaceScopePayload | null;
@@ -367,7 +362,7 @@ interface ThreadShellProps {
workspaceError?: string | null;
onWorkspaceScopeChange?: (scope: WorkspaceScopePayload) => void;
settingsSnapshot?: SettingsPayload | null;
onOpenModelSettings?: (intent?: ModelSetupIntent) => void;
onOpenModelSettings?: () => void;
skills?: SkillSummary[];
}
@@ -659,7 +654,6 @@ export function ThreadShell({
composerPortalTarget,
composerActive = true,
composerInputAriaLabel,
focusComposerRequest = 0,
emptyComposerVariant = "hero",
workspaceScope = null,
workspaceDefaultScope = null,
@@ -969,10 +963,6 @@ export function ThreadShell({
const modelBadgeLabel = modelBadge.needsSetup
? t("thread.composer.chooseAI", { defaultValue: "Choose your AI" })
: modelBadge.label;
const setupAvailability = useMemo(
() => modelSetupAvailability(settings?.providers),
[settings?.providers],
);
useEffect(() => {
if (showHeroComposer && !wasShowingHeroComposerRef.current) {
setHeroGreetingKey(randomHeroGreetingKey());
@@ -1527,7 +1517,6 @@ export function ThreadShell({
modelProvider={modelBadge.provider}
modelProviderLabel={modelBadge.providerLabel}
modelNeedsSetup={modelBadge.needsSetup}
modelSetupAvailability={setupAvailability}
fallbackModelName={fallbackModelName}
onModelBadgeClick={modelBadge.needsSetup ? onOpenModelSettings : undefined}
onManageModels={onOpenModelSettings}
@@ -1555,7 +1544,7 @@ export function ThreadShell({
transcriptionProvider={settingsSnapshot?.transcription?.provider}
ingressLimits={ingressLimits}
quotedContext={quotedContext}
focusRequest={composerFocusSignal + focusComposerRequest}
focusRequest={composerFocusSignal}
onQuotedContextChange={setQuotedContext}
/>
) : (
@@ -1577,7 +1566,6 @@ export function ThreadShell({
modelProvider={modelBadge.provider}
modelProviderLabel={modelBadge.providerLabel}
modelNeedsSetup={modelBadge.needsSetup}
modelSetupAvailability={setupAvailability}
fallbackModelName={fallbackModelName}
onModelBadgeClick={modelBadge.needsSetup ? onOpenModelSettings : undefined}
onManageModels={onOpenModelSettings}
@@ -1603,7 +1591,6 @@ export function ThreadShell({
onWorkspaceScopeChange={onWorkspaceScopeChange}
transcriptionProvider={settingsSnapshot?.transcription?.provider}
ingressLimits={ingressLimits}
focusRequest={composerFocusSignal + focusComposerRequest}
/>
)}
</>