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:1.被引用的模型/agent删除提示2.model_provider-“请选择模型提供商”不可选3.校验未通过不给保存
openJiuwen-botebeb277ff9b9
diff --git a/jiuwenclaw/channels/web/frontend/src/components/ConfigPanel/index.tsx b/jiuwenclaw/channels/web/frontend/src/components/ConfigPanel/index.tsxindex 6f2a6fa0e6..14ebc32bd2 100644--- a/jiuwenclaw/channels/web/frontend/src/components/ConfigPanel/index.tsx+++ b/jiuwenclaw/channels/web/frontend/src/components/ConfigPanel/index.tsx@@ -721,12 +721,16 @@ function MultiModelSection({onModelsChange,onModelValidate,isConnected,+ agents,+ onDeleteModel,t,}: {models: ModelEntry[];onModelsChange: (models: ModelEntry[]) => void;onModelValidate?: (fields: { api_base: string; api_key: string; model: string; model_provider: string }) => Promise<void>;isConnected: boolean;+ agents?: AgentEntry[];+ onDeleteModel?: (idx: number, modelName: string, references: string[]) => void;t: (key: string, options?: Record<string, unknown>) => string;}) {const [validatingModel, setValidatingModel] = useState<string | null>(null);@@ -739,6 +743,19 @@ function MultiModelSection({const [localError, setLocalError] = useState<string | null>(null);const [validateToast, setValidateToast] = useState<{ show: boolean; success: boolean; message: string }>({ show: false, success: true, message: "" });+ const getModelAgentReferences = (modelName: string, modelProvider: string, modelApiBase: string): string[] => {+ if (!agents) return [];+ const references: string[] = [];+ agents.forEach((agent) => {+ if (agent.model.model === modelName &&+ agent.model.provider === modelProvider &&+ agent.model.api_base === modelApiBase) {+ references.push(agent.name);+ }+ });+ return references;+ };+const handleValidate = async (model: ModelEntry) => {if (!onModelValidate) return;setValidatingModel(model.model_name);@@ -813,27 +830,11 @@ function MultiModelSection({return;}setLocalError(null);- const next = models.filter((_, i) => i !== idx);- // 维持不变量:主对话默认(首位)必须是其所在组的组内默认- if (next.length > 0) {- const headName = next[0].model_name;- if (!next[0].is_default) {- next[0] = { ...next[0], is_default: true };- }- for (let i = 1; i < next.length; i++) {- if (next[i].model_name === headName && next[i].is_default) {- next[i] = { ...next[i], is_default: false };- }- }+ const model = models[idx];+ const references = getModelAgentReferences(model.model_name, model.model_provider, model.api_base);+ if (onDeleteModel) {+ onDeleteModel(idx, model.model_name, references);}- onModelsChange(next);- // 调整展开索引:删除项在展开项之前则前移,删除的正是展开项则收起- setExpandedIdx((prev) => {- if (prev === null) return null;- if (idx === prev) return null;- if (idx < prev) return prev - 1;- return prev;- });};const handleSetActive = (idx: number) => {@@ -953,8 +954,9 @@ function MultiModelSection({};return (- <div className="space-y-2">- {localError && (+ <>+ <div className="space-y-2">+ {localError && (<div className="rounded-md border border-[var(--border-danger)] bg-danger-subtle px-3 py-2 text-xs text-danger">{localError}</div>@@ -1065,7 +1067,7 @@ function MultiModelSection({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">- <option value="">{t("config.selectModelProvider")}</option>+ <option value="" disabled>{t("config.selectModelProvider")}</option>{MODEL_PROVIDER_OPTIONS.map((p) => <option key={p} value={p}>{p}</option>)}</select>) : (@@ -1112,7 +1114,7 @@ function MultiModelSection({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">- <option value="">{t("config.selectModelProvider")}</option>+ <option value="" disabled>{t("config.selectModelProvider")}</option>{MODEL_PROVIDER_OPTIONS.map((p) => <option key={p} value={p}>{p}</option>)}</select>) : (@@ -1141,6 +1143,7 @@ function MultiModelSection({</button>)}</div>+ </>);}@@ -1191,6 +1194,20 @@ function MultiAgentSection({return references;};+ // 检查模型是否被其他Agent引用(排除当前agentIdx)+ const getModelReferences = (modelName: string, modelProvider: string, modelApiBase: string, excludeIdx: number): string[] => {+ const references: string[] = [];+ agents.forEach((agent, agentIdx) => {+ if (agentIdx === excludeIdx) return;+ if (agent.model.model === modelName &&+ agent.model.provider === modelProvider &&+ agent.model.api_base === modelApiBase) {+ references.push(agent.name);+ }+ });+ return references;+ };+const handleRemoveAgent = (idx: number) => {const agentName = agents[idx]?.name;if (!agentName) return;@@ -1327,9 +1344,11 @@ function MultiAgentSection({const label = sameNameCount > 1? `${m.model_name} #${sameNameIdx + 1}`: m.model_name;+ const modelRefs = getModelReferences(m.model_name, m.model_provider, m.api_base, idx);+ const isReferenced = modelRefs.length > 0;return (<option key={`${m.model_name}#${mi}`} value={`${m.model_name}#${mi}`}>- {label}+ {label}{isReferenced ? ` (${t("config.model.referencedBy", { count: modelRefs.length })})` : ""}</option>);})}@@ -1356,7 +1375,7 @@ function MultiAgentSection({min="1"value={agent[field] ?? 1}onChange={(e) => {- const v = parseInt(e.target.value);+ const v = parseInt(e.target.value.replace(/^0+/, '') || '1');updateAgentField(idx, field, v > 0 ? v : 1);}}className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"@@ -1367,7 +1386,10 @@ function MultiAgentSection({step="0.1"min="0"value={agent[field] ?? 0}- onChange={(e) => updateAgentField(idx, field, parseFloat(e.target.value) || 0)}+ onChange={(e) => {+ const v = parseFloat(e.target.value.replace(/^0+/, '')) || 0;+ updateAgentField(idx, field, v >= 0 ? v : 0);+ }}className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"/>) : (@@ -1460,7 +1482,7 @@ function MultiAgentSection({min="1"value={newAgent[field] ?? 1}onChange={(e) => {- const v = parseInt(e.target.value);+ const v = parseInt(e.target.value.replace(/^0+/, '') || '1');setNewAgent((p) => ({ ...p, [field]: v > 0 ? v : 1 }));}}className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"@@ -1471,7 +1493,10 @@ function MultiAgentSection({step="0.1"min="0"value={newAgent[field] ?? 0}- onChange={(e) => setNewAgent((p) => ({ ...p, [field]: parseFloat(e.target.value) || 0 }))}+ onChange={(e) => {+ const v = parseFloat(e.target.value.replace(/^0+/, '')) || 0;+ setNewAgent((p) => ({ ...p, [field]: v >= 0 ? v : 0 }));+ }}className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"/>) : (@@ -1510,6 +1535,7 @@ function TeamItemSection({agents,onDeleteTeamMember,teamIdx,+ teams,t,}: {team: TeamEntry;@@ -1517,6 +1543,7 @@ function TeamItemSection({agents: AgentEntry[];onDeleteTeamMember?: (teamIdx: number, memberIdx: number, memberName: string) => void;teamIdx?: number;+ teams?: TeamEntry[];t: (key: string, options?: Record<string, unknown>) => string;}) {const [openLeader, setOpenLeader] = useState(false);@@ -1541,12 +1568,32 @@ function TeamItemSection({const checkEnglishOnly = (value: string): string | null => {if (!value) return null;- if (!/^[a-zA-Z]+$/.test(value)) {- return t("config.team.memberNameEnglishOnly");+ if (!/^[a-zA-Z0-9_]+$/.test(value)) {+ return t("config.team.memberNameFormatInvalid");}return null;};+ const getAgentTeamReferences = (agentName: string): string[] => {+ if (!teams) return [];+ const references: string[] = [];+ teams.forEach((teamItem, tIdx) => {+ if (teamIdx !== undefined && tIdx === teamIdx) return;+ if (teamItem.leader?.agent_key === agentName) {+ references.push(teamItem.team_name || t("config.team.untitled"));+ }+ if (teamItem.teammate?.agent_key === agentName) {+ references.push(teamItem.team_name || t("config.team.untitled"));+ }+ for (const member of teamItem.predefined_members || []) {+ if (member.agent_key === agentName) {+ references.push(teamItem.team_name || t("config.team.untitled"));+ }+ }+ });+ return references;+ };+const updateLeader = (field: keyof Leader, value: string) => {if (field === "member_name") {const duplicateError = checkMemberNameDuplicate(value, team.predefined_members || []);@@ -1738,9 +1785,15 @@ function TeamItemSection({className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"><option value="">-- Select Agent --</option>- {agents.map((agent) => (- <option key={agent.name} value={agent.name}>{agent.name || "(unnamed)"}</option>- ))}+ {agents.map((agent) => {+ const refs = getAgentTeamReferences(agent.name);+ const isReferenced = refs.length > 0;+ return (+ <option key={agent.name} value={agent.name}>+ {agent.name || "(unnamed)"}{isReferenced ? ` (${t("config.team.referencedByTeams", { count: refs.length })})` : ""}+ </option>+ );+ })}</select>) : (<div className="flex-1">@@ -1786,9 +1839,15 @@ function TeamItemSection({className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"><option value="">-- Select Agent --</option>- {agents.map((agent) => (- <option key={agent.name} value={agent.name}>{agent.name || "(unnamed)"}</option>- ))}+ {agents.map((agent) => {+ const refs = getAgentTeamReferences(agent.name);+ const isReferenced = refs.length > 0;+ return (+ <option key={agent.name} value={agent.name}>+ {agent.name || "(unnamed)"}{isReferenced ? ` (${t("config.team.referencedByTeams", { count: refs.length })})` : ""}+ </option>+ );+ })}</select>) : (<input@@ -1856,9 +1915,15 @@ function TeamItemSection({className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"><option value="">-- Select Agent --</option>- {agents.map((agent) => (- <option key={agent.name} value={agent.name}>{agent.name || "(unnamed)"}</option>- ))}+ {agents.map((agent) => {+ const refs = getAgentTeamReferences(agent.name);+ const isReferenced = refs.length > 0;+ return (+ <option key={agent.name} value={agent.name}>+ {agent.name || "(unnamed)"}{isReferenced ? ` (${t("config.team.referencedByTeams", { count: refs.length })})` : ""}+ </option>+ );+ })}</select>) : (<div className="flex-1">@@ -1893,9 +1958,15 @@ function TeamItemSection({className="flex-1 rounded border border-border bg-bg px-2 py-1 text-text text-xs"><option value="">-- Select Agent --</option>- {agents.map((agent) => (- <option key={agent.name} value={agent.name}>{agent.name || "(unnamed)"}</option>- ))}+ {agents.map((agent) => {+ const refs = getAgentTeamReferences(agent.name);+ const isReferenced = refs.length > 0;+ return (+ <option key={agent.name} value={agent.name}>+ {agent.name || "(unnamed)"}{isReferenced ? ` (${t("config.team.referencedByTeams", { count: refs.length })})` : ""}+ </option>+ );+ })}</select>) : (<div className="flex-1">@@ -2036,6 +2107,7 @@ function TeamsSection({agents={agents}onDeleteTeamMember={onDeleteTeamMember}teamIdx={idx}+ teams={teams}t={t}/></div>@@ -2127,6 +2199,7 @@ export function ConfigPanel({const [saving, setSaving] = useState(false);const [error, setError] = useState<string | null>(null);const [deleteAgentConfirm, setDeleteAgentConfirm] = useState<{ idx: number; agentName: string; references: string[] } | null>(null);+ const [deleteModelConfirm, setDeleteModelConfirm] = useState<{ idx: number; modelName: string; references: string[] } | null>(null);const [deleteTeamConfirm, setDeleteTeamConfirm] = useState<{ idx: number; teamName: string } | null>(null);const [deleteTeamMemberConfirm, setDeleteTeamMemberConfirm] = useState<{ teamIdx: number; memberIdx: number; memberName: string } | null>(null);const [installedSkills, setInstalledSkills] = useState<string[]>([]);@@ -2151,6 +2224,31 @@ export function ConfigPanel({setDeleteAgentConfirm({ idx, agentName, references });};+ const handleDeleteModel = (idx: number, modelName: string, references: string[]) => {+ setDeleteModelConfirm({ idx, modelName, references });+ };++ const confirmDeleteModel = () => {+ if (!deleteModelConfirm) return;+ const model = draftModels[deleteModelConfirm.idx];+ if (model) {+ const next = draftModels.filter((_, i) => i !== deleteModelConfirm.idx);+ if (next.length > 0) {+ const headName = next[0].model_name;+ if (!next[0].is_default) {+ next[0] = { ...next[0], is_default: true };+ }+ for (let i = 1; i < next.length; i++) {+ if (next[i].model_name === headName && next[i].is_default) {+ next[i] = { ...next[i], is_default: false };+ }+ }+ }+ setDraftModels(next);+ }+ setDeleteModelConfirm(null);+ };+const confirmDeleteAgent = () => {if (!deleteAgentConfirm) return;const deletedName = deleteAgentConfirm.agentName;@@ -2417,6 +2515,22 @@ export function ConfigPanel({[draftModels],);+ const hasAgentsTeamsValidationError = useMemo(() => {+ for (const agent of draftAgents) {+ if (!agent.name.trim()) return true;+ if (!agent.model.model.trim()) return true;+ }+ for (const team of draftTeams) {+ if (!team.team_name.trim()) return true;+ for (const member of team.predefined_members || []) {+ if (!member.member_name.trim()) return true;+ if (!/^[a-zA-Z0-9_]+$/.test(member.member_name)) return true;+ }+ if (team.leader?.member_name && !/^[a-zA-Z0-9_]+$/.test(team.leader.member_name)) return true;+ }+ return false;+ }, [draftAgents, draftTeams]);+const handleFieldChange = (key: string, value: string) => {setDraftValues((prev) => ({ ...prev, [key]: value }));if (error) {@@ -2569,7 +2683,7 @@ export function ConfigPanel({<buttontype="button"onClick={() => void handleSaveAndRestart()}- disabled={!hasChanges || saving || hasMissingRequiredModelFields || hasMissingModelApiKey || hasMissingModelApiBase || (isProcessing && mode !== 'team')}+ disabled={!hasChanges || saving || hasMissingRequiredModelFields || hasMissingModelApiKey || hasMissingModelApiBase || hasAgentsTeamsValidationError || (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')}@@ -2591,6 +2705,11 @@ export function ConfigPanel({{t('config.modelList.apiBaseRequired')}</div>) : null}+ {!error && hasAgentsTeamsValidationError ? (+ <div className="mb-4 rounded-md border border-[var(--border-danger)] bg-danger-subtle px-3 py-2 text-sm text-danger">+ {t('config.agentsTeamsValidationError')}+ </div>+ ) : null}{!groups.length ? (<div className="text-sm text-text-muted flex-1 min-h-0">@@ -2635,6 +2754,8 @@ export function ConfigPanel({onModelsChange={setDraftModels}onModelValidate={onModelValidate}isConnected={isConnected}+ agents={draftAgents}+ onDeleteModel={handleDeleteModel}t={t}/></div>@@ -2807,6 +2928,44 @@ export function ConfigPanel({</div></div>)}+ {deleteModelConfirm && (+ <div className="fixed inset-0 z-[9999] flex items-center justify-center p-4">+ <div className="absolute inset-0 bg-black/35 backdrop-blur-[4px]" />+ <div className="relative w-full max-w-96 rounded-xl border border-[var(--border)] bg-[var(--card)] shadow-[var(--shadow-xl)] p-6">+ <div className="flex flex-col items-center text-center">+ <div className="w-12 h-12 rounded-full bg-danger/15 text-danger flex items-center justify-center mb-4">+ <svg className="w-7 h-7" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2">+ <path strokeLinecap="round" strokeLinejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" />+ </svg>+ </div>+ <h3 className="text-base font-semibold text-text mb-1">+ {t("config.model.deleteConfirmTitle")}+ </h3>+ <p className="text-sm text-text-muted mb-5">+ {deleteModelConfirm.references.length > 0+ ? t("config.model.deleteConfirmMessageSimple", { modelName: deleteModelConfirm.modelName, count: deleteModelConfirm.references.length })+ : t("config.model.deleteConfirmMessage", { modelName: deleteModelConfirm.modelName })}+ </p>+ <div className="flex gap-2">+ <button+ type="button"+ onClick={() => setDeleteModelConfirm(null)}+ className="btn !px-4 !py-2"+ >+ {t("common.cancel")}+ </button>+ <button+ type="button"+ onClick={confirmDeleteModel}+ className="btn danger !px-4 !py-2"+ >+ {t("common.delete")}+ </button>+ </div>+ </div>+ </div>+ </div>+ )}{deleteTeamConfirm && (<div className="fixed inset-0 z-[9999] flex items-center justify-center p-4"><div className="absolute inset-0 bg-black/35 backdrop-blur-[4px]" />diff --git a/jiuwenclaw/channels/web/frontend/src/i18n/locales/en.json b/jiuwenclaw/channels/web/frontend/src/i18n/locales/en.jsonindex 85bf0ad168..0fd7a82000 100644--- a/jiuwenclaw/channels/web/frontend/src/i18n/locales/en.json+++ b/jiuwenclaw/channels/web/frontend/src/i18n/locales/en.json@@ -524,6 +524,7 @@"groupsCount": "{{count}} configuration groups","paramsCount": "{{count}} parameters","requiredIncomplete": "Required model configuration is incomplete",+ "agentsTeamsValidationError": "Agent/Team configuration validation failed, please check before saving","empty": "No configuration loaded yet. Please check the backend service status.","selectModelProvider": "Select a model provider","enterValue": "Enter a configuration value",@@ -588,6 +589,12 @@"alias": "Alias","aliasPlaceholder": "Optional, defaults to empty"},+ "model": {+ "referencedBy": "Referenced by {{count}} Agent(s)",+ "deleteConfirmTitle": "Delete Model?",+ "deleteConfirmMessage": "Are you sure you want to delete model \"{{modelName}}\"?",+ "deleteConfirmMessageSimple": "Model \"{{modelName}}\" is referenced by {{count}} Agent(s). After deletion, related Agents will no longer be able to use this model."+ },"agentList": {"addAgent": "Add Agent","removeAgent": "Remove",@@ -612,7 +619,9 @@"deleteMemberConfirmTitle": "Delete Member?","deleteMemberConfirmMessage": "Are you sure you want to delete member \"{{memberName}}\"?","duplicateMemberName": "Member name already exists",- "memberNameEnglishOnly": "Member name can only contain English letters"+ "memberNameEnglishOnly": "Member name can only contain English letters",+ "memberNameFormatInvalid": "Member name only supports letters/numbers/underscore",+ "referencedByTeams": "Referenced by {{count}} Team(s)"},"groups": {"modelDefault": { "label": "Default Model (Main Chat)", "hint": "Primary chat model service and auth" },diff --git a/jiuwenclaw/channels/web/frontend/src/i18n/locales/zh.json b/jiuwenclaw/channels/web/frontend/src/i18n/locales/zh.jsonindex 0b89c67ee4..e49fa83e22 100644--- a/jiuwenclaw/channels/web/frontend/src/i18n/locales/zh.json+++ b/jiuwenclaw/channels/web/frontend/src/i18n/locales/zh.json@@ -523,6 +523,7 @@"groupsCount": "共 {{count}} 个配置组","paramsCount": "{{count}} 项参数","requiredIncomplete": "模型配置必填项未完成",+ "agentsTeamsValidationError": "Agent/Team 配置校验未通过,请检查后保存","empty": "暂未获取到配置,请确认后端服务状态。","selectModelProvider": "请选择模型提供商","enterValue": "请输入配置值",@@ -587,6 +588,12 @@"alias": "别名","aliasPlaceholder": "选填,默认为空"},+ "model": {+ "referencedBy": "被 {{count}} 个 Agent 引用",+ "deleteConfirmTitle": "确认删除模型?",+ "deleteConfirmMessage": "确定要删除模型 \"{{modelName}}\" 吗?",+ "deleteConfirmMessageSimple": "模型 \"{{modelName}}\" 正在被 {{count}} 个 Agent 引用,删除后相关 Agent 将无法使用该模型。"+ },"agentList": {"addAgent": "添加Agent","removeAgent": "删除",@@ -611,7 +618,9 @@"deleteMemberConfirmTitle": "确认删除成员?","deleteMemberConfirmMessage": "确定要删除成员 \"{{memberName}}\" 吗?","duplicateMemberName": "成员名称已存在",- "memberNameEnglishOnly": "成员名称只能包含英文字母"+ "memberNameEnglishOnly": "成员名称只能包含英文字母",+ "memberNameFormatInvalid": "成员名称仅支持字母/数字/下划线",+ "referencedByTeams": "被 {{count}} 个 Team 引用"},"groups": {"modelDefault": { "label": "默认模型(主对话)", "hint": "主对话模型服务与鉴权参数" },