Commit Graph

179 Commits

Author SHA1 Message Date
Luis Pater
aa36527752 fix(translator/claude): downgrade strict mode when schema misses required properties
- Recursively inspect JSON schema properties to detect optional fields not listed in the `required` array.
- Downgrade `strict` to false when schemas contain optional properties to prevent backend HTTP 400 rejections.

Closes: #5463
2026-09-04 02:02:19 +08:00
Luis Pater
893abbabc2 feat(translator): support cache write tokens in claude responses
- Extract cache write tokens from OpenAI and Codex usage details.
- Map cache write tokens to Claude `cache_creation_input_tokens` for streaming and non-streaming responses.

Closes: #4262
2026-09-01 19:56:40 +08:00
Luis Pater
17a65ee547 fix(codex): support reasoning_text in openai chat completion responses
- Handle `response.reasoning_text.delta` and `response.reasoning_text.done` stream events for delta reasoning content.
- Extract `reasoning_text` content from output reasoning items in non-streaming responses.

Closes: #5378
2026-09-01 18:12:52 +08:00
Luis Pater
9fdc460585 fix(claude): preserve tool pairing across intervening system messages
- Preserve pending tool use IDs across message-level system reminders to maintain tool call and result alignment.
- Merge adjacent Gemini request contents for consecutive user and system reminder turns.
- Relax tool response reordering condition and preserve non-response parts in Antigravity executor.
- Align tool results and buffer pending system reminders in OpenAI translator.

Closes: #5354
2026-08-31 19:27:20 +08:00
Luis Pater
f8c45c30c5 feat(codex): map claude output_config format to text format
- Map Claude `output_config.format` with `json_schema` type to Codex `text.format`.
- Preserve custom schema name and strict configuration with appropriate defaults.

Closes: #5280
2026-08-27 18:19:04 +08:00
Luis Pater
5b232e3e98 fix(gemini): generate deterministic sequential IDs for Gemini tool call pairing in Codex/Claude conversions
Closes: #5107
2026-08-21 03:21:55 +08:00
Luis Pater
2005788fc3 fix(codex): filter out prompt_cache_retention in OpenAI→Codex responses request conversion
Closes: #5068
2026-08-19 21:29:03 +08:00
Luis Pater
8b3b304952 perf(translator): switch response translators to batched raw-array insertion via SetRawArrayItems 2026-08-16 01:53:27 +08:00
Luis Pater
0c58c3c83d perf(translator): batch assemble translation arrays before writing JSON
- Refactor Gemini/OpenAI/Codex/Claude/Antigravity interaction and response translators to collect `parts`, `content`, `steps`, `tool_calls`, and `output` items in slices, then set each array once via `translatorcommon` helpers.
- Replace repeated incremental `sjson.SetRawBytes(..., ".-1", ...)` mutations with single-shot raw-array updates to avoid repeated rewrites.
- Keep existing step/content semantics while reducing ordering/overwrite risks when merging multi-fragment data (including thought/signature and web-search/function-call blocks).
2026-08-16 01:25:28 +08:00
Luis Pater
124dab6cc1 perf(translator): batch assemble response arrays and merge multi-choice parts
- Refactor multiple OpenAI/Gemini/Codex/Claude/Antigravity/Interactions response translators to collect output elements in slices and set arrays once via `translatorcommon.JoinRawArray`.
- Fix non-stream OpenAI→Gemini part handling so fields (`reasoning`, `content`, `functionCall`) from multiple choices overlay correctly on shared parts instead of being overwritten.
- Preserve explicit empty message fields in Gemini→OpenAI chat-completion conversion (`content`/`reasoning_content`) and add tests covering empty-text and cross-choice overlay cases.
2026-08-15 23:15:50 +08:00
Luis Pater
6edf9c4821 fix(translator): strip nested prompt_cache_breakpoint from Codex Responses payloads
- Remove `prompt_cache_breakpoint` from `input[].content[]` items during OpenAI Responses → Codex request conversion to avoid unsupported-field rejection.
- Keep message contents and existing `system`→`developer` role conversion behavior unchanged while applying the cleanup.

Closes: #4951
2026-08-15 00:37:09 +08:00
Luis Pater
8b54db36ae fix(translator): drop Gemini hidden thought parts during request conversion
Closes: #4914
2026-08-13 01:10:04 +08:00
Luis Pater
2ab25eae96 fix(codex): strip unsupported prompt_cache_options from OpenAI Responses requests
Closes: #4915
2026-08-12 17:18:21 +08:00
Luis Pater
e9c44ae256 fix(codex): fall back to current tool-call state when item IDs don’t match
- Update `findToolCallState` to only return `toolCallStates` entries when a non-nil state exists.
- Preserve `currentToolCall` fallback for unknown `item_id`, `id`, or `output_index` lookups to keep streaming tool-call context intact.

Closes: #4901
2026-08-12 01:44:07 +08:00
jizhenggang
c30e60a11b Reduce Codex request amplification for large payloads
Reuse immutable request bytes during input inspection and avoid a redundant websocket clone while preserving the required outbound envelope.

Constraint: Preserve request immutability and one final WebSocket request-body allocation
Rejected: In-place JSON mutation | request buffers are shared across translation and execution stages
Confidence: high
Scope-risk: narrow
Directive: Do not retain no-copy gjson results or mutate their backing payload while results are in use
Tested: GOTOOLCHAIN=local go test ./...; targeted 8 MiB allocation benchmarks
Not-tested: Live Codex upstream network traffic
2026-08-07 19:16:06 +08:00
Luis Pater
dcee14dd3c feat(compat): preserve compat-mode thinking/signature blocks for API-key models
- Added `is-compat` model metadata plumbing from config through executor and helpers, including hash computation.
- Introduced a compatibility-aware translation path (`TranslateRequestWithAPIKeyModelCompatibility`) and wired it into Claude/Gemini/Codex/Interactions request flows.
- Updated Claude message sanitization/translation behavior to keep empty-thinking compatibility blocks (including signatures) when `is-compat` is enabled, while keeping default behavior unchanged.
2026-08-06 17:19:24 +08:00
Luis Pater
9b8d97441e fix(responses): preserve original request model on response.created/response.in_progress payloads 2026-08-04 18:37:01 +08:00
Luis Pater
44d5e0bebc fix(codex): preserve base64 PDF document blocks when converting Claude requests to Codex
Closes: #4765
2026-08-04 03:07:00 +08:00
sususu
b3046d29b9 feat(thinking): preserve cross-protocol summary visibility 2026-07-30 21:53:30 +08:00
Luis Pater
fecebcca59 refactor(translator): overhaul function call handling in Codex response conversion
- Replaced `pendingCodexFunctionCall` with `codexFunctionCallStream` for enhanced function call tracking.
- Introduced `DeferredStreamEvents` to handle deferred event processing.
- Simplified and standardized codex function call state management with consolidated methods.
- Enhanced reasoning and thinking block handling to ensure proper closure and new block initiation.
- Removed redundant methods, improving maintainability.

Closes: #4655
2026-07-29 23:33:11 +08:00
Luis Pater
181242b1c0 feat(translator): enhance tool output parsing with support for input_image types
- Added handling for `input_image` in `toolOutputContentPart` and updated related parsing logic.
- Introduced `hasToolOutputImagePart` to check content for image-related types.
- Improved `setToolCallOutputContent` to handle structured content with image parts recursively.
- Refined detail extraction and type mapping for `input_image` and `image_url` cases.

Closes: #4458
2026-07-27 17:54:50 +08:00
Luis Pater
6491ce3991 refactor(translator): improve tool name handling and resolve conflicts
- Enhanced handling of unique and ambiguous tool names for `custom` and `function` types.
- Consolidated name validation and shortening logic for clarity.
- Refactored `resolveToolCall` to standardize tool call processing.
- Improved support for tool name disambiguation and metadata mapping.

Closes: #4208
2026-07-27 02:33:38 +08:00
Luis Pater
58ede93e33 refactor(translator): enhance tool call handling for streaming responses
- Introduced `toolCallStreamState` to manage tool call state transitions.
- Improved support for `custom_tool_call` types with fallback handling.
- Refactored argument emission logic for better clarity and flexibility.
- Added utility methods for managing and retrieving tool call states.

Closes: #4078
2026-07-26 23:51:19 +08:00
sususu98
94cf4674d7 fix(translator/codex): keep single thinking block per reasoning item in streaming translator (#4581)
Keep a single Claude thinking block open across multiple reasoning summary
parts for one Codex reasoning item, and finalize it only when output_item.done
delivers the item's final encrypted_content.

Previously, each summary part closed the preceding thinking block with the
pre-content encrypted_content snapshot captured at output_item.added. This
emitted N thinking blocks with placeholder signatures for one reasoning item,
causing client replay to append redundant placeholder reasoning items into
conversation history.

Add regression tests verifying that multi-part summary reasoning items produce
exactly one thinking block signed with the final encrypted_content.
2026-07-26 12:21:37 +08:00
Luis Pater
64291120e7 perf(translator): add unit tests for payload reuse and normalization across translators
- Added tests to ensure no-copy payload reuse for various translators (Codex, Gemini, OpenAI, Claude, etc.).
- Covered scenarios for field normalization, tool parameter cleaning, and thought signature sanitization.
- Included a benchmark for SanitizeGeminiRequestThoughtSignatures with large normalized payloads.
2026-07-20 03:50:35 +08:00
Luis Pater
0f52284e6c perf(translator): add normalization and reuse logic for Codex request payloads
- Introduced field normalization functions (`setCodexRequiredBool`, `setCodexRequiredInclude`) to ensure correct Codex input structure.
- Added tests for normalized payload reuse and field validation in `ConvertOpenAIResponsesRequestToCodex`.
- Implemented `deleteCodexRequestFields` utility to remove unsupported fields dynamically.
- Added benchmarks for normalized payload processing to measure performance across different payload sizes.

Closes: #4362
2026-07-20 02:23:15 +08:00
Luis Pater
7c61e982e4 perf(translator): optimize array allocation logic and replace JoinRawArray with SetRawArrayItems methods 2026-07-19 15:01:37 +08:00
Luis Pater
3c2010bcf3 test(translator): add benchmarks for request translation performance across large histories 2026-07-19 06:02:38 +08:00
Luis Pater
9f1e890419 Merge pull request #4366 from Johnnybyzhang/fix/claude-codex-allocation-fix
perf(translator): 降低 Claude → Codex 请求转换的内存分配
2026-07-19 04:29:52 +08:00
Luis Pater
da087d7fad feat(translator): prioritize service tier for fast responses in Claude requests
- Updated `codex_claude_request` to set the service tier as "priority" when `speed` is "fast".
- Enhanced request template generation logic to reflect dynamic service tier evaluation.

Closes: #4349
2026-07-18 00:54:50 +08:00
Johnnybyzhang
e1e2357a0b perf(translator): avoid redundant gjson array parsing 2026-07-16 16:00:53 +08:00
Johnnybyzhang
b3ffb11666 fix(translator): reduce Claude to Codex allocations 2026-07-16 15:43:29 +08:00
Luis Pater
09da52ad50 feat(translator): improve error handling and response conversion for incomplete statuses
- Enhanced response handling to support `response.incomplete` events across translator components and executors.
- Refactored `resultErrorFromError` to centralize error conversion and consolidate repeated logic for constructing custom errors.
- Updated handling of `max_output_tokens` and similar terminal reasons in OpenAI and Gemini translator workflows.
- Introduced `IsRequestScoped` and `IsRequestScopedError` to differentiate between request-scoped and non-request-scoped errors.
- Added comprehensive test cases for incomplete responses, terminal failures, and error propagation in both streaming and non-streaming conditions.

Closes: #3055
2026-07-16 04:38:19 +08:00
Luis Pater
9f62c8df28 feat(translator): enhance handling of custom tool calls and improve tool call batching logic
- Introduced support for custom tool calls in request serialization, including preservation of call IDs, input, and output.
- Enhanced tool call batching logic to handle ambiguous, missing, and reused call IDs across assistant messages.
- Updated processing of tool call outputs to ensure proper matching with pending calls and introduced synthesized IDs when necessary.
- Added extensive test cases to validate behavior for custom tool call histories, mixed call types, and edge cases with ambiguous or orphaned IDs.

Closes: #4256
2026-07-15 03:14:05 +08:00
sususu
041816c2fd feat(xai): encrypted reasoning replay for Responses/Claude with hardened cache
Preserve include=reasoning.encrypted_content, cache reasoning+assistant message
for store:false multi-turn, and accept Grok thinking signatures on Claude→Codex
for grok targets.

Harden replay cache: blob-level reasoning filter, never double-inject assistant
when history has a last message, isolate session keys by downstream API key,
clear cache on non-replayable completed turns, and normalize refusal parts.
2026-07-12 22:31:19 +08:00
Luis Pater
abb5224880 feat(translator): add support for cache_write_tokens in Codex response usage details
- Introduced handling for `cache_write_tokens` in `input_tokens_details` and mapped to `cached_creation_tokens` in output.
- Added comprehensive tests to validate correct parsing, preservation, and omission of `cache_write_tokens` in both streaming and non-streaming responses.

Closes: #4197
2026-07-10 23:03:25 +08:00
Luis Pater
cdccc72dfe fix(translator): resolve pending codex tool calls on terminal response 2026-07-08 05:25:34 +08:00
Luis Pater
8b9c4da245 feat(interactions): add support for Google Interactions
- Introduced API handlers and executor logic for Google Interactions
- Added request and response transformations for OpenAI and Claude Interactions.
- Integrated Gemini API with Interactions support.
- Updated tests to validate Interactions request parsing and error handling.
- Refactored translator logic for Interactions data flows.
2026-07-07 02:39:13 +08:00
Luis Pater
f1ed8912bb feat(translator): wrap message-level system roles as user-visible reminders
- Added `ClaudeMessageSystemReminderText` to convert system content into user-readable reminder text.
- Updated translators (Antigravity, Gemini, Codex, OpenAI) to wrap `system` roles as reminders with `<system-reminder>` tags.
- Adjusted related test cases to validate reminder wrapping logic.
2026-06-23 13:43:14 +08:00
Luis Pater
57e1bf97a5 feat(translator): ensure preservation of tool and call IDs in Gemini request and response translations
- Updated `ConvertGeminiRequestToClaude`, `ConvertGeminiRequestToCodex`, and their respective response counterparts to include logic for retaining and using tool/call IDs when present from gateway-provided inputs.
- Enhanced pairing logic between function calls and responses to handle custom and auto-generated IDs consistently.
- Introduced tests validating ID preservation and proper behavior in both streaming and non-streaming flows.

Closes: #3878
2026-06-20 14:12:14 +08:00
Luis Pater
379167c992 feat(translator): add benchmarking for convertSystemRoleToDeveloper with large inputs
- Introduced `BenchmarkConvertSystemRoleToDeveloperLargeInput` to evaluate performance on various input sizes and configurations.
- Improved `convertSystemRoleToDeveloper` logic to optimize JSON rebuilding and reduce unnecessary operations.
- Created helper `makeLargeResponsesInputForBenchmark` to generate test data for performance scenarios.

Closes: #3751
2026-06-20 11:10:53 +08:00
Luis Pater
34639c3cf9 feat(translator): defer Codex function call starts until function name is available
- Updated `ConvertCodexResponseToClaude` to delay emitting `function_call` start events until the `name` field is resolved.
- Introduced `pendingCodexFunctionCall` for buffering incomplete function calls.
- Added tests to ensure proper behavior for deferred starts, including argument buffering and finalization.

Closes: #3471
2026-06-20 00:11:12 +08:00
Luis Pater
51aa5ba925 feat(translator): preserve input_audio fields in OpenAI request conversions
- Updated `ConvertOpenAIRequestToGemini` and `ConvertOpenAIRequestToCodex` to handle `input_audio`, retaining `data` and `format` fields.
- Added helper `openAIInputAudioMimeType` for determining MIME types from audio formats.
- Introduced unit tests to validate correct preservation of `input_audio` data and format.

Closes: #3447
2026-06-20 00:03:54 +08:00
Luis Pater
041a065b2f Merge branch 'remove-gemini-cli' into dev
# Conflicts:
#	internal/api/handlers/management/auth_files.go
#	internal/thinking/provider/geminicli/apply.go
2026-06-19 14:40:29 +08:00
Luis Pater
893412e965 feat(translator): normalize service_tier in Codex requests and add tests
- Added `normalizeCodexServiceTier` to standardize `service_tier` values (`fast` to `priority`, omit unsupported tiers).
- Updated `ConvertClaudeRequestToCodex` to apply normalization logic.
- Introduced `TestConvertClaudeRequestToCodex_ServiceTier` to validate behavior across various `service_tier` inputs.

Closes: #3276 #3294
2026-06-19 03:58:55 +08:00
Luis Pater
78ba8ba731 chore: remove Gemini CLI-related translator packages and logic
- Deleted `geminicli` provider and related `Apply` logic.
- Removed all translator packages specific to Gemini CLI (Claude, Codex integrations).
- Purged associated test files for Gemini CLI translation.
- Removed `GeminiAuthenticator` and all associated authentication logic (OAuth flows, token handling, refresh logic).
- Deleted internal/executor Gemini OAuth support, including bearer token handling and runtime API logic.
- Purged all tests, configs, and command-line flags specific to Gemini OAuth flows.
- Updated documentation and aliases to reflect Gemini removal.
- Renamed `parseRetryDelay` to `ParseRetryDelay` and `deleteJSONField` to `DeleteJSONField`.
- Updated references in `antigravity_executor` and tests to use the new `helps` package.
- Adjusted import paths and test cases to ensure compatibility with the new location.
- Updated README files to reflect changes in the retry logic references.
- Updated `.github/ISSUE_TEMPLATE/bug_report.md` to remove deprecated Gemini CLI mention.
2026-06-18 13:33:10 +08:00
Luis Pater
a5cb88323d feat(translator): enhance content block handling and add stream-specific test
- Refactored content block start/stop logic into `startCodexTextBlock` and `stopCodexTextBlock` for better readability and reusability.
- Updated logic to ensure proper handling of "output_text" block events to avoid ghost stop emissions.
- Added `TestConvertCodexResponseToClaude_StreamTextBeforeToolCallsDoesNotEmitGhostStop` to validate content block start/stop behavior in streamed responses.
2026-06-17 00:41:08 +08:00
sususu98
30dc2e7f34 fix(translator): emit Claude server tool blocks for Codex web_search_call streams (#3868)
* fix(translator): emit Claude server tool blocks for Codex web_search_call streams

Map Codex Responses streaming web_search_call events to Claude SSE
server_tool_use and web_search_tool_result blocks, with deduplication
and a focused stream regression test.

* fix(translator): stabilize Codex web_search fallback tool_use IDs

Reuse the active fallback web_search tool_use ID across later stream
events so tool_result blocks stay paired when upstream omits item IDs.
This is defensive hardening; live Codex streams already provide ws_* IDs.

* fix(translator): emit Codex web_search blocks from populated items

Wait for output_item.done before emitting Claude web_search tool_use
and tool_result blocks, and avoid deduping early added/completed events
that arrive before action.query is available. Matches live Responses
stream ordering seen in local tmux verification.

* fix(translator): map Codex web_search_call items in non-stream Claude responses

Emit server_tool_use and web_search_tool_result blocks from completed
response.output web_search_call items, matching the streaming translator.

* fix(translator): keep non-stream web_search on end_turn and dedupe output items

Do not treat server web_search_call items as client tool_use for stop_reason.
Skip duplicate or query-less open_page web_search output items in non-stream
translation, matching spark live behavior.
2026-06-16 23:07:08 +08:00
sususu98
702295d73a fix: translate codex stream errors for claude 2026-06-08 21:07:21 +08:00
Luis Pater
365415c87a fix(translator): add fallback for system_instruction key in Gemini request parsing
- Added fallback to handle cases where `system_instruction.parts` is absent by checking for `systemInstruction.parts`.
2026-06-08 08:10:41 +08:00