






















@@ -7,14 +7,15 @@ const email = process.env.OPENWEBUI_ADMIN_EMAIL ?? "";
77const password = process.env.OPENWEBUI_ADMIN_PASSWORD ?? "";
88const expectedNonce = process.env.OPENWEBUI_EXPECTED_NONCE ?? "";
99const prompt = process.env.OPENWEBUI_PROMPT ?? "";
10+const MAX_TIMER_TIMEOUT_MS = 2_147_000_000;
1011const modelAttempts = readPositiveInt("OPENWEBUI_MODEL_ATTEMPTS", 72);
11-const modelRetryMs = readNonNegativeInt("OPENWEBUI_MODEL_RETRY_MS", 5000);
12-const fetchTimeoutMs = readPositiveInt("OPENWEBUI_FETCH_TIMEOUT_MS", 720000);
13-const controlTimeoutMs = readPositiveInt(
12+const modelRetryMs = readNonNegativeTimerMs("OPENWEBUI_MODEL_RETRY_MS", 5000);
13+const fetchTimeoutMs = readPositiveTimerMs("OPENWEBUI_FETCH_TIMEOUT_MS", 720000);
14+const controlTimeoutMs = readPositiveTimerMs(
1415"OPENWEBUI_CONTROL_TIMEOUT_MS",
1516Math.min(fetchTimeoutMs, 30000),
1617);
17-const chatTimeoutMs = readPositiveInt("OPENWEBUI_CHAT_TIMEOUT_MS", fetchTimeoutMs);
18+const chatTimeoutMs = readPositiveTimerMs("OPENWEBUI_CHAT_TIMEOUT_MS", fetchTimeoutMs);
1819const responseBodyMaxBytes = readPositiveInt("OPENWEBUI_RESPONSE_BODY_MAX_BYTES", 1024 * 1024);
1920const smokeMode =
2021process.env.OPENWEBUI_SMOKE_MODE ?? process.env.OPENCLAW_OPENWEBUI_SMOKE_MODE ?? "chat";
@@ -65,21 +66,36 @@ function readNonNegativeInt(name, fallback) {
6566return parsed;
6667}
676869+function clampTimerTimeoutMs(valueMs, minMs = 1) {
70+const min = Math.max(0, Math.floor(minMs));
71+const value = Number.isFinite(valueMs) ? valueMs : min;
72+return Math.min(Math.max(Math.floor(value), min), MAX_TIMER_TIMEOUT_MS);
73+}
74+75+function readPositiveTimerMs(name, fallback) {
76+return clampTimerTimeoutMs(readPositiveInt(name, fallback));
77+}
78+79+function readNonNegativeTimerMs(name, fallback) {
80+return clampTimerTimeoutMs(readNonNegativeInt(name, fallback), 0);
81+}
82+6883function createTimeoutError(label, timeoutMs) {
6984const error = new Error(`${label} timed out after ${timeoutMs}ms`);
7085error.code = "ETIMEDOUT";
7186return error;
7287}
73887489async function withRequestTimeout(label, timeoutMs, run) {
90+const resolvedTimeoutMs = clampTimerTimeoutMs(timeoutMs);
7591const controller = new AbortController();
76-const timeoutError = createTimeoutError(label, timeoutMs);
92+const timeoutError = createTimeoutError(label, resolvedTimeoutMs);
7793let timer;
7894const timeoutPromise = new Promise((_, reject) => {
7995timer = setTimeout(() => {
8096controller.abort(timeoutError);
8197reject(timeoutError);
82-}, timeoutMs);
98+}, resolvedTimeoutMs);
8399timer.unref?.();
84100});
85101try {
@@ -138,7 +154,7 @@ function buildAuthHeaders(token, cookie) {
138154139155function sleep(ms) {
140156return new Promise((resolve) => {
141-setTimeout(resolve, ms);
157+setTimeout(resolve, clampTimerTimeoutMs(ms, 0));
142158});
143159}
144160此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。