From 14fa749ca9fd743a867b420d1083b25a365069c8 Mon Sep 17 00:00:00 2001 From: Dex Miller Date: Fri, 6 Feb 2026 16:03:39 +0800 Subject: [PATCH] fix(opencode): reject save when no models configured (#932) Add validation to require at least one model before saving an OpenCode provider. Shows a localized toast error when models are empty. --- src/components/providers/forms/ProviderForm.tsx | 7 ++++++- src/i18n/locales/en.json | 1 + src/i18n/locales/ja.json | 1 + src/i18n/locales/zh.json | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/providers/forms/ProviderForm.tsx b/src/components/providers/forms/ProviderForm.tsx index ee7f19b02..8db5ca19e 100644 --- a/src/components/providers/forms/ProviderForm.tsx +++ b/src/components/providers/forms/ProviderForm.tsx @@ -746,7 +746,7 @@ export function ProviderForm({ return; } - // OpenCode: validate provider key + // OpenCode: validate provider key and models if (appId === "opencode") { const keyPattern = /^[a-z0-9]+(-[a-z0-9]+)*$/; if (!opencodeProviderKey.trim()) { @@ -761,6 +761,11 @@ export function ProviderForm({ toast.error(t("opencode.providerKeyDuplicate")); return; } + // Validate that at least one model is configured + if (Object.keys(opencodeModels).length === 0) { + toast.error(t("opencode.modelsRequired")); + return; + } } // 非官方供应商必填校验:端点和 API Key diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 4380ea56e..16d02e2a6 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -633,6 +633,7 @@ "modelId": "Model ID", "modelName": "Display Name", "noModels": "No models configured", + "modelsRequired": "Please add at least one model", "providerKey": "Provider Key", "providerKeyPlaceholder": "my-provider", "providerKeyHint": "Unique identifier in config file. Cannot be changed after creation. Use lowercase letters, numbers, and hyphens only.", diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index b16bb8fd0..a1c16d1ca 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -633,6 +633,7 @@ "modelId": "モデル ID", "modelName": "表示名", "noModels": "モデルが設定されていません", + "modelsRequired": "モデルを少なくとも1つ追加してください", "providerKey": "プロバイダーキー", "providerKeyPlaceholder": "my-provider", "providerKeyHint": "設定ファイルの一意の識別子。作成後は変更できません。小文字、数字、ハイフンのみ使用できます。", diff --git a/src/i18n/locales/zh.json b/src/i18n/locales/zh.json index a1a2b3a14..6da926cfe 100644 --- a/src/i18n/locales/zh.json +++ b/src/i18n/locales/zh.json @@ -633,6 +633,7 @@ "modelId": "模型 ID", "modelName": "显示名称", "noModels": "暂无模型配置", + "modelsRequired": "请至少添加一个模型配置", "providerKey": "供应商标识", "providerKeyPlaceholder": "my-provider", "providerKeyHint": "配置文件中的唯一标识符,创建后无法修改,只能使用小写字母、数字和连字符",