feat(network): centralize proxy settings and add MCP routing (NAN-315) (#6372)
* feat(network): share proxy settings across features and MCP (NAN-315) * fix(network): address shared proxy review regressions * test(network): align rebased OAuth fixtures with runtime admission * fix(webui): configure shared proxy without leaving connection drafts * feat(webui): add optional shared proxy authentication editor * fix(webui): align proxy save tests and loading skeleton
This commit is contained in:
1 parent
872a83340d
commit
084b6bb394
181 files changed
+3740
-807
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ToggleButton } from "@/components/ui/toggle-button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function ProxySettingsControl({ checked, disabled, onChange, onConfigure, className }: {
|
||||
checked: boolean;
|
||||
disabled?: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
onConfigure?: () => void;
|
||||
className?: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div data-proxy-control className={cn("flex items-center justify-between gap-4", className)}>
|
||||
<SettingsHint description={t("settings.network.useProxyHelp")}>
|
||||
<span className="block text-[13px] font-medium leading-5 text-foreground">{t("settings.network.useProxy")}</span>
|
||||
</SettingsHint>
|
||||
{onConfigure ? (
|
||||
<Button type="button" variant="outline" size="sm" onClick={onConfigure}
|
||||
className="h-7 shrink-0 rounded-full px-3 text-[13px] font-medium leading-5">
|
||||
{t("settings.network.configureProxy")}
|
||||
</Button>
|
||||
) : (
|
||||
<ToggleButton checked={checked} disabled={disabled} onChange={onChange} label={t("settings.network.useProxy")} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -39,9 +39,23 @@ function Group({ controls }: { controls: Control[] }) {
|
||||
return <section><Title /><SettingsGroup>{controls.map((control, index) => <Row key={index} control={control} />)}</SettingsGroup></section>;
|
||||
}
|
||||
|
||||
function ProxyGroup() {
|
||||
return <section><Title /><SettingsGroup>
|
||||
<div className="px-4 py-4 sm:px-5">
|
||||
<div data-shared-proxy-skeleton className="w-full space-y-3">
|
||||
<div data-proxy-address-skeleton className={cn(block, "h-10 w-full rounded-control")} />
|
||||
<div className="flex h-7 items-center justify-between gap-3 py-1">
|
||||
<div className={cn(block, "h-3 w-40")} /><div className={cn(block, "h-3.5 w-3.5 shrink-0")} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</SettingsGroup></section>;
|
||||
}
|
||||
|
||||
function RuntimeGroups({ page }: { page: RuntimeConfigPage }) {
|
||||
return <>{RUNTIME_CONFIG_GROUPS.filter((group) => group.page === page).map((group) => group.id === "chat"
|
||||
? <Group key={group.id} controls={["switch", "segments"]} />
|
||||
: group.id === "proxy" ? <ProxyGroup key={group.id} />
|
||||
: <Group key={group.id} controls={RUNTIME_CONFIG_FIELDS.filter((field) => field.group === group.id && (!field.when || field.when.value === true)).flatMap<Control>((field) =>
|
||||
field.kind === "idle-compaction" ? ["switch", "idle-timeout"] : [
|
||||
field.kind === "boolean" || field.kind === "toggle" ? "switch" : field.kind === "list" ? "edit" : field.kind === "duration" ? "duration" : "input",
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { useState, type ComponentProps, type Ref } from "react";
|
||||
import { ChevronDown } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { changeProxyAddress, changeProxyAuthentication, isProxyUrlReference, splitProxyUrl } from "@/lib/proxy-url";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type AddressProps = Pick<ComponentProps<typeof Input>, "id" | "aria-describedby" | "aria-invalid">;
|
||||
|
||||
export function SharedProxyEditor({ value, onChange, disabled, inputRef, addressProps, stackCredentials = false }: {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
disabled?: boolean;
|
||||
inputRef?: Ref<HTMLInputElement>;
|
||||
addressProps?: AddressProps;
|
||||
stackCredentials?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const parts = splitProxyUrl(value);
|
||||
const [expanded, setExpanded] = useState<boolean | null>(null);
|
||||
const open = expanded ?? parts.userinfo !== null;
|
||||
const reference = isProxyUrlReference(parts.address);
|
||||
const credentialsDisabled = disabled || !parts.address.trim() || reference;
|
||||
return (
|
||||
<div data-shared-proxy-editor className="w-full space-y-3">
|
||||
<Input {...addressProps} ref={inputRef} aria-label={t("settings.runtimeConfig.fields.network_proxy.label")}
|
||||
type="text" value={parts.address} disabled={disabled} autoComplete="off" spellCheck={false}
|
||||
placeholder="http://127.0.0.1:7890" className="h-10 rounded-control text-[13px]"
|
||||
onChange={(event) => onChange(changeProxyAddress(value, event.target.value))} />
|
||||
<button type="button" aria-expanded={open} onClick={() => setExpanded(!open)}
|
||||
className="flex w-full items-center justify-between gap-3 rounded-sm py-1 text-[13px] font-medium leading-5 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
{t("settings.network.authentication")}
|
||||
<ChevronDown aria-hidden className={cn("h-3.5 w-3.5 shrink-0 transition-transform motion-reduce:transition-none", open && "rotate-180")} />
|
||||
</button>
|
||||
{open ? reference ? (
|
||||
<p className="px-1 text-[12px] leading-5 text-muted-foreground">{t("settings.network.proxyReferenceAuth")}</p>
|
||||
) : (
|
||||
<div className={cn("grid gap-4", !stackCredentials && "sm:grid-cols-2")}>
|
||||
<label className="block space-y-1">
|
||||
<span className="px-1 text-[13px] leading-5 text-muted-foreground">{t("settings.network.username")}</span>
|
||||
<Input type="text" value={parts.username} disabled={credentialsDisabled} autoComplete="off" spellCheck={false}
|
||||
className="h-10 rounded-control text-[13px]"
|
||||
onChange={(event) => { setExpanded(true); onChange(changeProxyAuthentication(value, event.target.value, parts.password)); }} />
|
||||
</label>
|
||||
<label className="block space-y-1">
|
||||
<span className="px-1 text-[13px] leading-5 text-muted-foreground">{t("settings.network.password")}</span>
|
||||
<Input type="password" value={parts.password} disabled={credentialsDisabled} autoComplete="new-password"
|
||||
className="h-10 rounded-control text-[13px]"
|
||||
onChange={(event) => { setExpanded(true); onChange(changeProxyAuthentication(value, parts.username, event.target.value)); }} />
|
||||
</label>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { SharedProxyEditor } from "@/components/settings/shared/SharedProxyEditor";
|
||||
|
||||
export function SharedProxySetupDialog({ onClose, onSave, busy }: {
|
||||
busy: boolean;
|
||||
onClose: () => void;
|
||||
onSave: (address: string) => Promise<void>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [address, setAddress] = useState("");
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const input = useRef<HTMLInputElement>(null);
|
||||
const origin = useRef(document.activeElement?.closest("[data-proxy-control]") ?? null);
|
||||
const title = t("settings.runtimeConfig.fields.network_proxy.label");
|
||||
useEffect(() => { if (error && !saving) input.current?.focus(); }, [error, saving]);
|
||||
const save = async () => {
|
||||
if (saving || busy || !address.trim()) return;
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await onSave(address);
|
||||
onClose();
|
||||
} catch (cause) {
|
||||
setError(cause instanceof Error ? cause.message : String(cause));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Dialog open onOpenChange={(open) => { if (!open && !saving) onClose(); }}>
|
||||
<DialogContent className="max-w-sm" showCloseButton={!saving}
|
||||
onOpenAutoFocus={(event) => { event.preventDefault(); input.current?.focus(); }}
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
const row = origin.current;
|
||||
const target = row?.querySelector<HTMLElement>('[role="switch"]') ?? row?.querySelector<HTMLElement>("button:last-child");
|
||||
target?.focus();
|
||||
}}
|
||||
onEscapeKeyDown={(event) => { if (saving) event.preventDefault(); }}
|
||||
onPointerDownOutside={(event) => { if (saving) event.preventDefault(); }}>
|
||||
<form className="space-y-4" onSubmit={(event) => { event.preventDefault(); void save(); }}>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="pr-6 text-base">
|
||||
<SettingsHint description={t("settings.runtimeConfig.fields.network_proxy.help")}>{title}</SettingsHint>
|
||||
</DialogTitle>
|
||||
<DialogDescription>{t("settings.network.sharedProxyScope")}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2">
|
||||
<SharedProxyEditor value={address} inputRef={input} disabled={saving} stackCredentials
|
||||
addressProps={{ "aria-invalid": Boolean(error), "aria-describedby": error ? "shared-proxy-setup-error" : undefined }}
|
||||
onChange={(next) => { setAddress(next); setError(""); }} />
|
||||
{error ? <p id="shared-proxy-setup-error" role="alert" className="break-words text-[13px] text-destructive">{error}</p> : null}
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" disabled={saving} onClick={onClose}>{t("settings.actions.cancel")}</Button>
|
||||
<Button type="submit" disabled={saving || busy || !address.trim()}>{saving ? t("settings.actions.saving") : t("settings.actions.save")}</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user