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:
chengyongru authored and GitHub committed 2026-10-22 15:49:27 +08:00
1 parent 872a83340d
commit 084b6bb394
181 files changed
+3740 -807

No files matched your search

+1 -1
View File
@@ -1211,7 +1211,7 @@ export async function fetchProviderModels(
export async function runMcpPresetAction(
transport: WebUIMutationTransport,
action: "enable" | "disable" | "remove" | "test" | "reconnect",
action: "enable" | "disable" | "remove" | "test" | "reconnect" | "proxy",
name: string,
values: Record<string, string> = {},
): Promise<McpPresetsPayload> {
+63
View File
@@ -0,0 +1,63 @@
const environmentReference = /\$\{[A-Za-z_][A-Za-z0-9_]*\}/;
function decodeCredential(value: string): string {
try {
return decodeURIComponent(value);
} catch {
return value;
}
}
function encodeCredential(value: string): string {
return value.split(/(\$\{[A-Za-z_][A-Za-z0-9_]*\})/).map((part) =>
environmentReference.test(part) ? part : encodeURIComponent(part),
).join("");
}
export function splitProxyUrl(value: string) {
const schemeEnd = value.indexOf("://");
const start = schemeEnd < 0 ? 0 : schemeEnd + 3;
const authorityEnd = value.slice(start).search(/[/?#]/);
const end = authorityEnd < 0 ? value.length : start + authorityEnd;
const at = value.lastIndexOf("@", end - 1);
const userinfo = at >= start ? value.slice(start, at) : null;
const colon = userinfo?.indexOf(":") ?? -1;
const rawUsername = userinfo === null ? "" : colon < 0 ? userinfo : userinfo.slice(0, colon);
const rawPassword = userinfo === null || colon < 0 ? "" : userinfo.slice(colon + 1);
return {
address: userinfo === null ? value : value.slice(0, start) + value.slice(at + 1),
username: decodeCredential(rawUsername),
password: decodeCredential(rawPassword),
rawUsername,
rawPassword,
userinfo,
hasColon: colon >= 0,
};
}
function insertUserinfo(address: string, userinfo: string | null): string {
if (userinfo === null) return address;
const schemeEnd = address.indexOf("://");
const start = schemeEnd < 0 ? 0 : schemeEnd + 3;
return address.slice(0, start) + userinfo + "@" + address.slice(start);
}
export function changeProxyAddress(value: string, address: string): string {
if (!address.trim() || isProxyUrlReference(address)) return address;
const pasted = splitProxyUrl(address);
if (pasted.userinfo !== null) return address;
return insertUserinfo(address, splitProxyUrl(value).userinfo);
}
export function changeProxyAuthentication(value: string, username: string, password: string): string {
const current = splitProxyUrl(value);
if (!username && !password) return current.address;
const user = username === current.username ? current.rawUsername : encodeCredential(username);
const pass = password === current.password ? current.rawPassword : encodeCredential(password);
const separator = current.hasColon || password ? ":" : "";
return insertUserinfo(current.address, user + separator + pass);
}
export function isProxyUrlReference(address: string): boolean {
return /^\$\{[A-Za-z_][A-Za-z0-9_]*\}$/.test(address.trim());
}
+7 -5
View File
@@ -748,12 +748,12 @@ export interface SettingsPayload {
oauth_account?: string | null;
oauth_expires_at?: number | null;
oauth_login_supported?: boolean;
proxy?: string | null;
use_proxy?: boolean;
advanced_fields?: Array<
| "extra_headers"
| "extra_body"
| "extra_query"
| "proxy"
| "use_proxy"
| "thinking_style"
| "region"
| "profile"
@@ -779,7 +779,7 @@ export interface SettingsPayload {
};
web: {
enable: boolean;
proxy?: string | null;
use_proxy?: boolean;
user_agent?: string | null;
search: {
max_results: number;
@@ -1242,6 +1242,7 @@ export interface McpPresetInfo {
docs_url: string;
transport: "stdio" | "streamableHttp" | "sse" | "oauth" | string;
auth?: "oauth" | null;
use_proxy?: boolean;
requires: string;
note: string;
install_supported: boolean;
@@ -1290,6 +1291,7 @@ export interface McpOAuthFlowPayload {
export interface McpPresetsPayload {
presets: McpPresetInfo[];
proxy_configured?: boolean;
installed_count: number;
requires_restart?: boolean;
hot_reload?: {
@@ -1376,7 +1378,7 @@ export interface ProviderSettingsUpdate {
apiKey?: string;
apiBase?: string;
api?: ModelAPIConfig | null;
proxy?: string;
use_proxy?: boolean;
extraHeaders?: string;
extraBody?: string;
extraQuery?: string;
@@ -1390,7 +1392,7 @@ export interface ProviderCreationUpdate {
apiKey?: string;
apiBase: string;
api?: ModelAPIConfig | null;
proxy?: string;
use_proxy?: boolean;
extraHeaders?: string;
extraBody?: string;
extraQuery?: string;