Commit Graph

28 Commits

  • refactor(config): migrate to SDKConfig and streamline proxy handling
    - Replaced `config.Config` with `config.SDKConfig` across components for simpler configuration management.
    - Updated proxy setup functions and handlers to align with `SDKConfig` improvements.
    - Reorganized handler imports to match new SDK structure.
  • feat(logging): introduce centralized logging with custom format and Gin integration
    - Implemented a global logger with structured formatting for consistent log output.
    - Added support for rotating log files using Lumberjack.
    - Integrated new logging functionality with Gin HTTP server for unified log handling.
    - Replaced direct `log.Info` calls with `fmt.Printf` in non-critical paths to simplify core functionality.
  • refactor(gemini-web): Remove auto-refresh, auto-close, and caching
    This commit simplifies the Gemini web client by removing several complex, stateful features. The previous implementation for auto-refreshing cookies and auto-closing the client involved background goroutines, timers, and file system caching, which made the client's lifecycle difficult to manage.
    
    The following features have been removed:
    - The cookie auto-refresh mechanism, including the background goroutine (`rotateCookies`) and related configuration fields.
    - The file-based caching for the `__Secure-1PSIDTS` token. The `rotate1PSIDTS` function now fetches a new token on every call.
    - The auto-close functionality, which used timers to close the client after a period of inactivity.
    - Associated configuration options and methods (`WithAccountLabel`, `WithOnCookiesRefreshed`, `Close`, etc.).
    
    By removing this logic, the client becomes more stateless and predictable. The responsibility for managing the client's lifecycle and handling token expiration is now shifted to the caller, leading to a simpler and more robust integration.
  • refactor(auth): Centralize logging for saving credentials
    The logic for logging the path where credentials are saved was duplicated across several client implementations.
    
    This commit refactors this behavior by creating a new centralized function, `misc.LogSavingCredentials`, to handle this logging. The `SaveTokenToFile` method in each authentication token storage struct now calls this new function, ensuring consistent logging and reducing code duplication.
    
    The redundant logging statements in the client-level `SaveTokenToFile` methods have been removed.
  • Update internal module imports to use v5 package path
    - Updated all `github.com/luispater/CLIProxyAPI/internal/...` imports to point to `github.com/luispater/CLIProxyAPI/v5/internal/...`.
    - Adjusted `go.mod` to specify `module github.com/luispater/CLIProxyAPI/v5`.
  • Replace path with filepath for cross-platform compatibility
    - Updated imports and function calls to use `filepath` across all token storage implementations and server entry point.
    - Ensured consistent handling of directory and file paths for improved portability.
  • Refactor API handlers organization and simplify error response handling
    - Modularized handlers into dedicated packages (`gemini`, `claude`, `cli`) for better structure.
    - Centralized `ErrorResponse` and `ErrorDetail` types under `handlers` package for reuse.
    - Updated all handlers to utilize the shared `ErrorResponse` model.
    - Introduced specialization of handler structs (`GeminiAPIHandlers`, `ClaudeCodeAPIHandlers`, `GeminiCLIAPIHandlers`) for improved clarity and separation of concerns.
    - Refactored `getClient` logic with additional properties and better state management.
    
    Refactor `translator` package by modularizing code for `claude` and `gemini`
    
    - Moved Claude-specific logic (`PrepareClaudeRequest`, `ConvertCliToClaude`) to `translator/claude/code`.
    - Moved Gemini-specific logic (`FixCLIToolResponse`) to `translator/gemini/cli` for better package structure.
    - Updated affected handler imports and method references.
    
    Add comprehensive package-level documentation across key modules
    
    - Introduced detailed package-level documentation for core modules: `auth`, `client`, `cmd`, `handlers`, `util`, `watcher`, `config`, `translator`, and `api`.
    - Enhanced code readability and maintainability by clarifying the purpose and functionality of each package.
    - Aligned documentation style and tone with existing codebase conventions.
    
    Refactor API handlers and translator modules for improved clarity and consistency
    
    - Standardized handler struct names (`GeminiAPIHandlers`, `ClaudeCodeAPIHandlers`, `GeminiCLIAPIHandlers`, `OpenAIAPIHandlers`) and updated related comments.
    - Fixed unnecessary `else` blocks in streaming logic for cleaner error handling.
    - Renamed variables for better readability (`responseIdResult` to `responseIDResult`, `activationUrl` to `activationURL`, etc.).
    - Addressed minor inconsistencies in API handler comments and SSE header initialization.
    - Improved modularization of `claude` and `gemini` translator components.
    
    Standardize configuration field naming for consistency across modules
    
    - Renamed `ProxyUrl` to `ProxyURL`, `ApiKeys` to `APIKeys`, and `ConfigQuotaExceeded` to `QuotaExceeded`.
    - Updated all relevant references and comments in `config`, `auth`, `api`, `util`, and `watcher`.
    - Ensured consistent casing for `GlAPIKey` debug logs.
  • Enhance HTTP server with custom multiplexer in Auth flow
    - Replaced default `http` handler with `http.ServeMux` for improved routing control.
    - Refactored callback handling to utilize the custom multiplexer.
  • Refactor client handling and improve error responses
    - Centralized client retrieval logic with `getClient` function for reduced redundancy.
    - Simplified client rotation and error handling by removing excessive load balancing logic.
    - Updated server address in `auth.go` to use dynamic binding (`:8085`).
  • Refactor token management, client initialization, and project handling
    - Consolidated `TokenStorage` struct into `internal/auth/models.go` for better organization.
    - Updated `Client` to use `TokenStorage` for managing email and project ID.
    - Simplified `SetupUser` method to ensure proper token and project assignment.
    - Refactored API handlers to leverage new `GetEmail` and `GetProjectID` methods in `Client`.
    - Cleanup: Removed unused structures and redundant code from `client.go` and `auth.go`.
    - Adjusted CLI flow in `login.go` and `run.go` for streamlined user onboarding.
  • Refactor user onboarding and token management
    - Enhanced the `Client` initialization to include `TokenStorage` and configuration parameters.
    - Replaced `SaveTokenToFile` with a `Client` method for better encapsulation.
    - Improved onboarding flow with project ID verification and API enablement checks.
    - Refactored token saving logic to ensure proper handling of directory creation and JSON encoding.
    - Removed unused file-related code in `auth.go` for improved maintainability.
  • Refactor authentication and service initialization code
    - Moved login and service management logic to `internal/cmd` package (`login.go` and `run.go`).
    - Introduced `DoLogin` and `StartService` functions for modularity.
    - Enhanced error handling by using structured `ErrorMessage` in `Client`.
    - Improved token file saving process and added project-specific token identification.
    - Updated API handlers to handle more detailed error responses, including status codes.
  • Add SOCKS5 and HTTP/HTTPS proxy support
    - Updated `GetAuthenticatedClient` to handle proxy configuration via `proxy-url`.
    - Extended `Config` to include `proxy-url` property.
    - Adjusted error handling and removed unused JSON error response logic for API handlers.
    - Updated documentation and configuration examples to reflect new proxy settings.