Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

feat(settings): open a connection's services on their own profile

Bingxi Zhao (Frank)b356d4915456
diff --git a/web/components/settings/ConnectionsEditor.tsx b/web/components/settings/ConnectionsEditor.tsx
index 2e604943c..8f5dd897d 100644
--- a/web/components/settings/ConnectionsEditor.tsx
+++ b/web/components/settings/ConnectionsEditor.tsx
@@ -60,6 +60,14 @@ const SERVICE_HREF: Record<ServiceName, string> = {
videogen: "/settings/video",
};
+type ServiceLink = { service: ServiceName; profileId: string };
+
+/** Where a connection's service chip points: that service's page, opened on
+ * the profile this connection feeds. */
+function serviceHref(link: ServiceLink): string {
+ return `${SERVICE_HREF[link.service]}?profile=${encodeURIComponent(link.profileId)}`;
+}
+
function maskedKey(value: string): string {
const key = (value || "").trim();
if (!key) return "";
@@ -92,14 +100,19 @@ export function ConnectionsEditor() {
const connections = draft.connections ?? [];
- // Which profiles each connection currently feeds, by service.
+ // Which profiles each connection currently feeds. The profile id rides
+ // along so a service link can land on that exact profile — a service with
+ // several providers configured would otherwise open on whichever one
+ // happens to be selected, which is not where the click was aimed.
const linkage = useMemo(() => {
- const map = new Map<string, ServiceName[]>();
+ const map = new Map<string, ServiceLink[]>();
for (const service of CONNECTABLE_SERVICES) {
for (const profile of draft.services[service].profiles) {
if (!profile.connection_id) continue;
const list = map.get(profile.connection_id) ?? [];
- if (!list.includes(service)) list.push(service);
+ if (!list.some((item) => item.service === service)) {
+ list.push({ service, profileId: profile.id });
+ }
map.set(profile.connection_id, list);
}
}
@@ -285,7 +298,7 @@ function ConnectionRow({
}: {
connection: CatalogConnection;
target: ConnectionTarget | null;
- linked: ServiceName[];
+ linked: ServiceLink[];
first: boolean;
editing: boolean;
confirmingDelete: boolean;
@@ -300,7 +313,9 @@ function ConnectionRow({
const [showKey, setShowKey] = useState(false);
const available = CONNECTABLE_SERVICES.filter(
- (service) => target?.services[service] && !linked.includes(service),
+ (service) =>
+ target?.services[service] &&
+ !linked.some((item) => item.service === service),
);
return (
@@ -320,9 +335,22 @@ function ConnectionRow({
{maskedKey(connection.api_key) || t("No key")}
</span>
</div>
- <div className="mt-1 text-[11px] leading-relaxed text-[var(--muted-foreground)]">
+ {/* Each service it supplies is a way in, not just a label: the link
+ opens that service on this connection's own profile. */}
+ <div className="mt-1 flex flex-wrap items-center text-[11px] leading-relaxed text-[var(--muted-foreground)]">
{linked.length > 0
- ? linked.map(label).join(" · ")
+ ? linked.map((link, index) => (
+ <span key={link.service} className="inline-flex items-center">
+ {index > 0 && <span className="px-1.5 opacity-50">·</span>}
+ <Link
+ href={serviceHref(link)}
+ className="inline-flex items-center gap-0.5 underline-offset-2 transition-colors hover:text-[var(--foreground)] hover:underline"
+ >
+ {label(link.service)}
+ <ArrowUpRight className="h-2.5 w-2.5" />
+ </Link>
+ </span>
+ ))
: t("Not supplying any service yet")}
</div>
{available.length > 0 && (
@@ -446,20 +474,6 @@ function ConnectionRow({
)}
</p>
</div>
- {linked.length > 0 && (
- <div className="flex flex-wrap gap-x-3 gap-y-1 sm:col-span-2">
- {linked.map((service) => (
- <Link
- key={service}
- href={SERVICE_HREF[service]}
- className="inline-flex items-center gap-1 text-[11px] text-[var(--muted-foreground)] transition-colors hover:text-[var(--foreground)]"
- >
- {label(service)}
- <ArrowUpRight className="h-3 w-3" />
- </Link>
- ))}
- </div>
- )}
</div>
)}
</div>
diff --git a/web/components/settings/ServiceConfigEditor.tsx b/web/components/settings/ServiceConfigEditor.tsx
index 6d14c8a10..f92701065 100644
--- a/web/components/settings/ServiceConfigEditor.tsx
+++ b/web/components/settings/ServiceConfigEditor.tsx
@@ -1,9 +1,10 @@
"use client";
-import { useState } from "react";
+import { useEffect, useRef, useState } from "react";
import Link from "next/link";
import {
ArrowUpRight,
+ ArrowLeft,
CheckCircle2,
ChevronDown,
Eye,
@@ -109,6 +110,56 @@ export function ServiceConfigEditor({ service }: { service: ServiceName }) {
activeProfile,
);
+ // Arriving from Settings > Connections with ?profile=<id>: open on the
+ // profile that link was aimed at instead of whichever one happens to be
+ // selected. Selecting a profile in this editor is also what puts it in use,
+ // so the switch is announced with a one-click way back rather than done
+ // quietly — the click asked to see a provider, not to adopt it.
+ //
+ // 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.
+ 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");
+ if (!requested) {
+ 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;
+ deepLinkHandled.current = true;
+ // Drop the query so a refresh does not re-apply a switch already undone.
+ 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]);
+
+ 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 [diagnosticsOpen, setDiagnosticsOpen] = useState(false);
const [editingModelId, setEditingModelId] = useState<string | null>(null);
@@ -323,6 +374,34 @@ 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-[200px_minmax(0,1fr)] items-start gap-5">
{/* ── Profile list (sticky so it stays put while the editor scrolls) ── */}
diff --git a/web/components/settings/SettingsContext.tsx b/web/components/settings/SettingsContext.tsx
index e152dab49..b807c7d23 100644
--- a/web/components/settings/SettingsContext.tsx
+++ b/web/components/settings/SettingsContext.tsx
@@ -781,8 +781,18 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
// settings sub-pages share this state via the layout-level provider.
// Code-block switch hydration lives in AppShellContext (the single source),
// so no separate post-mount re-read is needed here.
+ //
+ // Guarded because `loadSettings` closes over `t`, whose identity changes
+ // once i18n resolves: without this the load ran a second time a moment
+ // after mount and re-cloned `draft` from the server, silently discarding
+ // anything edited in between. `reloadSettings` is the deliberate way to
+ // re-read.
+ const loadedOnce = useRef(false);
useEffect(() => {
- loadSettings();
+ if (!loadedOnce.current) {
+ loadedOnce.current = true;
+ loadSettings();
+ }
return () => {
if (eventSourceRef.current) eventSourceRef.current.close();
};
diff --git a/web/lib/settings-nav.ts b/web/lib/settings-nav.ts
index f9bf46b4c..faab8eaa3 100644
--- a/web/lib/settings-nav.ts
+++ b/web/lib/settings-nav.ts
@@ -101,6 +101,17 @@ const MODEL_CHILDREN: SettingsLeaf[] = [
tile: "bg-violet-500/10 text-violet-600 dark:text-violet-400",
service: "llm",
},
+ {
+ key: "task-models",
+ href: "/settings/task-models",
+ label: { zh: "任务模型", en: "Task models" },
+ blurb: {
+ zh: "会话标题与起始建议使用的模型。",
+ en: "The model behind conversation titles and starting points.",
+ },
+ icon: ListChecks,
+ tile: "bg-cyan-500/10 text-cyan-600 dark:text-cyan-400",
+ },
{
key: "embedding",
href: "/settings/embedding",
@@ -170,17 +181,6 @@ const MODEL_CHILDREN: SettingsLeaf[] = [
tile: "bg-indigo-500/10 text-indigo-600 dark:text-indigo-400",
service: "videogen",
},
- {
- key: "task-models",
- href: "/settings/task-models",
- label: { zh: "任务模型", en: "Task models" },
- blurb: {
- zh: "会话标题与起始建议使用的模型。",
- en: "The model behind conversation titles and starting points.",
- },
- icon: ListChecks,
- tile: "bg-cyan-500/10 text-cyan-600 dark:text-cyan-400",
- },
];
const CHAT_CHILDREN: SettingsLeaf[] = [
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index f49a10602..349534498 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -3602,5 +3602,7 @@
"Duration / Resolution": "Duration / Resolution",
"seconds": "seconds",
"Configured {{count}} services and made them active.": "Configured {{count}} services and made them active.",
- "Configured {{count}} services — {{kept}} kept your existing choice.": "Configured {{count}} services — {{kept}} kept your existing choice."
+ "Configured {{count}} services — {{kept}} kept your existing choice.": "Configured {{count}} services — {{kept}} kept your existing choice.",
+ "Opened from Connections. Applying will also make this the {{service}} profile in use.": "Opened from Connections. Applying will also make this the {{service}} profile in use.",
+ "Back to {{name}}": "Back to {{name}}"
}
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index d5b208746..50cd50117 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -3602,5 +3602,7 @@
"Duration / Resolution": "时长 / 分辨率",
"seconds": "秒",
"Configured {{count}} services and made them active.": "已配置 {{count}} 个服务并设为当前使用。",
- "Configured {{count}} services — {{kept}} kept your existing choice.": "已配置 {{count}} 个服务;{{kept}} 保留了你原有的选择。"
+ "Configured {{count}} services — {{kept}} kept your existing choice.": "已配置 {{count}} 个服务;{{kept}} 保留了你原有的选择。",
+ "Opened from Connections. Applying will also make this the {{service}} profile in use.": "从「连接」跳转而来。应用后,{{service}} 将改用这个配置。",
+ "Back to {{name}}": "改回 {{name}}"
}