This release represents a comprehensive transformation of the codebase from Codex to LLMX, enhanced with LiteLLM integration to support 100+ LLM providers through a unified API. ## Major Changes ### Phase 1: Repository & Infrastructure Setup - Established new repository structure and branching strategy - Created comprehensive project documentation (CLAUDE.md, LITELLM-SETUP.md) - Set up development environment and tooling configuration ### Phase 2: Rust Workspace Transformation - Renamed all Rust crates from `codex-*` to `llmx-*` (30+ crates) - Updated package names, binary names, and workspace members - Renamed core modules: codex.rs → llmx.rs, codex_delegate.rs → llmx_delegate.rs - Updated all internal references, imports, and type names - Renamed directories: codex-rs/ → llmx-rs/, codex-backend-openapi-models/ → llmx-backend-openapi-models/ - Fixed all Rust compilation errors after mass rename ### Phase 3: LiteLLM Integration - Integrated LiteLLM for multi-provider LLM support (Anthropic, OpenAI, Azure, Google AI, AWS Bedrock, etc.) - Implemented OpenAI-compatible Chat Completions API support - Added model family detection and provider-specific handling - Updated authentication to support LiteLLM API keys - Renamed environment variables: OPENAI_BASE_URL → LLMX_BASE_URL - Added LLMX_API_KEY for unified authentication - Enhanced error handling for Chat Completions API responses - Implemented fallback mechanisms between Responses API and Chat Completions API ### Phase 4: TypeScript/Node.js Components - Renamed npm package: @codex/codex-cli → @valknar/llmx - Updated TypeScript SDK to use new LLMX APIs and endpoints - Fixed all TypeScript compilation and linting errors - Updated SDK tests to support both API backends - Enhanced mock server to handle multiple API formats - Updated build scripts for cross-platform packaging ### Phase 5: Configuration & Documentation - Updated all configuration files to use LLMX naming - Rewrote README and documentation for LLMX branding - Updated config paths: ~/.codex/ → ~/.llmx/ - Added comprehensive LiteLLM setup guide - Updated all user-facing strings and help text - Created release plan and migration documentation ### Phase 6: Testing & Validation - Fixed all Rust tests for new naming scheme - Updated snapshot tests in TUI (36 frame files) - Fixed authentication storage tests - Updated Chat Completions payload and SSE tests - Fixed SDK tests for new API endpoints - Ensured compatibility with Claude Sonnet 4.5 model - Fixed test environment variables (LLMX_API_KEY, LLMX_BASE_URL) ### Phase 7: Build & Release Pipeline - Updated GitHub Actions workflows for LLMX binary names - Fixed rust-release.yml to reference llmx-rs/ instead of codex-rs/ - Updated CI/CD pipelines for new package names - Made Apple code signing optional in release workflow - Enhanced npm packaging resilience for partial platform builds - Added Windows sandbox support to workspace - Updated dotslash configuration for new binary names ### Phase 8: Final Polish - Renamed all assets (.github images, labels, templates) - Updated VSCode and DevContainer configurations - Fixed all clippy warnings and formatting issues - Applied cargo fmt and prettier formatting across codebase - Updated issue templates and pull request templates - Fixed all remaining UI text references ## Technical Details **Breaking Changes:** - Binary name changed from `codex` to `llmx` - Config directory changed from `~/.codex/` to `~/.llmx/` - Environment variables renamed (CODEX_* → LLMX_*) - npm package renamed to `@valknar/llmx` **New Features:** - Support for 100+ LLM providers via LiteLLM - Unified authentication with LLMX_API_KEY - Enhanced model provider detection and handling - Improved error handling and fallback mechanisms **Files Changed:** - 578 files modified across Rust, TypeScript, and documentation - 30+ Rust crates renamed and updated - Complete rebrand of UI, CLI, and documentation - All tests updated and passing **Dependencies:** - Updated Cargo.lock with new package names - Updated npm dependencies in llmx-cli - Enhanced OpenAPI models for LLMX backend This release establishes LLMX as a standalone project with comprehensive LiteLLM integration, maintaining full backward compatibility with existing functionality while opening support for a wide ecosystem of LLM providers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Sebastian Krüger <support@pivoine.art>
196 lines
5.7 KiB
Rust
196 lines
5.7 KiB
Rust
use base64::Engine;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Default)]
|
|
pub struct TokenData {
|
|
/// Flat info parsed from the JWT in auth.json.
|
|
#[serde(
|
|
deserialize_with = "deserialize_id_token",
|
|
serialize_with = "serialize_id_token"
|
|
)]
|
|
pub id_token: IdTokenInfo,
|
|
|
|
/// This is a JWT.
|
|
pub access_token: String,
|
|
|
|
pub refresh_token: String,
|
|
|
|
pub account_id: Option<String>,
|
|
}
|
|
|
|
/// Flat subset of useful claims in id_token from auth.json.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
|
|
pub struct IdTokenInfo {
|
|
pub email: Option<String>,
|
|
/// The ChatGPT subscription plan type
|
|
/// (e.g., "free", "plus", "pro", "business", "enterprise", "edu").
|
|
/// (Note: values may vary by backend.)
|
|
pub(crate) chatgpt_plan_type: Option<PlanType>,
|
|
/// Organization/workspace identifier associated with the token, if present.
|
|
pub chatgpt_account_id: Option<String>,
|
|
pub raw_jwt: String,
|
|
}
|
|
|
|
impl IdTokenInfo {
|
|
pub fn get_chatgpt_plan_type(&self) -> Option<String> {
|
|
self.chatgpt_plan_type.as_ref().map(|t| match t {
|
|
PlanType::Known(plan) => format!("{plan:?}"),
|
|
PlanType::Unknown(s) => s.clone(),
|
|
})
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub(crate) enum PlanType {
|
|
Known(KnownPlan),
|
|
Unknown(String),
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub(crate) enum KnownPlan {
|
|
Free,
|
|
Plus,
|
|
Pro,
|
|
Team,
|
|
Business,
|
|
Enterprise,
|
|
Edu,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
struct IdClaims {
|
|
#[serde(default)]
|
|
email: Option<String>,
|
|
#[serde(rename = "https://api.openai.com/auth", default)]
|
|
auth: Option<AuthClaims>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
struct AuthClaims {
|
|
#[serde(default)]
|
|
chatgpt_plan_type: Option<PlanType>,
|
|
#[serde(default)]
|
|
chatgpt_account_id: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum IdTokenInfoError {
|
|
#[error("invalid ID token format")]
|
|
InvalidFormat,
|
|
#[error(transparent)]
|
|
Base64(#[from] base64::DecodeError),
|
|
#[error(transparent)]
|
|
Json(#[from] serde_json::Error),
|
|
}
|
|
|
|
pub fn parse_id_token(id_token: &str) -> Result<IdTokenInfo, IdTokenInfoError> {
|
|
// JWT format: header.payload.signature
|
|
let mut parts = id_token.split('.');
|
|
let (_header_b64, payload_b64, _sig_b64) = match (parts.next(), parts.next(), parts.next()) {
|
|
(Some(h), Some(p), Some(s)) if !h.is_empty() && !p.is_empty() && !s.is_empty() => (h, p, s),
|
|
_ => return Err(IdTokenInfoError::InvalidFormat),
|
|
};
|
|
|
|
let payload_bytes = base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(payload_b64)?;
|
|
let claims: IdClaims = serde_json::from_slice(&payload_bytes)?;
|
|
|
|
match claims.auth {
|
|
Some(auth) => Ok(IdTokenInfo {
|
|
email: claims.email,
|
|
raw_jwt: id_token.to_string(),
|
|
chatgpt_plan_type: auth.chatgpt_plan_type,
|
|
chatgpt_account_id: auth.chatgpt_account_id,
|
|
}),
|
|
None => Ok(IdTokenInfo {
|
|
email: claims.email,
|
|
raw_jwt: id_token.to_string(),
|
|
chatgpt_plan_type: None,
|
|
chatgpt_account_id: None,
|
|
}),
|
|
}
|
|
}
|
|
|
|
fn deserialize_id_token<'de, D>(deserializer: D) -> Result<IdTokenInfo, D::Error>
|
|
where
|
|
D: serde::Deserializer<'de>,
|
|
{
|
|
let s = String::deserialize(deserializer)?;
|
|
parse_id_token(&s).map_err(serde::de::Error::custom)
|
|
}
|
|
|
|
fn serialize_id_token<S>(id_token: &IdTokenInfo, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: serde::Serializer,
|
|
{
|
|
serializer.serialize_str(&id_token.raw_jwt)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use serde::Serialize;
|
|
|
|
#[test]
|
|
fn id_token_info_parses_email_and_plan() {
|
|
#[derive(Serialize)]
|
|
struct Header {
|
|
alg: &'static str,
|
|
typ: &'static str,
|
|
}
|
|
let header = Header {
|
|
alg: "none",
|
|
typ: "JWT",
|
|
};
|
|
let payload = serde_json::json!({
|
|
"email": "user@example.com",
|
|
"https://api.openai.com/auth": {
|
|
"chatgpt_plan_type": "pro"
|
|
}
|
|
});
|
|
|
|
fn b64url_no_pad(bytes: &[u8]) -> String {
|
|
base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(bytes)
|
|
}
|
|
|
|
let header_b64 = b64url_no_pad(&serde_json::to_vec(&header).unwrap());
|
|
let payload_b64 = b64url_no_pad(&serde_json::to_vec(&payload).unwrap());
|
|
let signature_b64 = b64url_no_pad(b"sig");
|
|
let fake_jwt = format!("{header_b64}.{payload_b64}.{signature_b64}");
|
|
|
|
let info = parse_id_token(&fake_jwt).expect("should parse");
|
|
assert_eq!(info.email.as_deref(), Some("user@example.com"));
|
|
assert_eq!(info.get_chatgpt_plan_type().as_deref(), Some("Pro"));
|
|
}
|
|
|
|
#[test]
|
|
fn id_token_info_handles_missing_fields() {
|
|
#[derive(Serialize)]
|
|
struct Header {
|
|
alg: &'static str,
|
|
typ: &'static str,
|
|
}
|
|
let header = Header {
|
|
alg: "none",
|
|
typ: "JWT",
|
|
};
|
|
let payload = serde_json::json!({ "sub": "123" });
|
|
|
|
fn b64url_no_pad(bytes: &[u8]) -> String {
|
|
base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(bytes)
|
|
}
|
|
|
|
let header_b64 = b64url_no_pad(&serde_json::to_vec(&header).unwrap());
|
|
let payload_b64 = b64url_no_pad(&serde_json::to_vec(&payload).unwrap());
|
|
let signature_b64 = b64url_no_pad(b"sig");
|
|
let fake_jwt = format!("{header_b64}.{payload_b64}.{signature_b64}");
|
|
|
|
let info = parse_id_token(&fake_jwt).expect("should parse");
|
|
assert!(info.email.is_none());
|
|
assert!(info.get_chatgpt_plan_type().is_none());
|
|
}
|
|
}
|