fix: show only provider-relevant fields in Search settings

This commit is contained in:
Ilia Avdeev
2026-06-14 13:54:09 +02:00
parent 47f0003d5e
commit bd32753a9f
4 changed files with 144 additions and 50 deletions

View File

@@ -25,6 +25,7 @@ import {
useSettings,
} from "./SettingsContext";
import { DimensionField } from "./DimensionField";
import { searchProviderFields } from "./search-providers";
import {
activeProfileDetail,
deprecatedSearchProviders,
@@ -749,6 +750,15 @@ function ProfileFields({
const providerValue =
service === "search" ? profile.provider || "" : profile.binding || "";
// Only the search service hides fields by provider. LLM/embedding always
// expose Base URL and API Key, so default both to shown for them.
const fields =
service === "search"
? searchProviderFields(profile.provider)
: { apiKey: true, baseUrl: true, baseUrlRequired: false };
const searxngMissingBaseUrl =
fields.baseUrlRequired && !String(profile.base_url || "").trim();
return (
<div className="grid gap-4 sm:grid-cols-2">
<div className="sm:col-span-2">
@@ -822,61 +832,72 @@ function ProfileFields({
</p>
)}
</div>
<div className="sm:col-span-2">
<div className="mb-1.5 text-[12px] text-[var(--muted-foreground)]">
{service === "embedding" ? t("Endpoint URL") : t("Base URL")}
</div>
<input
className={inputClass}
value={profile.base_url}
onChange={(e) =>
updateProfileField(service, "base_url", e.target.value)
}
placeholder={
service === "embedding"
? "https://api.openai.com/v1/embeddings"
: "https://api.openai.com/v1"
}
/>
{service === "embedding" && (
<p className="mt-1.5 text-[11px] text-[var(--muted-foreground)]">
{t(
"Embedding requests are sent to this URL exactly; DeepTutor does not append /embeddings or /api/embed at request time.",
)}
</p>
)}
</div>
<div className="sm:col-span-2">
<div className="mb-1.5 text-[12px] text-[var(--muted-foreground)]">
{t("API Key")}
</div>
<div className="relative">
{fields.baseUrl && (
<div className="sm:col-span-2">
<div className="mb-1.5 text-[12px] text-[var(--muted-foreground)]">
{service === "embedding" ? t("Endpoint URL") : t("Base URL")}
</div>
<input
type={showApiKey ? "text" : "password"}
autoComplete="new-password"
spellCheck={false}
className={`${inputClass} pr-10 font-mono`}
value={profile.api_key}
className={inputClass}
value={profile.base_url}
onChange={(e) =>
updateProfileField(service, "api_key", e.target.value)
updateProfileField(service, "base_url", e.target.value)
}
placeholder={
service === "embedding"
? "https://api.openai.com/v1/embeddings"
: service === "search"
? "http://localhost:8888"
: "https://api.openai.com/v1"
}
placeholder="sk-..."
/>
<button
type="button"
onClick={() => setShowApiKey((prev) => !prev)}
className="absolute right-1 top-1/2 -translate-y-1/2 rounded-md p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--muted)] hover:text-[var(--foreground)]"
aria-label={showApiKey ? t("Hide API key") : t("Show API key")}
title={showApiKey ? t("Hide API key") : t("Show API key")}
>
{showApiKey ? (
<EyeOff className="h-4 w-4" />
) : (
<Eye className="h-4 w-4" />
)}
</button>
{service === "embedding" && (
<p className="mt-1.5 text-[11px] text-[var(--muted-foreground)]">
{t(
"Embedding requests are sent to this URL exactly; DeepTutor does not append /embeddings or /api/embed at request time.",
)}
</p>
)}
{searxngMissingBaseUrl && (
<p className="mt-1.5 text-[11px] text-amber-600 dark:text-amber-400">
{t("Required — without it, search falls back to DuckDuckGo.")}
</p>
)}
</div>
</div>
)}
{fields.apiKey && (
<div className="sm:col-span-2">
<div className="mb-1.5 text-[12px] text-[var(--muted-foreground)]">
{t("API Key")}
</div>
<div className="relative">
<input
type={showApiKey ? "text" : "password"}
autoComplete="new-password"
spellCheck={false}
className={`${inputClass} pr-10 font-mono`}
value={profile.api_key}
onChange={(e) =>
updateProfileField(service, "api_key", e.target.value)
}
placeholder="sk-..."
/>
<button
type="button"
onClick={() => setShowApiKey((prev) => !prev)}
className="absolute right-1 top-1/2 -translate-y-1/2 rounded-md p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--muted)] hover:text-[var(--foreground)]"
aria-label={showApiKey ? t("Hide API key") : t("Show API key")}
title={showApiKey ? t("Hide API key") : t("Show API key")}
>
{showApiKey ? (
<EyeOff className="h-4 w-4" />
) : (
<Eye className="h-4 w-4" />
)}
</button>
</div>
</div>
)}
<div className="sm:col-span-2 rounded-xl border border-[var(--border)]/60 bg-[var(--muted)]/20">
<button
type="button"

View File

@@ -0,0 +1,71 @@
// Which connection fields a web-search provider actually uses.
//
// This mirrors the backend resolver in
// `deeptutor/services/config/provider_runtime.py`
// (`resolve_search_runtime_config`): brave/tavily/jina/perplexity/serper
// authenticate with an API key, searxng is configured by its instance Base
// URL, and duckduckgo/none need no connection details at all. Every search
// provider ships an empty `base_url` from the settings API
// (`_provider_choices` in `deeptutor/api/routers/settings.py`), so the Base
// URL only ever carries a value for searxng.
//
// Keep this table in sync with SUPPORTED_SEARCH_PROVIDERS on the backend.
export type SearchProviderFieldSpec = {
/** Provider authenticates with an API key. */
apiKey: boolean;
/** Provider is configured with a Base URL. */
baseUrl: boolean;
/** The Base URL is mandatory — the provider cannot work without it. */
baseUrlRequired: boolean;
};
const KEY_ONLY: SearchProviderFieldSpec = {
apiKey: true,
baseUrl: false,
baseUrlRequired: false,
};
const NO_CREDENTIALS: SearchProviderFieldSpec = {
apiKey: false,
baseUrl: false,
baseUrlRequired: false,
};
const BASE_URL_ONLY: SearchProviderFieldSpec = {
apiKey: false,
baseUrl: true,
baseUrlRequired: true,
};
// Providers we don't model (a custom/unknown value, the deprecated
// exa/baidu/openrouter set, or an empty selection): show every field so we
// never hide a control the provider might actually need.
const UNKNOWN: SearchProviderFieldSpec = {
apiKey: true,
baseUrl: true,
baseUrlRequired: false,
};
const SEARCH_PROVIDER_FIELDS: Record<string, SearchProviderFieldSpec> = {
none: NO_CREDENTIALS,
duckduckgo: NO_CREDENTIALS,
searxng: BASE_URL_ONLY,
brave: KEY_ONLY,
tavily: KEY_ONLY,
jina: KEY_ONLY,
perplexity: KEY_ONLY,
serper: KEY_ONLY,
};
/**
* Resolve which connection fields to show for a search provider. Unknown,
* custom, or empty provider names fall back to showing every field.
*/
export function searchProviderFields(
provider: string | null | undefined,
): SearchProviderFieldSpec {
const key = (provider ?? "").trim().toLowerCase();
if (!key) return UNKNOWN;
return SEARCH_PROVIDER_FIELDS[key] ?? UNKNOWN;
}

View File

@@ -720,6 +720,7 @@
"Select provider...": "Select provider...",
"Perplexity requires API key. It will fail hard without credentials.": "Perplexity requires API key. It will fail hard without credentials.",
"Supported provider.": "Supported provider.",
"Required — without it, search falls back to DuckDuckGo.": "Required — without it, search falls back to DuckDuckGo.",
"Deprecated provider. Switch to brave/tavily/jina/searxng/duckduckgo/perplexity.": "Deprecated provider. Switch to brave/tavily/jina/searxng/duckduckgo/perplexity.",
"Unsupported provider. Use brave/tavily/jina/searxng/duckduckgo/perplexity.": "Unsupported provider. Use brave/tavily/jina/searxng/duckduckgo/perplexity.",
"API Version": "API Version",

View File

@@ -724,6 +724,7 @@
"Select provider...": "选择提供商...",
"Perplexity requires API key. It will fail hard without credentials.": "Perplexity 需要 API 密钥,缺少凭证将无法使用。",
"Supported provider.": "受支持的提供商。",
"Required — without it, search falls back to DuckDuckGo.": "必填——缺少它,搜索将回退到 DuckDuckGo。",
"Deprecated provider. Switch to brave/tavily/jina/searxng/duckduckgo/perplexity.": "已弃用的提供商。请切换到 brave/tavily/jina/searxng/duckduckgo/perplexity。",
"Unsupported provider. Use brave/tavily/jina/searxng/duckduckgo/perplexity.": "不受支持的提供商。请使用 brave/tavily/jina/searxng/duckduckgo/perplexity。",
"API Version": "API 版本",