Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src-tauri/src/agents/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,14 @@ pub(crate) async fn apply_agent_config(
oauth_configuration: bool,
claude_code_model_mappings: Option<ClaudeDesktopModelMappings>,
claude_desktop_model_mappings: Option<ClaudeDesktopModelMappings>,
codex_review_model: Option<codex_catalog::DefaultReviewModelRequest>,
) -> Result<AgentConfigActionResult, String> {
let client = AgentClient::parse(&client)?;
let _sync_guard = if client == AgentClient::Codex {
Some(CODEX_CATALOG_SYNC_LOCK.lock().await)
} else {
None
};
let home = app
.path()
.home_dir()
Expand All @@ -1069,7 +1075,17 @@ pub(crate) async fn apply_agent_config(
validate_codex_oauth_login(&home)?;
}
validate_agent_can_enable(client, &home, config.port, api_key)?;
let prepared = fetch_prepared_agent_models(client, &config).await?;
// 全局审批设置与主模型共用应用入口,生成时保留最新的单模型覆盖。
let runtime_models = if client == AgentClient::Codex && codex_review_model.is_some() {
Some(fetch_codex_catalog_runtime_models(&config).await?)
} else {
None
};
let prepared = if let Some(runtime_models) = &runtime_models {
prepare_codex_agent_models(runtime_models)?
} else {
fetch_prepared_agent_models(client, &config).await?
};
let model = resolve_available_agent_model(&prepared.models, &validate_agent_model(&model)?)?;
let claude_code_model_mappings = resolve_claude_code_model_mappings(
client,
Expand All @@ -1089,20 +1105,30 @@ pub(crate) async fn apply_agent_config(
let _guard = AGENT_CONFIG_FILE_LOCK
.lock()
.map_err(|_| "智能体配置文件锁已损坏".to_string())?;
apply_agent_configuration_with_oauth(
let apply = |catalog: Option<&str>| apply_agent_configuration_with_oauth(
client,
&home,
config.port,
api_key,
&model,
AgentConfigurationOptions {
models: &prepared.models,
codex_catalog: prepared.codex_catalog.as_deref(),
codex_catalog: catalog,
oauth_configuration,
claude_code_model_mappings: claude_code_model_mappings.as_ref(),
claude_desktop_model_mappings: claude_desktop_model_mappings.as_ref(),
},
)
);
if let (Some(request), Some(runtime_models)) = (codex_review_model, runtime_models) {
codex_catalog::apply_default_review_model(
&codex_model_customizations_path(&app)?,
&runtime_models,
request,
|catalog| apply(Some(catalog)),
)
} else {
apply(prepared.codex_catalog.as_deref())
}
}

#[tauri::command]
Expand Down
7 changes: 4 additions & 3 deletions src-tauri/src/codex_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::sync::{OnceLock, RwLock};
mod customizations;
mod runtime_context;
pub(crate) use customizations::{
editor_snapshot, load_customizations, save_customizations, CatalogEditorRequest,
CatalogEditorSnapshot,
apply_default_review_model, editor_snapshot, load_customizations, save_customizations,
CatalogEditorRequest, CatalogEditorSnapshot, DefaultReviewModelRequest,
};
pub(crate) use runtime_context::{apply_configured_context_limits, merge_context_definitions};

Expand Down Expand Up @@ -1371,7 +1371,6 @@ mod tests {
"guardian": null,
"node_repl_auto_review_required": false,
"node_repl_disabled": false,
"auto_review_model_override": null,
"model_specialty": null,
"tool_mode": null,
"multi_agent_version": null,
Expand All @@ -1392,6 +1391,8 @@ mod tests {
for (field, value) in expected.as_object().unwrap() {
assert_eq!(model.get(field), Some(value), "field: {field}");
}
// 默认审批行为要求省略覆盖字段,而不是从模板保留 null。
assert!(!model.contains_key("auto_review_model_override"));
assert_eq!(
model["model_messages"]["instructions_template"],
sources.fallback["base_instructions"]
Expand Down
Loading