Commit Graph

66 Commits

  • fix: apply thinkingLevel from model suffix metadata for Gemini 3
    The previous commit added thinkingLevel support but didn't apply it
    when the reasoning effort came from model name suffix (e.g., model(minimal)).
    
    This was because ResolveThinkingConfigFromMetadata returns nil for
    level-based models, bypassing the metadata application.
    
    Changes:
    - Add ApplyGemini3ThinkingLevelFromMetadata for standard Gemini API
    - Add ApplyGemini3ThinkingLevelFromMetadataCLI for CLI API format
    - Update gemini_cli_executor to apply Gemini 3 thinkingLevel from metadata
    - Update antigravity_executor to apply Gemini 3 thinkingLevel from metadata
    - Update aistudio_executor to apply Gemini 3 thinkingLevel from metadata
    - Add comprehensive test coverage for Gemini 3 thinkingLevel functions
  • feat: use thinkingLevel for Gemini 3 models per Google documentation
    Per Google's official documentation, Gemini 3 models should use
    thinkingLevel (string) instead of thinkingBudget (number) for
    optimal performance.
    
    From Google's Gemini Thinking docs:
    > Use the thinkingLevel parameter with Gemini 3 models. While
    > thinkingBudget is accepted for backwards compatibility, using
    > it with Gemini 3 Pro may result in suboptimal performance.
    
    Changes:
    - Add model family detection functions (IsGemini3Model, IsGemini25Model,
      IsGemini3ProModel, IsGemini3FlashModel)
    - Add ApplyGeminiThinkingLevel and ApplyGeminiCLIThinkingLevel functions
      for applying thinkingLevel config
    - Add ValidateGemini3ThinkingLevel for model-specific level validation
    - Add ThinkingBudgetToGemini3Level for backward compatibility conversion
    - Update NormalizeGeminiThinkingBudget to convert budget to level for
      Gemini 3 models
    - Update ApplyDefaultThinkingIfNeeded to not set a default level for
      Gemini 3 (lets API use its dynamic default "high")
    - Update ConvertThinkingLevelToBudget to preserve thinkingLevel for
      Gemini 3 models
    - Add Levels field to all Gemini 3 model definitions:
      - Gemini 3 Pro: ["low", "high"]
      - Gemini 3 Flash: ["minimal", "low", "medium", "high"]
    
    Backward compatibility:
    - Gemini 2.5 models continue to use thinkingBudget as before
    - If thinkingBudget is provided for Gemini 3, it's converted to the
      appropriate thinkingLevel
    - Existing configurations continue to work
  • feature: Improves schema flattening and tool use handling
    Updates schema flattening logic to handle multiple non-null types, providing a more descriptive "Accepts" hint.
    
    Removes redundant tracking of the current tool name in `Params` as it's no longer needed for streaming limits, simplifying the structure.
  • Update internal/util/translator.go
    Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
  • feature: Improves Gemini JSON schema compatibility
    Enhances compatibility with the Gemini API by implementing a schema cleaning process.
    
    This includes:
    - Centralizing schema cleaning logic for Gemini in a dedicated utility function.
    - Converting unsupported schema keywords to hints within the description field.
    - Flattening complex schema structures like `anyOf`, `oneOf`, and type arrays to simplify the schema.
    - Handling streaming responses with empty tool names, which can occur in subsequent chunks after the initial tool use.
  • fix(thinking): align budget effort mapping across translators
    Unify thinking budget-to-effort conversion in a shared helper, handle disabled/default thinking cases in translators, adjust zero-budget mapping, and drop the old OpenAI-specific helper with updated tests.
  • fix(thinking): normalize effort mapping
    Route OpenAI reasoning effort through ThinkingEffortToBudget for Claude
    translators, preserve "minimal" when translating OpenAI Responses, and
    treat blank/unknown efforts as no-ops for Gemini thinking configs.
    
    Also map budget -1 to "auto" and expand cross-protocol thinking tests.
  • fix(thinking): centralize reasoning_effort mapping
    Move OpenAI `reasoning_effort` -> Gemini `thinkingConfig` budget logic into
    shared helpers used by Gemini, Gemini CLI, and antigravity translators.
    
    Normalize Claude thinking handling by preferring positive budgets, applying
    budget token normalization, and gating by model support.
    
    Always convert Gemini `thinkingBudget` back to OpenAI `reasoning_effort` to
    support allowCompat models, and update tests for normalization behavior.
  • fix(executor): improve model compatibility handling for OpenAI-compatibility
    Enhances payload handling by introducing OpenAI-compatibility checks and refining how reasoning metadata is resolved, ensuring broader model support.
  • fix(thinking): map budgets to effort levels
    Ensure thinking settings translate correctly across providers:
    - Only apply reasoning_effort to level-based models and derive it from numeric
      budget suffixes when present
    - Strip effort string fields for budget-based models and skip Claude/Gemini
      budget resolution for level-based or unsupported models
    - Default Gemini include_thoughts when a nonzero budget override is set
    - Add cross-protocol conversion and budget range tests
  • refactor(thinking): use bracket tags for thinking meta
    Align thinking suffix handling on a single bracket-style marker.
    
    NormalizeThinkingModel strips a terminal `[value]` segment from
    model identifiers and turns it into either a thinking budget (for
    numeric values) or a reasoning effort hint (for strings). Emission
    of `ThinkingIncludeThoughtsMetadataKey` is removed.
    
    Executor helpers and the example config are updated so their
    comments reference the new `[value]` suffix format instead of the
    legacy dash variants.
    
    BREAKING CHANGE: dash-based thinking suffixes (`-thinking`,
    `-thinking-N`, `-reasoning`, `-nothinking`) are no longer parsed
    for thinking metadata; only `[value]` annotations are recognized.
  • fix(util): do not strip thinking suffix on registered models
    NormalizeThinkingModel now checks ModelSupportsThinking before removing
    "-thinking" or "-thinking-<ver>", avoiding accidental parsing of model
    names where the suffix is part of the official id (e.g., kimi-k2-thinking,
    qwen3-235b-a22b-thinking-2507).
    
    The registry adds ThinkingSupport metadata for several models and
    propagates it via ModelInfo (e.g., kimi-k2-thinking, deepseek-r1,
    qwen3-235b-a22b-thinking-2507, minimax-m2), enabling accurate detection
    of thinking-capable models and correcting base model inference.
  • feat(util): implement dynamic thinking suffix normalization and refactor budget resolution logic
    - Added support for parsing and normalizing dynamic thinking model suffixes.
    - Centralized budget resolution across executors and payload helpers.
    - Retired legacy Gemini-specific thinking handlers in favor of unified logic.
    - Updated executors to use metadata-based thinking configuration.
    - Added `ResolveOriginalModel` utility for resolving normalized upstream models using request metadata.
    - Updated executors (Gemini, Codex, iFlow, OpenAI, Qwen) to incorporate upstream model resolution and substitute model values in payloads and request URLs.
    - Ensured fallbacks handle cases with missing or malformed metadata to derive models robustly.
    - Refactored upstream model resolution to dynamically incorporate metadata for selecting and normalizing models.
    - Improved handling of thinking configurations and model overrides in executors.
    - Removed hardcoded thinking model entries and migrated logic to metadata-based resolution.
    - Updated payload mutations to always include the resolved model.
  • **feat(util): add -reasoning suffix support for Gemini models**
    Adds support for the `-reasoning` model name suffix which enables
    thinking/reasoning mode with dynamic budget. This allows clients to
    request reasoning-enabled inference using model names like
    `gemini-2.5-flash-reasoning` without explicit configuration.
    
    The suffix is normalized to the base model (e.g., gemini-2.5-flash)
    with thinkingBudget=-1 (dynamic) and include_thoughts=true.
    
    Follows the existing pattern established by -nothinking and
    -thinking-N suffixes.
  • Fixed: #291
    **feat(executor): add thinking level to budget conversion utility**
    
    - Introduced `ConvertThinkingLevelToBudget` to map thinking level ("high"/"low") to corresponding budget values.
    - Applied the utility in `aistudio_executor.go` before stripping unsupported configs.
    - Updated dependencies to include `tidwall/gjson` for JSON parsing.
  • 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 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.
  • Fixed: #129 #123 #102 #97
    feat: add all protocols request and response translation for Gemini and Gemini CLI compatibility
  • 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.
  • feat(registry, executor, util): add support for gemini-2.5-flash-image-preview and improve aspect ratio handling
    - Introduced `gemini-2.5-flash-image-preview` model to the registry with updated definitions.
    - Enhanced Gemini CLI and API executors to handle image aspect ratio adjustments for the new model.
    - Added utility function to create base64 white image placeholders based on aspect ratio configurations.
  • refactor(proxy): improve SOCKS5 proxy authentication handling
    - Added nil check for proxy user credentials to prevent potential nil pointer dereference.
    - Enhanced authentication logic for SOCKS5 proxies in `proxy_helpers.go` and `proxy.go`.
  • refactor(util): Centralize auth directory path resolution
    Introduces a new utility function, `util.ResolveAuthDir`, to handle the normalization and resolution of the authentication directory path.
    
    Previously, the logic for expanding the tilde (~) to the user's home directory was implemented inline in `main.go`. This refactoring extracts that logic into a reusable function within the `util` package.
    
    The new `ResolveAuthDir` function is now used consistently across the application:
    - During initial server startup in `main.go`.
    - When counting authentication files in `util.CountAuthFiles`.
    - When the configuration is reloaded by the watcher.
    
    This change eliminates code duplication, improves consistency, and makes the path resolution logic more robust and maintainable.
  • refactor(config): migrate to SDKConfig and streamline proxy handling
    - Replaced `config.Config` with `config.SDKConfig` across components for simpler configuration management.
    - Updated proxy setup functions and handlers to align with `SDKConfig` improvements.
    - Reorganized handler imports to match new SDK structure.
  • feat(logging): introduce centralized logging with custom format and Gin integration
    - Implemented a global logger with structured formatting for consistent log output.
    - Added support for rotating log files using Lumberjack.
    - Integrated new logging functionality with Gin HTTP server for unified log handling.
    - Replaced direct `log.Info` calls with `fmt.Printf` in non-critical paths to simplify core functionality.
  • chore(docs): add and refine package-level comments across modules
    - Added detailed package-level comments to improve documentation coverage.
    - Clarified parameter descriptions, return types, and functionality of exported methods across packages.
    - Enhanced overall code readability and API documentation consistency.
  • 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.