Commit Graph

41 Commits

  • 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.
  • Remove redundant dataUglyTag parsing logic in streaming responses
    Eliminated duplicate blocks handling `dataUglyTag` in `openai-compatibility_client.go`, simplifying the streaming response logic.
  • **Fix model switch logic when quota is exceeded**
    Ensure `modelName` is updated after switching to a new model, avoiding inconsistencies in subsequent iterations.
  • **Handle data: without trailing space in streaming responses**
    Add support for API providers that emit `data:` (no space) in Server‑Sent Events. Introduces a new `dataUglyTag` and corresponding parsing logic to correctly process and forward these lines, ensuring compatibility with non‑standard streaming formats.
    
    Fuck for them all
  • Refactor translator packages for OpenAI Chat Completions
    - Renamed `openai` packages to `chat_completions` across translator modules.
    - Introduced `openai_responses_handlers` with handlers for `/v1/models` and OpenAI-compatible chat completions endpoints.
    - Updated constants and registry identifiers for OpenAI response type.
    - Simplified request/response conversions and added detailed retry/error handling.
    - Added `golang.org/x/crypto` for additional cryptographic functions.
  • Enhance client reload process with new OpenAI compatibility support
    - Added handling for OpenAI-compatible providers during client reload.
    - Implemented client unregistration for old clients during reload.
    - Improved logging for detailed client reload insights.
    
    Expand `AuthDir` handling to support tilde (`~`) for home directory resolution
    
    - Added logic to replace `~` with the user's home directory in `AuthDir`.
    - Prevents errors when using `~` in configuration paths.
  • Add support for new GPT-5 model variants
    - Renamed existing GPT-5 variants for consistency (`nano` → `minimal`, `mini` → `low`, etc.).
    - Added metadata definitions for new variants: `gpt-5-minimal`, `gpt-5-low`, `gpt-5-medium`, and updated logic to reflect variant-specific reasoning efforts.
  • 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 documentation to clarify auth-dir configuration for Windows users
    - Added a note for setting `auth-dir` on Windows systems in both English and Chinese README files.
    - Improved descriptions for existing configuration options.
    
    Address Qwen3 tool injection issue to prevent random token insertions
    
    - Modify Qwen client to insert a placeholder tool when none is defined, avoiding erratic behavior in streaming responses.
  • Add nil-check for GetRequestMutex across handlers to prevent potential panics
    - Updated all handlers to safely unlock the request mutex only if it's non-nil.
    - Enhanced mutex locking and unlocking logic to avoid runtime errors.
    - Improved robustness of resource cleanup across clients.
    
    Add `GetRequestMutex` method for synchronization across clients
    
    - Introduced a new `GetRequestMutex` method in OpenAICompatibilityClient, CodexClient, GeminiCLIClient, GeminiClient, and QwenClient for request synchronization.
    - Ensures only one request is processed at a time to manage quotas effectively.
  • Suppress debug logs for model routing and ignore empty tools arrays
    - Comment out verbose routing logs in the API server to reduce noise.
    - Remove the `tools` field from Qwen client requests when it is an empty array.
    - Add guards in Claude, Codex, Gemini‑CLI, and Gemini translators to skip tool conversion when the `tools` array is empty, preventing unnecessary payload modifications.
  • Add support for localhost unauthenticated requests
    - Introduced `AllowLocalhostUnauthenticated` flag allowing unauthenticated requests from localhost.
    - Updated authentication middleware to bypass checks for localhost when enabled.
    
    Add new Gemini CLI models and update model registry function
    
    - Introduced `GetGeminiCLIModels` for updated Gemini CLI model definitions.
    - Added new models: "Gemini 2.5 Flash Lite" and "Gemini 2.5 Pro".
    - Updated `RegisterModels` to use `GetGeminiCLIModels` in Gemini client initialization.
  • 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.
  • Add request logging capabilities to API handlers and update .gitignore
    Enhance API response handling by storing responses in context and updating request logger to include API responses
  • Fix activation URL extraction logic and improve warning message formatting
    - Corrected JSON path for error code and activation URL extraction in client error handling.
    - Improved readability of the activation warning message with better spacing.
  • 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.
  • Fix alt parameter handling in URL construction
    - Ensured `alt` parameter is only appended when non-empty.
    - Added debug logging for constructed URLs.
  • Add GeminiGetHandler, enhance Gemini functionality, and enable token counting
    - Added `GeminiGetHandler` for handling GET requests with extended Gemini model support.
    - Introduced `geminiCountTokens` function to calculate token usage.
    - Refactored `APIRequest` and related methods to support `alt` parameter for enhanced flexibility.
    - Updated routes and request processing to integrate new handler and functions.
  • Improve error logging and add user guidance for issue reporting
    - Added fatal log in `login.go` for Cloud AI API enablement check failures, prompting users to report issues.
    - Enhanced error logging in `client.go` with warning messages directing users to copy and provide error details when creating issues.
  • Add Claude compatibility and enhance API handling
    - Integrated Claude API compatibility in handlers, translators, and server routes.
    - Introduced `/messages` endpoint and upgraded `AuthMiddleware` for `X-Api-Key` header.
    - Improved streaming response handling with `ConvertCliToClaude` for SSE compatibility.
    - Enhanced request processing and tool-response mapping in translators.
    - Updated README to reflect Claude integration and clarify supported features.
  • Add Gemini-compatible API and improve error handling
    - Introduced a new Gemini-compatible API with routes under `/v1beta`.
    - Added `GeminiHandler` to manage `generateContent` and `streamGenerateContent` actions.
    - Enhanced `AuthMiddleware` to support `X-Goog-Api-Key` header.
    - Improved client metadata handling and added conditional project ID updates in API calls.
    - Updated logging to debug raw API request payloads for better traceability.
  • Add system instruction support and enhance internal API handlers
    - Introduced `SystemInstruction` field in `PrepareRequest` and `GenerateContentRequest` for better message parsing.
    - Updated `SendMessage` and `SendMessageStream` to handle system instructions in client API calls.
    - Enhanced error handling and manual flushing logic in response flows.
    - Added new internal API endpoints `/v1internal:generateContent` and `/v1internal:streamGenerateContent`.
    - Improved proxy handling and transport logic in HTTP client initialization.
  • 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 API request flow and streamline response handling
    - Replaced `SendMessageStream` with synchronous `SendMessage` in API handlers for better manageability.
    - Simplified `ConvertCliToOpenAINonStream` to reduce complexity and improve efficiency.
    - Adjusted `client.go` functions to handle both streaming and non-streaming API requests more effectively.
    - Improved error handling and channel communication in API handlers.
    - Removed redundant and unused code for cleaner implementation.
  • 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.
  • 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.