系统配置页新增「版本与更新」卡片,顶栏版本号旁在有新版时亮出提示胶囊。 更新链路:下载发布包 → 比对 SHA256SUMS → -h 冒烟测试 → 暂存 artex.new → 以退出码 75 退出 → 守护脚本重新拉起并完成换装,页面轮询 /api/health 等版本号变化后自动刷新。 新增 start.sh / start.bat 作为正式启动入口,只按退出码决定是否重新拉起 (0 停止 / 75 应用新版 / 其余崩溃退避)。校验、冒烟、换装、回滚全部收在 selfupdate 包里而不写进脚本:这些逻辑在 sh 和 bat 上要写两套,而它们恰恰 最不能出错——换上跑不起来的二进制后守护进程会反复拉起它,只能上机器手工救。 Docker 的 ENTRYPOINT 一并改为该脚本,并由它转发 SIGTERM,否则 docker stop 只发给 PID 1,artex 做不了优雅关闭会被 SIGKILL 硬杀。 失败保护两道闸门互补:无法 exec 由换装前的冒烟挡住,能执行但初始化崩溃 由启动计数兜住(连续 3 次失败自动回滚 artex.old,坏的留作 artex.failed)。 GitHub 查询结果后端缓存 30 分钟(失败 2 分钟)。未认证 API 是每 IP 每小时 60 次,且这 60 次是服务器 IP 上所有用户共用的,顶栏每次整页加载都查一次, 不缓存会很快耗光配额导致真想更新时反而查不动。手动「检查更新」带 force=1 绕过缓存。 安全:只认 GitHub 域名且强制 HTTPS(逐跳校验重定向),发布源写死不可配置; 升级文件挂在可执行文件所在目录而非 CWD(服务化运行时 CWD 可能是 /); 开发构建版本号不可比较,禁用一键更新。 走完整 zip 而非裸二进制,因为现有 Release 的 SHA256SUMS 只覆盖 zip, 这样无需改 CI,也兼容已发布的历史版本。 已知限制:Docker 下只换程序不换镜像(工具链不同步、重建容器会退回镜像 版本);不同步发布包里的 skills/;更新即重启会中断运行中的任务。
648 lines
28 KiB
TypeScript
648 lines
28 KiB
TypeScript
"use client";
|
||
|
||
import * as React from "react";
|
||
|
||
import { CpuIcon, KeyboardIcon, RadioTowerIcon, SearchIcon, ShieldAlertIcon } from "lucide-react";
|
||
import { toast } from "sonner";
|
||
|
||
import { Button } from "@/components/ui/button";
|
||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||
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 { api } from "@/lib/api";
|
||
import { CHAT_SEND_MODE_OPTIONS, type ChatSendMode, setChatSendMode, useChatSendMode } from "@/lib/chat-send-mode";
|
||
import type { Settings } from "@/lib/types";
|
||
|
||
import { UpdateCard } from "./_components/update-card";
|
||
|
||
export default function SystemSettingsPage() {
|
||
const [trafficCapture, setTrafficCapture] = React.useState(false);
|
||
const [agentTrafficBinding, setAgentTrafficBinding] = React.useState(false);
|
||
const [webSearch, setWebSearch] = React.useState(false);
|
||
const [backend, setBackend] = React.useState("ddgs");
|
||
const [braveKeySet, setBraveKeySet] = React.useState(false);
|
||
const [braveKeyInput, setBraveKeyInput] = React.useState("");
|
||
const [tavilyKeySet, setTavilyKeySet] = React.useState(false);
|
||
const [tavilyKeyInput, setTavilyKeyInput] = React.useState("");
|
||
const [savingTavilyKey, setSavingTavilyKey] = React.useState(false);
|
||
const [proxyInput, setProxyInput] = React.useState("");
|
||
const [savingProxy, setSavingProxy] = React.useState(false);
|
||
const [globalProxyInput, setGlobalProxyInput] = React.useState("");
|
||
const [savingGlobalProxy, setSavingGlobalProxy] = React.useState(false);
|
||
const [testing, setTesting] = React.useState(false);
|
||
const [loaded, setLoaded] = React.useState(false);
|
||
const [saving, setSaving] = React.useState(false);
|
||
const [savingKey, setSavingKey] = React.useState(false);
|
||
const [pyInterp, setPyInterp] = React.useState("");
|
||
const [workers, setWorkers] = React.useState("3");
|
||
const [savingWorkers, setSavingWorkers] = React.useState(false);
|
||
// 操作约束注入范围(默认都开)。
|
||
const [injectPlanner, setInjectPlanner] = React.useState(true);
|
||
const [injectWorker, setInjectWorker] = React.useState(true);
|
||
// 纯前端偏好:不走 /api/settings,直接读写 localStorage。
|
||
const sendMode = useChatSendMode();
|
||
|
||
const apply = React.useCallback((s: Settings) => {
|
||
setTrafficCapture(!!s.traffic_capture);
|
||
setAgentTrafficBinding(!!s.agent_traffic_binding);
|
||
setWebSearch(!!s.web_search_enabled);
|
||
setBackend(s.web_search_backend || "ddgs");
|
||
setBraveKeySet(!!s.brave_key_set);
|
||
setTavilyKeySet(!!s.tavily_key_set);
|
||
setProxyInput(s.web_search_proxy ?? "");
|
||
setGlobalProxyInput(s.global_proxy ?? "");
|
||
setPyInterp(s.python_interpreter ?? "");
|
||
setWorkers(String(s.workers ?? 3));
|
||
setInjectPlanner(s.constraints_inject_planner !== false);
|
||
setInjectWorker(s.constraints_inject_worker !== false);
|
||
}, []);
|
||
|
||
const saveWorkers = () => {
|
||
const n = Number(workers);
|
||
if (!Number.isInteger(n) || n <= 0) {
|
||
toast.error("并发数必须是大于 0 的整数");
|
||
return;
|
||
}
|
||
setSavingWorkers(true);
|
||
api
|
||
.setSettings({ workers: n })
|
||
.then((s) => {
|
||
apply(s);
|
||
toast.success("已保存并发工作 agent 数(对之后启动的任务生效)");
|
||
})
|
||
.catch((e) => toast.error("保存失败:" + (e as Error).message))
|
||
.finally(() => setSavingWorkers(false));
|
||
};
|
||
|
||
const savePython = () => {
|
||
setSaving(true);
|
||
api
|
||
.setSettings({ python_interpreter: pyInterp.trim() })
|
||
.then((s) => {
|
||
apply(s);
|
||
toast.success("已保存 Python 解释器配置");
|
||
})
|
||
.catch((e) => toast.error("保存失败:" + (e as Error).message))
|
||
.finally(() => setSaving(false));
|
||
};
|
||
const detectPython = () => {
|
||
setSaving(true);
|
||
api
|
||
.detectPython()
|
||
.then((r) => setPyInterp(r.python_interpreter))
|
||
.catch(() => undefined)
|
||
.finally(() => setSaving(false));
|
||
};
|
||
|
||
React.useEffect(() => {
|
||
api
|
||
.settings()
|
||
.then(apply)
|
||
.catch(() => undefined)
|
||
.finally(() => setLoaded(true));
|
||
}, [apply]);
|
||
|
||
const toggleTraffic = (v: boolean) => {
|
||
setTrafficCapture(v); // optimistic
|
||
setSaving(true);
|
||
api
|
||
.setSettings({ traffic_capture: v })
|
||
.then(apply)
|
||
.catch(() => setTrafficCapture(!v)) // revert on failure
|
||
.finally(() => setSaving(false));
|
||
};
|
||
|
||
const toggleInjectPlanner = (v: boolean) => {
|
||
setInjectPlanner(v); // optimistic
|
||
api
|
||
.setSettings({ constraints_inject_planner: v })
|
||
.then(apply)
|
||
.catch(() => setInjectPlanner(!v)); // revert on failure
|
||
};
|
||
|
||
const toggleAgentTrafficBinding = (v: boolean) => {
|
||
setAgentTrafficBinding(v);
|
||
setSaving(true);
|
||
api
|
||
.setSettings({ agent_traffic_binding: v })
|
||
.then((s) => {
|
||
apply(s);
|
||
toast.success(v ? "已开启 Agent 自动绑定流量" : "已关闭 Agent 自动绑定流量");
|
||
})
|
||
.catch((e) => {
|
||
setAgentTrafficBinding(!v);
|
||
toast.error(`保存失败:${(e as Error).message}`);
|
||
})
|
||
.finally(() => setSaving(false));
|
||
};
|
||
|
||
const toggleInjectWorker = (v: boolean) => {
|
||
setInjectWorker(v); // optimistic
|
||
api
|
||
.setSettings({ constraints_inject_worker: v })
|
||
.then(apply)
|
||
.catch(() => setInjectWorker(!v)); // revert on failure
|
||
};
|
||
|
||
// Persist a web-search patch (enable and/or backend). Optimistic with refetch.
|
||
const saveWebSearch = (patch: Partial<Settings>) => {
|
||
setSaving(true);
|
||
api
|
||
.setSettings(patch)
|
||
.then((s) => {
|
||
apply(s);
|
||
toast.success("已保存网络搜索配置");
|
||
})
|
||
.catch((e) => {
|
||
toast.error("保存失败:" + (e as Error).message);
|
||
api
|
||
.settings()
|
||
.then(apply)
|
||
.catch(() => undefined);
|
||
})
|
||
.finally(() => setSaving(false));
|
||
};
|
||
|
||
const saveBraveKey = () => {
|
||
setSavingKey(true);
|
||
api
|
||
.setSettings({ brave_search_api_key: braveKeyInput })
|
||
.then((s) => {
|
||
apply(s);
|
||
setBraveKeyInput("");
|
||
toast.success("已保存 Brave API Key");
|
||
})
|
||
.catch((e) => toast.error("保存失败:" + (e as Error).message))
|
||
.finally(() => setSavingKey(false));
|
||
};
|
||
|
||
const saveTavilyKey = () => {
|
||
setSavingTavilyKey(true);
|
||
api
|
||
.setSettings({ tavily_search_api_key: tavilyKeyInput })
|
||
.then((s) => {
|
||
apply(s);
|
||
setTavilyKeyInput("");
|
||
toast.success("已保存 Tavily API Key");
|
||
})
|
||
.catch((e) => toast.error("保存失败:" + (e as Error).message))
|
||
.finally(() => setSavingTavilyKey(false));
|
||
};
|
||
|
||
const saveProxy = () => {
|
||
setSavingProxy(true);
|
||
api
|
||
.setSettings({ web_search_proxy: proxyInput.trim() })
|
||
.then((s) => {
|
||
apply(s);
|
||
toast.success(proxyInput.trim() ? "已保存出口代理" : "已清除出口代理(改为直连)");
|
||
})
|
||
.catch((e) => toast.error("保存失败:" + (e as Error).message))
|
||
.finally(() => setSavingProxy(false));
|
||
};
|
||
|
||
const saveGlobalProxy = () => {
|
||
setSavingGlobalProxy(true);
|
||
api
|
||
.setSettings({ global_proxy: globalProxyInput.trim() })
|
||
.then((s) => {
|
||
apply(s);
|
||
toast.success(globalProxyInput.trim() ? "已保存全局代理" : "已清除全局代理(改为直连)");
|
||
})
|
||
.catch((e) => toast.error("保存失败:" + (e as Error).message))
|
||
.finally(() => setSavingGlobalProxy(false));
|
||
};
|
||
|
||
// Run a real "test" search ("test") against the CURRENT form values (backend +
|
||
// proxy + entered key), falling back to saved values server-side. Toasts result.
|
||
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,
|
||
})
|
||
.then((r) => {
|
||
if (r.ok) toast.success(`搜索测试成功 · ${r.backend} 返回 ${r.count} 条结果`);
|
||
else toast.error("搜索测试失败:" + (r.error || "未知错误"));
|
||
})
|
||
.catch((e) => toast.error("搜索测试失败:" + (e as Error).message))
|
||
.finally(() => setTesting(false));
|
||
};
|
||
|
||
// brave-free selected but no key stored and none being entered → tool stays off.
|
||
const braveNeedsKey = webSearch && backend === "brave-free" && !braveKeySet;
|
||
|
||
return (
|
||
<div className="flex flex-1 flex-col gap-4 md:gap-6">
|
||
<div>
|
||
<h1 className="text-xl font-semibold tracking-tight">系统配置</h1>
|
||
<p className="text-muted-foreground text-sm">全局运行时开关</p>
|
||
</div>
|
||
|
||
{/* 多列而非 grid:网络搜索卡片比其余高数倍,且高度随所选后端变化(brave/tavily
|
||
的 key 输入是条件渲染)。grid 会按最高的一张撑满整行、在旁边留下大片空白,
|
||
多列则自动按内容高度平衡填充。卡片间距靠 mb 而非 gap——多列布局下
|
||
column-gap 只管列间距,行间距要由子元素自己给。 */}
|
||
<div className="columns-1 gap-4 md:gap-6 lg:columns-2">
|
||
<UpdateCard />
|
||
|
||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||
<CardHeader>
|
||
<CardTitle className="flex items-center gap-2 text-base">
|
||
<RadioTowerIcon className="size-4" />
|
||
流量捕获
|
||
</CardTitle>
|
||
<CardDescription>
|
||
开启后,所有 Agent 的 HTTP 流量经记录代理全量落库,并向 Agent 注入 traffic_search / traffic_get
|
||
工具与代理配置(提示词含代理说明)。
|
||
<br />
|
||
关闭(默认)时不记录任何流量:Agent
|
||
<b>不会</b>拿到代理配置与流量工具,提示词也<b>不含</b>代理相关内容。切换后会即时重建 Agent 生效。
|
||
</CardDescription>
|
||
</CardHeader>
|
||
<CardContent className="flex items-center justify-between gap-4">
|
||
<Label htmlFor="traffic-capture" className="text-sm font-normal text-muted-foreground">
|
||
{trafficCapture ? "已开启 · 正在记录流量并注入代理" : "已关闭 · 不记录、不注入代理"}
|
||
</Label>
|
||
<Switch
|
||
id="traffic-capture"
|
||
checked={trafficCapture}
|
||
disabled={!loaded || saving}
|
||
onCheckedChange={toggleTraffic}
|
||
/>
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||
<CardHeader>
|
||
<CardTitle className="flex items-center gap-2 text-base">
|
||
<RadioTowerIcon className="size-4" />
|
||
Agent 自动绑定流量
|
||
</CardTitle>
|
||
<CardDescription id="agent-traffic-binding-description">
|
||
默认关闭。开启后,漏洞入库时触发的报告 Agent 会核对已有 HTTP 请求/响应,关联对应流量后再编写报告。
|
||
<b>查阅数据包及额外的工具调用会增加 Token 消耗。</b>
|
||
<br />
|
||
TCP、未抓包或没有匹配流量时仍可正常上报。此开关不影响流量捕获、人工绑定及已保存证据的查看。 对下一轮 Agent
|
||
生效;关闭后会立即拒绝新的自动绑定。
|
||
</CardDescription>
|
||
</CardHeader>
|
||
<CardContent className="flex items-center justify-between gap-4">
|
||
<Label htmlFor="agent-traffic-binding" className="text-sm font-normal text-muted-foreground">
|
||
{agentTrafficBinding ? "已开启 · 会增加 Token 消耗" : "已关闭 · 可继续人工绑定"}
|
||
</Label>
|
||
<Switch
|
||
id="agent-traffic-binding"
|
||
aria-describedby="agent-traffic-binding-description"
|
||
checked={agentTrafficBinding}
|
||
disabled={!loaded || saving}
|
||
onCheckedChange={toggleAgentTrafficBinding}
|
||
/>
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||
<CardHeader>
|
||
<CardTitle className="flex items-center gap-2 text-base">
|
||
<RadioTowerIcon className="size-4" />
|
||
全局代理
|
||
</CardTitle>
|
||
<CardDescription>
|
||
所有 Agent 的<b>目标流量</b>经此代理出网(隐藏源 IP / 走跳板)。支持 <b>http / https / socks5</b>,可带{" "}
|
||
<code>user:pass</code> 认证。留空=直连。
|
||
<br />
|
||
开启<b>流量捕获</b>时,它作为记录代理的<b>上游</b>(流量仍全量落库,再经此代理出网);关闭捕获时,直接注入
|
||
Agent 的 bash / WebFetch 出网。与网络搜索代理、LLM 代理相互独立。
|
||
<br />
|
||
<b>提示</b>:socks5 在<b>关闭捕获</b>时依赖各命令行工具对 <code>ALL_PROXY</code> 的支持(curl
|
||
可用,部分工具可能忽略); 若主要用 socks5,建议开启流量捕获——此路径由 MITM
|
||
亲自拨号,工具无感知、稳定生效。
|
||
</CardDescription>
|
||
</CardHeader>
|
||
<CardContent className="flex flex-col gap-2">
|
||
<Label htmlFor="global-proxy" className="text-sm font-normal text-muted-foreground">
|
||
代理地址
|
||
</Label>
|
||
<div className="flex items-center gap-2">
|
||
<Input
|
||
id="global-proxy"
|
||
autoComplete="off"
|
||
placeholder="socks5://user:pass@host:1080 或 http://host:port(留空=直连)"
|
||
value={globalProxyInput}
|
||
disabled={!loaded || savingGlobalProxy}
|
||
onChange={(e) => setGlobalProxyInput(e.target.value)}
|
||
/>
|
||
<Button type="button" onClick={saveGlobalProxy} disabled={!loaded || savingGlobalProxy}>
|
||
保存
|
||
</Button>
|
||
</div>
|
||
<p className="text-muted-foreground text-xs">
|
||
{globalProxyInput.trim() ? "已配置 · 所有目标流量经此代理出网" : "未配置 · 目标流量直连出网"}
|
||
</p>
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||
<CardHeader>
|
||
<CardTitle className="flex items-center gap-2 text-base">
|
||
<ShieldAlertIcon className="size-4" />
|
||
操作约束注入
|
||
</CardTitle>
|
||
<CardDescription>
|
||
开启后,把每个任务的<b>操作约束</b>(在任务总览「操作约束」里维护的 allow/deny 条目)拼进对应 Agent
|
||
的系统提示,用来框定探索边界(如「仅测当前端口」「禁止爆破」)。
|
||
<br />
|
||
可分别控制注入到 <b>规划者(planner)</b>与 <b>执行者(worker)</b>
|
||
;默认都开。切换即时生效(下一轮读取),无需重建 Agent。关闭后该 Agent 不再看到约束。
|
||
</CardDescription>
|
||
</CardHeader>
|
||
<CardContent className="flex flex-col gap-4">
|
||
<div className="flex items-center justify-between gap-4">
|
||
<Label htmlFor="inject-planner" className="text-sm font-normal text-muted-foreground">
|
||
注入规划者(planner){injectPlanner ? " · 已开启" : " · 已关闭"}
|
||
</Label>
|
||
<Switch
|
||
id="inject-planner"
|
||
checked={injectPlanner}
|
||
disabled={!loaded}
|
||
onCheckedChange={toggleInjectPlanner}
|
||
/>
|
||
</div>
|
||
<div className="flex items-center justify-between gap-4">
|
||
<Label htmlFor="inject-worker" className="text-sm font-normal text-muted-foreground">
|
||
注入执行者(worker){injectWorker ? " · 已开启" : " · 已关闭"}
|
||
</Label>
|
||
<Switch
|
||
id="inject-worker"
|
||
checked={injectWorker}
|
||
disabled={!loaded}
|
||
onCheckedChange={toggleInjectWorker}
|
||
/>
|
||
</div>
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||
<CardHeader>
|
||
<CardTitle className="flex items-center gap-2 text-base">
|
||
<SearchIcon className="size-4" />
|
||
网络搜索
|
||
</CardTitle>
|
||
<CardDescription>
|
||
这是网络搜索的<b>总开关 + 来源配置</b>。开启后,才能在<b>每个 Agent 的配置</b>里单独选择是否启用
|
||
<b>web_search</b>(仅返回标题/链接/摘要,不抓取正文;抓取由 WebFetch 负责)。网络搜索<b>不走</b>
|
||
记录代理,独立于流量捕获。
|
||
<br />
|
||
来源可选 <b>DuckDuckGo(ddgs)</b>(无需 Key)、<b>Brave(免费版)</b>(需填写 Brave API Key)或{" "}
|
||
<b>Tavily</b>(需填写 Tavily API Key)。总开关关闭时,各 Agent 的网络搜索开关不可用。
|
||
</CardDescription>
|
||
</CardHeader>
|
||
<CardContent className="flex flex-col gap-4">
|
||
<div className="flex items-center justify-between gap-4">
|
||
<Label htmlFor="web-search" className="text-sm font-normal text-muted-foreground">
|
||
{webSearch ? "总开关已开启 · 可在各 Agent 配置里单独启用" : "已关闭 · 各 Agent 无法启用网络搜索"}
|
||
</Label>
|
||
<Switch
|
||
id="web-search"
|
||
checked={webSearch}
|
||
disabled={!loaded || saving}
|
||
onCheckedChange={(v) => {
|
||
setWebSearch(v); // optimistic
|
||
saveWebSearch({ web_search_enabled: v });
|
||
}}
|
||
/>
|
||
</div>
|
||
|
||
{webSearch && (
|
||
<div className="flex items-center justify-between gap-4">
|
||
<Label className="text-sm font-normal text-muted-foreground">搜索来源</Label>
|
||
<Select
|
||
value={backend}
|
||
disabled={!loaded || saving}
|
||
onValueChange={(v) => {
|
||
setBackend(v); // optimistic
|
||
saveWebSearch({ web_search_backend: v });
|
||
}}
|
||
>
|
||
<SelectTrigger className="w-48 shrink-0">
|
||
<SelectValue placeholder="选择来源" />
|
||
</SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="ddgs">DuckDuckGo(ddgs · 免费无 Key)</SelectItem>
|
||
<SelectItem value="brave-free">Brave(免费版 · 需 Key)</SelectItem>
|
||
<SelectItem value="tavily">Tavily(需 Key)</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
</div>
|
||
)}
|
||
|
||
{webSearch && backend === "brave-free" && (
|
||
<div className="flex flex-col gap-2">
|
||
<Label htmlFor="brave-key" className="text-sm font-normal text-muted-foreground">
|
||
Brave Search API Key
|
||
{braveKeySet && <span className="ml-2 text-xs text-emerald-500">已配置</span>}
|
||
</Label>
|
||
<div className="flex items-center gap-2">
|
||
<Input
|
||
id="brave-key"
|
||
type="password"
|
||
autoComplete="off"
|
||
placeholder={braveKeySet ? "已配置(留空则不变)" : "输入 Brave API Key"}
|
||
value={braveKeyInput}
|
||
disabled={!loaded || savingKey}
|
||
onChange={(e) => setBraveKeyInput(e.target.value)}
|
||
/>
|
||
<Button
|
||
type="button"
|
||
onClick={saveBraveKey}
|
||
disabled={!loaded || savingKey || braveKeyInput.trim() === ""}
|
||
>
|
||
保存
|
||
</Button>
|
||
</div>
|
||
{braveNeedsKey && (
|
||
<p className="text-xs text-amber-500">
|
||
已选择 Brave 但尚未配置 Key —— 在保存 Key 之前,搜索工具不会启用。
|
||
</p>
|
||
)}
|
||
<p className="text-muted-foreground text-xs">
|
||
免费版额度约 2,000 次/月。前往 https://brave.com/search/api/ 获取 Key。
|
||
</p>
|
||
</div>
|
||
)}
|
||
|
||
{webSearch && backend === "tavily" && (
|
||
<div className="flex flex-col gap-2">
|
||
<Label htmlFor="tavily-key" className="text-sm font-normal text-muted-foreground">
|
||
Tavily Search API Key
|
||
{tavilyKeySet && <span className="ml-2 text-xs text-emerald-500">已配置</span>}
|
||
</Label>
|
||
<div className="flex items-center gap-2">
|
||
<Input
|
||
id="tavily-key"
|
||
type="password"
|
||
autoComplete="off"
|
||
placeholder={tavilyKeySet ? "已配置(留空则不变)" : "输入 Tavily API Key(tvly-…)"}
|
||
value={tavilyKeyInput}
|
||
disabled={!loaded || savingTavilyKey}
|
||
onChange={(e) => setTavilyKeyInput(e.target.value)}
|
||
/>
|
||
<Button
|
||
type="button"
|
||
onClick={saveTavilyKey}
|
||
disabled={!loaded || savingTavilyKey || tavilyKeyInput.trim() === ""}
|
||
>
|
||
保存
|
||
</Button>
|
||
</div>
|
||
{webSearch && backend === "tavily" && !tavilyKeySet && (
|
||
<p className="text-xs text-amber-500">
|
||
已选择 Tavily 但尚未配置 Key —— 在保存 Key 之前,搜索工具不会启用。
|
||
</p>
|
||
)}
|
||
<p className="text-muted-foreground text-xs">前往 https://tavily.com 注册并获取 API Key。</p>
|
||
</div>
|
||
)}
|
||
|
||
{webSearch && (
|
||
<div className="flex flex-col gap-2">
|
||
<Label htmlFor="ws-proxy" className="text-sm font-normal text-muted-foreground">
|
||
出口代理(可选)
|
||
</Label>
|
||
<div className="flex items-center gap-2">
|
||
<Input
|
||
id="ws-proxy"
|
||
autoComplete="off"
|
||
placeholder="http://host:port 或 socks5://host:port(留空=直连)"
|
||
value={proxyInput}
|
||
disabled={!loaded || savingProxy}
|
||
onChange={(e) => setProxyInput(e.target.value)}
|
||
/>
|
||
<Button type="button" onClick={saveProxy} disabled={!loaded || savingProxy}>
|
||
保存
|
||
</Button>
|
||
</div>
|
||
<p className="text-muted-foreground text-xs">
|
||
独立出口代理,仅用于访问搜索端点(VPN/SOCKS 等)。与记录流量的 MITM 代理无关;网络不通时经此代理访问。
|
||
</p>
|
||
</div>
|
||
)}
|
||
|
||
{webSearch && (
|
||
<div className="flex items-center justify-between gap-4 border-t pt-4">
|
||
<p className="text-muted-foreground text-xs">
|
||
用当前配置(来源 + 代理 + Key)实际搜索一次「test」,验证是否可用。
|
||
</p>
|
||
<Button
|
||
type="button"
|
||
variant="outline"
|
||
onClick={runTest}
|
||
disabled={!loaded || testing}
|
||
className="shrink-0"
|
||
>
|
||
{testing ? "测试中…" : "测试搜索"}
|
||
</Button>
|
||
</div>
|
||
)}
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||
<CardHeader>
|
||
<CardTitle className="flex items-center gap-2 text-base">
|
||
<RadioTowerIcon className="size-4" />
|
||
自定义脚本 · Python 解释器
|
||
</CardTitle>
|
||
<CardDescription>
|
||
自定义 <b>script</b> 类型工具用它跑 Python。开机会自动检测(python3 优先);此处可手填 venv /
|
||
特定版本的绝对路径,留空则运行时自动检测。
|
||
</CardDescription>
|
||
</CardHeader>
|
||
<CardContent className="flex flex-col gap-3">
|
||
<div className="flex items-center gap-2">
|
||
<Input
|
||
className="font-mono text-sm"
|
||
placeholder="/usr/bin/python3(留空=自动检测)"
|
||
value={pyInterp}
|
||
disabled={!loaded || saving}
|
||
onChange={(e) => setPyInterp(e.target.value)}
|
||
/>
|
||
<Button variant="outline" onClick={detectPython} disabled={!loaded || saving}>
|
||
重新检测
|
||
</Button>
|
||
<Button onClick={savePython} disabled={!loaded || saving}>
|
||
保存
|
||
</Button>
|
||
</div>
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||
<CardHeader>
|
||
<CardTitle className="flex items-center gap-2 text-base">
|
||
<CpuIcon className="size-4" />
|
||
工作并发 · Work Agent 数
|
||
</CardTitle>
|
||
<CardDescription>
|
||
每个任务并发运行的工作 agent 数量(默认 3)。数值越大并发探测越多、消耗也越高。修改后
|
||
<b>对之后启动的任务生效</b>,正在运行的任务不受影响。
|
||
</CardDescription>
|
||
</CardHeader>
|
||
<CardContent className="flex flex-col gap-3">
|
||
<div className="flex items-center gap-2">
|
||
<Input
|
||
type="number"
|
||
min={1}
|
||
className="w-32 font-mono text-sm"
|
||
placeholder="3"
|
||
value={workers}
|
||
disabled={!loaded || savingWorkers}
|
||
onChange={(e) => setWorkers(e.target.value)}
|
||
/>
|
||
<Button onClick={saveWorkers} disabled={!loaded || savingWorkers}>
|
||
保存
|
||
</Button>
|
||
</div>
|
||
</CardContent>
|
||
</Card>
|
||
|
||
<Card className="mb-4 break-inside-avoid md:mb-6">
|
||
<CardHeader>
|
||
<CardTitle className="flex items-center gap-2 text-base">
|
||
<KeyboardIcon className="size-4" />
|
||
会话输入框发送键位
|
||
</CardTitle>
|
||
<CardDescription>
|
||
对话页与任务详情的主 Agent 会话输入框共用此设置,选择后立即生效、无需保存。
|
||
<br />
|
||
该偏好<b>只存在本浏览器</b>,不随账号同步,换浏览器或清理站点数据后需重新设置。
|
||
</CardDescription>
|
||
</CardHeader>
|
||
<CardContent className="flex items-center justify-between gap-4">
|
||
<Label htmlFor="chat-send-mode" className="text-sm font-normal text-muted-foreground">
|
||
发送方式
|
||
</Label>
|
||
<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}>
|
||
{option.label}
|
||
</SelectItem>
|
||
))}
|
||
</SelectContent>
|
||
</Select>
|
||
</CardContent>
|
||
</Card>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|