Commit Graph

29 Commits

  • refactor(access): centralize configaccess.Register and remove redundant calls
    - Added centralized `configaccess.Register` invocation in `server` initialization.
    - Removed duplicate `Register` calls from `reconcile.go` and `builder.go`.
    - Simplified logic by removing unnecessary `nil` checks in provider entry collection.
  • refactor(util): Centralize auth directory path resolution
    Introduces a new utility function, `util.ResolveAuthDir`, to handle the normalization and resolution of the authentication directory path.
    
    Previously, the logic for expanding the tilde (~) to the user's home directory was implemented inline in `main.go`. This refactoring extracts that logic into a reusable function within the `util` package.
    
    The new `ResolveAuthDir` function is now used consistently across the application:
    - During initial server startup in `main.go`.
    - When counting authentication files in `util.CountAuthFiles`.
    - When the configuration is reloaded by the watcher.
    
    This change eliminates code duplication, improves consistency, and makes the path resolution logic more robust and maintainable.
  • feat(config, usage): add usage-statistics-enabled option and dynamic toggling
    - Introduced `usage-statistics-enabled` configuration to control in-memory usage aggregation.
    - Updated API to include handlers for managing `usage-statistics-enabled` and `logging-to-file` options.
    - Enhanced `watcher` to log changes to both configurations dynamically.
    - Updated documentation and examples to reflect new configuration options.
  • 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.
  • feat(auth, docs): add SDK guides and local password support for management
    - Added extensive SDK usage guides for `cliproxy`, `sdk/access`, and watcher integration.
    - Introduced `--password` flag for specifying local management access passwords.
    - Enhanced management API with local password checks to secure localhost requests.
    - Updated documentation to reflect the new password functionality.
  • feat(auth): centralize token store management and enhance persistence
    - Introduced `RegisterTokenStore` and `GetTokenStore` to centralize token store access.
    - Replaced direct file operations with a unified token persistence API.
    - Updated all components to use the shared token store for consistent behavior.
    - Improved logging for token save operations to include file paths.
  • feat(logging): integrate logrus with custom Gin middleware for enhanced request logging and recovery
    - Added `GinLogrusLogger` for structured request logging using Logrus.
    - Implemented `GinLogrusRecovery` to handle panics and log stack traces.
    - Configured log rotation using Lumberjack for efficient log management.
    - Replaced Gin's default logger and recovery middleware with the custom implementations.
  • 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`.
  • Add dynamic log level adjustment and "type" field to auth files response
    - Introduced `SetLogLevel` utility function for unified log level management.
    - Updated dynamic log level handling across server and watcher components.
    - Extended auth files response by extracting and including the `type` field from file content.
    - Updated management API documentation with the new `type` field in auth files response.
  • Add versioning support to build artifacts and log outputs
    - Introduced `Version` variable, set during build via `-ldflags`, to embed application version.
    - Updated Dockerfile to accept `APP_VERSION` argument for version injection during build.
    - Modified `.goreleaser.yml` to pass GitHub release tag as version via `ldflags`.
    - Added version logging in the application startup.
  • 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.
  • Add file watcher for dynamic configuration and client reloading
    - Introduced `Watcher` for monitoring updates to the configuration file and authentication directory.
    - Integrated file watching into `StartService` to handle dynamic changes without restarting.
    - Enhanced API server and handlers to support client and configuration updates.
    - Updated `.gitignore` to include `docs/` directory.
    - Modified go dependencies to include `fsnotify` for the file watcher.
  • 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.