

























@@ -142,6 +142,39 @@ function sleep(ms) {
142142});
143143}
144144145+function escapeRegExp(value) {
146+return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
147+}
148+149+function redactDiagnosticText(text, extraSecrets = []) {
150+let redacted = text;
151+for (const secret of [email, password, ...extraSecrets]) {
152+if (!secret) {
153+continue;
154+}
155+redacted = redacted.replace(new RegExp(escapeRegExp(secret), "g"), "<redacted>");
156+redacted = redacted.replace(
157+new RegExp(escapeRegExp(JSON.stringify(secret).slice(1, -1)), "g"),
158+"<redacted>",
159+);
160+}
161+return redacted;
162+}
163+164+function cookieSecretValues(cookieHeader) {
165+if (!cookieHeader) {
166+return [];
167+}
168+return cookieHeader
169+.split(";")
170+.map((part) => {
171+const text = part.trim();
172+const separatorIndex = text.indexOf("=");
173+return separatorIndex === -1 ? "" : text.slice(separatorIndex + 1).trim();
174+})
175+.filter(Boolean);
176+}
177+145178async function fetchSignin() {
146179return await withRequestTimeout(
147180"Open WebUI signin",
@@ -155,7 +188,7 @@ async function fetchSignin() {
155188});
156189if (!response.ok) {
157190const body = await readBoundedResponseText(response, "Open WebUI signin", timeoutPromise);
158-throw new Error(`signin failed: HTTP ${response.status} ${body}`);
191+throw new Error(`signin failed: HTTP ${response.status} ${redactDiagnosticText(body)}`);
159192}
160193return {
161194cookie: getCookieHeader(response),
@@ -165,21 +198,22 @@ async function fetchSignin() {
165198);
166199}
167200168-async function fetchModels(authHeaders, attempt) {
201+async function fetchModels(authHeaders, attempt, diagnosticSecrets) {
169202return await withRequestTimeout(
170203`Open WebUI models attempt ${attempt}`,
171204controlTimeoutMs,
172205async (signal, timeoutPromise) => {
173206const response = await fetch(`${baseUrl}/api/models`, { headers: authHeaders, signal });
174207if (!response.ok) {
208+const text = await readBoundedResponseText(
209+response,
210+`Open WebUI models attempt ${attempt}`,
211+timeoutPromise,
212+);
175213return {
176214ok: false,
177215status: response.status,
178-text: await readBoundedResponseText(
179-response,
180-`Open WebUI models attempt ${attempt}`,
181-timeoutPromise,
182-),
216+text: redactDiagnosticText(text, diagnosticSecrets),
183217};
184218}
185219return {
@@ -194,7 +228,7 @@ async function fetchModels(authHeaders, attempt) {
194228);
195229}
196230197-async function fetchChatCompletion(authHeaders, targetModel) {
231+async function fetchChatCompletion(authHeaders, targetModel, diagnosticSecrets) {
198232return await withRequestTimeout(
199233"Open WebUI chat completion",
200234chatTimeoutMs,
@@ -217,7 +251,12 @@ async function fetchChatCompletion(authHeaders, targetModel) {
217251"Open WebUI chat completion",
218252timeoutPromise,
219253);
220-throw new Error(`/api/chat/completions failed: HTTP ${response.status} ${body}`);
254+throw new Error(
255+`/api/chat/completions failed: HTTP ${response.status} ${redactDiagnosticText(
256+ body,
257+ diagnosticSecrets,
258+ )}`,
259+);
221260}
222261return await readBoundedResponseJson(response, "Open WebUI chat completion", timeoutPromise);
223262},
@@ -245,12 +284,13 @@ const authHeaders = {
245284 ...buildAuthHeaders(token, signin.cookie),
246285accept: "application/json",
247286};
287+const diagnosticSecrets = [token, signin.cookie, ...cookieSecretValues(signin.cookie)];
248288249289let modelIds = [];
250290let targetModel = "";
251291let lastModelsError = "";
252292for (let attempt = 1; attempt <= modelAttempts; attempt += 1) {
253-const modelsResult = await fetchModels(authHeaders, attempt).catch(
293+const modelsResult = await fetchModels(authHeaders, attempt, diagnosticSecrets).catch(
254294/** @param {unknown} error */ (error) => {
255295lastModelsError = error instanceof Error ? error.message : String(error);
256296return undefined;
@@ -281,7 +321,7 @@ if (smokeMode === "models") {
281321process.exit(0);
282322}
283323284-const chatJson = await fetchChatCompletion(authHeaders, targetModel);
324+const chatJson = await fetchChatCompletion(authHeaders, targetModel, diagnosticSecrets);
285325const reply =
286326chatJson?.choices?.[0]?.message?.content ?? chatJson?.message?.content ?? chatJson?.content ?? "";
287327if (typeof reply !== "string" || !reply.includes(expectedNonce)) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。