Skip to content

Commit 0a02334

Browse files
committed
feat: implement codex client with configuration and session management
Introduced the codex-client module, encompassing a comprehensive set of functionalities for managing codex configurations, session files, and interactions with the codex app server. This includes modules for handling profiles, projects, and model providers, along with caching mechanisms for session data. The new structure enhances the application's capability to manage user sessions and configurations dynamically, significantly improving user experience and application robustness.
1 parent 0974c92 commit 0a02334

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+288
-79
lines changed

codex-client/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "codex-client"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
tauri = { version = "2", features = ["protocol-asset"] }
8+
tokio = { version = "1", features = ["full"] }
9+
serde = { version = "1", features = ["derive"] }
10+
serde_json = "1"
11+
log = "0.4"
12+
walkdir = "2.3"
13+
chrono = { version = "0.4", features = ["serde"] }
14+
dirs = "6.0"
15+
toml = "0.9.5"
16+
toml_edit = "0.20"
17+
base64 = "0.22.1"
18+
regex = "1.12.2"
19+
20+
codex-app-server-protocol = { git = "https://github.com/openai/codex.git", package = "codex-app-server-protocol", rev = "54e6e4ac" }
21+
codex-protocol = { git = "https://github.com/openai/codex.git", package = "codex-protocol", rev = "54e6e4ac" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
77
use std::collections::HashMap;
88
use std::path::PathBuf;
99

10-
use crate::mcp::McpServerConfig;
10+
use super::mcp::McpServerConfig;
1111

1212
#[derive(Debug, Clone, Serialize, Deserialize)]
1313
pub struct CodexConfig {
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};
22
use std::collections::HashMap;
33
use std::fs;
44
use std::str::FromStr;
5-
use tauri::command;
65
use toml_edit::{Document, Item, Table};
76

87
use super::{get_config_path, CodexConfig};
@@ -15,7 +14,6 @@ pub struct Profile {
1514
pub model: Option<String>,
1615
}
1716

18-
#[command]
1917
pub async fn read_profiles() -> Result<HashMap<String, Profile>, String> {
2018
let config_path = get_config_path()?;
2119

@@ -32,7 +30,6 @@ pub async fn read_profiles() -> Result<HashMap<String, Profile>, String> {
3230
Ok(config.profiles)
3331
}
3432

35-
#[command]
3633
pub async fn get_provider_config(
3734
provider_name: String,
3835
) -> Result<Option<(ModelProvider, Option<Profile>)>, String> {
@@ -56,13 +53,11 @@ pub async fn get_provider_config(
5653
}
5754
}
5855

59-
#[command]
6056
pub async fn get_profile_config(profile_name: String) -> Result<Option<Profile>, String> {
6157
let profiles = read_profiles().await?;
6258
Ok(profiles.get(&profile_name).cloned())
6359
}
6460

65-
#[command]
6661
pub async fn add_or_update_profile(profile_name: String, profile: Profile) -> Result<(), String> {
6762
let config_path = get_config_path()?;
6863

@@ -97,7 +92,6 @@ pub async fn add_or_update_profile(profile_name: String, profile: Profile) -> Re
9792
Ok(())
9893
}
9994

100-
#[command]
10195
pub async fn delete_profile(profile_name: String) -> Result<(), String> {
10296
let config_path = get_config_path()?;
10397

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};
22
use std::fs;
33
use std::path::PathBuf;
44
use std::str::FromStr;
5-
use tauri::command;
65
use toml_edit::{Document, Item, Table};
76

87
use super::{get_config_path, CodexConfig};
@@ -19,7 +18,6 @@ pub struct Project {
1918
pub trust_level: String,
2019
}
2120

22-
#[command]
2321
pub async fn read_codex_config() -> Result<Vec<Project>, String> {
2422
let config_path = get_config_path()?;
2523

@@ -46,15 +44,13 @@ pub async fn read_codex_config() -> Result<Vec<Project>, String> {
4644
}
4745

4846
/// Check if a given path is a Git repository (version controlled).
49-
#[command]
5047
pub async fn is_version_controlled(path: String) -> Result<bool, String> {
5148
let path_buf = PathBuf::from(&path);
5249
let git_path = path_buf.join(".git");
5350
Ok(git_path.exists())
5451
}
5552

5653
/// Set or update a project's trust level in `~/.codex/config.toml`.
57-
#[command]
5854
pub async fn set_project_trust(path: String, trust_level: String) -> Result<(), String> {
5955
let config_path = get_config_path()?;
6056

@@ -89,7 +85,6 @@ pub async fn set_project_trust(path: String, trust_level: String) -> Result<(),
8985
Ok(())
9086
}
9187

92-
#[command]
9388
pub async fn get_project_name(path: String) -> Result<String, String> {
9489
let path_buf = PathBuf::from(&path);
9590
let name = path_buf
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};
22
use std::collections::HashMap;
33
use std::fs;
44
use std::str::FromStr;
5-
use tauri::command;
65
use toml_edit::{Document, Item, Table};
76

87
use super::{get_config_path, CodexConfig};
@@ -15,7 +14,6 @@ pub struct ModelProvider {
1514
pub env_key: Option<String>,
1615
}
1716

18-
#[command]
1917
pub async fn read_model_providers() -> Result<HashMap<String, ModelProvider>, String> {
2018
let config_path = get_config_path()?;
2119

@@ -32,7 +30,6 @@ pub async fn read_model_providers() -> Result<HashMap<String, ModelProvider>, St
3230
Ok(config.model_providers)
3331
}
3432

35-
#[command]
3633
pub async fn add_or_update_model_provider(
3734
provider_name: String,
3835
provider: ModelProvider,
@@ -78,7 +75,6 @@ pub async fn add_or_update_model_provider(
7875
Ok(())
7976
}
8077

81-
#[command]
8278
pub async fn delete_model_provider(provider_name: String) -> Result<(), String> {
8379
let config_path = get_config_path()?;
8480

File renamed without changes.

0 commit comments

Comments
 (0)