mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
refactor(openclaw): make primary model read-only in Agents panel
The primary model field in the Agents defaults panel now displays as read-only, eliminating the duplicate edit entry with the "Set as Default Model" button on provider cards. Fallback models and runtime parameters remain editable.
This commit is contained in:
@@ -17,7 +17,6 @@ const AgentsDefaultsPanel: React.FC = () => {
|
||||
const { data: agentsData, isLoading } = useOpenClawAgentsDefaults();
|
||||
const saveAgentsMutation = useSaveOpenClawAgentsDefaults();
|
||||
const [defaults, setDefaults] = useState<OpenClawAgentsDefaults | null>(null);
|
||||
const [primaryModel, setPrimaryModel] = useState("");
|
||||
const [fallbacks, setFallbacks] = useState("");
|
||||
|
||||
// Extra known fields from agents.defaults
|
||||
@@ -26,13 +25,15 @@ const AgentsDefaultsPanel: React.FC = () => {
|
||||
const [contextTokens, setContextTokens] = useState("");
|
||||
const [maxConcurrent, setMaxConcurrent] = useState("");
|
||||
|
||||
// Primary model is read-only — set via the "Set as default model" button on provider cards
|
||||
const primaryModel = agentsData?.model?.primary ?? "";
|
||||
|
||||
useEffect(() => {
|
||||
// agentsData is undefined while loading, null when config section is absent
|
||||
if (agentsData === undefined) return;
|
||||
setDefaults(agentsData);
|
||||
|
||||
if (agentsData) {
|
||||
setPrimaryModel(agentsData.model?.primary ?? "");
|
||||
setFallbacks((agentsData.model?.fallbacks ?? []).join(", "));
|
||||
|
||||
// Extract known extra fields
|
||||
@@ -48,17 +49,21 @@ const AgentsDefaultsPanel: React.FC = () => {
|
||||
// Preserve all unknown fields from original data
|
||||
const updated: OpenClawAgentsDefaults = { ...defaults };
|
||||
|
||||
// Model configuration
|
||||
// Model configuration — primary is read-only, preserve original value
|
||||
const fallbackList = fallbacks
|
||||
.split(",")
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
if (primaryModel.trim()) {
|
||||
const origPrimary = defaults?.model?.primary;
|
||||
if (origPrimary) {
|
||||
updated.model = {
|
||||
primary: primaryModel.trim(),
|
||||
primary: origPrimary,
|
||||
...(fallbackList.length > 0 ? { fallbacks: fallbackList } : {}),
|
||||
};
|
||||
} else if (fallbackList.length > 0) {
|
||||
// No primary set but user provided fallbacks — keep fallbacks only
|
||||
updated.model = { primary: "", fallbacks: fallbackList };
|
||||
}
|
||||
|
||||
// Optional fields
|
||||
@@ -122,12 +127,9 @@ const AgentsDefaultsPanel: React.FC = () => {
|
||||
<Label className="mb-1.5 block">
|
||||
{t("openclaw.agents.primaryModel")}
|
||||
</Label>
|
||||
<Input
|
||||
value={primaryModel}
|
||||
onChange={(e) => setPrimaryModel(e.target.value)}
|
||||
placeholder="provider/model-id"
|
||||
className="font-mono text-xs"
|
||||
/>
|
||||
<div className="h-9 px-3 flex items-center rounded-md border border-input bg-muted/50 font-mono text-xs text-muted-foreground">
|
||||
{primaryModel || t("openclaw.agents.notSet")}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
{t("openclaw.agents.primaryModelHint")}
|
||||
</p>
|
||||
|
||||
@@ -1218,7 +1218,8 @@
|
||||
"description": "Manage agents.defaults in openclaw.json (default model, runtime parameters, etc.)",
|
||||
"modelSection": "Model Configuration",
|
||||
"primaryModel": "Primary Model",
|
||||
"primaryModelHint": "Format: provider/model-id",
|
||||
"primaryModelHint": "Set via the \"Set as Default Model\" button in the provider list",
|
||||
"notSet": "Not set",
|
||||
"fallbackModels": "Fallback Models",
|
||||
"fallbackModelsHint": "Comma-separated, ordered by priority",
|
||||
"runtimeSection": "Runtime Parameters",
|
||||
|
||||
@@ -1218,7 +1218,8 @@
|
||||
"description": "openclaw.json の agents.defaults 設定を管理(デフォルトモデル、ランタイムパラメータなど)",
|
||||
"modelSection": "モデル設定",
|
||||
"primaryModel": "プライマリモデル",
|
||||
"primaryModelHint": "形式: provider/model-id",
|
||||
"primaryModelHint": "プロバイダ一覧の「デフォルトモデルに設定」ボタンで設定します",
|
||||
"notSet": "未設定",
|
||||
"fallbackModels": "フォールバックモデル",
|
||||
"fallbackModelsHint": "カンマ区切り、優先度順",
|
||||
"runtimeSection": "ランタイムパラメータ",
|
||||
|
||||
@@ -1218,7 +1218,8 @@
|
||||
"description": "管理 openclaw.json 中的 agents.defaults 配置(默认模型、运行参数等)",
|
||||
"modelSection": "模型配置",
|
||||
"primaryModel": "主模型",
|
||||
"primaryModelHint": "格式:provider/model-id",
|
||||
"primaryModelHint": "在供应商列表中通过「设为默认模型」按钮设置",
|
||||
"notSet": "未设置",
|
||||
"fallbackModels": "回退模型",
|
||||
"fallbackModelsHint": "逗号分隔,按优先级排列",
|
||||
"runtimeSection": "运行参数",
|
||||
|
||||
Reference in New Issue
Block a user