Commit Graph

38 Commits

  • feat(server): add keep-alive endpoint with timeout handling
    - Introduced a keep-alive endpoint to monitor service activity.
    - Added timeout-specific shutdown functionality when the endpoint is idle.
    - Implemented password-protected access for the keep-alive endpoint.
    - Updated server startup to support configurable keep-alive options.
  • 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.
  • chore(docs): add and refine package-level comments across modules
    - Added detailed package-level comments to improve documentation coverage.
    - Clarified parameter descriptions, return types, and functionality of exported methods across packages.
    - Enhanced overall code readability and API documentation consistency.
  • refactor(auth): Centralize auth file reading with snapshot preference
    The logic for reading authentication files, which includes retries and a preference for cookie snapshot files, was previously implemented locally within the `watcher` package. This was done to handle potential file locks during writes.
    
    This change moves this functionality into a shared `ReadAuthFileWithRetry` function in the `util` package to promote code reuse and consistency.
    
    The `watcher` package is updated to use this new centralized function. Additionally, the initial token loading in the `run` command now also uses this logic, making it more resilient to file access issues and consistent with the watcher's behavior.
  • 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`.
  • Fixed bug #38
    Add support for API key indexing in OpenAI compatibility clients
    
    - Updated `NewOpenAICompatibilityClient` to accept `apiKeyIndex` for managing multiple API keys.
    - Modified client instantiation loops to initialize one client per API key.
    - Adjusted client ID format to include `apiKeyIndex` for unique identification.
    - Removed API key rotation logic within `GetCurrentAPIKey`.
    - Updated `.gitignore` to include `AGENTS.md`.
  • refactor(watcher): restructure client management and API key handling
    - separate file-based and API key-based clients in watcher
    - improve client reloading logic with better locking and error handling
    - add dedicated functions for building API key clients and loading file clients
    - update combined client map generation to include cached API key clients
    - enhance logging and debugging information during client reloads
    - fix potential race conditions in client updates and removals
  • Add support for Codex API key authentication
    - Introduced functionality to handle Codex API keys, including initialization and management via new endpoints in the management API.
    - Updated Codex client to support both OAuth and API key authentication.
    - Documented Codex API key configuration in both English and Chinese README files.
    - Enhanced logging to distinguish between API key and OAuth usage scenarios.
  • Add management API handlers for config and auth file management
    - Implemented CRUD operations for authentication files.
    - Added endpoints for managing API keys, quotas, proxy settings, and other configurations.
    - Enhanced management access with robust validation, remote access control, and persistence support.
    - Updated README with new configuration details.
    
    Fixed OpenAI Chat Completions for codex
  • Add token refresh handling for 401 responses across clients
    - Implemented `RefreshTokens` method in client interfaces and Gemini clients.
    - Updated handlers to call `RefreshTokens` on 401 responses and retry requests if token refresh succeeds.
    - Enhanced error handling and retry logic to accommodate token refresh flow.
    
    Update README to include Qwen login instructions
    
    - Added Qwen OAuth login command instructions in both English and Chinese README files.
    - Made minor updates to existing command examples for consistency.
  • Add OpenAI compatibility support and improve resource cleanup
    - Introduced OpenAI compatibility configurations for external providers, enabling model alias routing via the OpenAI API format.
    - Enhanced provider logic in `GetProviderName` to handle OpenAI aliases and added new helper functions for compatibility checks.
    - Updated API handlers and client initialization to support OpenAI compatibility models.
    - Improved resource cleanup across clients by closing response bodies and streams using deferred functions.
  • 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 API handlers and proxy logic
    - Centralized `getClient` logic into a dedicated function to reduce redundancy.
    - Moved proxy initialization to a new utility function `SetProxy` in `internal/util/proxy.go`.
    - Replaced `Internal` handler with `CLIHandler` in `server.go` for improved clarity and consistency.
    - Removed unused functions and redundant HTTP client setup across the codebase for better maintainability.
  • Add support for Generative Language API Key and improve client initialization
    - Added `GlAPIKey` support in configuration to enable Generative Language API.
    - Integrated `GenerativeLanguageAPIKey` handling in client and API handlers.
    - Updated response translators to manage generative language responses properly.
    - Enhanced HTTP client initialization logic with proxy support for API requests.
    - Refactored streaming and non-streaming flows to account for generative language-specific logic.
  • Enhance quota management and refactor configuration handling
    - Introduced `QuotaExceeded` settings in configuration to handle quota limits more effectively.
    - Added preview model switching logic to `Client` to automatically use fallback models on quota exhaustion.
    - Refactored `APIHandlers` to leverage new configuration structure.
    - Simplified server initialization and removed redundant `ServerConfig` structure.
    - Streamlined client initialization by unifying configuration handling throughout the project.
    - Improved error handling and response mechanisms in both streaming and non-streaming flows.
  • 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.