Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix: api_key设置为必填项

cycong_192f08a94a1be
diff --git a/jiuwenclaw/agentserver/deep_agent/interface_deep.py b/jiuwenclaw/agentserver/deep_agent/interface_deep.py
index dcde0eb3d2..6676fd6ea8 100644
--- a/jiuwenclaw/agentserver/deep_agent/interface_deep.py
+++ b/jiuwenclaw/agentserver/deep_agent/interface_deep.py
@@ -220,7 +220,6 @@ _ACP_BLOCKED_DEFAULT_TOOL_NAMES = frozenset(
"code",
}
)
-_PLACEHOLDER_API_KEYS = frozenset({"sk-xxxxxxxxx", "your-api-key", "your_api_key", "YOUR_API_KEY"})
_PLACEHOLDER_API_BASES = frozenset({"https://example.com/compatible-mode/v1"})
@@ -240,10 +239,10 @@ def _get_skill_create_enabled(config: dict[str, Any] | None) -> bool:
def _mcc_looks_usable(mcc: dict) -> bool:
- """检查 model_client_config 是否包含有效的 API 凭据(非占位符)。"""
+ """检查 model_client_config 是否包含有效的 API 凭据。"""
api_key = str(mcc.get("api_key", "") or "").strip()
api_base = str(mcc.get("api_base", "") or "").strip()
- return bool(api_key) and api_key not in _PLACEHOLDER_API_KEYS and api_base not in _PLACEHOLDER_API_BASES
+ return bool(api_key) and bool(api_base) and api_base not in _PLACEHOLDER_API_BASES
def parse_int(value: Any, default: int) -> int:
diff --git a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx b/jiuwenclaw/web/src/components/ConfigPanel/index.tsx
index d76b247ced..29970e7278 100644
--- a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx
+++ b/jiuwenclaw/web/src/components/ConfigPanel/index.tsx
@@ -813,6 +813,10 @@ function MultiModelSection({
const handleAddNew = () => {
const name = newModel.model_name.trim();
if (!name) return;
+ if (!newModel.api_key.trim()) {
+ setLocalError(t("config.modelList.apiKeyRequired"));
+ return;
+ }
setLocalError(null);
// 新增条目:同名组已有条目时 is_default=false,否则 is_default=true
const sameNameExists = models.some((m) => m.model_name === name);
@@ -927,7 +931,9 @@ function MultiModelSection({
<div className="border-t border-border px-3 py-2 space-y-2">
{(["model_name", "api_base", "api_key", "model_provider"] as const).map((field) => (
<div key={field} className="flex items-center gap-2 text-xs">
- <label className="w-28 text-text-muted shrink-0">{field}</label>
+ <label className="w-28 text-text-muted shrink-0">
+ {field}{field === "api_key" && <span className="text-danger ml-0.5">*</span>}
+ </label>
{field === "model_provider" ? (
<select
value={models[idx]?.[field] ?? ""}
@@ -943,6 +949,7 @@ function MultiModelSection({
value={models[idx]?.[field] ?? ""}
onChange={(e) => updateModel(idx, field, e.target.value)}
className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"
+ placeholder={field === "api_key" ? t("config.modelList.apiKeyPlaceholder") : ""}
/>
)}
</div>
@@ -971,7 +978,9 @@ function MultiModelSection({
<div className="rounded-lg border border-accent/40 bg-accent/5 px-3 py-2 space-y-2">
{(["model_name", "api_base", "api_key", "model_provider"] as const).map((field) => (
<div key={field} className="flex items-center gap-2 text-xs">
- <label className="w-28 text-text-muted shrink-0">{field}</label>
+ <label className="w-28 text-text-muted shrink-0">
+ {field}{field === "api_key" && <span className="text-danger ml-0.5">*</span>}
+ </label>
{field === "model_provider" ? (
<select
value={newModel[field]}
@@ -987,7 +996,7 @@ function MultiModelSection({
value={newModel[field]}
onChange={(e) => setNewModel((p) => ({ ...p, [field]: e.target.value }))}
className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"
- placeholder={field === "model_name" ? "e.g. gpt-4o" : ""}
+ placeholder={field === "model_name" ? "e.g. gpt-4o" : field === "api_key" ? t("config.modelList.apiKeyPlaceholder") : ""}
/>
)}
</div>
@@ -2014,6 +2023,10 @@ export function ConfigPanel({
[draftValues],
);
const hasMissingRequiredModelFields = missingRequiredModelFields.length > 0;
+ const hasMissingModelApiKey = useMemo(
+ () => draftModels.some((m) => !m.api_key.trim()),
+ [draftModels],
+ );
const handleFieldChange = (key: string, value: string) => {
setDraftValues((prev) => ({ ...prev, [key]: value }));
@@ -2039,6 +2052,10 @@ export function ConfigPanel({
setError(t('config.errors.requiredModelFields', { fields: missingRequiredModelFields.join('、') }));
return;
}
+ if (hasMissingModelApiKey) {
+ setError(t('config.modelList.apiKeyRequired'));
+ return;
+ }
setSaving(true);
setError(null);
try {
@@ -2162,7 +2179,7 @@ export function ConfigPanel({
<button
type="button"
onClick={() => void handleSaveAndRestart()}
- disabled={!hasChanges || saving || hasMissingRequiredModelFields || (isProcessing && mode !== 'team')}
+ disabled={!hasChanges || saving || hasMissingRequiredModelFields || hasMissingModelApiKey || (isProcessing && mode !== 'team')}
className="btn primary !px-3 !py-1.5 disabled:opacity-50 disabled:cursor-not-allowed"
>
{saving ? t('common.saving') : t('common.save')}
diff --git a/jiuwenclaw/web/src/i18n/locales/en.json b/jiuwenclaw/web/src/i18n/locales/en.json
index 67f05d2e4f..af623b4dbf 100644
--- a/jiuwenclaw/web/src/i18n/locales/en.json
+++ b/jiuwenclaw/web/src/i18n/locales/en.json
@@ -457,7 +457,9 @@
"groupDefault": "Group Default",
"setPrimaryDefault": "Set as Primary Default",
"isDefault": "Group Default",
- "onlyOneInGroup": "Only one in group, auto-default"
+ "onlyOneInGroup": "Only one in group, auto-default",
+ "apiKeyRequired": "API Key is required, please fill it in before saving",
+ "apiKeyPlaceholder": "Local models don't need an API Key — enter any value, e.g. sk-1234"
},
"agentList": {
"addAgent": "Add Agent",
diff --git a/jiuwenclaw/web/src/i18n/locales/zh.json b/jiuwenclaw/web/src/i18n/locales/zh.json
index fcbbbe5f12..205c5983a5 100644
--- a/jiuwenclaw/web/src/i18n/locales/zh.json
+++ b/jiuwenclaw/web/src/i18n/locales/zh.json
@@ -456,7 +456,9 @@
"groupDefault": "组内默认",
"setPrimaryDefault": "设为主对话默认",
"isDefault": "组内默认",
- "onlyOneInGroup": "同模型名仅一个,自动默认"
+ "onlyOneInGroup": "同模型名仅一个,自动默认",
+ "apiKeyRequired": "API Key 为必填项,请填写后再保存",
+ "apiKeyPlaceholder": "本地模型无需 API Key 可随意填写,如 sk-1234"
},
"agentList": {
"addAgent": "添加Agent",