DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
feat(settings): model pages as provider cards you open into models
Bingxi Zhao (Frank)5b04fb675d2d
diff --git a/web/components/settings/ModelCards.tsx b/web/components/settings/ModelCards.tsxnew file mode 100644index 000000000..d2183ed72--- /dev/null+++ b/web/components/settings/ModelCards.tsx@@ -0,0 +1,424 @@+"use client";++import { ArrowLeft, Check, ChevronDown, Plus, Trash2 } from "lucide-react";+import { useTranslation } from "react-i18next";++import ProviderIcon from "@/components/common/ProviderIcon";+import type {+ CatalogModel,+ CatalogProfile,+ ServiceName,+} from "./SettingsContext";++/**+ * The two levels of a model settings page, as cards.+ *+ * A page shows the providers configured for its service; opening one shows+ * the models under it. Cards rather than a list because each one carries more+ * than a name — what it points at, how many models it holds, whether it is the+ * one actually running — and because "open this" and "put this to use" have to+ * be visibly different acts, which a row that does both on click cannot say.+ *+ * The visual language is the one measured off the rest of the app: hairline+ * borders, the accent tint the sidebar uses for its selected row, one radius+ * from the settings scale, no shadows.+ */++export function SectionHead({+ title,+ action,+}: {+ title: string;+ action?: React.ReactNode;+}) {+ return (+ <div className="mb-3 flex items-center justify-between gap-2 border-b border-[var(--border)]/60 pb-2">+ <h2 className="text-[13px] font-medium text-[var(--foreground)]">+ {title}+ </h2>+ {action}+ </div>+ );+}++export function CardAction({+ onClick,+ disabled,+ children,+}: {+ onClick: () => void;+ disabled?: boolean;+ children: React.ReactNode;+}) {+ return (+ <button+ type="button"+ onClick={onClick}+ disabled={disabled}+ className="inline-flex items-center gap-1 rounded-lg border border-[var(--border)]/50 px-2.5 py-1 text-[12px] text-[var(--muted-foreground)] transition-colors hover:border-[var(--border)] hover:text-[var(--foreground)] disabled:opacity-40"+ >+ {children}+ </button>+ );+}++export function CardGrid({ children }: { children: React.ReactNode }) {+ return (+ <div className="grid gap-2.5 sm:grid-cols-2 xl:grid-cols-3">{children}</div>+ );+}++export function BackRow({+ label,+ current,+ onBack,+}: {+ label: string;+ current: string;+ onBack: () => void;+}) {+ return (+ <div className="mb-4 flex items-center gap-1.5 text-[12px]">+ <button+ type="button"+ onClick={onBack}+ className="inline-flex items-center gap-1 rounded-md py-0.5 pr-1.5 text-[var(--muted-foreground)] transition-colors hover:text-[var(--foreground)]"+ >+ <ArrowLeft className="h-3.5 w-3.5" />+ {label}+ </button>+ <span aria-hidden className="text-[var(--muted-foreground)]/40">+ /+ </span>+ <span className="min-w-0 truncate font-medium text-[var(--foreground)]">+ {current}+ </span>+ </div>+ );+}++export function AddCard({+ label,+ onClick,+}: {+ label: string;+ onClick: () => void;+}) {+ return (+ <button+ type="button"+ onClick={onClick}+ className="flex min-h-[86px] items-center justify-center gap-1.5 rounded-xl border border-dashed border-[var(--border)] text-[12.5px] text-[var(--muted-foreground)] transition-colors hover:border-[var(--foreground)]/30 hover:bg-[var(--accent)]/30 hover:text-[var(--foreground)]"+ >+ <Plus className="h-3.5 w-3.5" />+ {label}+ </button>+ );+}++/** Shared chrome: the frame, the name row and the expand affordance. */+function CardShell({+ expanded,+ inUse,+ onOpen,+ children,+}: {+ expanded: boolean;+ inUse: boolean;+ onOpen?: () => void;+ children: React.ReactNode;+}) {+ return (+ <div+ className={`group relative flex min-h-[86px] flex-col justify-between gap-2 rounded-xl border p-3 transition-colors ${+ expanded+ ? "border-[var(--foreground)]/25 bg-[var(--accent)]/40"+ : inUse+ ? "border-[var(--border)] bg-[var(--accent)]/25"+ : "border-[var(--border)]/70"+ } ${onOpen ? "cursor-pointer hover:border-[var(--foreground)]/25 hover:bg-[var(--accent)]/30" : ""}`}+ onClick={onOpen}+ role={onOpen ? "button" : undefined}+ tabIndex={onOpen ? 0 : undefined}+ onKeyDown={+ onOpen+ ? (event) => {+ if (event.key === "Enter" || event.key === " ") {+ event.preventDefault();+ onOpen();+ }+ }+ : undefined+ }+ >+ {children}+ </div>+ );+}++function NameRow({+ icon,+ name,+ renaming,+ renameValue,+ onRenameChange,+ onRenameCommit,+ onRenameCancel,+ onRenameStart,+ expanded,+ onToggleExpand,+ expandLabel,+}: {+ icon?: React.ReactNode;+ name: string;+ renaming: boolean;+ renameValue: string;+ onRenameChange: (value: string) => void;+ onRenameCommit: () => void;+ onRenameCancel: () => void;+ onRenameStart: () => void;+ expanded: boolean;+ onToggleExpand: () => void;+ expandLabel: string;+}) {+ if (renaming) {+ return (+ <input+ autoFocus+ value={renameValue}+ onClick={(event) => event.stopPropagation()}+ onChange={(event) => onRenameChange(event.target.value)}+ onBlur={onRenameCommit}+ onKeyDown={(event) => {+ if (event.key === "Enter") event.currentTarget.blur();+ if (event.key === "Escape") {+ event.preventDefault();+ onRenameCancel();+ }+ }}+ className="w-full rounded-md border border-[var(--border)] bg-[var(--background)] px-1.5 py-0.5 text-[13px] font-medium text-[var(--foreground)] outline-none focus:border-[var(--ring)]"+ />+ );+ }+ return (+ <div className="flex items-start gap-2">+ {icon}+ <span+ onDoubleClick={(event) => {+ event.stopPropagation();+ onRenameStart();+ }}+ className="min-w-0 flex-1 truncate text-[13px] font-medium leading-5 text-[var(--foreground)]"+ >+ {name}+ </span>+ <button+ type="button"+ aria-label={expandLabel}+ aria-expanded={expanded}+ onClick={(event) => {+ event.stopPropagation();+ onToggleExpand();+ }}+ className="-mr-1 -mt-0.5 shrink-0 rounded-md p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--accent)] hover:text-[var(--foreground)]"+ >+ <ChevronDown+ className={`h-3.5 w-3.5 transition-transform ${expanded ? "rotate-180" : ""}`}+ />+ </button>+ </div>+ );+}++/** "In use" is stated; everything else offers to become it. */+function UseRow({+ inUse,+ onUse,+ detail,+}: {+ inUse: boolean;+ onUse: () => void;+ detail?: string;+}) {+ const { t } = useTranslation();+ return (+ <div className="flex items-end justify-between gap-2">+ <span className="min-w-0 truncate text-[11px] text-[var(--muted-foreground)]">+ {detail}+ </span>+ {inUse ? (+ <span className="inline-flex shrink-0 items-center gap-1 text-[11px] font-medium text-[var(--foreground)]">+ <Check className="h-3 w-3" />+ {t("In use")}+ </span>+ ) : (+ <button+ type="button"+ onClick={(event) => {+ event.stopPropagation();+ onUse();+ }}+ className="shrink-0 rounded-md px-1 text-[11px] text-[var(--muted-foreground)] underline-offset-2 transition-colors hover:text-[var(--foreground)] hover:underline"+ >+ {t("Set as active")}+ </button>+ )}+ </div>+ );+}++export function ProfileCard({+ profile,+ service,+ inUse,+ expanded,+ renaming,+ renameValue,+ onRenameChange,+ onRenameCommit,+ onRenameCancel,+ onRenameStart,+ onOpen,+ onToggleExpand,+ onUse,+}: {+ profile: CatalogProfile;+ service: ServiceName;+ inUse: boolean;+ expanded: boolean;+ renaming: boolean;+ renameValue: string;+ onRenameChange: (value: string) => void;+ onRenameCommit: () => void;+ onRenameCancel: () => void;+ onRenameStart: () => void;+ /** Absent for search, which has no models to drill into. */+ onOpen?: () => void;+ onToggleExpand: () => void;+ onUse: () => void;+}) {+ const { t } = useTranslation();+ const provider =+ service === "search" ? profile.provider || "" : profile.binding || "";+ const endpoint = (profile.base_url || "").replace(/^https?:\/\//, "");+ const count = profile.models.length;++ return (+ <CardShell expanded={expanded} inUse={inUse} onOpen={onOpen}>+ <NameRow+ icon={+ <ProviderIcon provider={provider} size={15} className="mt-0.5" />+ }+ name={profile.name}+ renaming={renaming}+ renameValue={renameValue}+ onRenameChange={onRenameChange}+ onRenameCommit={onRenameCommit}+ onRenameCancel={onRenameCancel}+ onRenameStart={onRenameStart}+ expanded={expanded}+ onToggleExpand={onToggleExpand}+ expandLabel={t("Edit connection")}+ />+ <div className="min-w-0">+ <p className="truncate font-mono text-[10.5px] text-[var(--muted-foreground)]/80">+ {endpoint || t("Provider default endpoint")}+ </p>+ </div>+ <UseRow+ inUse={inUse}+ onUse={onUse}+ detail={+ service === "search"+ ? undefined+ : t("{{count}} models", { count })+ }+ />+ </CardShell>+ );+}++export function ModelCard({+ model,+ service,+ language,+ index,+ inUse,+ expanded,+ renaming,+ renameValue,+ onRenameChange,+ onRenameCommit,+ onRenameCancel,+ onRenameStart,+ onToggleExpand,+ onUse,+ onDelete,+}: {+ model: CatalogModel;+ service: ServiceName;+ language: "en" | "zh";+ index: number;+ inUse: boolean;+ expanded: boolean;+ renaming: boolean;+ renameValue: string;+ onRenameChange: (value: string) => void;+ onRenameCommit: () => void;+ onRenameCancel: () => void;+ onRenameStart: () => void;+ onToggleExpand: () => void;+ onUse: () => void;+ onDelete: () => void;+}) {+ const { t } = useTranslation();+ const name =+ (model.name || "").trim() ||+ (language === "zh" ? `模型 ${index + 1}` : `Model ${index + 1}`);+ const detail =+ service === "llm"+ ? model.context_window+ ? t("{{n}} ctx", { n: model.context_window })+ : undefined+ : service === "embedding"+ ? model.dimension+ ? t("{{n}} dim", { n: model.dimension })+ : undefined+ : service === "tts"+ ? model.voice || undefined+ : undefined;++ return (+ <CardShell expanded={expanded} inUse={inUse} onOpen={onToggleExpand}>+ <NameRow+ name={name}+ renaming={renaming}+ renameValue={renameValue}+ onRenameChange={onRenameChange}+ onRenameCommit={onRenameCommit}+ onRenameCancel={onRenameCancel}+ onRenameStart={onRenameStart}+ expanded={expanded}+ onToggleExpand={onToggleExpand}+ expandLabel={t("Edit model")}+ />+ <div className="flex min-w-0 items-center gap-2">+ <p className="min-w-0 flex-1 truncate font-mono text-[10.5px] text-[var(--muted-foreground)]/80">+ {model.model || t("No model id yet")}+ </p>+ <button+ type="button"+ aria-label={t("Delete")}+ onClick={(event) => {+ event.stopPropagation();+ onDelete();+ }}+ className="shrink-0 rounded-md p-1 text-[var(--muted-foreground)]/0 transition-colors hover:bg-[var(--accent)] hover:text-red-500 focus-visible:text-red-500 group-hover:text-[var(--muted-foreground)]/70 max-sm:text-[var(--muted-foreground)]/70"+ >+ <Trash2 className="h-3 w-3" />+ </button>+ </div>+ <UseRow inUse={inUse} onUse={onUse} detail={detail} />+ </CardShell>+ );+}diff --git a/web/components/settings/ServiceConfigEditor.tsx b/web/components/settings/ServiceConfigEditor.tsxindex e3a51e83e..2a7c5001d 100644--- a/web/components/settings/ServiceConfigEditor.tsx+++ b/web/components/settings/ServiceConfigEditor.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";import Link from "next/link";import {ArrowUpRight,@@ -16,6 +16,7 @@ import {RefreshCw,Terminal,Trash2,+ X,} from "lucide-react";import { useTranslation } from "react-i18next";@@ -43,6 +44,15 @@ import {useSettings,} from "./SettingsContext";import { DimensionField } from "./DimensionField";+import {+ AddCard,+ BackRow,+ CardAction,+ CardGrid,+ ModelCard,+ ProfileCard,+ SectionHead,+} from "./ModelCards";import { nextProfileName } from "./profile-naming";import { searchProviderFields } from "./search-providers";import {@@ -81,19 +91,76 @@ export function ServiceConfigEditor({ service }: { service: ServiceName }) {removeActiveProfile,addModel,removeActiveModel,- updateProfileField,- updateModelField,- updateModelBoolField,- updateContextWindowField,- updateReasoningEffort,+ updateProfileField: setProfileField,+ updateModelField: setModelField,+ updateModelBoolField: setModelBoolField,+ updateContextWindowField: setContextWindowField,+ updateReasoningEffort: setReasoningEffort,llmContextDetection,applyDetectedContextWindow,runDetailedTest,setToast,} = useSettings();- const activeProfile = getActiveProfile(draft, service);- const activeModel = getActiveModel(draft, service);+ const profiles = draft.services[service].profiles;+ const inUseProfileId = draft.services[service].active_profile_id;+ const inUseModelId = draft.services[service].active_model_id;++ // ── Browsing vs using ───────────────────────────────────────────────────+ //+ // A page opens on its providers. Opening one drills into its models;+ // expanding one edits its connection in place. Neither adopts it — "in use"+ // is now a separate, deliberate act, which is what lets you look at a+ // provider you are not currently running on without switching to it.+ const [openProfileId, setOpenProfileId] = useState<string | null>(null);+ const [expandedProfileId, setExpandedProfileId] = useState<string | null>(+ null,+ );+ const [expandedModelId, setExpandedModelId] = useState<string | null>(null);++ const openedProfile = profiles.find((item) => item.id === openProfileId) ?? null;+ const expandedProfile =+ profiles.find((item) => item.id === expandedProfileId) ?? null;++ // Whatever the field editors below are pointed at. Falling back to the+ // profile in use keeps every reference working before anything is opened.+ const activeProfile =+ openedProfile ?? expandedProfile ?? getActiveProfile(draft, service);+ const activeModel = openedProfile+ ? ((expandedModelId+ ? openedProfile.models.find((item) => item.id === expandedModelId)+ : null) ?? null)+ : getActiveModel(draft, service);++ // The context's mutators write to whatever is in use unless told otherwise.+ // Binding them to what is on screen here means the ~300 lines of field+ // editors below need no knowledge of any of this.+ const updateProfileField = useCallback(+ (svc: ServiceName, field: keyof CatalogProfile, value: string) =>+ setProfileField(svc, field, value, activeProfile?.id),+ [setProfileField, activeProfile?.id],+ );+ const updateModelField = useCallback(+ (svc: ServiceName, field: keyof CatalogModel, value: string) =>+ setModelField(svc, field, value, activeProfile?.id, activeModel?.id),+ [setModelField, activeProfile?.id, activeModel?.id],+ );+ const updateModelBoolField = useCallback(+ (svc: ServiceName, field: keyof CatalogModel, value: boolean) =>+ setModelBoolField(svc, field, value, activeProfile?.id, activeModel?.id),+ [setModelBoolField, activeProfile?.id, activeModel?.id],+ );+ const updateContextWindowField = useCallback(+ (value: string) =>+ setContextWindowField(value, activeProfile?.id, activeModel?.id),+ [setContextWindowField, activeProfile?.id, activeModel?.id],+ );+ const updateReasoningEffort = useCallback(+ (value: string) =>+ setReasoningEffort(value, activeProfile?.id, activeModel?.id),+ [setReasoningEffort, activeProfile?.id, activeModel?.id],+ );+const activeProviderValue =service === "search"? activeProfile?.provider || ""@@ -119,10 +186,11 @@ export function ServiceConfigEditor({ service }: { service: ServiceName }) {// The query is read from `window.location` rather than `useSearchParams()`// so no settings page needs a Suspense boundary for something that only// exists after hydration.+ // Arriving from Settings > Connections with ?profile=<id>: open that+ // provider's connection panel. It used to have to *adopt* the profile to+ // show it, because selecting and using were the same act — with the two+ // separated, following the link costs nothing and needs no warning.const deepLinkHandled = useRef(false);- const [deepLink, setDeepLink] = useState<{ from: string; to: string } | null>(- null,- );useEffect(() => {if (deepLinkHandled.current) return;const requested = new URLSearchParams(window.location.search).get("profile");@@ -130,35 +198,14 @@ export function ServiceConfigEditor({ service }: { service: ServiceName }) {deepLinkHandled.current = true;return;}- const bucket = draft.services[service];- const target = bucket.profiles.find((item) => item.id === requested);// The catalog may still be loading; leave the flag down and retry.- if (!target) return;+ if (!profiles.some((item) => item.id === requested)) return;deepLinkHandled.current = true;- // Drop the query so a refresh does not re-apply a switch already undone.+ // Drop the query so a refresh does not re-open something already closed.window.history.replaceState(null, "", window.location.pathname);- const previous = bucket.active_profile_id;- if (previous === requested) return;- setDeepLink({ from: previous ?? "", to: requested });- mutateCatalog((next) => {- next.services[service].active_profile_id = requested;- if (service !== "search") {- next.services[service].active_model_id = target.models[0]?.id ?? null;- }- });- }, [draft, service, mutateCatalog]);+ setExpandedProfileId(requested);+ }, [profiles]);- const deepLinkFromProfile = deepLink- ? (draft.services[service].profiles.find(- (item) => item.id === deepLink.from,- ) ?? null)- : null;- // Only while the deep-linked profile is still the selected one — once the- // user picks something else the offer to go back would name the wrong thing.- const showDeepLinkNotice =- deepLink !== null &&- deepLinkFromProfile !== null &&- draft.services[service].active_profile_id === deepLink.to;const [showApiKey, setShowApiKey] = useState(false);const [confirmingProfileDelete, setConfirmingProfileDelete] = useState(false);@@ -377,219 +424,169 @@ export function ServiceConfigEditor({ service }: { service: ServiceName }) {return (<div data-tour={`tour-${service}`} className="space-y-5">- {showDeepLinkNotice && deepLink && deepLinkFromProfile && (- <div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-xl border border-[var(--border)] bg-[var(--muted)]/25 px-4 py-2.5">- <span className="text-[11.5px] leading-relaxed text-[var(--muted-foreground)]">- {t(- "Opened from Connections. Applying will also make this the {{service}} profile in use.",- { service: t(SERVICE_LABEL[service]) },- )}- </span>- <button- type="button"- onClick={() => {- const back = deepLinkFromProfile;- mutateCatalog((next) => {- next.services[service].active_profile_id = back.id;- if (service !== "search") {- next.services[service].active_model_id =- back.models[0]?.id ?? null;- }- });- setDeepLink(null);- }}- className="inline-flex h-7 shrink-0 items-center gap-1.5 rounded-lg border border-[var(--border)] px-2.5 text-[11.5px] text-[var(--foreground)] transition-colors hover:bg-[var(--muted)]"- >- <ArrowLeft className="h-3 w-3" />- {t("Back to {{name}}", { name: deepLinkFromProfile.name })}- </button>- </div>- )}{activeProfile ? (- <div className="grid grid-cols-1 items-start gap-5 md:grid-cols-[200px_minmax(0,1fr)]">- {/* ── Profile list (sticky so it stays put while the editor scrolls;- stacked above the editor when there is no room beside it) ── */}- <aside className="self-start rounded-xl bg-[var(--accent)]/40 p-2 md:sticky md:top-4">- <div className="px-2 pb-2 pt-1 text-[11px] font-medium uppercase tracking-wide text-[var(--muted-foreground)]/70">- {t("Profiles")}- </div>- <div className="space-y-0.5">- {draft.services[service].profiles.map((profile) => {- const isActive =- profile.id === draft.services[service].active_profile_id;- const profileDetail = activeProfileDetail(profile, service, t);- const isManagedProfile = isManagedCodexProfile(profile);- const isEditing =- editingProfileId === profile.id && !isManagedProfile;- return (- <div+ <div>+ {/* ── Level 1: the providers configured for this service ──────────+ A card is a place, not a switch: opening one drills into its+ models, the chevron edits its connection in place, and+ neither one changes which provider the app is running on.+ That is what "In use" is for. */}+ {!openedProfile && (+ <>+ <SectionHead+ title={t("Providers")}+ action={+ <CardAction onClick={() => addProfile(service)}>+ <Plus className="h-3 w-3" />+ {t("Add provider")}+ </CardAction>+ }+ />+ <CardGrid>+ {profiles.map((profile) => (+ <ProfileCardkey={profile.id}- role="button"- tabIndex={isEditing ? -1 : 0}- onClick={() => {- if (isEditing) return;+ profile={profile}+ service={service}+ inUse={profile.id === inUseProfileId}+ expanded={profile.id === expandedProfileId}+ renaming={editingProfileId === profile.id}+ renameValue={editingProfileName}+ onRenameChange={setEditingProfileName}+ onRenameCommit={() => commitProfileRename(profile.id)}+ onRenameCancel={cancelProfileRename}+ onRenameStart={() => startProfileRename(profile)}+ onOpen={+ service === "search"+ ? undefined+ : () => {+ setOpenProfileId(profile.id);+ setExpandedProfileId(null);+ setExpandedModelId(+ profile.id === inUseProfileId+ ? (inUseModelId ?? null)+ : (profile.models[0]?.id ?? null),+ );+ }+ }+ onToggleExpand={() => {+ setExpandedProfileId(+ profile.id === expandedProfileId ? null : profile.id,+ );+ }}+ onUse={() =>mutateCatalog((next) => {next.services[service].active_profile_id = profile.id;if (service !== "search") {next.services[service].active_model_id =profile.models[0]?.id ?? null;}- });- }}- onDoubleClick={() => {- if (!isManagedProfile) startProfileRename(profile);- }}- onKeyDown={(e) => {- if (isEditing) return;- if (e.key === "Enter" || e.key === " ") {- e.preventDefault();- mutateCatalog((next) => {- next.services[service].active_profile_id = profile.id;- if (service !== "search") {- next.services[service].active_model_id =- profile.models[0]?.id ?? null;- }- });- }- }}- title={- isEditing || isManagedProfile- ? undefined- : t("Double-click to rename")+ })}- className={`group relative cursor-pointer rounded-lg px-3 py-2 text-left transition-colors ${- isActive- ? "bg-[var(--muted)]/70 text-[var(--foreground)]"- : "text-[var(--muted-foreground)] hover:bg-[var(--muted)]/30"- }`}- >- {isActive && (- <span className="absolute inset-y-2 left-0 w-0.5 rounded-r-full bg-[var(--foreground)]/80" />- )}- {isEditing ? (- <input- autoFocus- className="block w-full rounded border border-[var(--border)] bg-[var(--background)] px-1.5 py-0.5 text-[13px] font-medium text-[var(--foreground)] outline-none focus:border-[var(--ring)]"- value={editingProfileName}- onChange={(e) => setEditingProfileName(e.target.value)}- onBlur={() => commitProfileRename(profile.id)}- onClick={(e) => e.stopPropagation()}- onKeyDown={(e) => {- if (e.key === "Enter") {- e.currentTarget.blur();- }- if (e.key === "Escape") {- e.preventDefault();- cancelProfileRename();- }- }}- aria-label={t("Rename profile")}- />- ) : (- <div className="flex items-center gap-1.5">- <ProviderIcon- provider={- service === "search"- ? profile.provider- : profile.binding- }- size={13}- />- <div- className={`min-w-0 flex-1 truncate text-[13px] leading-tight ${- isActive ? "font-semibold" : "font-medium"- }`}+ />+ ))}+ <AddCard+ label={t("Add provider")}+ onClick={() => addProfile(service)}+ />+ </CardGrid>+ </>+ )}++ {/* ── Level 2: the models under one provider ─────────────────── */}+ {openedProfile && (+ <>+ <BackRow+ label={t("All providers")}+ current={openedProfile.name}+ onBack={() => {+ setOpenProfileId(null);+ setExpandedModelId(null);+ }}+ />+ <SectionHead+ title={t("Models")}+ action={+ <span className="flex items-center gap-2">+ {service === "llm" &&+ openedProfile.binding === "codebuddy" && (+ <CardAction+ onClick={() => void syncProviderModels()}+ disabled={modelsSyncing}>- {profile.name}- </div>- {!isManagedProfile && (- <button- type="button"- onClick={(e) => {- e.stopPropagation();- startProfileRename(profile);- }}- className="-mr-1 shrink-0 rounded-md p-1 text-[var(--muted-foreground)]/60 transition-colors hover:bg-[var(--muted)] hover:text-[var(--foreground)]"- aria-label={t("Rename profile")}- title={t("Rename profile")}- >- <Pencil className="h-3 w-3" />- </button>- )}- </div>- )}- <div className="mt-0.5 truncate text-[11px] leading-tight text-[var(--muted-foreground)]/70">- {profileDetail}- </div>- </div>- );- })}- </div>- {/* Deleting takes the whole provider with it — its key and every- model under it — and it sits one hairline below the list the- user is clicking through, so it asks first. */}- <div className="mt-2 border-t border-[var(--border)]/40 pt-2">- {confirmingProfileDelete ? (- <div className="px-1.5 py-1">- <p className="text-[11px] leading-relaxed text-[var(--muted-foreground)]">- {t("Delete this profile and every model under it?")}- </p>- <div className="mt-1.5 flex items-center gap-1.5">- <button- type="button"- onClick={() => setConfirmingProfileDelete(false)}- className="h-6 rounded-md px-2 text-[11px] text-[var(--muted-foreground)] hover:text-[var(--foreground)]"- >- {t("Cancel")}- </button>- <button- type="button"- onClick={() => {- removeActiveProfile(service);- setConfirmingProfileDelete(false);- }}- className="h-6 rounded-md bg-red-500/10 px-2 text-[11px] font-medium text-red-600 transition-colors hover:bg-red-500/15 dark:text-red-400"+ <RefreshCw+ className={`h-3 w-3 ${modelsSyncing ? "animate-spin" : ""}`}+ />+ {t("Sync models")}+ </CardAction>+ )}+ <CardAction+ onClick={() => addModel(service, openedProfile.id)}>- {t("Delete")}- </button>- </div>- </div>- ) : (- <button- onClick={() => setConfirmingProfileDelete(true)}- disabled={!activeProfile || isManagedCodex}- className="flex w-full items-center gap-1.5 rounded-lg px-3 py-1.5 text-left text-[11px] text-[var(--muted-foreground)]/60 transition-colors hover:bg-red-500/5 hover:text-red-500 disabled:opacity-30"- title={- activeProfile && !isManagedCodex- ? t("Permanently remove the currently selected profile.")- : undefined+ <Plus className="h-3 w-3" />+ {t("Add model")}+ </CardAction>+ </span>}- >- <Trash2 className="h-3 w-3 shrink-0" />- <span className="truncate">- {activeProfile- ? t("Delete “{{name}}”", { name: activeProfile.name })- : t("Delete profile")}- </span>- </button>- )}- </div>- </aside>+ />+ <CardGrid>+ {openedProfile.models.map((model, index) => (+ <ModelCard+ key={model.id}+ model={model}+ service={service}+ language={language}+ index={index}+ inUse={+ openedProfile.id === inUseProfileId &&+ model.id === inUseModelId+ }+ expanded={model.id === expandedModelId}+ renaming={editingModelId === model.id}+ renameValue={editingModelName}+ onRenameChange={setEditingModelName}+ onRenameCommit={() => commitModelRename(model.id)}+ onRenameCancel={cancelModelRename}+ onRenameStart={() => startModelRename(model)}+ onToggleExpand={() =>+ setExpandedModelId(+ model.id === expandedModelId ? null : model.id,+ )+ }+ onUse={() =>+ mutateCatalog((next) => {+ next.services[service].active_profile_id =+ openedProfile.id;+ next.services[service].active_model_id = model.id;+ })+ }+ onDelete={() =>+ removeActiveModel(service, openedProfile.id, model.id)+ }+ />+ ))}+ <AddCard+ label={t("Add model")}+ onClick={() => addModel(service, openedProfile.id)}+ />+ </CardGrid>+ </>+ )}- {/* ── Editor ── */}<div className="min-w-0 space-y-7">- <div>+ {expandedProfile && !openedProfile && (+ <div className="mt-4"><div className="mb-2.5 flex items-center justify-between gap-2 border-b border-[var(--border)]/60 pb-2"><div className="text-[13px] font-medium text-[var(--foreground)]">{t("Provider connection")}</div><buttontype="button"- onClick={() => addProfile(service)}+ onClick={() => setExpandedProfileId(null)}className="inline-flex items-center gap-1 rounded-lg border border-[var(--border)]/50 px-2.5 py-1 text-[12px] text-[var(--muted-foreground)] transition-colors hover:border-[var(--border)] hover:text-[var(--foreground)]">- <Plus className="h-3 w-3" />- {t("Profile")}+ <X className="h-3 w-3" />+ {t("Close")}</button></div><ProfileFields@@ -642,129 +639,23 @@ export function ServiceConfigEditor({ service }: { service: ServiceName }) {}}/></div>+ )}- {service !== "search" && (+ {service !== "search" && openedProfile && (<div>- <div className="mb-2.5 flex items-center justify-between gap-2 border-b border-[var(--border)]/60 pb-2">- <div className="text-[13px] font-medium text-[var(--foreground)]">- {t("Models")}- </div>- {!isCodexOAuth && (- <div className="flex items-center gap-2">- {service === "llm" &&- activeProfile.binding === "codebuddy" && (- <button- type="button"- onClick={() => void syncProviderModels()}- disabled={modelsSyncing}- className="inline-flex items-center gap-1 rounded-lg border border-[var(--border)]/50 px-2.5 py-1 text-[12px] text-[var(--muted-foreground)] transition-colors hover:border-[var(--border)] hover:text-[var(--foreground)] disabled:opacity-40"- >- <RefreshCw- className={`h-3 w-3 ${modelsSyncing ? "animate-spin" : ""}`}- />- {t("Sync models")}- </button>- )}- <button- type="button"- onClick={() => addModel(service)}- className="inline-flex items-center gap-1 rounded-lg border border-[var(--border)]/50 px-2.5 py-1 text-[12px] text-[var(--muted-foreground)] transition-colors hover:border-[var(--border)] hover:text-[var(--foreground)]"- >- <Plus className="h-3 w-3" />- {t("Model")}- </button>- <button- onClick={() => removeActiveModel(service)}- disabled={!activeModel}- className="inline-flex items-center gap-1 text-[11px] text-[var(--muted-foreground)]/40 transition-colors hover:text-red-500 disabled:opacity-30"- >- <Trash2 className="h-3 w-3" />- {t("Delete")}- </button>+ {activeModel && (!isCodexOAuth || isBoundManagedCodex) && (+ <div className="mb-2.5 flex items-center justify-between gap-2 border-b border-[var(--border)]/60 pb-2">+ <div className="min-w-0 truncate text-[13px] font-medium text-[var(--foreground)]">+ {(activeModel.name || "").trim() || t("Model")}</div>- )}- </div>- {activeProfile.models.length > 0 && (- <div className="mb-4 flex flex-wrap items-center gap-1.5">- {activeProfile.models.map((model, index) => {- const isActive =- model.id === draft.services[service].active_model_id;- const label =- (model.name || "").trim() ||- defaultModelLabel(language, index + 1);- const metric =- service === "llm"- ? formatCompactTokens(model.context_window)- : service === "embedding"- ? formatDimensionBadge(model.dimension)- : service === "tts"- ? formatVoiceBadge(model.voice)- : "";- return (- <div key={model.id} className="min-w-0">- {editingModelId === model.id && !isCodexOAuth ? (- <input- autoFocus- className="h-8 w-60 rounded-lg border border-[var(--border)] bg-[var(--background)] px-2.5 text-[12.5px] text-[var(--foreground)] outline-none focus:border-[var(--ring)]"- value={editingModelName}- onChange={(e) =>- setEditingModelName(e.target.value)- }- onBlur={() => commitModelRename(model.id)}- onKeyDown={(e) => {- if (e.key === "Enter") {- e.currentTarget.blur();- }- if (e.key === "Escape") {- e.preventDefault();- cancelModelRename();- }- }}- aria-label={t("Rename model")}- />- ) : (- <button- type="button"- onClick={() =>- mutateCatalog((next) => {- next.services[service].active_model_id =- model.id;- })- }- onDoubleClick={() => {- if (!isCodexOAuth) startModelRename(model);- }}- title={- isCodexOAuth- ? undefined- : t("Double-click to rename")- }- className={`inline-flex h-8 items-center gap-1.5 rounded-lg px-2.5 text-[12.5px] transition-colors ${- isActive- ? "bg-[var(--muted)] text-[var(--foreground)]"- : "text-[var(--muted-foreground)] hover:bg-[var(--muted)]/40"- }`}- >- {isActive && (- <CheckCircle2 className="h-3 w-3 shrink-0 text-[var(--foreground)]/70" />- )}- <span- className={`max-w-[280px] truncate leading-none ${- isActive ? "font-medium" : ""- }`}- >- {label}- </span>- {metric && (- <span className="shrink-0 text-[10.5px] tabular-nums leading-none text-[var(--muted-foreground)]/80">- {metric}- </span>- )}- </button>- )}- </div>- );- })}+ <button+ type="button"+ onClick={() => setExpandedModelId(null)}+ className="inline-flex items-center gap-1 rounded-lg border border-[var(--border)]/50 px-2.5 py-1 text-[12px] text-[var(--muted-foreground)] transition-colors hover:border-[var(--border)] hover:text-[var(--foreground)]"+ >+ <X className="h-3 w-3" />+ {t("Close")}+ </button></div>)}{activeModel && (!isCodexOAuth || isBoundManagedCodex) && (diff --git a/web/components/settings/SettingsContext.tsx b/web/components/settings/SettingsContext.tsxindex 77c74656c..da9c62903 100644--- a/web/components/settings/SettingsContext.tsx+++ b/web/components/settings/SettingsContext.tsx@@ -561,26 +561,44 @@ type SettingsContextValue = {// Catalog mutationmutateCatalog: (mutator: (next: Catalog) => void) => void;addProfile: (service: ServiceName) => void;- removeActiveProfile: (service: ServiceName) => void;- addModel: (service: ServiceName) => void;- removeActiveModel: (service: ServiceName) => void;+ /** Omitting the id targets whatever is in use — the historical meaning. */+ removeActiveProfile: (service: ServiceName, profileId?: string) => void;+ addModel: (service: ServiceName, profileId?: string) => void;+ removeActiveModel: (+ service: ServiceName,+ profileId?: string,+ modelId?: string,+ ) => void;updateProfileField: (service: ServiceName,field: keyof CatalogProfile,value: string,+ profileId?: string,) => void;updateModelField: (service: ServiceName,field: keyof CatalogModel,value: string,+ profileId?: string,+ modelId?: string,) => void;updateModelBoolField: (service: ServiceName,field: keyof CatalogModel,value: boolean,+ profileId?: string,+ modelId?: string,+ ) => void;+ updateContextWindowField: (+ value: string,+ profileId?: string,+ modelId?: string,+ ) => void;+ updateReasoningEffort: (+ value: string,+ profileId?: string,+ modelId?: string,) => void;- updateContextWindowField: (value: string) => void;- updateReasoningEffort: (value: string) => void;// Connections + task modelsconnectionTargets: ConnectionTarget[];@@ -1028,15 +1046,19 @@ export function SettingsProvider({ children }: { children: ReactNode }) {);const removeActiveProfile = useCallback(- (service: ServiceName) => {+ (service: ServiceName, profileId?: string) => {mutateCatalog((next) => {const target = next.services[service];+ const doomed = profileId ?? target.active_profile_id;target.profiles = target.profiles.filter(- (profile) => profile.id !== target.active_profile_id,+ (profile) => profile.id !== doomed,);- target.active_profile_id = target.profiles[0]?.id ?? null;- if (service !== "search") {- target.active_model_id = target.profiles[0]?.models?.[0]?.id ?? null;+ // Deleting a profile that was not in use leaves the selection alone.+ if (target.active_profile_id === doomed) {+ target.active_profile_id = target.profiles[0]?.id ?? null;+ if (service !== "search") {+ target.active_model_id = target.profiles[0]?.models?.[0]?.id ?? null;+ }}});},@@ -1044,14 +1066,15 @@ export function SettingsProvider({ children }: { children: ReactNode }) {);const addModel = useCallback(- (service: ServiceName) => {+ (service: ServiceName, profileId?: string) => {if (service === "search") return;mutateCatalog((next) => {const target = next.services[service];- const profile =- target.profiles.find(- (item) => item.id === target.active_profile_id,- ) ?? null;+ const profile = profileId+ ? (target.profiles.find((item) => item.id === profileId) ?? null)+ : (target.profiles.find(+ (item) => item.id === target.active_profile_id,+ ) ?? null);if (!profile) return;const providerOption = (providers[service] || []).find((p) => p.value === profile.binding,@@ -1077,7 +1100,11 @@ export function SettingsProvider({ children }: { children: ReactNode }) {}: {}),});- target.active_model_id = modelId;+ // A model added to the profile in use becomes the one in use; adding+ // to any other profile must not move what chat resolves.+ if (profile.id === target.active_profile_id) {+ target.active_model_id = modelId;+ }});},[embeddingDefaultDim, language, mutateCatalog, providers],@@ -1284,64 +1311,121 @@ export function SettingsProvider({ children }: { children: ReactNode }) {);const removeActiveModel = useCallback(- (service: ServiceName) => {+ (service: ServiceName, profileId?: string, modelId?: string) => {if (service === "search") return;mutateCatalog((next) => {const target = next.services[service];- const profile =- target.profiles.find(- (item) => item.id === target.active_profile_id,- ) ?? null;+ const profile = profileId+ ? (target.profiles.find((item) => item.id === profileId) ?? null)+ : (target.profiles.find(+ (item) => item.id === target.active_profile_id,+ ) ?? null);if (!profile) return;- profile.models = profile.models.filter(- (item) => item.id !== target.active_model_id,- );- target.active_model_id = profile.models[0]?.id ?? null;+ const doomed = modelId ?? target.active_model_id;+ profile.models = profile.models.filter((item) => item.id !== doomed);+ if (target.active_model_id === doomed) {+ target.active_model_id =+ profile.id === target.active_profile_id+ ? (profile.models[0]?.id ?? null)+ : target.active_model_id;+ }});},[mutateCatalog],);+ /**+ * Which profile/model an edit lands on.+ *+ * Everything here used to write to whatever was *active*, because selecting+ * a profile and putting it into use were the same act. The model pages now+ * let you open a profile without adopting it, so an edit has to name its+ * target — omitting it keeps the old meaning, so no existing caller changes.+ */+ const targetProfile = useCallback(+ (next: Catalog, service: ServiceName, profileId?: string) =>+ profileId+ ? (next.services[service].profiles.find(+ (item) => item.id === profileId,+ ) ?? null)+ : getActiveProfile(next, service),+ [],+ );++ const targetModel = useCallback(+ (+ next: Catalog,+ service: ServiceName,+ profileId?: string,+ modelId?: string,+ ) => {+ if (!profileId && !modelId) return getActiveModel(next, service);+ const profile = targetProfile(next, service, profileId);+ if (!profile) return null;+ return modelId+ ? (profile.models.find((item) => item.id === modelId) ?? null)+ : (profile.models[0] ?? null);+ },+ [targetProfile],+ );+const updateProfileField = useCallback(- (service: ServiceName, field: keyof CatalogProfile, value: string) => {+ (+ service: ServiceName,+ field: keyof CatalogProfile,+ value: string,+ profileId?: string,+ ) => {mutateCatalog((next) => {- const profile = getActiveProfile(next, service);+ const profile = targetProfile(next, service, profileId);if (!profile) return;(profile[field] as string | undefined) = value;});},- [mutateCatalog],+ [mutateCatalog, targetProfile],);const updateModelField = useCallback(- (service: ServiceName, field: keyof CatalogModel, value: string) => {+ (+ service: ServiceName,+ field: keyof CatalogModel,+ value: string,+ profileId?: string,+ modelId?: string,+ ) => {if (service === "search") return;mutateCatalog((next) => {- const model = getActiveModel(next, service);+ const model = targetModel(next, service, profileId, modelId);if (!model) return;(model[field] as string | undefined) = value;});},- [mutateCatalog],+ [mutateCatalog, targetModel],);const updateModelBoolField = useCallback(- (service: ServiceName, field: keyof CatalogModel, value: boolean) => {+ (+ service: ServiceName,+ field: keyof CatalogModel,+ value: boolean,+ profileId?: string,+ modelId?: string,+ ) => {if (service === "search") return;mutateCatalog((next) => {- const model = getActiveModel(next, service);+ const model = targetModel(next, service, profileId, modelId);if (!model) return;(model[field] as boolean | undefined) = value;});},- [mutateCatalog],+ [mutateCatalog, targetModel],);const updateContextWindowField = useCallback(- (value: string) => {+ (value: string, profileId?: string, modelId?: string) => {const normalized = value.replace(/[^\d]/g, "");mutateCatalog((next) => {- const model = getActiveModel(next, "llm");+ const model = targetModel(next, "llm", profileId, modelId);if (!model) return;if (normalized) {model.context_window = normalized;@@ -1354,18 +1438,18 @@ export function SettingsProvider({ children }: { children: ReactNode }) {}});},- [mutateCatalog],+ [mutateCatalog, targetModel],);const updateReasoningEffort = useCallback(- (value: string) => {+ (value: string, profileId?: string, modelId?: string) => {mutateCatalog((next) => {- const model = getActiveModel(next, "llm");+ const model = targetModel(next, "llm", profileId, modelId);if (!model) return;setModelReasoningEffort(model, value);});},- [mutateCatalog],+ [mutateCatalog, targetModel],);const applyDetectedContextWindow = useCallback(() => {diff --git a/web/components/settings/SettingsToolbar.tsx b/web/components/settings/SettingsToolbar.tsxindex cea040ac1..ad0af7dcf 100644--- a/web/components/settings/SettingsToolbar.tsx+++ b/web/components/settings/SettingsToolbar.tsx@@ -83,7 +83,7 @@ export function SettingsToolbar() {className="inline-flex items-center gap-1.5 rounded-lg border border-[var(--border)]/50 px-3 py-1.5 text-[12px] font-medium text-[var(--muted-foreground)] transition-colors hover:border-[var(--border)] hover:text-[var(--foreground)]"><Rocket className="h-3 w-3" />- {t("Tour")}+ <span className="max-sm:hidden">{t("Tour")}</span></button>{canApply && (<button@@ -93,7 +93,7 @@ export function SettingsToolbar() {className="inline-flex items-center gap-1.5 rounded-lg border border-[var(--border)]/50 px-3 py-1.5 text-[12px] font-medium text-[var(--muted-foreground)] transition-colors hover:border-[var(--border)] hover:text-[var(--foreground)] disabled:opacity-40"><Undo2 className="h-3 w-3" />- {t("Discard")}+ <span className="max-sm:hidden">{t("Discard")}</span></button>)}<button@@ -107,7 +107,7 @@ export function SettingsToolbar() {) : (<Save className="h-3 w-3" />)}- {t("Save draft")}+ <span className="max-sm:hidden">{t("Save draft")}</span></button><buttondata-tour="tour-actions"@@ -121,7 +121,7 @@ export function SettingsToolbar() {) : (<Wand2 className="h-3 w-3" />)}- {t("Apply")}+ <span className="max-sm:hidden">{t("Apply")}</span></button></div></div>diff --git a/web/locales/en/app.json b/web/locales/en/app.jsonindex 2d0c716a6..0aef07cac 100644--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@ -3631,5 +3631,15 @@"Set up with DeepTutor": "Set up with DeepTutor","Delete this profile and every model under it?": "Delete this profile and every model under it?","Model services": "Model services",- "Test passed": "Test passed"+ "Test passed": "Test passed",+ "Providers": "Providers",+ "Add provider": "Add provider",+ "Add model": "Add model",+ "All providers": "All providers",+ "Edit model": "Edit model",+ "Provider default endpoint": "Provider default endpoint",+ "{{n}} ctx": "{{n}} ctx",+ "{{n}} dim": "{{n}} dim",+ "No model id yet": "No model id yet",+ "Set as active": "Set as active"}diff --git a/web/locales/zh/app.json b/web/locales/zh/app.jsonindex 749f8700c..7f992887f 100644--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@ -3631,5 +3631,15 @@"Set up with DeepTutor": "让 DeepTutor 帮我配置","Delete this profile and every model under it?": "删除这个配置,以及它下面的所有模型?","Model services": "模型服务",- "Test passed": "测试通过"+ "Test passed": "测试通过",+ "Providers": "供应商",+ "Add provider": "添加供应商",+ "Add model": "添加模型",+ "All providers": "全部供应商",+ "Edit model": "编辑模型",+ "Provider default endpoint": "供应商默认地址",+ "{{n}} ctx": "{{n}} 上下文",+ "{{n}} dim": "{{n}} 维",+ "No model id yet": "还没填模型 ID",+ "Set as active": "设为使用中"}