Commit Graph

33 Commits

  • Fixed: #942
    fix(executor): ignore non-SSE lines in OpenAI-compatible streams
  • feat(executor): enhance payload translation with original request context
    Refactored `applyPayloadConfig` to `applyPayloadConfigWithRoot`, adding support for default rule validation against the original payload when available. Updated all executors to use `applyPayloadConfigWithRoot` and incorporate an optional original request payload for translations.
  • refactor(thinking): export thinking helpers
    Expose thinking/effort normalization helpers from the executor package
    so conversion tests use production code and stay aligned with runtime
    validation behavior.
  • fix(executor): add allowCompat support for reasoning effort normalization
    Introduced `allowCompat` parameter to improve compatibility handling for reasoning effort in payloads across OpenAI and similar models.
  • fix(openai-compat): prevent model alias from being overwritten by ResolveOriginalModel
    When using OpenAI-compatible providers with model aliases (e.g., glm-4.6-zai -> glm-4.6),
    the alias resolution was correctly applied but then immediately overwritten by
    ResolveOriginalModel, causing 'Unknown Model' errors from upstream APIs.
    
    This fix skips the ResolveOriginalModel override when a model alias has already
    been resolved, ensuring the correct model name is sent to the upstream provider.
    
    Co-authored-by: Amp <amp@ampcode.com>
  • Merge pull request #481 from sususu98/fix/increase-buffer-size
    fix: increase buffer size for stream scanners to 50MB across multiple executors
  • 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.
  • **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.
  • **feat(runtime): add payload configuration support for executors**
    Introduce `PayloadConfig` in the configuration to define default and override rules for modifying payload parameters. Implement `applyPayloadConfig` and `applyPayloadConfigWithRoot` to apply these rules across various executors, ensuring consistent parameter handling for different models and protocols. Update all relevant executors to utilize this functionality.
  • fix(executor): ensure usage reporting for upstream responses lacking usage data
    Add `ensurePublished` to guarantee request counting even when usage fields (e.g., tokens) are absent in OpenAI-compatible executor responses, particularly for streaming paths.
  • Fixed: #140 #133 #80
    feat(translator): add token counting functionality for Gemini, Claude, and CLI
    
    - Introduced `TokenCount` handling across various Codex translators (Gemini, Claude, CLI) with respective implementations.
    - Added utility methods for token counting and formatting responses.
    - Integrated `tiktoken-go/tokenizer` library for tokenization.
    - Updated CodexExecutor with token counting logic to support multiple models including GPT-5 variants.
    - Refined go.mod and go.sum to include new dependencies.
    
    feat(runtime): add token counting functionality across executors
    
    - Implemented token counting in OpenAICompatExecutor, QwenExecutor, and IFlowExecutor.
    - Added utilities for token counting and response formatting using `tiktoken-go/tokenizer`.
    - Integrated token counting into translators for Gemini, Claude, and Gemini CLI.
    - Enhanced multiple model support, including GPT-5 variants, for token counting.
    
    docs: update environment variable instructions for multi-model support
    
    - Added details for setting `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, and `ANTHROPIC_DEFAULT_HAIKU_MODEL` for version 2.x.x.
    - Clarified usage of `ANTHROPIC_MODEL` and `ANTHROPIC_SMALL_FAST_MODEL` for version 1.x.x.
    - Expanded examples for setting environment variables across different models including Gemini, GPT-5, Claude, and Qwen3.
  • 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.
  • Enhance logging for API requests and responses across executors
    - Added detailed logging of upstream request metadata including URL, method, headers, and body for Codex, Gemini, IFlow, OpenAI Compat, and Qwen executors.
    - Implemented error logging for API response failures to capture errors during HTTP requests.
    - Introduced structured logging for authentication details (AuthID, AuthLabel, AuthType, AuthValue) to improve traceability.
    - Updated response logging to include status codes and headers for better debugging.
    - Ensured that all executors consistently log API interactions to facilitate monitoring and troubleshooting.
  • feat(registry/runtime): add Gemini 2.5 model and increase buffer sizes
    - Added new "Gemini 2.5 Flash Image Preview" model definition, with enhanced image generation capabilities.
    - Increased scanner buffer size to 20,971,520 bytes across executors and translators to handle larger payloads.
  • feat(auth): improve OpenAI compatibility normalization and API key handling
    - Refined trimming and normalization logic for `baseURL` and `apiKey` attributes.
    - Updated `Authorization` header logic to omit empty API keys.
    - Enhanced compatibility processing by handling empty `api-key-entries`.
    - Improved legacy format fallback and added safeguards for empty credentials across executor paths.
  • feat(runtime): introduce newProxyAwareHTTPClient for enhanced proxy handling
    - Added `newProxyAwareHTTPClient` to centralize proxy configuration with priority on `auth.ProxyURL` and `cfg.ProxyURL`.
    - Integrated enhanced proxy support across executors for HTTP, HTTPS, and SOCKS5 protocols.
    - Refactored redundant HTTP client initialization to use `newProxyAwareHTTPClient` for consistent behavior.
  • feat(usage): implement usage tracking infrastructure across executors
    - Added `LoggerPlugin` to log usage metrics for observability.
    - Introduced a new `Manager` to handle usage record queuing and plugin registration.
    - Integrated new usage reporter and detailed metrics parsing into executors, covering providers like OpenAI, Codex, Claude, and Gemini.
    - Improved token usage breakdown across streaming and non-streaming responses.
  • feat(executor): add CountTokens support across all executors
    - Introduced `CountTokens` method to Codex, Claude, Gemini, Qwen, OpenAI-compatible, and other executors.
    - Implemented `ExecuteCount` in `AuthManager` for token counting via provider round-robin.
    - Updated handlers to leverage `ExecuteCountWithAuthManager` for streamlined token counting.
    - Added fallback and error handling logic for token counting requests.
  • chore(executor): add debug logging for API request errors
    - Added detailed debug logs in all executors (Codex, Claude, Gemini, Qwen, OpenAI-compatible) to capture HTTP status and response body for failed API requests.
  • feat(openai-compat): enhance provider key handling and model resolution
    - Introduced dynamic `providerKey` resolution for OpenAI-compatible providers, incorporating attributes like `provider_key` and `compat_name`.
    - Implemented upstream model overrides via `resolveUpstreamModel` and `overrideModel` methods in the OpenAI executor.
    - Updated registry logic to correctly store provider mappings and register clients using normalized keys.
    - Ensured consistency in handling empty or default provider names across components.
  • chore(logging): add debug logs for executor Refresh methods
    - Introduced `logrus` for structured debugging across all executors.
    - Added debug log messages in `Refresh` methods for better traceability.
    - Updated `Manager` to log additional details during refresh checks.
  • 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.