Commit Graph

18 Commits

  • Merge pull request #58 from router-for-me/v6-test
    refactor(gemini-web): Remove auto-refresh, auto-close, and caching
  • 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.
  • 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.
  • feat(gemini-executor): implement CountTokens method with request translation and API integration
    - Added `CountTokens` for token counting requests in Gemini executor.
    - Integrated request translation via `sdktranslator` and response handling.
    - Improved error handling, logging, and API request configuration with headers.
  • 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.
  • refactor(headers): centralize header logic using EnsureHeader utility
    - Introduced `EnsureHeader` in `internal/misc/header_utils.go` to streamline header setting across executors.
    - Updated Codex, Claude, and Gemini executors to utilize `EnsureHeader` for consistent header application.
    - Incorporated Gin context headers (if available) into request header manipulation for better integration.
  • refactor(executor): centralize header application logic for executors
    - Replaced repetitive header setting logic with helper methods (`applyCodexHeaders`, `applyClaudeHeaders`, `applyQwenHeaders`) in Codex, Claude, and Qwen executors.
    - Ensured consistent headers in HTTP requests across all executors.
    - Introduced UUID and additional structured headers for better traceability (e.g., session IDs, metadata).
  • 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(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(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: implement token refresh support for executors
    - Added `Refresh` method implementations for Codex, Claude, Gemini, and Qwen executors.
    - Introduced OAuth-based token handling for Gemini and Qwen with support for refresh tokens.
    - Updated Codex and Claude to use new internal auth services.
    - Enhanced metadata structure and consistency for token storage across all executors.
  • 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.