Commit Graph

13 Commits

  • 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: add prioritize-model-mappings config option
    Add a configuration option to control whether model mappings take
    precedence over local API keys for Amp CLI requests.
    
    - Add PrioritizeModelMappings field to AmpCode config struct
    - When false (default): Local API keys take precedence (original behavior)
    - When true: Model mappings take precedence over local API keys
    - Add management API endpoints GET/PUT /prioritize-model-mappings
    
    This allows users who want mapping priority to enable it explicitly
    while preserving backward compatibility.
    
    Config example:
      ampcode:
        model-mappings:
          - from: claude-opus-4-5-20251101
            to: gemini-claude-opus-4-5-thinking
        prioritize-model-mappings: true
  • fix(amp): pass mapped model to gemini bridge via context
    Gemini handler extracts model from URL path, not JSON body, so
    rewriting the request body alone wasn't sufficient for model mapping.
    
    - Add MappedModelContextKey constant for context passing
    - Update routes.go to use NewFallbackHandlerWithMapper
    - Add check for valid mapping before routing to local handler
    - Add tests for gemini bridge model mapping
  • feat(amp): add model mapping support for routing unavailable models to alternatives
    - Add AmpModelMapping config to route models like 'claude-opus-4.5' to 'claude-sonnet-4'
    - Add ModelMapper interface and DefaultModelMapper implementation with hot-reload support
    - Enhance FallbackHandler to apply model mappings before falling back to ampcode.com
    - Add structured logging for routing decisions (local provider, mapping, amp credits)
    - Update config.example.yaml with amp-model-mappings documentation
  • fix(amp): enable OAuth fallback for Gemini v1beta1 routes
    AMP CLI sends Gemini requests to non-standard paths that were being
    directly proxied to ampcode.com without checking for local OAuth.
    
    This fix adds:
    - GeminiBridge handler to transform AMP CLI paths to standard format
    - Enhanced model extraction from AMP's /publishers/google/models/* paths
    - FallbackHandler wrapper to check for local OAuth before proxying
    
    Flow:
    - If user has local Google OAuth → use it (free tier)
    - If no local OAuth → fallback to ampcode.com (charges credits)
    
    Fixes issue where gemini-3-pro-preview requests always charged AMP
    credits even when user had valid Google Cloud OAuth configured.
  • fix(amp): filter context-1m beta header for local OAuth providers
    Amp CLI sends 'context-1m-2025-08-07' in Anthropic-Beta header which
    requires a special 1M context window subscription. After upstream rebase
    to v6.3.7 (commit 38cfbac), CLIProxyAPI now respects client-provided
    Anthropic-Beta headers instead of always using defaults.
    
    When users configure local OAuth providers (Claude, etc), requests bypass
    the ampcode.com proxy and use their own API subscriptions. These personal
    subscriptions typically don't include the 1M context beta feature, causing
    'long context beta not available' errors.
    
    Changes:
    - Add filterBetaFeatures() helper to strip specific beta features
    - Filter context-1m-2025-08-07 in fallback handler when using local providers
    - Preserve full headers when proxying to ampcode.com (paid users get all features)
    - Add 7 test cases covering all edge cases
    
    This fix is isolated to the Amp module and only affects the local provider
    path. Users proxying through ampcode.com are unaffected and receive full
    1M context support as part of their paid service.
  • 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