From f84b14c41c200a6f0fa3e35d71fd58c970ab0cfd Mon Sep 17 00:00:00 2001 From: lzt404 <2596933790@qq.com> Date: Fri, 21 Aug 2026 17:05:39 +0800 Subject: [PATCH] fix(agents): allow launching clients before applying configuration --- src-tauri/src/agents/launch.rs | 41 +--------------------------------- src/pages/AgentsPage.tsx | 34 ++++++++-------------------- 2 files changed, 10 insertions(+), 65 deletions(-) diff --git a/src-tauri/src/agents/launch.rs b/src-tauri/src/agents/launch.rs index adf42a7..13c089f 100644 --- a/src-tauri/src/agents/launch.rs +++ b/src-tauri/src/agents/launch.rs @@ -27,9 +27,6 @@ pub(crate) fn launch_agent( if !status.installed { return Err("未检测到 Pi CLI,请先安装 Pi 并重新检测".to_string()); } - if !status.configured { - return Err("请先安装并配置 Pi CLIProxyAPI provider 插件".to_string()); - } let executable = find_pi_executable(&home).ok_or_else(|| "未找到 Pi CLI 可执行文件".to_string())?; let launch_directory = resolve_launch_directory(working_directory.as_deref(), &home)?; @@ -44,11 +41,6 @@ pub(crate) fn launch_agent( if !status.installed { return Err(format!("未检测到 {},请先安装并重新检测", client.name())); } - validate_agent_launch_configuration(client, &status)?; - if client == AgentClient::Codex && status.oauth_configuration { - validate_codex_oauth_login(&home)?; - } - let default_target = match client { AgentClient::ClaudeDesktop | AgentClient::ZCode => "app", AgentClient::Codex if find_codex_app_installation(&home).is_some() => "app", @@ -88,27 +80,11 @@ pub(crate) fn launch_agent( } #[tauri::command] -pub(crate) async fn restart_codex_app( - app: tauri::AppHandle, - gui_config_state: tauri::State<'_, GuiConfigState>, -) -> Result<(), String> { +pub(crate) async fn restart_codex_app(app: tauri::AppHandle) -> Result<(), String> { let home = app .path() .home_dir() .map_err(|error| format!("无法获取用户目录: {error}"))?; - let config = gui_config_state.snapshot()?; - let status = inspect_agent_config( - AgentClient::Codex, - &home, - config.port, - effective_agent_api_key(&config), - ); - if !status.installed { - return Err("未检测到 Codex,请先安装并重新检测".to_string()); - } - if status.oauth_configuration { - validate_codex_oauth_login(&home)?; - } let target = find_codex_app_installation(&home) .ok_or_else(|| "未检测到 Codex 桌面应用,请重新检测或改用 Codex CLI".to_string())?; @@ -120,21 +96,6 @@ pub(crate) async fn restart_codex_app( .map_err(|error| format!("重启 Codex App 任务失败: {error}"))? } -fn validate_agent_launch_configuration( - client: AgentClient, - status: &AgentConfigStatus, -) -> Result<(), String> { - if client == AgentClient::Codex - || (status.modification_enabled && status.modification_state == "applied") - { - return Ok(()); - } - Err(format!( - "请先为 {} 应用配置修改,确保 CPA 配置生效后再启动", - client.name() - )) -} - fn resolve_launch_directory(value: Option<&str>, fallback: &Path) -> Result { let Some(value) = value.map(str::trim).filter(|value| !value.is_empty()) else { return Ok(fallback.to_path_buf()); diff --git a/src/pages/AgentsPage.tsx b/src/pages/AgentsPage.tsx index 20190d9..a62709a 100644 --- a/src/pages/AgentsPage.tsx +++ b/src/pages/AgentsPage.tsx @@ -959,11 +959,7 @@ export function AgentsPage() { const appLaunchTarget = activeLaunchTargets.find((target) => target.id === 'app') ?? null; const launchEnabled = Boolean( activeStatus?.supportedPlatform - && activeStatus.installed - && (selected === 'codex' - || (selected === 'pi' - ? activeStatus.configured - : activeStatus.modificationEnabled && activeStatus.modificationState === 'applied')), + && activeStatus.installed, ); const canLaunchTarget = (target: AgentLaunchTarget | null) => launchEnabled && Boolean(target); const activeLaunchDirectoryHistory = launchDirectoryHistory[selected] ?? []; @@ -1356,7 +1352,6 @@ export function AgentsPage() { setBusyAction(action); setLaunchError(''); try { - if (draftChanged) throw new Error(t('agents.error.applyFirst')); await invoke('launch_agent', { client: selected, target: target.id, @@ -1391,7 +1386,6 @@ export function AgentsPage() { setBusyAction('restart-app'); setLaunchError(''); try { - if (draftChanged) throw new Error(t('agents.error.applyFirst')); await invoke('restart_codex_app'); } catch (requestError) { if (!handleOAuthLoginError(requestError, 'launch')) { @@ -1887,10 +1881,8 @@ export function AgentsPage() { type="button" className="secondary-button agent-launch-button" onClick={() => void launchAgent(cliLaunchTarget)} - disabled={busy || !canLaunchTarget(cliLaunchTarget) || draftChanged} - title={draftChanged - ? t('agents.launch.applyFirst') - : cliLaunchTarget?.detail ?? t('agents.launch.unavailable')} + disabled={busy || !canLaunchTarget(cliLaunchTarget)} + title={cliLaunchTarget?.detail ?? t('agents.launch.unavailable')} > {busyAction === 'launch-cli' ? @@ -1903,10 +1895,8 @@ export function AgentsPage() { type="button" className="primary-button agent-launch-button" onClick={() => void launchAgent(appLaunchTarget)} - disabled={busy || !canLaunchTarget(appLaunchTarget) || draftChanged} - title={draftChanged - ? t('agents.launch.applyFirst') - : appLaunchTarget?.detail ?? t('agents.launch.unavailable')} + disabled={busy || !canLaunchTarget(appLaunchTarget)} + title={appLaunchTarget?.detail ?? t('agents.launch.unavailable')} > {busyAction === 'launch-app' ? @@ -1919,10 +1909,8 @@ export function AgentsPage() { type="button" className="secondary-button agent-launch-button" onClick={() => void restartCodexApp()} - disabled={busy || !canLaunchTarget(appLaunchTarget) || draftChanged} - title={draftChanged - ? t('agents.launch.applyFirst') - : appLaunchTarget?.detail ?? t('agents.launch.unavailable')} + disabled={busy || !canLaunchTarget(appLaunchTarget)} + title={appLaunchTarget?.detail ?? t('agents.launch.unavailable')} > {busyAction === 'restart-app' ? @@ -1937,12 +1925,8 @@ export function AgentsPage() { type="button" className="primary-button agent-launch-button" onClick={() => void launchAgent(defaultLaunchTarget)} - disabled={busy || !canLaunchTarget(defaultLaunchTarget) || draftChanged} - title={draftChanged - ? t('agents.launch.applyFirst') - : defaultLaunchTarget?.detail ?? (launchEnabled - ? t('agents.launch.unavailable') - : t('agents.launch.enableFirst'))} + disabled={busy || !canLaunchTarget(defaultLaunchTarget)} + title={defaultLaunchTarget?.detail ?? t('agents.launch.unavailable')} > {busyAction === 'launch' ?