Commit Graph

41 Commits

  • 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: use underscore suffix in short name mapping
    Replace the "~<n>" suffix with "_<n>" when generating unique short names in codex translators (Claude, Gemini, OpenAI chat).
    This avoids using a special character in identifiers, improving compatibility with downstream APIs while preserving length constraints.
  • Fixed: #193
    fix(translator): consolidate temperature and top_p conditionals in OpenAI Claude request
    
    Fixed: #169
    
    fix(translator): adjust instruction strings in Codex Claude and OpenAI responses
  • 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(translator): remove unused log dependency and comment out debug logging
    docs: add GPT-5 Codex guidelines for CLI usage
    
    - Added detailed guidelines for GPT-5 Codex in Codex CLI.
    - Expanded instructions on sandboxing, approvals, editing constraints, and style requirements.
    - Included presentation and response formatting best practices.
    
    fix(codex_instructions): update comparison logic to use prefix matching
    
    - Changed system instructions comparison to use `strings.HasPrefix` for improved flexibility.
  • docs: add GPT-5 Codex guidelines for internal usage
    - Added comprehensive instructions for Codex CLI harness, sandboxing, approvals, and editing constraints to `internal/misc/codex_instructions/`.
    - Clarified `approval_policy` configurations and scenarios requiring escalated permissions.
    - Provided detailed style and structure guidelines for presenting results in the Codex CLI.
  • Fixed: #137
    refactor: simplify ConvertCodexResponseToClaudeNonStream by removing bufio.Scanner usage and restructuring response parsing logic
  • Fixed #91
    refactor(translator): streamline Codex response handling and remove redundant code
    
    - Updated `ConvertCodexResponseToOpenAIResponses` logic for clarity and consistency.
    - Simplified `ConvertCodexResponseToOpenAIResponsesNonStream` by removing unnecessary buffer setup and scanner logic.
    - Switched to using `sjson.SetRaw` for improved processing of raw input strings.
  • Fixed: #121
    feat(translator): map Claude web search tool type to Codex web_search
    
    - Added special handling to replace `web_search_20250305` tool type with `{"type":"web_search"}` in Claude request processing.
  • feat(translator): improve Claude request handling with enhanced content processing
    - Introduced helper functions (`appendTextContent`, `appendImageContent`, etc.) for structured content construction.
    - Refactored message generation logic for better clarity, supporting mixed content scenarios (text, images, and function calls).
    - Added `flushMessage` to ensure proper grouping of message contents.
  • Fixed: #86
    feat(translator): add support for single input string in Codex responses parser
    
    - Modified input parsing logic to handle cases where input is a single string instead of an array.
    - Added functionality to convert single string inputs into structured JSON format.
  • 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.
  • fix(translator): remove unsupported token limit fields for Codex Responses API
    The OpenAI Codex Responses API (chatgpt.com/backend-api/codex/responses)
    rejects requests containing max_output_tokens and max_completion_tokens fields,
    causing Factory CLI to fail with "Unsupported parameter" errors.
    
    This fix strips these incompatible fields during request translation, allowing
    Factory CLI to work properly with CLIProxyAPI when using ChatGPT Plus/Pro OAuth.
    
    Fixes compatibility issue where Factory sends token limit parameters that aren't
    supported by the Codex Responses endpoint.
  • 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(translators): improve system instruction extraction and input handling for OpenAI and Claude responses
    - Enhanced support for extracting system instructions from input arrays.
    - Improved input message role and type determination logic for consistent message processing.
    - Refined instruction handling logic across translator types for better compatibility.
  • feat(translators/claude): implement non-streaming response parsing for various translator types
    - Added `ConvertCodexResponseToClaudeNonStream`, `ConvertGeminiCLIResponseToClaudeNonStream`, `ConvertGeminiResponseToClaudeNonStream`, and `ConvertOpenAIResponseToClaudeNonStream` methods for handling non-streaming JSON response conversion.
    - Introduced logic for parsing and structuring content, handling reasoning, text, and tool usage blocks.
    - Enhanced support for stop reasons and refined token usage data aggregation.
  • feat: introduce custom provider example and remove redundant debug logs
    - Added `examples/custom-provider/main.go` showcasing custom executor and translator integration using the SDK.
    - Removed redundant debug logs from translator modules to enhance code cleanliness.
    - Updated SDK documentation with new usage and advanced examples.
    - Expanded the management API with new endpoints, including request logging and GPT-5 Codex features.
  • 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.
  • refactor: remove redundant Codex instruction validation logic
    - Eliminated unnecessary calls to `misc.CodexInstructions` and corresponding checks in response processing.
    - Streamlined instruction handling by directly updating "instructions" field from the original request payload.
  • Refine Codex instructions for GPT-5 use case
    - Simplified `gpt_5_instructions.txt` by removing redundancy and aligning scope with AGENTS.md standard instructions.
    - Enhanced clarity and relevance of directives per Codex context.
  • feat: implement model-specific Codex instructions for GPT-5
    - Added `CodexInstructions(modelName string)` function to dynamically select instructions based on the model (e.g., GPT-5 Codex).
    - Introduced `gpt_5_instructions.txt` and `gpt_5_codex_instructions.txt` for respective model configurations.
    - Updated translators to pass `modelName` and use the new instruction logic.
  • Update internal module imports to use v5 package path
    - Updated all `github.com/luispater/CLIProxyAPI/internal/...` imports to point to `github.com/luispater/CLIProxyAPI/v5/internal/...`.
    - Adjusted `go.mod` to specify `module github.com/luispater/CLIProxyAPI/v5`.
  • Codex CLI - setting 'store = false'
    store = true leads to:
    BadRequestError("Error code: 400 - {'detail': 'Store must be set to false'}")
  • Add FunctionCallIndex to ConvertCliToOpenAIParams and enhance tool call handling
    - Introduced `FunctionCallIndex` to track and manage function call indices within `ConvertCliToOpenAIParams`.
    - Enhanced handling for `response.completed` and `response.output_item.done` data types to support tool call scenarios.
    - Improved logic for restoring original tool names and setting function arguments during response parsing.
  • Add reverse mappings for original tool names and improve error logging
    - Introduced reverse mapping logic for tool names in translators to restore original names when shortened.
    - Enhanced error handling by logging API response errors consistently across handlers.
    - Refactored request and response loggers to include API error details, improving debugging capabilities.
    - Integrated robust tool name shortening and uniqueness mechanisms for OpenAI, Gemini, and Claude requests.
    - Improved handler retry logic to properly capture and respond to errors.
  • 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
  • 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.