Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): localize missing request secret errors
Xubin Ren7575269e7a42
diff --git a/webui/src/components/settings/models/ProviderParameterFields.tsx b/webui/src/components/settings/models/ProviderParameterFields.tsxindex b1e34b0a2..c4aa71eab 100644--- a/webui/src/components/settings/models/ProviderParameterFields.tsx+++ b/webui/src/components/settings/models/ProviderParameterFields.tsx@@ -7,6 +7,7 @@ import {type ProviderForm,} from "@/components/settings/models/providerForm";import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";+import { ApiError } from "@/lib/api";const PARAMETER_FIELDS = [{ field: "extra_headers", formKey: "extraHeaders", titleKey: "settings.providers.extraHeaders", placeholder: '{"X-Header":"value"}' },@@ -56,8 +57,18 @@ export function ProviderParameterFields({ fields, form, onChange, onSave, inherithrow new Error(t("settings.providers.stringValuesRequired"));}const update = { [item.formKey]: value };- if (onSave) await onSave(update);- else onChange(update);+ try {+ if (onSave) await onSave(update);+ else onChange(update);+ } catch (error) {+ // The gateway alone can tell whether a mask has a saved value to retain.+ if (item.field !== "extra_body" && error instanceof ApiError && error.status === 400+ && Object.entries(parsed).some(([key, entry]) => entry === "••••••••"+ && error.message === `${item.field}.${key}: Input should be a valid string`)) {+ throw new Error(t("settings.providers.maskedSecretMissing"), { cause: error });+ }+ throw error;+ }}}trigger={<button type="button" className="settings-hover flex min-h-12 w-full items-center gap-3 border-b border-border/60 px-3 py-3 text-left last:border-b-0">diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.jsonindex b12d7d4ff..0337bc9bf 100644--- a/webui/src/i18n/locales/en/common.json+++ b/webui/src/i18n/locales/en/common.json@@ -1195,6 +1195,7 @@"draftHint": "Save the new preset to apply these settings.","invalidObject": "Enter a JSON object, for example: {\"key\":\"value\"}.","stringValuesRequired": "Use text values for headers and query parameters.",+ "maskedSecretMissing": "No saved secret matches this mask. Enter the actual value or remove the entry.","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "Local",diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.jsonindex e63971726..96ef6e11d 100644--- a/webui/src/i18n/locales/es/common.json+++ b/webui/src/i18n/locales/es/common.json@@ -771,6 +771,7 @@"draftHint": "Guarda el nuevo preajuste para aplicar estos ajustes.","invalidObject": "Introduce un objeto JSON, por ejemplo: {\"key\":\"value\"}.","stringValuesRequired": "Usa valores de texto en cabeceras y parámetros de consulta.",+ "maskedSecretMissing": "No hay un secreto guardado que corresponda a esta máscara. Introduce el valor real o elimina la entrada.","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "Local",diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.jsonindex 5e658624e..dd7c78638 100644--- a/webui/src/i18n/locales/fr/common.json+++ b/webui/src/i18n/locales/fr/common.json@@ -771,6 +771,7 @@"draftHint": "Enregistrez le nouveau préréglage pour appliquer ces réglages.","invalidObject": "Saisissez un objet JSON, par exemple : {\"key\":\"value\"}.","stringValuesRequired": "Utilisez des valeurs textuelles pour les en-têtes et les paramètres de requête.",+ "maskedSecretMissing": "Aucun secret enregistré ne correspond à ce masque. Saisissez la valeur réelle ou supprimez l’entrée.","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "Local",diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.jsonindex 4aa7eb014..9f4cfa62d 100644--- a/webui/src/i18n/locales/id/common.json+++ b/webui/src/i18n/locales/id/common.json@@ -771,6 +771,7 @@"draftHint": "Simpan preset baru untuk menerapkan pengaturan ini.","invalidObject": "Masukkan objek JSON, misalnya: {\"key\":\"value\"}.","stringValuesRequired": "Gunakan nilai teks untuk header dan parameter kueri.",+ "maskedSecretMissing": "Tidak ada rahasia tersimpan yang sesuai dengan nilai tersamarkan ini. Masukkan nilai sebenarnya atau hapus entri ini.","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "Lokal",diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.jsonindex 6249e5457..5c2e8226a 100644--- a/webui/src/i18n/locales/ja/common.json+++ b/webui/src/i18n/locales/ja/common.json@@ -771,6 +771,7 @@"draftHint": "新しいプリセットを保存すると、この設定が適用されます。","invalidObject": "JSON オブジェクトを入力してください。例:{\"key\":\"value\"}。","stringValuesRequired": "ヘッダーとクエリパラメーターの値には文字列を使用してください。",+ "maskedSecretMissing": "このマスクに対応する保存済みのシークレットがありません。実際の値を入力するか、この項目を削除してください。","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "ローカル",diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.jsonindex 7bf8fab20..e8d4fd381 100644--- a/webui/src/i18n/locales/ko/common.json+++ b/webui/src/i18n/locales/ko/common.json@@ -771,6 +771,7 @@"draftHint": "새 프리셋을 저장하면 이 설정이 적용됩니다.","invalidObject": "JSON 객체를 입력하세요. 예: {\"key\":\"value\"}.","stringValuesRequired": "헤더와 쿼리 매개변수의 값은 문자열로 입력하세요.",+ "maskedSecretMissing": "이 마스크에 해당하는 저장된 비밀 값이 없습니다. 실제 값을 입력하거나 항목을 삭제하세요.","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "로컬",diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.jsonindex 33445ecbb..2adcb37b0 100644--- a/webui/src/i18n/locales/pt-BR/common.json+++ b/webui/src/i18n/locales/pt-BR/common.json@@ -1009,6 +1009,7 @@"draftHint": "Salve a nova predefinição para aplicar estes ajustes.","invalidObject": "Insira um objeto JSON, por exemplo: {\"key\":\"value\"}.","stringValuesRequired": "Use valores de texto nos cabeçalhos e parâmetros de consulta.",+ "maskedSecretMissing": "Nenhum segredo salvo corresponde a esta máscara. Digite o valor real ou remova a entrada.","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "Local",diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.jsonindex 2e72e99fc..3091c47c4 100644--- a/webui/src/i18n/locales/vi/common.json+++ b/webui/src/i18n/locales/vi/common.json@@ -771,6 +771,7 @@"draftHint": "Lưu cấu hình mẫu mới để áp dụng các thiết lập này.","invalidObject": "Nhập một đối tượng JSON, ví dụ: {\"key\":\"value\"}.","stringValuesRequired": "Dùng giá trị văn bản cho tiêu đề và tham số truy vấn.",+ "maskedSecretMissing": "Không có giá trị bí mật đã lưu tương ứng với phần che này. Nhập giá trị thật hoặc xóa mục này.","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "Cục bộ",diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.jsonindex ff8052257..1f5b5d5b2 100644--- a/webui/src/i18n/locales/zh-CN/common.json+++ b/webui/src/i18n/locales/zh-CN/common.json@@ -1195,6 +1195,7 @@"draftHint": "保存新预设后,这些设置才会生效。","invalidObject": "请输入 JSON 对象,例如:{\"key\":\"value\"}。","stringValuesRequired": "请求头和查询参数的值须使用文本。",+ "maskedSecretMissing": "掩码没有对应的已保存密钥。请输入实际值,或删除该项。","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "本地",diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.jsonindex 7f66c721c..cf462c557 100644--- a/webui/src/i18n/locales/zh-TW/common.json+++ b/webui/src/i18n/locales/zh-TW/common.json@@ -771,6 +771,7 @@"draftHint": "儲存新預設後,這些設定才會生效。","invalidObject": "請輸入 JSON 物件,例如:{\"key\":\"value\"}。","stringValuesRequired": "請求標頭和查詢參數的值須使用文字。",+ "maskedSecretMissing": "遮罩沒有對應的已儲存金鑰。請輸入實際值,或刪除該項。","providerGroupOAuth": "OAuth","providerGroupApiKey": "API Key","providerGroupLocal": "本地",diff --git a/webui/src/tests/i18n.test.tsx b/webui/src/tests/i18n.test.tsxindex c188844c3..44b0904e5 100644--- a/webui/src/tests/i18n.test.tsx+++ b/webui/src/tests/i18n.test.tsx@@ -49,6 +49,7 @@ const SETTINGS_NAV_KEYS = ["advanced",];const LOCALIZED_SETTINGS_COPY_KEYS = [+ "settings.providers.maskedSecretMissing","settings.backToChat","settings.sidebar.title","settings.sidebar.ariaLabel",diff --git a/webui/src/tests/provider-parameter-fields.test.tsx b/webui/src/tests/provider-parameter-fields.test.tsxindex 1b1b3ed31..a341939de 100644--- a/webui/src/tests/provider-parameter-fields.test.tsx+++ b/webui/src/tests/provider-parameter-fields.test.tsx@@ -2,12 +2,44 @@ import { act, cleanup, fireEvent, render, screen, within } from "@testing-librarimport { afterEach, beforeEach, expect, it, vi } from "vitest";import { ProviderParameterFields } from "@/components/settings/models/ProviderParameterFields";import i18n from "@/i18n";+import { ApiError } from "@/lib/api";beforeEach(async () => { await i18n.changeLanguage("en"); });afterEach(cleanup);const form = { extraHeaders: "", extraQuery: "", extraBody: "{}" };+it.each([+ { field: "extra_headers", formKey: "extraHeaders", title: "请求头" },+ { field: "extra_query", formKey: "extraQuery", title: "查询参数" },+] as const)("localizes a rejected secret mask in $field and allows a corrected retry", async ({ field, formKey, title }) => {+ await i18n.changeLanguage("zh-CN");+ const save = vi.fn().mockRejectedValueOnce(new ApiError(400, `${field}.X-Token: Input should be a valid string`)).mockResolvedValue(undefined);+ render(<ProviderParameterFields inherit fields={[field]} form={form} onChange={vi.fn()} onSave={save} />);+ fireEvent.click(screen.getByRole("button", { name: `${title} 使用提供商设置 编辑` }));+ const dialog = screen.getByRole("dialog", { name: title });+ const editor = within(dialog).getByRole("textbox");+ fireEvent.change(editor, { target: { value: '{"X-Token":"••••••••"}' } });+ fireEvent.click(within(dialog).getByRole("button", { name: "保存", exact: true }));+ expect(await within(dialog).findByRole("alert")).toHaveTextContent("掩码没有对应的已保存密钥。请输入实际值,或删除该项。");+ expect(editor).toHaveValue('{"X-Token":"••••••••"}');+ expect(editor).toHaveFocus();+ fireEvent.change(editor, { target: { value: '{"X-Token":"fixture-value"}' } });+ await act(async () => { fireEvent.click(within(dialog).getByRole("button", { name: "保存", exact: true })); });+ expect(save).toHaveBeenLastCalledWith({ [formKey]: '{"X-Token":"fixture-value"}' });+ expect(screen.queryByRole("dialog", { name: title })).not.toBeInTheDocument();+});++it("lets the gateway preserve an existing masked secret without rejecting it in the editor", async () => {+ const masked = '{"X-Token":"••••••••"}';+ const save = vi.fn().mockResolvedValue(undefined);+ render(<ProviderParameterFields inherit fields={["extra_headers"]} form={{ ...form, extraHeaders: masked }} onChange={vi.fn()} onSave={save} />);+ fireEvent.click(screen.getByRole("button", { name: "Headers Entries: 1 Edit" }));+ await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Save", exact: true })); });+ expect(save).toHaveBeenCalledWith({ extraHeaders: masked });+ expect(screen.queryByRole("dialog", { name: "Headers" })).not.toBeInTheDocument();+});+it("distinguishes a new preset draft from persisted settings and validates before applying", async () => {const change = vi.fn();render(<ProviderParameterFields inherit draft fields={["extra_headers"]} form={form} onChange={change} />);