mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-11-25 10:11:50 +08:00
feat: 多模型 Worker 池(#41,Codex 重写:绑定配置不可用时报错而非回退)
Code authored by Codex CLI (gpt-6-astra main implementation; gpt-6-sol / gpt-6-astra continuation passes).
This commit is contained in:
1 parent
6ffe04cf3d
commit
d1b2b5a996
9 files changed
+733
-29
No files matched your search
@@ -14,7 +14,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
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 type { LLMProfile, Settings, WorkerPool } from "@/lib/types";
|
||||
|
||||
import { BasicAuthCard } from "./_components/basic-auth-card";
|
||||
import { UpdateCard } from "./_components/update-card";
|
||||
@@ -45,6 +45,8 @@ export default function SystemSettingsPage() {
|
||||
const [pyInterp, setPyInterp] = React.useState("");
|
||||
const [workers, setWorkers] = React.useState("3");
|
||||
const [savingWorkers, setSavingWorkers] = React.useState(false);
|
||||
const [workerPools, setWorkerPools] = React.useState<WorkerPool[]>([]);
|
||||
const [llmProfiles, setLlmProfiles] = React.useState<LLMProfile[]>([]);
|
||||
// 操作约束注入范围(默认都开)。
|
||||
const [injectPlanner, setInjectPlanner] = React.useState(true);
|
||||
const [injectWorker, setInjectWorker] = React.useState(true);
|
||||
@@ -67,6 +69,7 @@ export default function SystemSettingsPage() {
|
||||
setGlobalProxyInput(s.global_proxy ?? "");
|
||||
setPyInterp(s.python_interpreter ?? "");
|
||||
setWorkers(String(s.workers ?? 3));
|
||||
setWorkerPools(s.worker_pools);
|
||||
setInjectPlanner(s.constraints_inject_planner !== false);
|
||||
setInjectWorker(s.constraints_inject_worker !== false);
|
||||
setNoaCompaction(!!s.noa_compaction);
|
||||
@@ -74,13 +77,46 @@ export default function SystemSettingsPage() {
|
||||
|
||||
const saveWorkers = () => {
|
||||
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("请选择每个模型池的 LLM 配置");
|
||||
return;
|
||||
}
|
||||
if (workerPools.some((pool) => !Number.isInteger(Number(pool.workers)) || Number(pool.workers) <= 0)) {
|
||||
toast.error("每个模型池的 Worker 数必须是大于 0 的整数");
|
||||
return;
|
||||
}
|
||||
if (total > 50) {
|
||||
toast.error("Worker 总数不能超过 50");
|
||||
return;
|
||||
}
|
||||
const ids = workerPools.map((pool) => pool.profile_id);
|
||||
if (new Set(ids).size !== ids.length) {
|
||||
toast.error("不能重复选择同一个 LLM 配置");
|
||||
return;
|
||||
}
|
||||
setSavingWorkers(true);
|
||||
api
|
||||
.setSettings({
|
||||
workers: total,
|
||||
worker_pools: workerPools.map((pool) => ({ ...pool, workers: Number(pool.workers) })),
|
||||
})
|
||||
.then((s) => {
|
||||
apply(s);
|
||||
toast.success("已保存多模型 Worker 池(对之后启动的任务生效)");
|
||||
})
|
||||
.catch((e) => toast.error(`保存失败:${(e as Error).message}`))
|
||||
.finally(() => setSavingWorkers(false));
|
||||
return;
|
||||
}
|
||||
if (!Number.isInteger(n) || n <= 0) {
|
||||
toast.error("并发数必须是大于 0 的整数");
|
||||
return;
|
||||
}
|
||||
setSavingWorkers(true);
|
||||
api
|
||||
.setSettings({ workers: n })
|
||||
.setSettings({ workers: n, worker_pools: [] })
|
||||
.then((s) => {
|
||||
apply(s);
|
||||
toast.success("已保存并发工作 agent 数(对之后启动的任务生效)");
|
||||
@@ -89,6 +125,8 @@ export default function SystemSettingsPage() {
|
||||
.finally(() => setSavingWorkers(false));
|
||||
};
|
||||
|
||||
const addWorkerPool = () => setWorkerPools((pools) => [...pools, { profile_id: "", workers: 1 }]);
|
||||
|
||||
const savePython = () => {
|
||||
setSaving(true);
|
||||
api
|
||||
@@ -117,6 +155,13 @@ export default function SystemSettingsPage() {
|
||||
.finally(() => setLoaded(true));
|
||||
}, [apply]);
|
||||
|
||||
React.useEffect(() => {
|
||||
api
|
||||
.llmProfiles()
|
||||
.then(setLlmProfiles)
|
||||
.catch(() => setLlmProfiles([]));
|
||||
}, []);
|
||||
|
||||
const toggleTraffic = (v: boolean) => {
|
||||
setTrafficCapture(v); // optimistic
|
||||
setSaving(true);
|
||||
@@ -756,6 +801,73 @@ export default function SystemSettingsPage() {
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
<div className="flex flex-col gap-2 rounded-md border p-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-sm">多模型 Worker 池</Label>
|
||||
<Button variant="outline" size="sm" onClick={addWorkerPool} disabled={!loaded || savingWorkers}>
|
||||
添加模型池
|
||||
</Button>
|
||||
</div>
|
||||
{workerPools.map((pool, index) => {
|
||||
const selected = llmProfiles.find((profile) => profile.id === pool.profile_id);
|
||||
const placeholder =
|
||||
selected?.name || (pool.profile_id ? `配置 #${pool.profile_id} 已删除/不可用` : "选择 LLM 配置");
|
||||
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}
|
||||
onValueChange={(value) =>
|
||||
setWorkerPools((current) =>
|
||||
current.map((item, itemIndex) =>
|
||||
itemIndex === index ? { ...item, profile_id: value } : item,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
<SelectTrigger className="min-w-0 flex-1">
|
||||
<SelectValue placeholder={placeholder} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{!selected && pool.profile_id ? (
|
||||
<SelectItem value={pool.profile_id}>配置 #{pool.profile_id} 已删除/不可用</SelectItem>
|
||||
) : null}
|
||||
{llmProfiles.map((profile) => (
|
||||
<SelectItem key={profile.id} value={profile.id}>
|
||||
{profile.name} · {profile.model}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
className="w-24 font-mono text-sm"
|
||||
value={pool.workers}
|
||||
onChange={(event) =>
|
||||
setWorkerPools((current) =>
|
||||
current.map((item, itemIndex) =>
|
||||
itemIndex === index ? { ...item, workers: Number(event.target.value) } : item,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setWorkerPools((current) => current.filter((_, itemIndex) => itemIndex !== index))}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{workerPools.length > 0 ? (
|
||||
<div className="text-muted-foreground text-sm">
|
||||
当前合计:{workerPools.reduce((sum, pool) => sum + (Number(pool.workers) || 0), 0)} 个 Worker 会话
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
type="number"
|
||||
@@ -763,9 +875,12 @@ export default function SystemSettingsPage() {
|
||||
className="w-32 font-mono text-sm"
|
||||
placeholder="3"
|
||||
value={workers}
|
||||
disabled={!loaded || savingWorkers}
|
||||
disabled={!loaded || savingWorkers || workerPools.length > 0}
|
||||
onChange={(e) => setWorkers(e.target.value)}
|
||||
/>
|
||||
{workerPools.length > 0 ? (
|
||||
<span className="text-muted-foreground text-xs">已配置模型池时由各池数量决定并发。</span>
|
||||
) : null}
|
||||
<Button onClick={saveWorkers} disabled={!loaded || savingWorkers}>
|
||||
保存
|
||||
</Button>
|
||||
|
||||
@@ -3338,6 +3338,7 @@ export const settings: Settings = {
|
||||
global_proxy: "",
|
||||
python_interpreter: "/usr/bin/python3",
|
||||
workers: 3,
|
||||
worker_pools: [],
|
||||
llm_pool_enabled: true,
|
||||
llm_pool_bind_fallback: false,
|
||||
noa_compaction: false,
|
||||
|
||||
@@ -2249,7 +2249,15 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
if (path === "/traffic") return D.traffic;
|
||||
if (path === "/traffic/exchange") return D.trafficDetail;
|
||||
if (path === "/settings" && m === "GET") return D.settings;
|
||||
if (path === "/settings" && m === "PUT") return { ...D.settings, ...b };
|
||||
if (path === "/settings" && m === "PUT") {
|
||||
const next = { ...D.settings, ...b };
|
||||
if (!Array.isArray(next.worker_pools)) next.worker_pools = D.settings.worker_pools;
|
||||
if (next.worker_pools.length > 0) {
|
||||
next.workers = next.worker_pools.reduce((sum, pool) => sum + Number(pool.workers), 0);
|
||||
}
|
||||
Object.assign(D.settings, next);
|
||||
return next;
|
||||
}
|
||||
if (path === "/settings/basic-auth" && m === "GET") return { enabled: false, username: "", password_set: false };
|
||||
if (path === "/settings/basic-auth" && m === "PUT")
|
||||
throw new Error("演示模式不支持修改 HTTP Basic Auth,请在实际部署中配置");
|
||||
@@ -2467,7 +2475,8 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
|
||||
const from = q.get("from") || "";
|
||||
const to = q.get("to") || "";
|
||||
if (status && !["pending", "allowed", "denied", "timeout"].includes(status)) throw new Error("无效审批状态");
|
||||
if (decisionSource && !["model", "rule", "manual", "unknown"].includes(decisionSource)) throw new Error("无效判定来源");
|
||||
if (decisionSource && !["model", "rule", "manual", "unknown"].includes(decisionSource))
|
||||
throw new Error("无效判定来源");
|
||||
if ([...search].length > 200) throw new Error("搜索关键词不能超过 200 个字符");
|
||||
if (search.startsWith("#") && !/^#[1-9]\d*$/.test(search)) throw new Error("审批编号必须为 # 后接正整数");
|
||||
for (const value of [from, to]) {
|
||||
|
||||
@@ -968,6 +968,7 @@ export interface Settings {
|
||||
global_proxy?: string;
|
||||
python_interpreter?: string; // 自定义脚本工具的 python 解释器路径(空=运行时检测)
|
||||
workers?: number; // 并发工作 agent 数(默认3);对之后启动的任务生效
|
||||
worker_pools: WorkerPool[];
|
||||
// 任务并发上限:同时「运行中」的任务数上限。关闭=不限;开启后新建任务超限则排队,有空位自动启动。
|
||||
task_concurrency_enabled?: boolean; // 默认 false
|
||||
task_concurrency_limit?: number; // 开启后默认 5
|
||||
@@ -989,6 +990,11 @@ export interface Settings {
|
||||
notify_digest_interval_min?: number; // 汇总模式周期(分钟),默认 30
|
||||
}
|
||||
|
||||
export interface WorkerPool {
|
||||
profile_id: string;
|
||||
workers: number;
|
||||
}
|
||||
|
||||
// ---- 漏洞 IM 推送 ----
|
||||
|
||||
// NotificationFilter 是渠道的过滤条件,字段全部可选,缺省即不过滤。
|
||||
|
||||
Reference in new issue
Block a user