Commit Graph

40 Commits

  • feat(store): introduce GitTokenStore for token persistence via Git backend
    - Added `GitTokenStore` to handle token storage and metadata using Git as a backing storage.
    - Implemented methods for initialization, save, retrieval, listing, and deletion of auth files.
    - Updated `go.mod` and `go.sum` to include new dependencies for Git integration.
    - Integrated support for Git-backed configuration via `GitTokenStore`.
    - Updated server logic to clone, initialize, and manage configurations from Git repositories.
    - Added helper functions for verifying and synchronizing configuration files.
    - Improved error handling and contextual logging for Git operations.
    - Modified Dockerfile to include `config.example.yaml` for initial setup.
    - Added `gitCommitter` interface to handle Git-based commit and push operations.
    - Configured `Watcher` to detect and leverage Git-backed token stores.
    - Implemented `commitConfigAsync` and `commitAuthAsync` methods for asynchronous change synchronization.
    - Enhanced `GitTokenStore` with `CommitPaths` method to support selective file commits.
  • feat(auth): include email attribute in auth files response
    - Added logic to parse and include the "email" attribute from auth files.
    - Updated file data extraction to support additional metadata.
  • feat(auth): enhance Gemini CLI onboarding and project verification
    - Added `ensureGeminiProjectAndOnboard` to streamline project onboarding.
    - Implemented API checks for Cloud AI enablement to ensure compatibility.
    - Extended record metadata with additional onboarding details such as `auto` and `checked`.
    - Centralized OAuth success HTML response in `oauthCallbackSuccessHTML`.
  • feat(auth): add callback forwarder support for Web UI in OAuth flows
    - Introduced callback forwarders for Anthropic, Gemini, Codex, and iFlow OAuth flows.
    - Added `is_webui` query parameter detection to enhance Web UI compatibility.
    - Implemented mechanisms to start and stop callback forwarders dynamically.
    - Improved error handling and logging for callback server initialization.
  • refactor(auth): simplify inline API key provider logic and improve configuration consistency
    - Replaced `SyncInlineAPIKeys` with `MakeInlineAPIKeyProvider` for better clarity and reduced redundancy.
    - Removed legacy logic for inline API key syncing and migration.
    - Enhanced provider synchronization logic to handle empty states consistently.
    - Added normalization to API key handling across configurations.
    - Updated handlers to reflect streamlined provider update logic.
  • feat(auth): normalize OpenAI compatibility entries and enhance proxy configuration
    - Added automatic trimming of API keys and migration of legacy `api-keys` to `api-key-entries`.
    - Introduced per-key `proxy-url` handling across OpenAI, Codex, and Claude API configurations.
    - Updated documentation to clarify usage of `proxy-url` with examples, ensuring backward compatibility.
    - Added normalization logic to reduce duplication and improve configuration consistency.
  • refactor(auth): replace TokenRecord with coreauth.Auth and migrate TokenStore to coreauth.Store
    - Replaced `TokenRecord` with `coreauth.Auth` for centralized and consistent authentication data structures.
    - Migrated `TokenStore` interface to `coreauth.Store` for alignment with core CLIProxy authentication.
    - Updated related login methods, token persistence logic, and file storage handling to use the new `coreauth.Auth` model.
  • refactor(access): migrate to SDKConfig for authentication and provider management
    - Replaced `config.Config` with `SDKConfig` in authentication and provider logic for consistency with SDK changes.
    - Updated provider registration, reconciliation, and build functions to align with the `SDKConfig` structure.
    - Refactored related imports and handlers to support the new configuration approach.
    - Improved clarity and reduced redundancy in API key synchronization and provider initialization.
  • 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(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 label support for Gemini web token management
    - Added `label` field to the management API for better token identification.
    - Updated request payload and validation logic to include `label` as a required field.
    - Adjusted documentation (`MANAGEMENT_API.md`, `MANAGEMENT_API_CN.md`) to reflect changes.
  • 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.
  • refactor(config, auth): remove allow-localhost-unauthenticated support and related handlers
    - Eliminated `allow-localhost-unauthenticated` configuration field and its usage.
    - Removed associated management API handlers and middleware logic.
    - Simplified authentication middleware by deprecating localhost-specific checks.
  • refactor(config): remove force-gpt-5-codex option and related handlers
    - Eliminated the deprecated `force-gpt-5-codex` configuration option from all configs, handlers, and documentation.
    - Updated examples and README files to reflect the removal.
    - Streamlined related code by dropping unused fields and logging.
  • feat(auth): add Gemini Web token saving endpoint
    - Introduced `POST /gemini-web-token` endpoint to save Gemini Web cookies directly.
    - Added payload validation and hashed-based file naming for persistence.
    - Updated documentation to reflect the new management API 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(usage): add in-memory usage statistics tracking and API endpoint
    - Introduced in-memory request statistics aggregation in `LoggerPlugin`.
    - Added new structures for detailed metrics collection (e.g., token breakdown, request success/failure).
    - Implemented `/usage` management API endpoint for retrieving aggregated statistics.
    - Updated management handlers to support the new usage statistics functionality.
    - Enhanced documentation to describe the usage metrics API.
  • fix(auth): address index logic bug and remove redundant conditions
    - Updated loop iteration in `AuthSelector` to correct index management for selecting candidates.
    - Fixed cursor index reset condition for large values to prevent overflow.
    - Removed unnecessary conditional reassignment of `allowRemote` in management handler for clarity and correctness.
  • feat(auth): standardize last_refresh metadata handling across executors
    - Added `last_refresh` timestamp to metadata for Codex, Claude, Qwen, and Gemini executors.
    - Implemented `extractLastRefreshTimestamp` utility for parsing diverse timestamp formats in management handlers.
    - Ensured consistent update and preservation of `last_refresh` in file-based auth handling.
  • feat(auth): introduce auth.providers for flexible authentication configuration
    - Replaced legacy `api-keys` field with `auth.providers` in configuration, supporting multiple authentication providers including `config-api-key`.
    - Added synchronization to maintain compatibility with legacy `api-keys`.
    - Updated core components like request handling and middleware to use the new provider system.
    - Enhanced management API endpoints for seamless integration with `auth.providers`.
  • refactor: standardize constant naming and improve file-based auth handling
    - Renamed constants from uppercase to CamelCase for consistency.
    - Replaced redundant file-based auth handling logic with the new `util.CountAuthFiles` helper.
    - Fixed various error-handling inconsistencies and enhanced robustness in file operations.
    - Streamlined auth client reload logic in server and watcher components.
    - Applied minor code readability improvements across multiple packages.
  • Add support for forcing GPT-5 Codex model configuration
    - Introduced a new `ForceGPT5Codex` configuration option in settings.
    - Added relevant API endpoints for managing `ForceGPT5Codex`.
    - Enhanced Codex client to handle GPT-5 Codex-specific logic and mapping.
    - Updated example configuration file to include the new option.
    
    Add GPT-5 Codex model support and configuration options in documentation
  • 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`.
  • Implement IP-based rate limiting and ban mechanism for management API
    - Introduced a new `attemptInfo` structure to track failed login attempts per IP.
    - Added logic to temporarily ban IPs exceeding the allowed number of failures.
    - Enhanced middleware to reset failed attempt counters on successful authentication.
    - Updated `Handler` to include a `failedAttempts` map with thread-safe access.
  • Enhance OAuth handling for Anthropic, Codex, Gemini, and Qwen tokens
    - Transitioned OAuth callback handling from temporary servers to predefined persistent endpoints.
    - Simplified token retrieval by replacing in-memory handling with state-file-based persistence.
    - Introduced unified `oauthStatus` map for tracking flow progress and errors.
    - Added new `/auth/*/callback` routes, streamlining code and state management for OAuth flows.
    - Improved error handling and logging in token exchange and callback flows.
  • Add OAuth support for Gemini CLI, Claude, Codex, and Qwen authentication
    - Implemented new handlers (`RequestGeminiCLIToken`, `RequestAnthropicToken`, `RequestCodexToken`, `RequestQwenToken`) for initiating OAuth flows.
    - Added endpoints for authorization URLs in management API.
    - Extracted `GenerateRandomState` to a reusable utility in `misc` package.
    - Refactored related logic in `openai_login.go` and `anthropic_login.go` for consistency.
    
    Add endpoints for initiating OAuth flows in management API documentation
    
    - Documented new endpoints for Anthropic, Codex, Gemini CLI, and Qwen login URLs.
    - Provided request and response examples for each endpoint in both English and Chinese versions.
  • 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 JSON annotations to configuration structs and new /config management endpoint
    - Added JSON annotations across all configuration structs in `config.go`.
    - Introduced `/config` management API endpoint to fetch complete configuration.
    - Updated management API documentation (`MANAGEMENT_API.md`, `MANAGEMENT_API_CN.md`) with `/config` usage.
    - Implemented `GetConfig` handler in `config_basic.go`.
  • 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