Commit Graph

134 Commits

Author SHA1 Message Date
hkfires 3ac5f05e8c feat(gemini): prefer official reasoning fields, add extra_body(cherry studio) fallback 2025-10-29 19:19:18 +08:00
hkfires 2a3ee8d0e3 fix(translators): normalize thinking budgets 2025-10-29 19:19:17 +08:00
hkfires 41577bce07 feat(claude): map Anthropic 'thinking' to Gemini thinkingBudget 2025-10-29 19:19:17 +08:00
hkfires 680b3f5010 fix(translator): avoid default thinkingConfig in Gemini requests 2025-10-29 19:19:17 +08:00
Luis Pater 0defb68c6c fix(translator): improve error handling for function parameters schema transformation
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Added fallback to set default `parametersJsonSchema` when `parameters` key is absent.
- Enhanced logging to capture detailed errors during schema transformation.
- Refined tool declaration appending logic for robustness.
2025-10-28 22:57:26 +08:00
tobwen e5ed2cba4a 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.
2025-10-28 01:41:54 +01:00
Luis Pater 6f9c23af5e #167
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
refactor(translator): consolidate Claude content handling logic

- Unified logic for text and image content conversion to improve maintainability.
- Introduced `convertClaudeContentPart` utility for consistent content transformation.
- Replaced redundant string operations with streamlined JSON modifications.
- Adjusted validation checks for message content generation.
2025-10-27 22:43:59 +08:00
hkfires 7061cd6058 fix(gemini): map responseModalities to uppercase IMAGE/TEXT 2025-10-26 19:35:22 +08:00
Luis Pater a552a45b81 Fixed: #140 #133 #80
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
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.
2025-10-26 05:39:15 +08:00
Luis Pater f6cf784cd1 refactor(translator): remove unused log dependency and comment out debug logging
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
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.
2025-10-24 12:15:15 +08:00
Luis Pater e6d7677373 docs: add GPT-5 Codex guidelines for internal usage
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- 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.
2025-10-23 09:14:56 +08:00
Luis Pater 243bf5c108 feat: enhance tool call handling in OpenAI response conversion
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
2025-10-21 20:04:24 +08:00
Luis Pater 307ae76ed4 refactor: streamline ConvertCodexResponseToGeminiNonStream by removing unnecessary buffer and improving response handling
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
2025-10-18 16:08:30 +08:00
Luis Pater 735b21394c Fixed: #137
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
refactor: simplify ConvertCodexResponseToClaudeNonStream by removing bufio.Scanner usage and restructuring response parsing logic
2025-10-18 06:22:42 +08:00
Luis Pater 9cdef937af fix: initialize contentBlocks with an empty slice and improve content handling in ConvertOpenAIResponseToClaudeNonStream
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
2025-10-17 08:47:09 +08:00
Luis Pater 4477c729a4 Fixed: #129 #123 #102 #97
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
feat: add all protocols request and response translation for Gemini and Gemini CLI compatibility
2025-10-17 02:11:29 +08:00
Luis Pater 0d89a22aa0 feat: add handling for function call finish reasons in OpenAI response conversion
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
2025-10-17 00:19:32 +08:00
Luis Pater eb2549a782 fix(gemini): update response template to omit finishReason until known
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
2025-10-16 06:41:04 +08:00
Luis Pater c419264a70 fix(responses): handle empty and invalid rawJSON in ConvertOpenAIChatCompletionsResponseToOpenAIResponses 2025-10-16 06:34:00 +08:00
Luis Pater 5ab0854b5b fix(claude): track message_start event in streaming response
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
Add a `MessageStarted` flag to `ConvertOpenAIResponseToAnthropicParams` to ensure the `message_start` event is emitted only once during streaming.
Refactor response handling to detect streaming mode via the `stream` field instead of the `object` type, simplifying the branching logic.
Update the streaming conversion to set `MessageStarted` after sending the `message_start` event, preventing duplicate starts.
These changes improve correctness of streaming response handling for Claude integration.
2025-10-16 03:54:48 +08:00
Luis Pater b641d90287 Fixed #91
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
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.
2025-10-15 12:58:18 +08:00
Luis Pater 4576f9915b Fixed: #121
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
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.
2025-10-15 09:32:12 +08:00
Luis Pater c945e35983 feat(translator): improve Claude request handling with enhanced content processing
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- 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.
2025-10-14 23:58:37 +08:00
Luis Pater 599986495b feat(translator): enhance OpenAI Gemini request handling for mixed content
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Replaced `contentParts` with `aggregatedParts` to support mixed content (text and inline data).
- Introduced `textBuilder` for efficient text concatenation.
- Added support for inline data processing, including base64-encoded image URLs.
- Updated `msg["content"]` logic to handle both plain text and mixed content scenarios.
2025-10-13 02:15:55 +08:00
hkfires c3f88126e6 refactor(provider): remove Gemini Web cookie-based support 2025-10-11 12:56:07 +08:00
hkfires b895018ff5 refactor(provider): remove Gemini Web cookie-based provider 2025-10-11 12:53:03 +08:00
Luis Pater 11f090c223 Fixed #102
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
feat(translator): add support for removing `strict` in Gemini request transformation

- Updated API and CLI translators to remove the `strict` path during request transformation, in addition to existing predefined JSON paths.
2025-10-10 02:59:21 +08:00
hkfires 01be94a0de feat(translator): Map OpenAI modalities to Gemini responseModalities 2025-10-09 19:38:07 +08:00
hkfires d1933075c3 Revert "feat(translator): Pass through imageConfig" 2025-10-09 16:35:08 +08:00
hkfires a602ae859b feat(translator): Add support for openrouter image_config 2025-10-09 15:47:06 +08:00
hkfires c5d7137d66 feat(translator): Pass through imageConfig 2025-10-09 13:50:43 +08:00
Luis Pater d6f671250e Fixed: #97
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
feat(translator): enhance request and response parsing for Gemini API and CLI

- Added support for removing predefined JSON paths (`additionalProperties`, `$schema`, `ref`) during request transformation for Gemini.
- Introduced `FunctionIndex` parameter to manage function call indexing in streaming responses for both API and CLI translators.
- Improved handling of tool call content and function call templates in response parsing logic.
2025-10-08 23:49:21 +08:00
Luis Pater 4bc8a52771 Merge pull request #90 from router-for-me/dethink
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
Dethink
2025-10-07 03:41:19 +08:00
Luis Pater b727e4e12e Fixed: #86
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
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.
2025-10-07 02:10:59 +08:00
hkfires 31659c790d feat(translator/gemini-cli): support inline image data in responses 2025-10-06 17:06:04 +08:00
Luis Pater bbdd68a8b4 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.
2025-10-06 04:44:45 +08:00
Luis Pater 644a3ad220 feat(translator): emit response.output_item.done event for reasoning summary completion
- Added `response.output_item.done` event emission in OpenAI responses.
- Enhanced reasoning output finalization with additional response event for improved tracking.
2025-09-29 17:25:41 +08:00
Ben Vargas 9e3b84939f 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.
2025-09-27 15:44:33 -06:00
Luis Pater 40255b128e feat(translator): add usage metadata aggregation for Claude and OpenAI responses
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Integrated input, output, reasoning, and total token tracking in response processing for Claude and OpenAI.
- Ensured support for usage details even when specific fields are missing in the response.
- Enhanced completion outputs with aggregated usage details for accurate reporting.
2025-09-27 01:12:47 +08:00
Luis Pater 6524d3a51e feat(translator): add usage metadata mapping for Gemini responses
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Implemented mapping for input, output, and total token usage in Gemini OpenAI response processing.
- Ensured compatibility with existing response structure even when specific token details are unavailable.
2025-09-27 00:23:09 +08:00
Luis Pater 92c8cd7c72 refactor(translator): remove unnecessary debug log in ConvertOpenAIRequestToGeminiCLI function 2025-09-26 23:18:58 +08:00
Luis Pater 6d4b43dd7a feat(translator): add user metadata generation for Claude transformation requests
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
- Introduced unique `user_id` metadata generation in OpenAI to Claude transformation functions.
- Utilized `uuid` and `sha256` for deterministic `account`, `session`, and `user` values.
- Embedded `user_id` into request payloads to enhance request tracking and identification.
2025-09-26 22:47:21 +08:00
Luis Pater f5dc380b63 rebuild branch
docker-image / docker (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
2025-09-25 10:32:48 +08:00
Luis Pater 3f69254f43 remove all 2025-09-25 10:31:02 +08:00
Luis Pater 0db0b03db9 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.
2025-09-25 00:14:17 +08:00
Luis Pater 48bbd9e214 fix(gemini): handle "[DONE]" chunk, trim "data:" prefix, and remove session_id from requests
- Adjusted stream handling to skip "[DONE]" chunks.
- Ensured "data:" prefix is trimmed for non-prefixed input in translation.
- Removed `session_id` from request bodies before processing.
2025-09-24 23:34:46 +08:00
Luis Pater 3dd5095792 feat(translators): add token counting support for Claude and Gemini responses
- Implemented `TokenCount` transform method across translators to calculate token usage.
- Integrated token counting logic into executor pipelines for Claude, Gemini, and CLI translators.
- Added corresponding API endpoints and handlers (`/messages/count_tokens`) for token usage retrieval.
- Enhanced translation registry to support `TokenCount` functionality alongside existing response types.
2025-09-24 11:59:38 +08:00
Luis Pater 3ade03f3b3 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.
2025-09-24 03:49:09 +08:00
Luis Pater d41ff2076f 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.
2025-09-23 23:12:34 +08:00
Luis Pater b018072914 fix(gemini): trim "data:" prefix in raw JSON and resolve variable shadowing in stream translation 2025-09-23 21:22:41 +08:00