Commit Graph

26 Commits

  • 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.
  • 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.
  • 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 /v1/completions endpoint with OpenAI compatibility
    - Implemented `/v1/completions` endpoint mirroring OpenAI's completions API specification.
    - Added conversion functions to translate between completions and chat completions formats.
    - Introduced streaming and non-streaming response handling for completions requests.
    - Updated `server.go` to register the new endpoint and include it in the API's metadata.
  • 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.
  • Refactor API handlers to implement retry mechanism with configurable limits and improved error handling
    - Introduced retry counter with a configurable ` RequestRetry ` limit in all handlers.
    - Enhanced error handling with specific HTTP status codes for switching clients.
    - Standardized response forwarding for non-retriable errors.
    - Improved logging for quota and client switch scenarios.
  • 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.
  • 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.
  • Add GeminiModels handler and enhance API key validation
    - Introduced `GeminiModels` handler to serve Gemini model information under `/v1beta/models`.
    - Updated `AuthMiddleware` to validate API keys from query parameters for improved flexibility.
    - Adjusted route to use the new handler for model retrieval.
  • 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.
  • 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 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.
  • 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.