Commit Graph

22 Commits

  • refactor(gemini-web): Move provider logic to its own package
    The Gemini Web API client logic has been relocated from `internal/client/gemini-web` to a new, more specific `internal/provider/gemini-web` package. This refactoring improves code organization and modularity by better isolating provider-specific implementations.
    
    As a result of this move, the `GeminiWebState` struct and its methods have been exported (capitalized) to make them accessible from the executor. All call sites have been updated to use the new package path and the exported identifiers.
  • refactor(usage): replace channel-based queue with mutex-protected slice
    - Switched to a slice-based queue with mutex and condition variable for better control over queuing and dispatching.
    - Removed fixed buffer size to handle dynamic queuing.
    - Enhanced shutdown logic to safely close the queue and wake up waiting goroutines.
  • feat(usage): implement usage tracking infrastructure across executors
    - Added `LoggerPlugin` to log usage metrics for observability.
    - Introduced a new `Manager` to handle usage record queuing and plugin registration.
    - Integrated new usage reporter and detailed metrics parsing into executors, covering providers like OpenAI, Codex, Claude, and Gemini.
    - Improved token usage breakdown across streaming and non-streaming responses.
  • feat(claude-executor): add ZSTD decoding support for Claude executor responses
    - Integrated ZSTD decompression via `github.com/klauspost/compress` for responses with "zstd" content-encoding.
    - Added helper `hasZSTDEcoding` to detect ZSTD-encoded responses.
    - Updated response handling logic to initialize and use a ZSTD decoder when necessary.
    
    refactor(api-handlers): split streaming and non-streaming response handling
    
    - Introduced `handleNonStreamingResponse` for processing non-streaming requests in `ClaudeCodeAPIHandler`.
    - Improved code clarity by separating streaming and non-streaming logic.
    
    fix(service): remove redundant token refresh interval assignment logic in `cliproxy` service.
  • 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.
  • refactor(auth): replace NextRefreshAfter with NextRetryAfter for clarity and consistency
    - Renamed field `NextRefreshAfter` to `NextRetryAfter` across `AuthManager`, `types`, and selector logic.
    - Updated references to ensure proper handling of retry timing logic.
    - Improved code readability and clarified retry behavior for different auth states.
  • feat(auth): enable model suspension and resumption logic in AuthManager
    - Added model suspension with reason tracking for 401 (unauthorized) and 402/403 (payment-related) errors.
    - Implemented resumption logic upon model quota recovery or auth state changes.
    - Enhanced registry to manage suspended clients, including counts and observability data.
    - Updated availability computation to exclude suspended clients, ensuring accurate client model tracking.
  • feat(auth): enhance watcher with asynchronous dispatch and buffering
    - Added async dispatch loop to `Watcher` for handling incremental `AuthUpdate` with in-memory buffering.
    - Improved resilience against high-frequency auth changes by coalescing updates and reducing redundant processing.
    - Updated `cliproxy` service to increase auth update queue capacity and optimize backlog consumption.
    - Added detailed SDK integration documentation in English and Chinese (`sdk-watcher.md`, `sdk-watcher_CN.md`).
  • feat(auth): implement incremental auth updates with queue integration
    - Added support for incremental auth updates using `AuthUpdate` and `AuthUpdateAction`.
    - Integrated `SetAuthUpdateQueue` to propagate updates through a dedicated channel.
    - Introduced new methods for handling auth add, modify, and delete actions.
    - Updated service to ensure auth update queues are correctly initialized and consumed.
    - Improved auth state synchronization across core and file-based clients with real-time updates.
    - Refactored redundant auth handling logic for better efficiency and maintainability.
  • feat(executor): add CountTokens support across all executors
    - Introduced `CountTokens` method to Codex, Claude, Gemini, Qwen, OpenAI-compatible, and other executors.
    - Implemented `ExecuteCount` in `AuthManager` for token counting via provider round-robin.
    - Updated handlers to leverage `ExecuteCountWithAuthManager` for streamlined token counting.
    - Added fallback and error handling logic for token counting requests.
  • chore(executor): add debug logging for API request errors
    - Added detailed debug logs in all executors (Codex, Claude, Gemini, Qwen, OpenAI-compatible) to capture HTTP status and response body for failed API requests.
  • feat(openai-compat): enhance provider key handling and model resolution
    - Introduced dynamic `providerKey` resolution for OpenAI-compatible providers, incorporating attributes like `provider_key` and `compat_name`.
    - Implemented upstream model overrides via `resolveUpstreamModel` and `overrideModel` methods in the OpenAI executor.
    - Updated registry logic to correctly store provider mappings and register clients using normalized keys.
    - Ensured consistency in handling empty or default provider names across components.
  • refactor(auth): remove unused Refresh methods from authenticators
    - Deleted `Refresh` implementations in Codex, Claude, Gemini, Qwen, and Gemini-web authenticators.
    - Updated the `Authenticator` interface to exclude `Refresh` for cleaner design.
    - Revised `Manager` and related components to handle refresh logic improvements.
    - Simplified token refresh behavior and eliminated redundant code paths.
  • chore(logging): add debug logs for executor Refresh methods
    - Introduced `logrus` for structured debugging across all executors.
    - Added debug log messages in `Refresh` methods for better traceability.
    - Updated `Manager` to log additional details during refresh checks.
  • 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`.
  • feat: enhance request logging and account handling in CLI proxy
    - Added helper functions to log API request and response payloads in the Gin context.
    - Improved `AccountInfo` to support cookie-based authentication in addition to API key and OAuth.
    - Updated log messages for better clarity on account types used.
  • 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.