Commit Graph

117 Commits

  • **refactor(cliproxy, config): remove vertex-compat flow, streamline Vertex API key handling**
    - Removed `vertex-compat` executor and related configuration.
    - Consolidated Vertex compatibility checks into `vertex` handling with `apikey`-based model resolution.
    - Streamlined model generation logic for Vertex API key entries.
  • feat: Add support for VertexAI compatible service (#375)
    feat: consolidate Vertex AI compatibility with API key support in Gemini
  • **fix(executor, auth): ensure index assignment consistency for auth objects**
    - Updated `usage_helpers.go` to call `EnsureIndex()` for proper index assignment in reporter initialization.
    - Adjusted `auth/manager.go` to assign auth indices inside a locked section when they are unassigned, ensuring thread safety and consistency.
  • Fixed: #339
    **feat(handlers, executor): add Gemini 3 Pro Preview support and refine Claude system instructions**
    
    - Added support for the new "Gemini 3 Pro Preview" action in Gemini handlers, including detailed metadata and configuration.
    - Removed redundant `cache_control` field from Claude system instructions for cleaner payload structure.
  • **fix(handlers): refactor API response capture to append data safely**
    - Introduced `appendAPIResponse` helper to preserve and append data to existing API responses.
    - Ensured newline inclusion when appending, if necessary.
    - Improved `nil` and data type checks for response handling.
    - Updated middleware to skip request logging for `GET` requests.
  • **fix(auth): resolve index reassignment issue during auth management**
    - Fixed improper handling of `indexAssigned` and `Index` during auth reassignment.
    - Ensured `EnsureIndex` is invoked after validating existing auth entries.
  • #293
    **feat(retry): add configurable retry logic with cooldown support**
    
    - Introduced `max-retry-interval` configuration for cooldown durations between retries.
    - Added `SetRetryConfig` in `Manager` to handle retry attempts and cooldown intervals.
    - Enhanced provider execution logic to include retry attempts, cooldown management, and dynamic wait periods.
    - Updated API endpoints and YAML configuration to support `max-retry-interval`.
  • **refactor(auth): use customizable HTTP client for Antigravity requests**
    - Replaced `http.DefaultClient` with a configurable `http.Client` instance for Antigravity OAuth flow methods.
    - Updated `exchangeAntigravityCode` and `fetchAntigravityUserInfo` to accept `httpClient` as a parameter.
    - Added `util.SetProxy` usage to initialize the `httpClient` with proxy support.
  • **feat(auth, executor, cmd): add Antigravity provider integration**
    - Implemented OAuth login flow for the Antigravity provider in `auth/antigravity.go`.
    - Added `AntigravityExecutor` for handling requests and streaming via Antigravity APIs.
    - Created `antigravity_login.go` command for triggering Antigravity authentication.
    - Introduced OpenAI-to-Antigravity translation logic in `translator/antigravity/openai/chat-completions`.
    
    **refactor(translator, executor): update Gemini CLI response translation and add Antigravity payload customization**
    
    - Renamed Gemini CLI translation methods to align with response handling (`ConvertGeminiCliResponseToGemini` and `ConvertGeminiCliResponseToGeminiNonStream`).
    - Updated `init.go` to reflect these method changes.
    - Introduced `geminiToAntigravity` function to embed metadata (`model`, `userAgent`, `project`, etc.) into Antigravity payloads.
    - Added random project, request, and session ID generators for enhanced tracking.
    - Streamlined `buildRequest` to use `geminiToAntigravity` transformation before request execution.
  • **refactor(middleware): extract request logging logic and optimize condition checks**
    - Added `shouldLogRequest` helper to simplify path-based request logging logic.
    - Updated middleware to skip management endpoints for improved security.
    - Introduced an explicit `nil` logger check for minimal overhead.
    - Updated dependencies in `go.mod`.
    
    **feat(auth): add handling for 404 response with retry logic**
    
    - Introduced support for 404 `not_found` status with a 12-hour backoff period.
    - Updated `manager.go` to align state and status messages for 404 scenarios.
    
    **refactor(translator): comment out debug logging in Gemini responses request**
  • **refactor(executor): simplify Gemini CLI execution and remove internal retry logic**
    - Removed nested retry handling for 429 rate limit errors.
    - Simplified request/response handling by cleaning redundant retry-related code.
    - Eliminated `parseRetryDelay` function and max retry configuration logic.
  • Add AMP fallback proxy and shared Gemini normalization
    - add fallback handler that forwards Amp provider requests to ampcode.com when the provider isn’t configured locally
    - wrap AMP provider routes with the fallback so requests always have a handler
    - share Gemini thinking model normalization helper between core handlers and AMP fallback
  • feat: Add Amp CLI integration with comprehensive documentation
    Add full Amp CLI support to enable routing AI model requests through the proxy
    while maintaining Amp-specific features like thread management, user info, and
    telemetry. Includes complete documentation and pull bot configuration.
    
    Features:
    - Modular architecture with RouteModule interface for clean integration
    - Reverse proxy for Amp management routes (thread/user/meta/ads/telemetry)
    - Provider-specific route aliases (/api/provider/{provider}/*)
    - Secret management with precedence: config > env > file
    - 5-minute secret caching to reduce file I/O
    - Automatic gzip decompression for responses
    - Proper connection cleanup to prevent leaks
    - Localhost-only restriction for management routes (configurable)
    - CORS protection for management endpoints
    
    Documentation:
    - Complete setup guide (USING_WITH_FACTORY_AND_AMP.md)
    - OAuth setup for OpenAI (ChatGPT Plus/Pro) and Anthropic (Claude Pro/Max)
    - Factory CLI config examples with all model variants
    - Amp CLI/IDE configuration examples
    - tmux setup for remote server deployment
    - Screenshots and diagrams
    
    Configuration:
    - Pull bot disabled for this repo (manual rebase workflow)
    - Config fields: AmpUpstreamURL, AmpUpstreamAPIKey, AmpRestrictManagementToLocalhost
    - Compatible with upstream DisableCooling and other features
    
    Technical details:
    - internal/api/modules/amp/: Complete Amp routing module
    - sdk/api/httpx/: HTTP utilities for gzip/transport
    - 94.6% test coverage with 34 comprehensive test cases
    - Clean integration minimizes merge conflict risk
    
    Security:
    - Management routes restricted to localhost by default
    - Configurable via amp-restrict-management-to-localhost
    - Prevents drive-by browser attacks on user data
    
    This provides a production-ready foundation for Amp CLI integration while
    maintaining clean separation from upstream code for easy rebasing.
    
    Amp-Thread-ID: https://ampcode.com/threads/T-9e2befc5-f969-41c6-890c-5b779d58cf18
  • feat(gemini-cli): add multi-project support and enhance credential handling
    Introduce support for multi-project Gemini CLI logins, including shared and virtual credential management. Enhance runtime, metadata handling, and token updates for better project granularity and consistency across virtual and shared credentials. Extend onboarding to allow activating all available projects.
  • feat: add auto model resolution and model creation timestamp tracking
    - Add 'created' field to model registry for tracking model creation time
    - Implement GetFirstAvailableModel() to find the first available model by newest creation timestamp
    - Add ResolveAutoModel() utility function to resolve "auto" model name to actual available model
    - Update request handler to resolve "auto" model before processing requests
    - Ensures automatic model selection when "auto" is specified as model name
    
    This enables dynamic model selection based on availability and creation time, improving the user experience when no specific model is requested.
  • feat(vertex): add support for Vertex AI Gemini authentication and execution
    Introduce Vertex AI Gemini integration with support for service account-based authentication, credential storage, and import functionality. Added new executor for Vertex AI requests, including execution and streaming paths, and integrated it into the core manager. Enhanced CLI with `--vertex-import` flag for importing service account keys.
  • fix(service): skip disabled auth entries during executor binding
    Prevent disabled auth entries from overriding active provider executors, addressing lingering configs during reloads (e.g., removed OpenAI-compat entries).
  • feat(registry): add client model support check for executor filtering
    - Introduced `ClientSupportsModel` function to `ModelRegistry` for verifying client support for specific models.
    - Integrated model support validation into executor candidate filtering logic.
    - Updated CLIProxy registry interface to include the new support check method.
  • feat(translator): add built-in translator registry and helpers
    - Introduced `builtin` package exposing a default registry and pipeline for built-in translators.
    - Added format constants for common schemas (e.g., OpenAI, Gemini, Codex).
    - Implemented helper functions for schema translation using format name strings.
    - Provided example usage for integration with translator helpers.
  • Add support for dynamic model providers
    Implements functionality to parse model names with provider information in the format "provider://model" This allows dynamic provider selection rather than relying only on predefined mappings.
    
    The change affects all execution methods to properly handle these dynamic model specifications while maintaining compatibility with the existing approach for standard model names.
  • feat(claude): add model alias mapping and improve key normalization
    - Introduced model alias mapping for Claude configurations, enabling upstream and client-facing model name associations.
    - Added `computeClaudeModelsHash` to generate a consistent hash for model aliases.
    - Implemented `normalizeClaudeKey` function to standardize input API key configuration, including models.
    - Enhanced executor to resolve model aliases to upstream names dynamically.
    - Updated documentation and configuration examples to reflect new model alias support.
  • feat: add websocket routing and executor unregister API
    - Introduce Server.AttachWebsocketRoute(path, handler) to mount websocket
      upgrade handlers on the Gin engine.
    - Track registered WS paths via wsRoutes with wsRouteMu to prevent
      duplicate registrations; initialize in NewServer and import sync.
    - Add Manager.UnregisterExecutor(provider) for clean executor lifecycle
      management.
    - Add github.com/gorilla/websocket v1.5.3 dependency and update go.sum.
    
    Motivation: enable services to expose WS endpoints through the core server
    and allow removing auth executors dynamically while avoiding duplicate
    route setup. No breaking changes.
  • feat: improve error handling with added status codes and headers
    - Updated Execute methods to include enhanced error handling via `StatusCode` and `Headers` extraction.
    - Introduced structured error responses for cooling down scenarios, providing additional metadata and retry suggestions.
    - Refined quota management, allowing for differentiation between cool-down, disabled, and other block reasons.
    - Improved model filtering logic based on client availability and suspension criteria.
  • Refactor executor error handling and usage reporting
    - Updated the Execute methods in various executors (GeminiCLIExecutor, GeminiExecutor, IFlowExecutor, OpenAICompatExecutor, QwenExecutor) to return a response and error as named return values for improved clarity.
    - Enhanced error handling by deferring failure tracking in usage reporters, ensuring that failures are reported correctly.
    - Improved response body handling by ensuring proper closure and error logging for HTTP responses across all executors.
    - Added failure tracking and reporting in the usage reporter to capture unsuccessful requests.
    - Updated the usage logging structure to include a 'Failed' field for better tracking of request outcomes.
    - Adjusted the logic in the RequestStatistics and Record methods to accommodate the new failure tracking mechanism.
  • Feature: #103
    feat(gemini): add Gemini thinking configuration support and metadata normalization
    
    - Introduced logic to parse and apply `thinkingBudget` and `include_thoughts` configurations from metadata.
    - Enhanced request handling to include normalized Gemini model metadata, preserving the original model identifier.
    - Updated Gemini and Gemini-CLI executors to apply thinking configuration based on metadata overrides.
    - Refactored handlers to support metadata extraction and cloning during request preparation.
  • fix: add Claude→Claude passthrough to prevent SSE event fragmentation
    When from==to (Claude→Claude scenario), directly forward SSE stream
    line-by-line without invoking TranslateStream. This preserves the
    multi-line SSE event structure (event:/data:/blank) and prevents
    JSON parsing errors caused by event fragmentation.
    
    Resolves: JSON parsing error when using Claude Code streaming responses
    
    fix: correct SSE event formatting in Handler layer
    
    Remove duplicate newline additions (\n\n) that were breaking SSE event format.
    The Executor layer already provides properly formatted SSE chunks with correct
    line endings, so the Handler should forward them as-is without modification.
    
    Changes:
    - Remove redundant \n\n addition after each chunk
    - Add len(chunk) > 0 check before writing
    - Format error messages as proper SSE events (event: error\ndata: {...}\n\n)
    - Add chunkIdx counter for future debugging needs
    
    This fixes JSON parsing errors caused by malformed SSE event streams.
    
    fix: update comments for clarity in SSE event forwarding
  • feat(usage): add support for tracking request source in usage records
    - Introduced `Source` field to usage-related structs for better origin tracking.
    - Updated `newUsageReporter` to resolve and populate the `Source` attribute.
    - Implemented `resolveUsageSource` to determine source from auth metadata or API key.