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
12 changes: 6 additions & 6 deletions src-tauri/resources/codex_models/model-catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"use_responses_lite": true,
"include_skills_usage_instructions": false,
"auto_review_model_override": null,
"context_window": 372000,
"max_context_window": 372000,
"context_window": 272000,
"max_context_window": 872000,
"auto_compact_token_limit": null,
"comp_hash": "3000",
"reasoning_summary_format": "experimental",
Expand Down Expand Up @@ -183,8 +183,8 @@
"use_responses_lite": true,
"include_skills_usage_instructions": false,
"auto_review_model_override": null,
"context_window": 372000,
"max_context_window": 372000,
"context_window": 272000,
"max_context_window": 872000,
"auto_compact_token_limit": null,
"comp_hash": "3000",
"reasoning_summary_format": "experimental",
Expand Down Expand Up @@ -294,8 +294,8 @@
"use_responses_lite": true,
"include_skills_usage_instructions": false,
"auto_review_model_override": null,
"context_window": 372000,
"max_context_window": 372000,
"context_window": 272000,
"max_context_window": 872000,
"auto_compact_token_limit": null,
"comp_hash": "3000",
"reasoning_summary_format": "experimental",
Expand Down
6 changes: 6 additions & 0 deletions src-tauri/src/agents/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ pub(crate) async fn apply_agent_config(
client: String,
model: String,
oauth_configuration: bool,
remote_compaction: bool,
claude_code_model_mappings: Option<ClaudeDesktopModelMappings>,
claude_desktop_model_mappings: Option<ClaudeDesktopModelMappings>,
) -> Result<AgentConfigActionResult, String> {
Expand Down Expand Up @@ -894,6 +895,7 @@ pub(crate) async fn apply_agent_config(
models: &prepared.models,
codex_catalog: prepared.codex_catalog.as_deref(),
oauth_configuration,
remote_compaction,
claude_code_model_mappings: claude_code_model_mappings.as_ref(),
claude_desktop_model_mappings: claude_desktop_model_mappings.as_ref(),
},
Expand Down Expand Up @@ -924,6 +926,7 @@ pub(crate) async fn reset_agent_config_to_default(
client: String,
model: String,
oauth_configuration: bool,
remote_compaction: bool,
claude_code_model_mappings: Option<ClaudeDesktopModelMappings>,
claude_desktop_model_mappings: Option<ClaudeDesktopModelMappings>,
) -> Result<AgentConfigActionResult, String> {
Expand Down Expand Up @@ -967,6 +970,7 @@ pub(crate) async fn reset_agent_config_to_default(
models: &prepared.models,
codex_catalog: prepared.codex_catalog.as_deref(),
oauth_configuration,
remote_compaction,
claude_code_model_mappings: claude_code_model_mappings.as_ref(),
claude_desktop_model_mappings: claude_desktop_model_mappings.as_ref(),
})
Expand Down Expand Up @@ -1038,6 +1042,7 @@ pub(crate) async fn set_agent_config_enabled(
models: &prepared.models,
codex_catalog: prepared.codex_catalog.as_deref(),
oauth_configuration: false,
remote_compaction: false,
claude_code_model_mappings: claude_code_model_mappings.as_ref(),
claude_desktop_model_mappings: claude_desktop_model_mappings.as_ref(),
},
Expand Down Expand Up @@ -1098,6 +1103,7 @@ pub(crate) async fn update_agent_config(
models: &prepared.models,
codex_catalog: prepared.codex_catalog.as_deref(),
oauth_configuration: false,
remote_compaction: false,
claude_code_model_mappings: claude_code_model_mappings.as_ref(),
claude_desktop_model_mappings: claude_desktop_model_mappings.as_ref(),
},
Expand Down
17 changes: 15 additions & 2 deletions src-tauri/src/agents/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) fn build_agent_updates(
models,
codex_catalog,
oauth_configuration: false,
remote_compaction: false,
claude_code_model_mappings: None,
claude_desktop_model_mappings: None,
},
Expand All @@ -38,6 +39,7 @@ pub(crate) fn build_agent_updates_with_oauth(
models,
codex_catalog,
oauth_configuration,
remote_compaction,
claude_code_model_mappings,
claude_desktop_model_mappings,
} = options;
Expand Down Expand Up @@ -125,6 +127,7 @@ pub(crate) fn build_agent_updates_with_oauth(
api_key,
model,
oauth_configuration,
remote_compaction,
)
.or_else(|_| {
build_codex_agent_config_with_oauth(
Expand All @@ -133,6 +136,7 @@ pub(crate) fn build_agent_updates_with_oauth(
api_key,
model,
oauth_configuration,
remote_compaction,
)
})?;
let mut updates = vec![AgentFileUpdate {
Expand Down Expand Up @@ -2460,7 +2464,7 @@ pub(crate) fn build_codex_agent_config(
api_key: &str,
model: &str,
) -> Result<String, String> {
build_codex_agent_config_with_oauth(existing, base_url, api_key, model, false)
build_codex_agent_config_with_oauth(existing, base_url, api_key, model, false, false)
}

pub(crate) fn build_codex_agent_config_with_oauth(
Expand All @@ -2469,6 +2473,7 @@ pub(crate) fn build_codex_agent_config_with_oauth(
api_key: &str,
model: &str,
oauth_configuration: bool,
remote_compaction: bool,
) -> Result<String, String> {
use toml_edit::{value, Document, Item, Table};

Expand Down Expand Up @@ -2510,7 +2515,15 @@ pub(crate) fn build_codex_agent_config_with_oauth(
.get_mut(MANAGED_AGENT_PROVIDER_ID)
.and_then(Item::as_table_mut)
.ok_or_else(|| "Codex cpa-gui provider 必须是 TOML 表".to_string())?;
set_codex_table_item(provider, "name", value("EasyCLIProxyAPI"));
// Codex currently uses the exact provider name `OpenAI` as its capability
// marker for Remote Compaction V2. Keep the product name by default because
// not every upstream account or proxy route supports the V2 response item.
let provider_name = if remote_compaction {
CODEX_REMOTE_COMPACTION_PROVIDER_NAME
} else {
CODEX_MANAGED_PROVIDER_NAME
};
set_codex_table_item(provider, "name", value(provider_name));
set_codex_table_item(provider, "base_url", value(base_url));
set_codex_table_item(provider, "wire_api", value("responses"));
set_codex_table_item(provider, "experimental_bearer_token", value(api_key));
Expand Down
57 changes: 37 additions & 20 deletions src-tauri/src/agents/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ pub(crate) fn inspect_pi_provider_status(
configuration_synchronized: configured,
current_model: current_model.clone(),
oauth_configuration: false,
remote_compaction: false,
modification_enabled: configured,
modification_state: modification_state.to_string(),
backup_available: false,
Expand Down Expand Up @@ -905,21 +906,28 @@ pub(crate) fn inspect_agent_config(
let paths = agent_config_paths(client, home);
let config_exists = paths.iter().any(|path| path.is_file());
let result = inspect_agent_managed_config(client, &paths, port, api_key).and_then(
|(configured, model, oauth_configuration)| {
|(configured, model, oauth_configuration, remote_compaction)| {
if client == AgentClient::Codex && configured {
let model = model
.as_deref()
.ok_or_else(|| "Codex 配置缺少默认模型".to_string())?;
validate_codex_catalog_file(&paths[0], model)?;
}
Ok((configured, model, oauth_configuration))
Ok((configured, model, oauth_configuration, remote_compaction))
},
);
let (configured, current_model, oauth_configuration, config_valid, error) = match result {
Ok((configured, model, oauth_configuration)) => {
(configured, model, oauth_configuration, true, None)
let (
configured,
current_model,
oauth_configuration,
remote_compaction,
config_valid,
error,
) = match result {
Ok((configured, model, oauth_configuration, remote_compaction)) => {
(configured, model, oauth_configuration, remote_compaction, true, None)
}
Err(error) => (false, None, false, false, Some(error)),
Err(error) => (false, None, false, false, false, Some(error)),
};
let executable = find_agent_executable(client, home);
// Desktop application executables are not CLIs. Invoking them with
Expand Down Expand Up @@ -1000,6 +1008,7 @@ pub(crate) fn inspect_agent_config(
configuration_synchronized,
current_model,
oauth_configuration,
remote_compaction,
modification_enabled: modification.enabled,
modification_state: modification.state,
backup_available: modification.backup_available,
Expand Down Expand Up @@ -1197,24 +1206,24 @@ pub(crate) fn inspect_agent_managed_config(
paths: &[PathBuf],
port: u16,
api_key: &str,
) -> Result<(bool, Option<String>, bool), String> {
) -> Result<(bool, Option<String>, bool, bool), String> {
match client {
AgentClient::ClaudeCode => inspect_claude_agent_config(&paths[0], port, api_key)
.map(|(configured, model)| (configured, model, false)),
.map(|(configured, model)| (configured, model, false, false)),
AgentClient::ClaudeDesktop if client.supported_platform() => {
inspect_claude_desktop_agent_config(paths, port, api_key)
.map(|(configured, model)| (configured, model, false))
.map(|(configured, model)| (configured, model, false, false))
}
AgentClient::ClaudeDesktop => Ok((false, None, false)),
AgentClient::ClaudeDesktop => Ok((false, None, false, false)),
AgentClient::Codex => inspect_codex_agent_config(&paths[0], port, api_key),
AgentClient::OpenCode => inspect_opencode_agent_config(&paths[0], port, api_key)
.map(|(configured, model)| (configured, model, false)),
.map(|(configured, model)| (configured, model, false, false)),
AgentClient::OpenClaw => inspect_openclaw_agent_config(&paths[0], port, api_key)
.map(|(configured, model)| (configured, model, false)),
.map(|(configured, model)| (configured, model, false, false)),
AgentClient::Hermes => inspect_hermes_agent_config(&paths[0], port, api_key)
.map(|(configured, model)| (configured, model, false)),
.map(|(configured, model)| (configured, model, false, false)),
AgentClient::DeepSeekHarness => inspect_deepseek_harness_config(paths, port, api_key)
.map(|(configured, model)| (configured, model, false)),
.map(|(configured, model)| (configured, model, false, false)),
AgentClient::ZCode => {
if paths.len() != 2 {
return Err("ZCode 配置路径数量无效".to_string());
Expand All @@ -1226,12 +1235,13 @@ pub(crate) fn inspect_agent_managed_config(
app_configured && cli_configured && models_match,
cli_model.or(app_model),
false,
false,
))
}
AgentClient::KimiCode => inspect_kimi_code_agent_config(&paths[0], port, api_key)
.map(|(configured, model)| (configured, model, false)),
.map(|(configured, model)| (configured, model, false, false)),
AgentClient::GrokBuild => inspect_grok_build_agent_config(&paths[0], port, api_key)
.map(|(configured, model)| (configured, model, false)),
.map(|(configured, model)| (configured, model, false, false)),
}
}

Expand Down Expand Up @@ -3244,9 +3254,9 @@ pub(crate) fn inspect_codex_agent_config(
path: &Path,
port: u16,
api_key: &str,
) -> Result<(bool, Option<String>, bool), String> {
) -> Result<(bool, Option<String>, bool, bool), String> {
if !path.is_file() {
return Ok((false, None, false));
return Ok((false, None, false, false));
}
let root: toml::Value = toml::from_str(
&fs::read_to_string(path).map_err(|error| format!("读取 Codex 配置失败: {error}"))?,
Expand All @@ -3266,6 +3276,10 @@ pub(crate) fn inspect_codex_agent_config(
.and_then(|provider| provider.get("requires_openai_auth"))
.and_then(toml::Value::as_bool)
== Some(true);
let remote_compaction = provider
.and_then(|provider| provider.get("name"))
.and_then(toml::Value::as_str)
== Some(CODEX_REMOTE_COMPACTION_PROVIDER_NAME);
let auth_path = path.with_file_name("auth.json");
let auth_configured = if oauth_configuration {
codex_auth_file_has_oauth_tokens(&auth_path)
Expand All @@ -3279,7 +3293,10 @@ pub(crate) fn inspect_codex_agent_config(
&& provider
.and_then(|provider| provider.get("name"))
.and_then(toml::Value::as_str)
== Some("EasyCLIProxyAPI")
.is_some_and(|name| {
name == CODEX_MANAGED_PROVIDER_NAME
|| name == CODEX_REMOTE_COMPACTION_PROVIDER_NAME
})
&& provider
.and_then(|provider| provider.get("base_url"))
.and_then(toml::Value::as_str)
Expand All @@ -3296,7 +3313,7 @@ pub(crate) fn inspect_codex_agent_config(
.map(str::trim)
.filter(|value| !value.is_empty())
.map(str::to_string);
Ok((configured, model, oauth_configuration))
Ok((configured, model, oauth_configuration, remote_compaction))
}

pub(crate) fn validate_codex_catalog_file(config_path: &Path, model: &str) -> Result<(), String> {
Expand Down
15 changes: 12 additions & 3 deletions src-tauri/src/agents/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ pub(crate) fn fresh_agent_contents(
models: &models,
codex_catalog: None,
oauth_configuration: false,
remote_compaction: false,
claude_code_model_mappings: None,
claude_desktop_model_mappings: None,
},
Expand All @@ -685,6 +686,7 @@ pub(crate) fn fresh_agent_contents_with_oauth(
let AgentConfigurationOptions {
models,
oauth_configuration,
remote_compaction,
claude_code_model_mappings,
claude_desktop_model_mappings,
..
Expand Down Expand Up @@ -719,6 +721,7 @@ pub(crate) fn fresh_agent_contents_with_oauth(
api_key,
model,
oauth_configuration,
remote_compaction,
)?]),
AgentClient::OpenCode => Ok(vec![build_opencode_agent_config(
None,
Expand Down Expand Up @@ -1537,6 +1540,7 @@ pub(crate) fn apply_agent_configuration(
models,
codex_catalog,
oauth_configuration: false,
remote_compaction: false,
claude_code_model_mappings: None,
claude_desktop_model_mappings: None,
},
Expand Down Expand Up @@ -1586,6 +1590,7 @@ pub(crate) fn reset_agent_configuration_to_default(
}],
codex_catalog,
oauth_configuration: false,
remote_compaction: false,
claude_code_model_mappings: None,
claude_desktop_model_mappings: None,
})
Expand All @@ -1600,6 +1605,7 @@ pub(crate) struct AgentDefaultConfiguration<'a> {
pub(crate) models: &'a [AgentModelOption],
pub(crate) codex_catalog: Option<&'a str>,
pub(crate) oauth_configuration: bool,
pub(crate) remote_compaction: bool,
pub(crate) claude_code_model_mappings: Option<&'a ClaudeDesktopModelMappings>,
pub(crate) claude_desktop_model_mappings: Option<&'a ClaudeDesktopModelMappings>,
}
Expand All @@ -1616,6 +1622,7 @@ pub(crate) fn reset_agent_configuration_to_default_with_oauth(
models,
codex_catalog,
oauth_configuration,
remote_compaction,
claude_code_model_mappings,
claude_desktop_model_mappings,
} = request;
Expand All @@ -1630,6 +1637,7 @@ pub(crate) fn reset_agent_configuration_to_default_with_oauth(
models,
codex_catalog,
oauth_configuration,
remote_compaction,
claude_code_model_mappings,
claude_desktop_model_mappings,
},
Expand All @@ -1653,6 +1661,7 @@ pub(crate) fn reset_agent_configuration_to_default_with_oauth(
models,
codex_catalog,
oauth_configuration,
remote_compaction,
claude_code_model_mappings,
claude_desktop_model_mappings,
},
Expand Down Expand Up @@ -1824,7 +1833,7 @@ pub(crate) fn enable_agent_modification(
Vec::new(),
));
}
let (_, current_model, _) =
let (_, current_model, _, _) =
inspect_agent_managed_config(client, &paths, port, DEFAULT_API_KEY)?;
if agent_has_managed_marker(client, &paths)? {
if let Some(current_model) = current_model.as_deref() {
Expand Down Expand Up @@ -1903,7 +1912,7 @@ pub(crate) fn disable_agent_modification(
let mut record = match load_agent_record(client, &paths)? {
Some(record) => record,
None => {
let (_, model, _) =
let (_, model, _, _) =
inspect_agent_managed_config(client, &paths, port, DEFAULT_API_KEY)?;
if !agent_has_managed_marker(client, &paths)? {
return Ok(action_result(
Expand Down Expand Up @@ -1989,7 +1998,7 @@ pub(crate) fn update_agent_modification(
let record = match load_agent_record(client, &paths)? {
Some(record) => record,
None => {
let (_, current_model, _) =
let (_, current_model, _, _) =
inspect_agent_managed_config(client, &paths, port, DEFAULT_API_KEY)?;
if !agent_has_managed_marker(client, &paths)? {
return Err("请先应用配置修改".to_string());
Expand Down
Loading