mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-02 20:01:51 +08:00
refactor(web): reorganize ARTEX settings page into modular category cards
- Split monolithic settings page into focused card modules with shared SettingsSectionCard/SettingRow primitives. - Group settings into 6 categories with URL hash persistence, quick status overview bar, and enhanced cross-category search. - Clean up legacy masonry utility classes and add bilingual i18n labels for new settings groups.
This commit is contained in:
1 parent
d5926d6420
commit
ee5ac6e6dd
11 files changed
+1927
-1148
No files matched your search
@@ -0,0 +1,314 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
|
||||
import { BrainCircuitIcon, FlaskConicalIcon, ShieldAlertIcon } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { localizedError } from "@/i18n/errors";
|
||||
import { useLiveTranslation } from "@/i18n/use-live-translation";
|
||||
import { api } from "@/lib/api";
|
||||
import type { Settings } from "@/lib/types";
|
||||
|
||||
import { SettingRow, SettingsSectionCard } from "./settings-primitives";
|
||||
|
||||
export function ConstraintsCard({
|
||||
loaded,
|
||||
injectPlanner,
|
||||
injectWorker,
|
||||
onSettingsUpdated,
|
||||
}: {
|
||||
loaded: boolean;
|
||||
injectPlanner: boolean;
|
||||
injectWorker: boolean;
|
||||
onSettingsUpdated: (s: Settings) => void;
|
||||
}) {
|
||||
const { t } = useLiveTranslation();
|
||||
const [plannerVal, setPlannerVal] = React.useState(injectPlanner);
|
||||
const [workerVal, setWorkerVal] = React.useState(injectWorker);
|
||||
|
||||
React.useEffect(() => {
|
||||
setPlannerVal(injectPlanner);
|
||||
}, [injectPlanner]);
|
||||
React.useEffect(() => {
|
||||
setWorkerVal(injectWorker);
|
||||
}, [injectWorker]);
|
||||
|
||||
const togglePlanner = (v: boolean) => {
|
||||
setPlannerVal(v);
|
||||
api
|
||||
.setSettings({ constraints_inject_planner: v })
|
||||
.then(onSettingsUpdated)
|
||||
.catch(() => setPlannerVal(!v));
|
||||
};
|
||||
|
||||
const toggleWorker = (v: boolean) => {
|
||||
setWorkerVal(v);
|
||||
api
|
||||
.setSettings({ constraints_inject_worker: v })
|
||||
.then(onSettingsUpdated)
|
||||
.catch(() => setWorkerVal(!v));
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={ShieldAlertIcon}
|
||||
title={t("settings.constraintInjection")}
|
||||
description={
|
||||
<>
|
||||
{t("settings.constraintHelpStart")}
|
||||
<b>{t("settings.constraints")}</b>
|
||||
{t("settings.constraintHelpMiddle")}
|
||||
<br />
|
||||
{t("settings.constraintTargetsStart")}
|
||||
<b>{t("settings.planner")}</b>
|
||||
{t("settings.and")}
|
||||
<b>{t("settings.worker")}</b>
|
||||
{t("settings.constraintTargetsEnd")}
|
||||
</>
|
||||
}
|
||||
contentClassName="divide-y"
|
||||
>
|
||||
<SettingRow
|
||||
htmlFor="inject-planner"
|
||||
title={t("settings.injectPlanner")}
|
||||
badge={
|
||||
<Badge variant={plannerVal ? "outline" : "secondary"} className="font-normal text-[11px]">
|
||||
{plannerVal ? t("settings.status.on") : t("settings.status.off")}
|
||||
</Badge>
|
||||
}
|
||||
control={<Switch id="inject-planner" checked={plannerVal} disabled={!loaded} onCheckedChange={togglePlanner} />}
|
||||
/>
|
||||
<SettingRow
|
||||
htmlFor="inject-worker"
|
||||
title={t("settings.injectWorker")}
|
||||
badge={
|
||||
<Badge variant={workerVal ? "outline" : "secondary"} className="font-normal text-[11px]">
|
||||
{workerVal ? t("settings.status.on") : t("settings.status.off")}
|
||||
</Badge>
|
||||
}
|
||||
control={<Switch id="inject-worker" checked={workerVal} disabled={!loaded} onCheckedChange={toggleWorker} />}
|
||||
/>
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
|
||||
export function IntelligenceCard({
|
||||
loaded,
|
||||
intelligenceEnabled,
|
||||
credentialAgent,
|
||||
credentialBinding,
|
||||
onSettingsUpdated,
|
||||
}: {
|
||||
loaded: boolean;
|
||||
intelligenceEnabled: boolean;
|
||||
credentialAgent: boolean;
|
||||
credentialBinding: boolean;
|
||||
onSettingsUpdated: (s: Settings) => void;
|
||||
}) {
|
||||
const { t } = useLiveTranslation();
|
||||
const [savingIntelligence, setSavingIntelligence] = React.useState(false);
|
||||
const [savingCredentials, setSavingCredentials] = React.useState(false);
|
||||
|
||||
const toggleIntelligence = async (value: boolean) => {
|
||||
setSavingIntelligence(true);
|
||||
try {
|
||||
const updated = await api.setSettings({ task_intelligence_enabled: value });
|
||||
onSettingsUpdated(updated);
|
||||
toast.success(value ? t("settings.autoRecordEnabled") : t("settings.autoRecordDisabled"));
|
||||
} catch (error) {
|
||||
toast.error(t("settings.saveFailedPrefix") + localizedError(error, t));
|
||||
} finally {
|
||||
setSavingIntelligence(false);
|
||||
}
|
||||
};
|
||||
|
||||
const saveCredentialOptions = async (patch: Partial<Settings>) => {
|
||||
setSavingCredentials(true);
|
||||
try {
|
||||
const updated = await api.setSettings(patch);
|
||||
onSettingsUpdated(updated);
|
||||
toast.success(t("settings.credentialsSaved"));
|
||||
} catch (e) {
|
||||
toast.error(t("settings.saveFailedPrefix") + localizedError(e, t));
|
||||
} finally {
|
||||
setSavingCredentials(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={BrainCircuitIcon}
|
||||
title={t("settings.intelligence")}
|
||||
badge={
|
||||
<Badge variant={intelligenceEnabled ? "default" : "secondary"}>
|
||||
{intelligenceEnabled ? t("settings.status.on") : t("settings.status.off")}
|
||||
</Badge>
|
||||
}
|
||||
description={t("settings.intelligenceHelp")}
|
||||
contentClassName="divide-y"
|
||||
>
|
||||
<SettingRow
|
||||
htmlFor="task-intelligence"
|
||||
title={t("settings.autoRecord")}
|
||||
description={t("settings.autoRecordHelp")}
|
||||
control={
|
||||
<Switch
|
||||
id="task-intelligence"
|
||||
checked={intelligenceEnabled}
|
||||
disabled={!loaded || savingIntelligence || savingCredentials}
|
||||
onCheckedChange={(value) => void toggleIntelligence(value)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<SettingRow
|
||||
htmlFor="credential-agent"
|
||||
title={t("settings.credentialAgent")}
|
||||
description={t("settings.credentialAgentHelp")}
|
||||
indented
|
||||
control={
|
||||
<Switch
|
||||
id="credential-agent"
|
||||
checked={credentialAgent}
|
||||
disabled={!loaded || savingCredentials || savingIntelligence || !intelligenceEnabled}
|
||||
onCheckedChange={(value) => void saveCredentialOptions({ credential_agent_enabled: value })}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{credentialAgent ? (
|
||||
<SettingRow
|
||||
htmlFor="credential-traffic"
|
||||
title={t("settings.bindTraffic")}
|
||||
description={t("settings.bindTrafficHelp")}
|
||||
indented
|
||||
control={
|
||||
<Switch
|
||||
id="credential-traffic"
|
||||
checked={credentialBinding}
|
||||
disabled={!loaded || savingCredentials}
|
||||
onCheckedChange={(value) => void saveCredentialOptions({ credential_traffic_binding: value })}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
|
||||
export function AutomationExperimentalCard({
|
||||
loaded,
|
||||
taskAutoTitleEnabled,
|
||||
chatAutoTitleEnabled,
|
||||
noaCompaction,
|
||||
onSettingsUpdated,
|
||||
}: {
|
||||
loaded: boolean;
|
||||
taskAutoTitleEnabled: boolean;
|
||||
chatAutoTitleEnabled: boolean;
|
||||
noaCompaction: boolean;
|
||||
onSettingsUpdated: (s: Settings) => void;
|
||||
}) {
|
||||
const { t } = useLiveTranslation();
|
||||
const [taskTitleVal, setTaskTitleVal] = React.useState(taskAutoTitleEnabled);
|
||||
const [chatTitleVal, setChatTitleVal] = React.useState(chatAutoTitleEnabled);
|
||||
const [noaVal, setNoaVal] = React.useState(noaCompaction);
|
||||
|
||||
React.useEffect(() => {
|
||||
setTaskTitleVal(taskAutoTitleEnabled);
|
||||
}, [taskAutoTitleEnabled]);
|
||||
React.useEffect(() => {
|
||||
setChatTitleVal(chatAutoTitleEnabled);
|
||||
}, [chatAutoTitleEnabled]);
|
||||
React.useEffect(() => {
|
||||
setNoaVal(noaCompaction);
|
||||
}, [noaCompaction]);
|
||||
|
||||
const toggleAutoTitle = (key: "task_auto_title_enabled" | "chat_auto_title_enabled", value: boolean) => {
|
||||
const setter = key === "task_auto_title_enabled" ? setTaskTitleVal : setChatTitleVal;
|
||||
const patch: Partial<Settings> =
|
||||
key === "task_auto_title_enabled" ? { task_auto_title_enabled: value } : { chat_auto_title_enabled: value };
|
||||
setter(value);
|
||||
api
|
||||
.setSettings(patch)
|
||||
.then(onSettingsUpdated)
|
||||
.catch((e) => {
|
||||
setter(!value);
|
||||
toast.error(t("settings.saveFailedPrefix") + localizedError(e, t));
|
||||
});
|
||||
};
|
||||
|
||||
const toggleNoa = (v: boolean) => {
|
||||
setNoaVal(v);
|
||||
api
|
||||
.setSettings({ noa_compaction: v })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(v ? t("settings.noaEnabled") : t("settings.noaDisabled"));
|
||||
})
|
||||
.catch((e) => {
|
||||
setNoaVal(!v);
|
||||
toast.error(t("settings.saveFailed", { message: localizedError(e, t) }));
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={FlaskConicalIcon}
|
||||
title={t("settings.automationTitle")}
|
||||
description={t("settings.automationHelp")}
|
||||
contentClassName="divide-y"
|
||||
>
|
||||
<SettingRow
|
||||
htmlFor="task-auto-title"
|
||||
title={t("settings.taskNames")}
|
||||
description={t("settings.taskNamesHelp")}
|
||||
control={
|
||||
<Switch
|
||||
id="task-auto-title"
|
||||
checked={taskTitleVal}
|
||||
disabled={!loaded}
|
||||
onCheckedChange={(value) => toggleAutoTitle("task_auto_title_enabled", value)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<SettingRow
|
||||
htmlFor="chat-auto-title"
|
||||
title={t("settings.chatTitles")}
|
||||
description={t("settings.chatTitlesHelp")}
|
||||
control={
|
||||
<Switch
|
||||
id="chat-auto-title"
|
||||
checked={chatTitleVal}
|
||||
disabled={!loaded}
|
||||
onCheckedChange={(value) => toggleAutoTitle("chat_auto_title_enabled", value)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<SettingRow
|
||||
htmlFor="noa-compaction"
|
||||
title={t("settings.noa")}
|
||||
badge={
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="border-amber-500/40 font-normal text-[11px] text-amber-600 dark:text-amber-400"
|
||||
>
|
||||
{t("settings.experimentalBadge")}
|
||||
</Badge>
|
||||
}
|
||||
description={
|
||||
<>
|
||||
{t("settings.experimentalHelp")}
|
||||
<br />
|
||||
<b>{t("settings.noa")}</b>
|
||||
{t("settings.noaHelpStart")}
|
||||
<b>{t("settings.noaAgentTypes")}</b>
|
||||
{t("settings.noaHelpEnd")}
|
||||
</>
|
||||
}
|
||||
control={<Switch id="noa-compaction" checked={noaVal} disabled={!loaded} onCheckedChange={toggleNoa} />}
|
||||
/>
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ export function BackupCard() {
|
||||
const last = status?.last_restore;
|
||||
|
||||
return (
|
||||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-base">
|
||||
<DatabaseBackupIcon className="size-4" />
|
||||
|
||||
@@ -60,7 +60,7 @@ export function BasicAuthCard() {
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<ShieldCheckIcon className="size-4" />
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
"use client";
|
||||
|
||||
import { KeyboardIcon } from "lucide-react";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { useLiveTranslation } from "@/i18n/use-live-translation";
|
||||
import { CHAT_SEND_MODE_OPTIONS, type ChatSendMode, setChatSendMode, useChatSendMode } from "@/lib/chat-send-mode";
|
||||
|
||||
import { SettingRow, SettingsSectionCard } from "./settings-primitives";
|
||||
|
||||
export function ChatPreferencesCard() {
|
||||
const { t } = useLiveTranslation();
|
||||
const sendMode = useChatSendMode();
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={KeyboardIcon}
|
||||
title={t("settings.chatSendShortcut")}
|
||||
badge={
|
||||
<Badge variant="outline" className="font-normal text-[11px]">
|
||||
{t("settings.localScopeBadge")}
|
||||
</Badge>
|
||||
}
|
||||
description={
|
||||
<>
|
||||
{t("settings.chatSendShortcutHelp")}
|
||||
<br />
|
||||
{t("settings.preferenceScopeStart")}
|
||||
<b>{t("settings.browserOnly")}</b>
|
||||
{t("settings.preferenceScopeEnd")}
|
||||
</>
|
||||
}
|
||||
>
|
||||
<SettingRow
|
||||
htmlFor="chat-send-mode"
|
||||
title={t("settings.sendMode")}
|
||||
control={
|
||||
<Select value={sendMode} onValueChange={(v) => setChatSendMode(v as ChatSendMode)}>
|
||||
<SelectTrigger id="chat-send-mode" className="w-72">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{CHAT_SEND_MODE_OPTIONS.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
{t(`settings.sendMode.${option.value}`)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
}
|
||||
/>
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
@@ -228,7 +228,7 @@ export function McpServerCard() {
|
||||
const limit = (n: number) => (n > 0 ? String(n) : t("settings.mcpServer.unlimited"));
|
||||
|
||||
return (
|
||||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<PlugZapIcon className="size-4" />
|
||||
|
||||
@@ -0,0 +1,626 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
|
||||
import { CpuIcon, PlusIcon, SearchIcon, TerminalIcon, Trash2Icon } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { localizedError } from "@/i18n/errors";
|
||||
import { useLiveTranslation } from "@/i18n/use-live-translation";
|
||||
import { api } from "@/lib/api";
|
||||
import type { LLMProfile, Settings, WorkerPool } from "@/lib/types";
|
||||
|
||||
import { SettingRow, SettingsSectionCard } from "./settings-primitives";
|
||||
|
||||
export function WorkersCard({
|
||||
loaded,
|
||||
settingsLoaded,
|
||||
initialWorkers,
|
||||
initialWorkerPools,
|
||||
llmProfiles,
|
||||
onSettingsUpdated,
|
||||
}: {
|
||||
loaded: boolean;
|
||||
settingsLoaded: boolean;
|
||||
initialWorkers: string;
|
||||
initialWorkerPools: WorkerPool[];
|
||||
llmProfiles: LLMProfile[];
|
||||
onSettingsUpdated: (s: Settings) => void;
|
||||
}) {
|
||||
const { t } = useLiveTranslation();
|
||||
const [workers, setWorkers] = React.useState(initialWorkers);
|
||||
const [workerPools, setWorkerPools] = React.useState<WorkerPool[]>(initialWorkerPools);
|
||||
const [savingWorkers, setSavingWorkers] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
setWorkers(initialWorkers);
|
||||
}, [initialWorkers]);
|
||||
|
||||
React.useEffect(() => {
|
||||
setWorkerPools(initialWorkerPools);
|
||||
}, [initialWorkerPools]);
|
||||
|
||||
const poolTotal = workerPools.reduce((sum, pool) => sum + (Number(pool.workers) || 0), 0);
|
||||
const displayTotal = workerPools.length > 0 ? poolTotal : Number(workers) || 0;
|
||||
|
||||
const addWorkerPool = () => setWorkerPools((pools) => [...pools, { profile_id: "", workers: 1 }]);
|
||||
|
||||
const saveWorkers = () => {
|
||||
if (!settingsLoaded) {
|
||||
toast.error(t("settings.workerConfigLoadFailed"));
|
||||
return;
|
||||
}
|
||||
const n = Number(workers);
|
||||
if (workerPools.length > 0) {
|
||||
const total = workerPools.reduce((sum, pool) => sum + Number(pool.workers), 0);
|
||||
if (workerPools.some((pool) => !pool.profile_id)) {
|
||||
toast.error(t("settings.choosePoolProfile"));
|
||||
return;
|
||||
}
|
||||
if (workerPools.some((pool) => !Number.isInteger(Number(pool.workers)) || Number(pool.workers) <= 0)) {
|
||||
toast.error(t("settings.positivePoolWorkers"));
|
||||
return;
|
||||
}
|
||||
if (total > 50) {
|
||||
toast.error(t("settings.workerLimit"));
|
||||
return;
|
||||
}
|
||||
const ids = workerPools.map((pool) => pool.profile_id);
|
||||
if (new Set(ids).size !== ids.length) {
|
||||
toast.error(t("settings.duplicatePoolProfile"));
|
||||
return;
|
||||
}
|
||||
setSavingWorkers(true);
|
||||
api
|
||||
.setSettings({
|
||||
workers: total,
|
||||
worker_pools: workerPools.map((pool) => ({ ...pool, workers: Number(pool.workers) })),
|
||||
})
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(t("settings.workerPoolsSaved"));
|
||||
})
|
||||
.catch((e) => toast.error(t("settings.saveFailed", { message: localizedError(e, t) })))
|
||||
.finally(() => setSavingWorkers(false));
|
||||
return;
|
||||
}
|
||||
if (!Number.isInteger(n) || n <= 0) {
|
||||
toast.error(t("settings.positiveConcurrency"));
|
||||
return;
|
||||
}
|
||||
setSavingWorkers(true);
|
||||
api
|
||||
.setSettings({ workers: n, worker_pools: [] })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(t("settings.workersSaved"));
|
||||
})
|
||||
.catch((e) => toast.error(t("settings.saveFailedPrefix") + localizedError(e, t)))
|
||||
.finally(() => setSavingWorkers(false));
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={CpuIcon}
|
||||
title={t("settings.workers")}
|
||||
badge={
|
||||
<Badge variant="secondary" className="font-mono text-xs tabular-nums">
|
||||
{displayTotal}
|
||||
</Badge>
|
||||
}
|
||||
description={
|
||||
<>
|
||||
{t("settings.workersHelpStart")}
|
||||
<b>{t("settings.workersLiveUpdate")}</b>
|
||||
{t("settings.workersDrainHelp")}
|
||||
</>
|
||||
}
|
||||
contentClassName="flex flex-col gap-3.5"
|
||||
>
|
||||
<div className="flex flex-col gap-2.5 rounded-lg border bg-muted/20 p-3">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<Label className="font-medium text-sm">{t("settings.workerPools")}</Label>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={addWorkerPool}
|
||||
disabled={!loaded || !settingsLoaded || savingWorkers}
|
||||
>
|
||||
<PlusIcon className="mr-1 size-3.5" />
|
||||
{t("settings.addPool")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{workerPools.map((pool, index) => {
|
||||
const selected = llmProfiles.find((profile) => profile.id === pool.profile_id);
|
||||
const placeholder =
|
||||
selected?.name ||
|
||||
(pool.profile_id ? t("settings.unavailableProfile", { id: pool.profile_id }) : t("settings.chooseProfile"));
|
||||
return (
|
||||
// biome-ignore lint/suspicious/noArrayIndexKey: pool rows are edited in place and only deleted.
|
||||
<div className="flex items-center gap-2" key={`${pool.profile_id}-${index}`}>
|
||||
<Select
|
||||
value={pool.profile_id || undefined}
|
||||
disabled={!settingsLoaded || savingWorkers}
|
||||
onValueChange={(value) =>
|
||||
setWorkerPools((current) =>
|
||||
current.map((item, itemIndex) => (itemIndex === index ? { ...item, profile_id: value } : item)),
|
||||
)
|
||||
}
|
||||
>
|
||||
<SelectTrigger className="min-w-0 flex-1 bg-background">
|
||||
<SelectValue placeholder={placeholder} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{!selected && pool.profile_id ? (
|
||||
<SelectItem value={pool.profile_id}>
|
||||
{t("settings.profilePrefix")}
|
||||
{pool.profile_id}
|
||||
{t("settings.profileUnavailableSuffix")}
|
||||
</SelectItem>
|
||||
) : null}
|
||||
{llmProfiles
|
||||
.filter((profile) => profile.format !== "jev")
|
||||
.map((profile) => (
|
||||
<SelectItem key={profile.id} value={profile.id}>
|
||||
{profile.name} · {profile.model}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
className="w-24 bg-background font-mono text-sm"
|
||||
value={pool.workers}
|
||||
disabled={!settingsLoaded || savingWorkers}
|
||||
onChange={(event) =>
|
||||
setWorkerPools((current) =>
|
||||
current.map((item, itemIndex) =>
|
||||
itemIndex === index ? { ...item, workers: Number(event.target.value) } : item,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
disabled={!settingsLoaded || savingWorkers}
|
||||
onClick={() => setWorkerPools((current) => current.filter((_, itemIndex) => itemIndex !== index))}
|
||||
aria-label={t("settings.delete")}
|
||||
title={t("settings.delete")}
|
||||
>
|
||||
<Trash2Icon className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
{workerPools.length > 0 ? (
|
||||
<div className="text-muted-foreground text-xs">{t("settings.workerTotal", { count: poolTotal })}</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
className="w-32 font-mono text-sm"
|
||||
placeholder="3"
|
||||
value={workers}
|
||||
disabled={!loaded || !settingsLoaded || savingWorkers || workerPools.length > 0}
|
||||
onChange={(e) => setWorkers(e.target.value)}
|
||||
/>
|
||||
{workerPools.length > 0 ? (
|
||||
<span className="text-muted-foreground text-xs">{t("settings.poolConcurrencyHelp")}</span>
|
||||
) : null}
|
||||
<Button onClick={saveWorkers} disabled={!loaded || !settingsLoaded || savingWorkers} className="ml-auto">
|
||||
{t("settings.save")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{!settingsLoaded && loaded ? (
|
||||
<p className="text-destructive text-xs">{t("settings.workerConfigLockedHelp")}</p>
|
||||
) : null}
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
|
||||
export function PythonInterpreterCard({
|
||||
loaded,
|
||||
initialInterpreter,
|
||||
onSettingsUpdated,
|
||||
}: {
|
||||
loaded: boolean;
|
||||
initialInterpreter: string;
|
||||
onSettingsUpdated: (s: Settings) => void;
|
||||
}) {
|
||||
const { t } = useLiveTranslation();
|
||||
const [pyInterp, setPyInterp] = React.useState(initialInterpreter);
|
||||
const [saving, setSaving] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
setPyInterp(initialInterpreter);
|
||||
}, [initialInterpreter]);
|
||||
|
||||
const savePython = () => {
|
||||
setSaving(true);
|
||||
api
|
||||
.setSettings({ python_interpreter: pyInterp.trim() })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(t("settings.pythonSaved"));
|
||||
})
|
||||
.catch((e) => toast.error(t("settings.saveFailedPrefix") + localizedError(e, t)))
|
||||
.finally(() => setSaving(false));
|
||||
};
|
||||
|
||||
const detectPython = () => {
|
||||
setSaving(true);
|
||||
api
|
||||
.detectPython()
|
||||
.then((r) => setPyInterp(r.python_interpreter))
|
||||
.catch(() => undefined)
|
||||
.finally(() => setSaving(false));
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={TerminalIcon}
|
||||
title={t("settings.python")}
|
||||
description={
|
||||
<>
|
||||
{t("settings.custom")}
|
||||
<b>script</b>
|
||||
{t("settings.pythonHelp")}
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Input
|
||||
className="min-w-[200px] flex-1 font-mono text-sm"
|
||||
placeholder={t("settings.pythonPlaceholder")}
|
||||
value={pyInterp}
|
||||
disabled={!loaded || saving}
|
||||
onChange={(e) => setPyInterp(e.target.value)}
|
||||
/>
|
||||
<Button variant="outline" onClick={detectPython} disabled={!loaded || saving}>
|
||||
{t("settings.detectAgain")}
|
||||
</Button>
|
||||
<Button onClick={savePython} disabled={!loaded || saving}>
|
||||
{t("settings.save")}
|
||||
</Button>
|
||||
</div>
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
|
||||
export function WebSearchCard({
|
||||
loaded,
|
||||
settings,
|
||||
onSettingsUpdated,
|
||||
}: {
|
||||
loaded: boolean;
|
||||
settings: {
|
||||
enabled: boolean;
|
||||
backend: string;
|
||||
braveKeySet: boolean;
|
||||
tavilyKeySet: boolean;
|
||||
deepSeekKeySet: boolean;
|
||||
proxy: string;
|
||||
};
|
||||
onSettingsUpdated: (s: Settings) => void;
|
||||
}) {
|
||||
const { t } = useLiveTranslation();
|
||||
const [webSearch, setWebSearch] = React.useState(settings.enabled);
|
||||
const [backend, setBackend] = React.useState(settings.backend);
|
||||
const [braveKeyInput, setBraveKeyInput] = React.useState("");
|
||||
const [tavilyKeyInput, setTavilyKeyInput] = React.useState("");
|
||||
const [deepSeekKeyInput, setDeepSeekKeyInput] = React.useState("");
|
||||
const [proxyInput, setProxyInput] = React.useState(settings.proxy);
|
||||
const [saving, setSaving] = React.useState(false);
|
||||
const [savingKey, setSavingKey] = React.useState(false);
|
||||
const [savingTavilyKey, setSavingTavilyKey] = React.useState(false);
|
||||
const [savingDeepSeekKey, setSavingDeepSeekKey] = React.useState(false);
|
||||
const [savingProxy, setSavingProxy] = React.useState(false);
|
||||
const [testing, setTesting] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
setWebSearch(settings.enabled);
|
||||
setBackend(settings.backend);
|
||||
setProxyInput(settings.proxy);
|
||||
}, [settings.enabled, settings.backend, settings.proxy]);
|
||||
|
||||
const saveWebSearch = (patch: Partial<Settings>) => {
|
||||
setSaving(true);
|
||||
api
|
||||
.setSettings(patch)
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(t("settings.webSearchSaved"));
|
||||
})
|
||||
.catch((e) => {
|
||||
toast.error(t("settings.saveFailedPrefix") + localizedError(e, t));
|
||||
api
|
||||
.settings()
|
||||
.then(onSettingsUpdated)
|
||||
.catch(() => undefined);
|
||||
})
|
||||
.finally(() => setSaving(false));
|
||||
};
|
||||
|
||||
const saveBraveKey = () => {
|
||||
setSavingKey(true);
|
||||
api
|
||||
.setSettings({ brave_search_api_key: braveKeyInput })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
setBraveKeyInput("");
|
||||
toast.success(t("settings.braveKeySaved"));
|
||||
})
|
||||
.catch((e) => toast.error(t("settings.saveFailedPrefix") + localizedError(e, t)))
|
||||
.finally(() => setSavingKey(false));
|
||||
};
|
||||
|
||||
const saveTavilyKey = () => {
|
||||
setSavingTavilyKey(true);
|
||||
api
|
||||
.setSettings({ tavily_search_api_key: tavilyKeyInput })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
setTavilyKeyInput("");
|
||||
toast.success(t("settings.tavilyKeySaved"));
|
||||
})
|
||||
.catch((e) => toast.error(t("settings.saveFailedPrefix") + localizedError(e, t)))
|
||||
.finally(() => setSavingTavilyKey(false));
|
||||
};
|
||||
|
||||
const saveDeepSeekKey = () => {
|
||||
setSavingDeepSeekKey(true);
|
||||
api
|
||||
.setSettings({ deepseek_search_api_key: deepSeekKeyInput })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
setDeepSeekKeyInput("");
|
||||
toast.success(t("settings.deepSeekKeySaved"));
|
||||
})
|
||||
.catch((e) => toast.error(t("settings.saveFailed", { message: localizedError(e, t) })))
|
||||
.finally(() => setSavingDeepSeekKey(false));
|
||||
};
|
||||
|
||||
const saveProxy = () => {
|
||||
setSavingProxy(true);
|
||||
api
|
||||
.setSettings({ web_search_proxy: proxyInput.trim() })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(proxyInput.trim() ? t("settings.searchProxySaved") : t("settings.searchProxyCleared"));
|
||||
})
|
||||
.catch((e) => toast.error(t("settings.saveFailedPrefix") + localizedError(e, t)))
|
||||
.finally(() => setSavingProxy(false));
|
||||
};
|
||||
|
||||
const runTest = () => {
|
||||
setTesting(true);
|
||||
api
|
||||
.testWebSearch({
|
||||
web_search_backend: backend,
|
||||
web_search_proxy: proxyInput.trim(),
|
||||
brave_search_api_key: braveKeyInput,
|
||||
tavily_search_api_key: tavilyKeyInput,
|
||||
deepseek_search_api_key: deepSeekKeyInput,
|
||||
})
|
||||
.then((r) => {
|
||||
if (r.ok) toast.success(t("settings.searchTestSucceeded", { backend: r.backend, count: r.count }));
|
||||
else toast.error(t("settings.searchTestFailedPrefix") + (r.error || t("settings.unknownError")));
|
||||
})
|
||||
.catch((e) => toast.error(t("settings.searchTestFailedPrefix") + localizedError(e, t)))
|
||||
.finally(() => setTesting(false));
|
||||
};
|
||||
|
||||
const braveNeedsKey = webSearch && backend === "brave-free" && !settings.braveKeySet;
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={SearchIcon}
|
||||
title={t("settings.webSearch")}
|
||||
badge={
|
||||
<Badge variant={webSearch ? "default" : "secondary"}>
|
||||
{webSearch ? t("settings.status.on") : t("settings.status.off")}
|
||||
</Badge>
|
||||
}
|
||||
description={
|
||||
<>
|
||||
{t("settings.webSearchOverview")}
|
||||
<br />
|
||||
{t("settings.searchProviderHelp")}
|
||||
</>
|
||||
}
|
||||
contentClassName="flex flex-col gap-4"
|
||||
>
|
||||
<SettingRow
|
||||
htmlFor="web-search"
|
||||
title={webSearch ? t("settings.searchOn") : t("settings.searchOff")}
|
||||
control={
|
||||
<Switch
|
||||
id="web-search"
|
||||
checked={webSearch}
|
||||
disabled={!loaded || saving}
|
||||
onCheckedChange={(v) => {
|
||||
setWebSearch(v);
|
||||
saveWebSearch({ web_search_enabled: v });
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
{webSearch ? (
|
||||
<div className="space-y-4 border-t pt-4">
|
||||
<div className="flex flex-wrap items-center justify-between gap-4">
|
||||
<Label className="font-medium text-sm">{t("settings.searchProvider")}</Label>
|
||||
<Select
|
||||
value={backend}
|
||||
disabled={!loaded || saving}
|
||||
onValueChange={(v) => {
|
||||
setBackend(v);
|
||||
saveWebSearch({ web_search_backend: v });
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="w-56 shrink-0">
|
||||
<SelectValue placeholder={t("settings.chooseProvider")} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ddgs">{t("settings.duckDuckGo")}</SelectItem>
|
||||
<SelectItem value="brave-free">{t("settings.braveOption")}</SelectItem>
|
||||
<SelectItem value="tavily">{t("settings.tavilyOption")}</SelectItem>
|
||||
<SelectItem value="deepseek">{t("settings.deepSeekOption")}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{backend === "deepseek" ? (
|
||||
<div className="flex flex-col gap-2 rounded-lg border border-border/60 bg-muted/30 p-3">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<p className="font-medium text-sm">{t("settings.deepSeekSearch")}</p>
|
||||
{settings.deepSeekKeySet ? (
|
||||
<Badge variant="outline" className="border-emerald-500/40 text-[11px] text-emerald-600">
|
||||
{t("settings.keyConfigured")}
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
<p className="text-muted-foreground text-xs leading-relaxed">{t("settings.deepSeekHelp")}</p>
|
||||
<p className="text-muted-foreground text-xs leading-relaxed">{t("settings.deepSeekNetworkHelp")}</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
type="password"
|
||||
autoComplete="off"
|
||||
placeholder={
|
||||
settings.deepSeekKeySet ? t("settings.keyConfiguredPlaceholder") : "DeepSeek Search API Key"
|
||||
}
|
||||
value={deepSeekKeyInput}
|
||||
disabled={!loaded || savingDeepSeekKey}
|
||||
onChange={(e) => setDeepSeekKeyInput(e.target.value)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={saveDeepSeekKey}
|
||||
disabled={!loaded || savingDeepSeekKey || deepSeekKeyInput.trim() === ""}
|
||||
>
|
||||
{t("settings.save")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{backend === "brave-free" ? (
|
||||
<div className="flex flex-col gap-2 rounded-lg border border-border/60 bg-muted/30 p-3">
|
||||
<Label htmlFor="brave-key" className="font-medium text-sm">
|
||||
Brave Search API Key
|
||||
{settings.braveKeySet ? (
|
||||
<span className="ml-2 font-normal text-emerald-500 text-xs">{t("settings.configured")}</span>
|
||||
) : null}
|
||||
</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
id="brave-key"
|
||||
type="password"
|
||||
autoComplete="off"
|
||||
placeholder={
|
||||
settings.braveKeySet ? t("settings.keyConfiguredPlaceholder") : t("settings.braveKeyPlaceholder")
|
||||
}
|
||||
value={braveKeyInput}
|
||||
disabled={!loaded || savingKey}
|
||||
onChange={(e) => setBraveKeyInput(e.target.value)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={saveBraveKey}
|
||||
disabled={!loaded || savingKey || braveKeyInput.trim() === ""}
|
||||
>
|
||||
{t("settings.save")}
|
||||
</Button>
|
||||
</div>
|
||||
{braveNeedsKey ? <p className="text-amber-500 text-xs">{t("settings.braveMissingKey")}</p> : null}
|
||||
<p className="text-muted-foreground text-xs">{t("settings.braveQuota")}</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{backend === "tavily" ? (
|
||||
<div className="flex flex-col gap-2 rounded-lg border border-border/60 bg-muted/30 p-3">
|
||||
<Label htmlFor="tavily-key" className="font-medium text-sm">
|
||||
Tavily Search API Key
|
||||
{settings.tavilyKeySet ? (
|
||||
<span className="ml-2 font-normal text-emerald-500 text-xs">{t("settings.configured")}</span>
|
||||
) : null}
|
||||
</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
id="tavily-key"
|
||||
type="password"
|
||||
autoComplete="off"
|
||||
placeholder={
|
||||
settings.tavilyKeySet ? t("settings.keyConfiguredPlaceholder") : t("settings.tavilyKeyPlaceholder")
|
||||
}
|
||||
value={tavilyKeyInput}
|
||||
disabled={!loaded || savingTavilyKey}
|
||||
onChange={(e) => setTavilyKeyInput(e.target.value)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={saveTavilyKey}
|
||||
disabled={!loaded || savingTavilyKey || tavilyKeyInput.trim() === ""}
|
||||
>
|
||||
{t("settings.save")}
|
||||
</Button>
|
||||
</div>
|
||||
{!settings.tavilyKeySet ? (
|
||||
<p className="text-amber-500 text-xs">{t("settings.tavilyMissingKey")}</p>
|
||||
) : null}
|
||||
<p className="text-muted-foreground text-xs">{t("settings.tavilySignup")}</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="ws-proxy" className="font-medium text-sm">
|
||||
{t("settings.outboundProxy")}
|
||||
</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
id="ws-proxy"
|
||||
autoComplete="off"
|
||||
placeholder={t("settings.proxyPlaceholder")}
|
||||
value={proxyInput}
|
||||
disabled={!loaded || savingProxy}
|
||||
onChange={(e) => setProxyInput(e.target.value)}
|
||||
/>
|
||||
<Button type="button" onClick={saveProxy} disabled={!loaded || savingProxy}>
|
||||
{t("settings.save")}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-muted-foreground text-xs">{t("settings.searchProxyHelp")}</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 border-t pt-4">
|
||||
<p className="text-muted-foreground text-xs">{t("settings.searchTestHelp")}</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={runTest}
|
||||
disabled={!loaded || testing}
|
||||
className="shrink-0"
|
||||
>
|
||||
{testing ? t("settings.testing") : t("settings.testSearch")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
"use client";
|
||||
|
||||
import type * as React from "react";
|
||||
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function SettingsSectionCard({
|
||||
icon: Icon,
|
||||
title,
|
||||
badge,
|
||||
description,
|
||||
action,
|
||||
children,
|
||||
contentClassName,
|
||||
}: {
|
||||
icon: React.ComponentType<{ className?: string }>;
|
||||
title: React.ReactNode;
|
||||
badge?: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
action?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
contentClassName?: string;
|
||||
}) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row flex-wrap items-start justify-between gap-3">
|
||||
<div className="flex min-w-0 flex-1 items-start gap-3">
|
||||
<div className="mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-lg border bg-muted/60 text-foreground">
|
||||
<Icon className="size-4" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1 space-y-1">
|
||||
<CardTitle className="flex flex-wrap items-center gap-2 text-base leading-snug">
|
||||
<span>{title}</span>
|
||||
{badge}
|
||||
</CardTitle>
|
||||
{description ? <CardDescription className="leading-relaxed">{description}</CardDescription> : null}
|
||||
</div>
|
||||
</div>
|
||||
{action ? <div className="shrink-0">{action}</div> : null}
|
||||
</CardHeader>
|
||||
<CardContent className={contentClassName}>{children}</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function SettingRow({
|
||||
htmlFor,
|
||||
title,
|
||||
badge,
|
||||
description,
|
||||
descriptionId,
|
||||
control,
|
||||
indented = false,
|
||||
className,
|
||||
}: {
|
||||
htmlFor?: string;
|
||||
title: React.ReactNode;
|
||||
badge?: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
descriptionId?: string;
|
||||
control: React.ReactNode;
|
||||
indented?: boolean;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-start justify-between gap-4 py-3.5 first:pt-0 last:pb-0",
|
||||
indented && "border-border/70 border-l-2 pl-4",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div className="min-w-0 flex-1 space-y-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{htmlFor ? (
|
||||
<Label htmlFor={htmlFor} className="cursor-pointer font-medium text-sm leading-snug">
|
||||
{title}
|
||||
</Label>
|
||||
) : (
|
||||
<span className="font-medium text-sm leading-snug">{title}</span>
|
||||
)}
|
||||
{badge}
|
||||
</div>
|
||||
{description ? (
|
||||
<p id={descriptionId} className="text-muted-foreground text-xs leading-relaxed">
|
||||
{description}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="shrink-0 pt-0.5">{control}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
|
||||
import Link from "next/link";
|
||||
|
||||
import { CameraIcon, ExternalLinkIcon, RadioTowerIcon, ShieldIcon } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { localizedError } from "@/i18n/errors";
|
||||
import { useLiveTranslation } from "@/i18n/use-live-translation";
|
||||
import { api } from "@/lib/api";
|
||||
import type { Settings } from "@/lib/types";
|
||||
|
||||
import { SettingRow, SettingsSectionCard } from "./settings-primitives";
|
||||
|
||||
export function TrafficRecordingCard({
|
||||
loaded,
|
||||
trafficCapture,
|
||||
agentTrafficBinding,
|
||||
onSettingsUpdated,
|
||||
}: {
|
||||
loaded: boolean;
|
||||
trafficCapture: boolean;
|
||||
agentTrafficBinding: boolean;
|
||||
onSettingsUpdated: (s: Settings) => void;
|
||||
}) {
|
||||
const { t } = useLiveTranslation();
|
||||
const [savingCapture, setSavingCapture] = React.useState(false);
|
||||
const [savingBinding, setSavingBinding] = React.useState(false);
|
||||
const [captureVal, setCaptureVal] = React.useState(trafficCapture);
|
||||
const [bindingVal, setBindingVal] = React.useState(agentTrafficBinding);
|
||||
|
||||
React.useEffect(() => {
|
||||
setCaptureVal(trafficCapture);
|
||||
}, [trafficCapture]);
|
||||
|
||||
React.useEffect(() => {
|
||||
setBindingVal(agentTrafficBinding);
|
||||
}, [agentTrafficBinding]);
|
||||
|
||||
const toggleTraffic = (v: boolean) => {
|
||||
setCaptureVal(v);
|
||||
setSavingCapture(true);
|
||||
api
|
||||
.setSettings({ traffic_capture: v })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
})
|
||||
.catch(() => setCaptureVal(!v))
|
||||
.finally(() => setSavingCapture(false));
|
||||
};
|
||||
|
||||
const toggleBinding = (v: boolean) => {
|
||||
setBindingVal(v);
|
||||
setSavingBinding(true);
|
||||
api
|
||||
.setSettings({ agent_traffic_binding: v })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(v ? t("settings.trafficBindingEnabled") : t("settings.trafficBindingDisabled"));
|
||||
})
|
||||
.catch((e) => {
|
||||
setBindingVal(!v);
|
||||
toast.error(t("settings.saveFailed", { message: localizedError(e, t) }));
|
||||
})
|
||||
.finally(() => setSavingBinding(false));
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={RadioTowerIcon}
|
||||
title={t("settings.trafficRecordingTitle")}
|
||||
badge={
|
||||
<Badge variant={captureVal ? "default" : "secondary"}>
|
||||
{captureVal ? t("settings.status.on") : t("settings.status.off")}
|
||||
</Badge>
|
||||
}
|
||||
description={t("settings.trafficRecordingHelp")}
|
||||
>
|
||||
<div className="divide-y">
|
||||
<SettingRow
|
||||
htmlFor="traffic-capture"
|
||||
title={t("settings.trafficCapture")}
|
||||
badge={
|
||||
<Badge variant={captureVal ? "outline" : "secondary"} className="font-normal text-[11px]">
|
||||
{captureVal ? t("settings.captureOn") : t("settings.captureOff")}
|
||||
</Badge>
|
||||
}
|
||||
description={
|
||||
<>
|
||||
{t("settings.trafficCaptureHelp")}
|
||||
<br />
|
||||
{t("settings.trafficCaptureOffStart")}
|
||||
<b>{t("settings.willNot")}</b>
|
||||
{t("settings.trafficCaptureOffMiddle")}
|
||||
<b>{t("settings.doNotContain")}</b>
|
||||
{t("settings.trafficCaptureOffEnd")}
|
||||
</>
|
||||
}
|
||||
control={
|
||||
<Switch
|
||||
id="traffic-capture"
|
||||
checked={captureVal}
|
||||
disabled={!loaded || savingCapture}
|
||||
onCheckedChange={toggleTraffic}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
<SettingRow
|
||||
htmlFor="agent-traffic-binding"
|
||||
title={t("settings.trafficBinding")}
|
||||
descriptionId="agent-traffic-binding-description"
|
||||
badge={
|
||||
<Badge variant={bindingVal ? "outline" : "secondary"} className="font-normal text-[11px]">
|
||||
{bindingVal ? t("settings.bindingOn") : t("settings.bindingOff")}
|
||||
</Badge>
|
||||
}
|
||||
description={
|
||||
<>
|
||||
{t("settings.trafficBindingHelp")}
|
||||
<b>{t("settings.trafficBindingCost")}</b>
|
||||
<br />
|
||||
{t("settings.trafficBindingDetails")}
|
||||
</>
|
||||
}
|
||||
control={
|
||||
<Switch
|
||||
id="agent-traffic-binding"
|
||||
aria-describedby="agent-traffic-binding-description"
|
||||
checked={bindingVal}
|
||||
disabled={!loaded || savingBinding}
|
||||
onCheckedChange={toggleBinding}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p className="mt-3 rounded-md border bg-muted/30 px-3 py-2 text-muted-foreground text-xs">
|
||||
{t("settings.storeErrorTrafficHint")}
|
||||
</p>
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
|
||||
export function BrowserSecurityCard({
|
||||
loaded,
|
||||
browserScreenshot,
|
||||
browserScreenshotTimestamp,
|
||||
opsecEnabled,
|
||||
onSettingsUpdated,
|
||||
}: {
|
||||
loaded: boolean;
|
||||
browserScreenshot: boolean;
|
||||
browserScreenshotTimestamp: boolean;
|
||||
opsecEnabled: boolean;
|
||||
onSettingsUpdated: (s: Settings) => void;
|
||||
}) {
|
||||
const { t } = useLiveTranslation();
|
||||
const [saving, setSaving] = React.useState(false);
|
||||
const [screenshotVal, setScreenshotVal] = React.useState(browserScreenshot);
|
||||
const [timestampVal, setTimestampVal] = React.useState(browserScreenshotTimestamp);
|
||||
const [opsecVal, setOpsecVal] = React.useState(opsecEnabled);
|
||||
|
||||
React.useEffect(() => {
|
||||
setScreenshotVal(browserScreenshot);
|
||||
}, [browserScreenshot]);
|
||||
React.useEffect(() => {
|
||||
setTimestampVal(browserScreenshotTimestamp);
|
||||
}, [browserScreenshotTimestamp]);
|
||||
React.useEffect(() => {
|
||||
setOpsecVal(opsecEnabled);
|
||||
}, [opsecEnabled]);
|
||||
|
||||
const toggleBrowserScreenshot = (v: boolean) => {
|
||||
setScreenshotVal(v);
|
||||
setSaving(true);
|
||||
api
|
||||
.setSettings({ browser_screenshot_enabled: v })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(v ? t("settings.screenshotsEnabled") : t("settings.screenshotsDisabled"));
|
||||
})
|
||||
.catch((e) => {
|
||||
setScreenshotVal(!v);
|
||||
toast.error(t("settings.saveFailed", { message: localizedError(e, t) }));
|
||||
})
|
||||
.finally(() => setSaving(false));
|
||||
};
|
||||
|
||||
const toggleBrowserScreenshotTimestamp = (v: boolean) => {
|
||||
setTimestampVal(v);
|
||||
setSaving(true);
|
||||
api
|
||||
.setSettings({ browser_screenshot_timestamp_enabled: v })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(v ? t("settings.timestampsEnabled") : t("settings.timestampsDisabled"));
|
||||
})
|
||||
.catch((e) => {
|
||||
setTimestampVal(!v);
|
||||
toast.error(t("settings.saveFailed", { message: localizedError(e, t) }));
|
||||
})
|
||||
.finally(() => setSaving(false));
|
||||
};
|
||||
|
||||
const toggleOpsec = (v: boolean) => {
|
||||
setOpsecVal(v);
|
||||
setSaving(true);
|
||||
api
|
||||
.setSettings({ opsec_enabled: v })
|
||||
.then((s) => {
|
||||
onSettingsUpdated(s);
|
||||
toast.success(v ? t("settings.opsecEnabled") : t("settings.opsecDisabled"));
|
||||
})
|
||||
.catch((e) => {
|
||||
setOpsecVal(!v);
|
||||
toast.error(t("settings.saveFailed", { message: localizedError(e, t) }));
|
||||
})
|
||||
.finally(() => setSaving(false));
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={CameraIcon}
|
||||
title={t("settings.browserSecurity")}
|
||||
description={t("settings.browserSecurityHelp")}
|
||||
contentClassName="divide-y"
|
||||
>
|
||||
<SettingRow
|
||||
htmlFor="browser-screenshot"
|
||||
title={t("settings.browserScreenshots")}
|
||||
description={t("settings.browserScreenshotsHelp")}
|
||||
control={
|
||||
<Switch
|
||||
id="browser-screenshot"
|
||||
checked={screenshotVal}
|
||||
disabled={!loaded || saving}
|
||||
onCheckedChange={toggleBrowserScreenshot}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<SettingRow
|
||||
htmlFor="browser-screenshot-timestamp"
|
||||
title={t("settings.screenshotTimestamp")}
|
||||
description={t("settings.screenshotTimestampHelp")}
|
||||
indented
|
||||
control={
|
||||
<Switch
|
||||
id="browser-screenshot-timestamp"
|
||||
checked={timestampVal}
|
||||
disabled={!loaded || saving}
|
||||
onCheckedChange={toggleBrowserScreenshotTimestamp}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<SettingRow
|
||||
htmlFor="opsec-enabled"
|
||||
title={t("settings.opsec")}
|
||||
badge={
|
||||
opsecVal ? (
|
||||
<Badge variant="default" className="text-[11px]">
|
||||
{t("settings.status.on")}
|
||||
</Badge>
|
||||
) : null
|
||||
}
|
||||
description={t("settings.opsecHelp")}
|
||||
control={
|
||||
<Switch id="opsec-enabled" checked={opsecVal} disabled={!loaded || saving} onCheckedChange={toggleOpsec} />
|
||||
}
|
||||
/>
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
|
||||
export function ProxyShortcutCard({
|
||||
proxyPoolCount,
|
||||
globalProxySummary,
|
||||
}: {
|
||||
proxyPoolCount: number;
|
||||
globalProxySummary: string;
|
||||
}) {
|
||||
const { t } = useLiveTranslation();
|
||||
let statusLabel = t("settings.proxyUnconfigured");
|
||||
if (proxyPoolCount > 0) {
|
||||
statusLabel = `${t("settings.proxyPool")} (${proxyPoolCount})`;
|
||||
} else if (globalProxySummary.trim()) {
|
||||
statusLabel = t("settings.proxyConfigured");
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingsSectionCard
|
||||
icon={ShieldIcon}
|
||||
title={t("settings.globalProxy")}
|
||||
badge={
|
||||
<Badge variant={proxyPoolCount > 0 || globalProxySummary.trim() ? "default" : "secondary"}>{statusLabel}</Badge>
|
||||
}
|
||||
description={t("settings.proxyMovedDesc")}
|
||||
action={
|
||||
<Button type="button" variant="outline" size="sm" asChild>
|
||||
<Link href="/system/proxy" className="gap-1.5">
|
||||
{t("settings.openProxyPage")}
|
||||
<ExternalLinkIcon className="size-3.5" />
|
||||
</Link>
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<p className="text-muted-foreground text-xs">{t("settings.storeErrorTrafficHint")}</p>
|
||||
</SettingsSectionCard>
|
||||
);
|
||||
}
|
||||
@@ -247,8 +247,7 @@ export function UpdateCard() {
|
||||
const pct = downloading ? Math.max(progress?.percent ?? 0, 0) : 100;
|
||||
|
||||
return (
|
||||
// 设置页是多列瀑布流布局,卡片自己负责行间距并禁止跨列断开(见 page.tsx 的注释)。
|
||||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-base">
|
||||
<DownloadIcon className="size-4" />
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -848,4 +848,40 @@ export const settingsMessages = {
|
||||
"settings.egressCheck.direct": ["① 直连出口 IP", "① Direct outbound IP"],
|
||||
"settings.egressCheck.global": ["② 全局代理出口 IP", "② Global proxy outbound IP"],
|
||||
"settings.noGlobalProxy": ["未配置全局代理", "No global proxy configured"],
|
||||
"settings.category.maintenance": ["系统与维护", "System & maintenance"],
|
||||
"settings.category.maintenanceHint": ["版本更新与数据备份", "Updates and backups"],
|
||||
"settings.category.security": ["安全与接入", "Security & access"],
|
||||
"settings.category.securityHint": ["登录认证与外部 MCP", "Auth and external MCP"],
|
||||
"settings.category.runtime": ["沙箱与运行", "Sandbox & runtime"],
|
||||
"settings.category.runtimeHint": ["容器隔离、并发与脚本", "Containers, workers and Python"],
|
||||
"settings.category.preferences": ["搜索与交互", "Search & interface"],
|
||||
"settings.category.preferencesHint": ["网络搜索与快捷键", "Web search and shortcuts"],
|
||||
"settings.searchCount": ["匹配 {{count}} 项", "{{count}} matched"],
|
||||
"settings.searchNoResults": ["未找到匹配的设置项", "No matching settings found"],
|
||||
"settings.searchNoResultsHint": [
|
||||
"试试搜索「沙箱」「代理」「截图」「并发」「MCP」等关键词。",
|
||||
"Try keywords such as sandbox, proxy, screenshot, workers, or MCP.",
|
||||
],
|
||||
"settings.status.on": ["已开启", "On"],
|
||||
"settings.status.off": ["已关闭", "Off"],
|
||||
"settings.overview.capture": ["流量捕获", "Capture"],
|
||||
"settings.overview.opsec": ["OPSEC", "OPSEC"],
|
||||
"settings.overview.search": ["网络搜索", "Search"],
|
||||
"settings.overview.workers": ["并发", "Workers"],
|
||||
"settings.trafficRecordingTitle": ["流量捕获与自动绑定", "Traffic capture & auto-binding"],
|
||||
"settings.trafficRecordingHelp": [
|
||||
"控制 Agent HTTP 流量录制及漏洞报告自动关联流量证据。",
|
||||
"Control Agent HTTP traffic recording and automatic traffic evidence binding for findings.",
|
||||
],
|
||||
"settings.storeErrorTrafficHint": [
|
||||
"连接失败与 DNS 错误流量默认不落库;如需排查,可在「代理与出口」或「流量」页随时开启。",
|
||||
"Connection and DNS error traffic is dropped by default; enable it anytime in Proxy & Egress or Traffic.",
|
||||
],
|
||||
"settings.automationTitle": ["自动化与实验功能", "Automation & experimental"],
|
||||
"settings.automationHelp": [
|
||||
"管理任务/对话自动命名与实验性上下文压缩策略。",
|
||||
"Manage automatic naming for tasks/chats and experimental context compaction.",
|
||||
],
|
||||
"settings.experimentalBadge": ["实验", "Experimental"],
|
||||
"settings.localScopeBadge": ["仅当前浏览器", "Browser only"],
|
||||
} satisfies Record<string, readonly [string, string]>;
|
||||
Reference in new issue
Block a user