Commit Graph

663 Commits

Author SHA1 Message Date
Luis Pater
ca67caf087 **fix(xai): improve namespace-specific tool parameter handling and simplify Codex automation schema**
- Refined tool normalization logic to pass namespace context (`namespaceName`) to `normalizeXAITool`.
- Limited schema simplification to `codex_app.automation_update` to avoid unintended modifications to unrelated tools or namespaces.
- Updated `xaiFunctionParametersNeedSimplification` to match tools by exact namespace and name.
- Enhanced tests to validate correct schema simplification for `codex_app.automation_update` while preserving unrelated tool definitions.
2026-07-10 13:28:35 +08:00
Luis Pater
bf25331c77 Merge pull request #4157 from Wraient/fix/xai-desktop-tool-schema-and-free-usage-retry 2026-07-10 13:03:59 +08:00
hkfires
f9162d391c feat(executor): add image generation function tool checks and corresponding tests 2026-07-10 11:59:29 +08:00
Luis Pater
26d45fd46a feat(models): add model header overrides from configuration
- Introduced `override_header` in model configurations to support runtime customization of upstream request headers.
- Added `applyModelHeaderOverrides` utility to enforce header overrides for relevant executor and websocket paths.
- Updated model registry and `models.json` with enhanced configurations for header customizations.
- Implemented and extended test cases to validate header override behavior for various models and scenarios.
2026-07-10 05:30:12 +08:00
Luis Pater
b4c594050e chore(models): update default client version and user agent, revise GPT-5.5 configurations
- Bumped the `defaultClientVersion` and `defaultCodexUserAgent` to `0.144.0`.
- Replaced GPT-5.6 Sol with GPT-5.5 in model registry, adjusting metadata including context window length and reasoning levels.
- Updated `usage_helpers` to include `cache_write_tokens` logic for input token details.
2026-07-10 01:54:37 +08:00
Wraient
0df267adbb fix(xai): prevent Desktop hang on complex tool schemas and set free-usage Retry-After
Codex Desktop injects codex_app.automation_update with a large oneOf+$ref
schema. On xAI free/build Responses, that request accepts HTTP but never
emits SSE, so clients hang until cancel.

- Simplify automation_update (and similar large oneOf+$ref schemas) to a
  permissive object schema before upstream xAI
- Map subscription free-usage-exhausted 429s to a 24h RetryAfter for
  account rotation/cooldown
- Add unit tests for both behaviors
2026-07-09 21:49:01 +05:30
Luis Pater
bea9567051 feat(translator): add cache control handling for responses and messages
- Introduced `AttachCacheControl` and `AttachMessageCacheControl` utilities for consistent cache control injection in content parts and messages.
- Updated Claude translator modules to preserve and apply cache control metadata for responses, messages, tools, and parts.
- Added unit tests to validate proper cache control behavior across multiple scenarios.

Closes: #4146
2026-07-09 04:02:51 +08:00
Luis Pater
3fd189262d feat(executor): integrate model registry for reasoning effort support in XAI
- Replaced hardcoded model allowlist with dynamic model registry metadata lookup.
- Enhanced `xaiSupportsReasoningEffort` to utilize metadata for reasoning capability validation.
- Updated `sanitizeXAIResponsesBody` to log reasoning effort stripping for unsupported models.
- Added unit tests to verify registry-based reasoning effort handling across models, including Grok 4.5.

Closes: #4147
2026-07-09 03:37:11 +08:00
sususu98
4f2e19042c Update Antigravity hub user agent (#4142) 2026-07-08 16:47:37 +08:00
Luis Pater
dea4787970 refactor(executor): centralize OpenAI stream usage handling with StreamUsageBuffer
- Introduced `StreamUsageBuffer` to encapsulate stream usage observation and publishing logic.
- Updated OpenAI-compatible executors and helpers to use `StreamUsageBuffer` for consistent stream usage tracking.
- Added unit tests to validate `StreamUsageBuffer` behavior, ensuring proper handling of usage details.

Closes: #4053
2026-07-08 04:01:22 +08:00
Luis Pater
4f157fbdff fix(executor): map message_too_big WebSocket errors to structured API responses
- Added `mapCodexWebsocketReadError` to handle `CloseMessageTooBig` errors with proper status and error code mapping.
- Updated error propagation and logging in Codex WebSocket executor.
- Introduced corresponding unit test to verify `message_too_big` error mapping in streamed responses.

Closes: #4017
2026-07-08 03:07:55 +08:00
Luis Pater
ab6ed392f2 test(executor): add unit test to validate complete SSE event passthrough in Claude executor
- Verified proper chunking and streaming of SSE events in `ExecuteStream`.
- Refactored executor to ensure complete SSE event delivery without partial fragments.

Closes: #4121
2026-07-07 15:23:02 +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
5afc0f1d5e fix(translator): remove temperature parameter handling in Claude request transformations
Closes: #4071
2026-07-04 00:36:58 +08:00
Wolfgang Schoenberger
956ce7cf78 fix(registry): add Claude Sonnet 5 model metadata 2026-06-30 20:06:40 -07:00
Luis Pater
a26d38450e Merge pull request #4043 from sususu98/fix/responses-gemini-reasoning-signature-upstream-dev
fix(translator): OpenAI Responses reasoning signatures for Gemini
2026-06-29 15:58:40 +08:00
sususu98
ca7478a1f4 fix(antigravity): align CLI User-Agent with agy 1.0.13 short form (#4045)
Use the aidev_client parenthetical suffix for default Antigravity UA and
route loadCodeAssist through the short UA. Keep onboardUser on the long UA
with google-api-nodejs-client.
2026-06-29 15:37:10 +08:00
sususu98
4b51f85c4c fix(translator): map OpenAI Responses reasoning to Gemini two-part signatures
Build Gemini-native model contents for reasoning items when the routed model
uses the Gemini signature provider: thought summary on a thought part and the
replay signature on the adjacent visible part. Merge following assistant
visible text when it is not trailing prefill, and keep reasoning history when
stripping trailing model-authored prefill.

Extend Responses translator tests for signature compatibility and Antigravity
wrapper coverage; clarify stale replay signature expectations in executor tests.
2026-06-29 13:40:09 +08:00
Luis Pater
2fa4dabe93 feat(executor): improve downstream response ID rewrite and add test for repeated response scenarios 2026-06-26 16:34:02 +08:00
sususu98
38ed7aefc6 fix(codex): sanitize downstream UA for direct image calls
Direct OpenAI image calls can inherit downstream User-Agent values from the Gin request context, which may trigger upstream Cloudflare 1010 blocks.

Clone inbound Codex headers for direct image requests and remove only User-Agent before applying defaults. This keeps Version, X-Codex-Turn-Metadata, X-Client-Request-Id, and Originator forwarding intact.

Expand direct image regression coverage for downstream identity headers and align edit endpoint expectations with /images/edits.
2026-06-24 14:43:44 +08:00
Luis Pater
70053beadb feat(auth): refactor credential kind detection and add dynamic source classification
- Introduced `AuthKind` and `AuthSourceKind` methods for improved credential type and source classification.
- Replaced legacy fallback logic with normalized attribute-based handling in `AuthKind`.
- Consolidated metadata inspection for both API key and OAuth attributes.
- Updated calls to replace direct `AccountInfo` usage with `AuthKind` and `AuthSourceKind`.
- Enhanced unit tests to validate explicit and fallback credential resolution scenarios.
2026-06-23 23:21:33 +08:00
sususu98
05d1792d43 feat(xai): replay Grok reasoning for Claude messages (#3962)
Add Grok-native reasoning replay for Claude-sourced xAI Responses requests. Replay state is scoped by model and session, normalized to reasoning/function_call/custom_tool_call items, and injected with the same tool-call alignment semantics used by Codex.

Include the minimal Grok encrypted_content validator needed on upstream/dev so replay cache entries cannot accept Codex/GPT, Gemini, or Claude signature shapes. Cache completed output items from HTTP, streaming, and WebSocket xAI responses.

Cover two-turn Claude replay, tool_result continuity, valid Grok cache storage, and rejection of Codex-shaped encrypted_content.
2026-06-23 14:57:53 +08:00
sususu98
53a21dfb0b [codex] Drop foreign encrypted_content before xAI Grok upstream (#3961)
* Drop foreign encrypted_content before xAI Grok upstream

xAI Grok accepts provider-native encrypted_content as opaque replay state, but GPT/Codex reasoning signatures, Gemini thoughtSignature blobs, and Claude thinking signatures can all travel through OpenAI Responses-style reasoning.encrypted_content while remaining incompatible with xAI. Forwarding those foreign blobs to Grok causes upstream validation failures, especially when the foreign value is high-entropy enough to look ciphertext-like.

Add a Grok encrypted_content transport validator that stays conservative and shape-oriented:

- require unpadded standard base64 with no foreign characters
- reject obvious GPT/Codex gAAAA reasoning signatures before decode
- reject strict Claude thinking signatures in both official E-form and Antigravity R-form
- reject known Gemini thoughtSignature envelopes by reusing the central Gemini validator, covering Gemini 2.5 field-1 and Gemini 3.x field-2 shapes
- require decoded payloads to be long enough and high-entropy enough to look like native Grok ciphertext
- avoid decrypting, protobuf-parsing, or otherwise interpreting native Grok payloads on the hot path

Wire the validator into the xAI Responses request preparation path for reasoning and compaction input items. Invalid encrypted_content fields are deleted before the request is sent upstream, while the surrounding item is preserved and debug logging records only redacted metadata.

Extend coverage with native Grok corpus preservation, Gemini field-1/field-2 rejection, Claude E-form and R-form rejection, invalid-blob sanitizer tests, and compact/websocket replay preservation. The foreign-provider checks are deliberately narrow so high-entropy Grok blobs are not rejected merely because they look random.

* fix(xai): harden encrypted content sanitizer
2026-06-23 14:33:27 +08:00
Luis Pater
7c390a7a2e feat(runtime): add Claude Code session handling with caching and tests
- Introduced `ClaudeCodeSessionID` resolution logic, preferring headers over payload metadata.
- Added `ClaudeCodePromptCache` to map sessions to stable prompt cache keys.
- Refactored existing logic to integrate `ClaudeCodePromptCache` for session-based handling.
- Included extensive unit tests to validate session ID extraction, cache reuse, and header prioritization.
2026-06-23 13:19:13 +08:00
Luis Pater
bd646819ed test(translator, runtime): ensure empty text parts are skipped without null values
- Added tests for `ConvertOpenAIRequestToAntigravity` and `ConvertOpenAIRequestToGemini` to verify skipping of empty text parts while maintaining non-null structure.
- Refactored part index logic to correctly handle placement of replay parts in `antigravity_reasoning_replay`.
- Introduced helper functions `antigravityExistingReplayPartPath` and `antigravityReplayPartWritePath` for consistent replay part path management.
2026-06-23 08:07:03 +08:00
Luis Pater
5d9ea1667b Merge pull request #3963 from router-for-me/home
feat(plugins): sync home plugin manifests
2026-06-22 22:39:15 +08:00
hkfires
c58da381c7 feat(plugins): sync home plugin manifests 2026-06-22 22:25:44 +08:00
fdreamsu
36ed0e5c9c fix(codex): strip model prefix for websocket payloads
* fix(codex): strip model prefix before sending upstream websocket payloads

* test(codex): assert prefixed downstream models are rewritten for websocket sends
2026-06-22 18:11:06 +08:00
sususu98
1f2504ebcc fix(claude): bypass signature sanitizer for non-Claude models (#3946)
* fix(claude): bypass signature sanitizer for non-Claude models

* test(claude): use subtests for sanitizer gate model cases
2026-06-21 23:06:38 +08:00
Luis Pater
eb8d0d0684 Merge pull request #3900 from sususu98/fix/antigravity-replay-fc-order-upstream-dev
fix(antigravity): HOME Gemini replay and functionCall ordering before functionResponse
2026-06-20 14:55:48 +08:00
Luis Pater
790ec307f9 feat(config): add support for rebuild_mid_system_message configuration
- Introduced `RebuildMidSystemMessage` field in config to move system messages into the top-level Claude system field.
- Updated executor to handle mid-system message rebuilding when enabled via config or auth attributes.
- Added unit tests to verify rebuilding behavior and default behavior when disabled.
- Updated configuration example and API handlers to support the new field.

Closes: #3792
2026-06-20 12:15:06 +08:00
Luis Pater
28e2f9798c feat(executor): add session isolation for grok-composer models
- Introduced `xaiRequiresIsolatedConversation` to enforce session ID generation for `grok-composer` models.
- Updated request preparation logic to handle isolated conversations by setting `prompt_cache_key` and `x-grok-conv-id`.
- Added unit tests with coverage for session isolation, stateless models, and explicit `prompt_cache_key` scenarios.

Closes: #3750
2026-06-20 10:54:16 +08:00
Luis Pater
75fa62653f feat(executor): normalize parallel_tool_calls based on tools presence
- Added `normalizeCodexParallelToolCallsForTools` to conditionally remove `parallel_tool_calls` when `tools` are missing or empty.
- Integrated normalization into Codex executor workflows for improved request handling.
- Introduced unit tests to validate behavior across different tool scenarios.

Closes: #3903
2026-06-20 09:47:45 +08:00
Luis Pater
c44d4fcc7c feat(schema): add removal of $comment and enumDescriptions in JSON schema processing
- Updated JSON schema handling to remove `$comment` and `enumDescriptions` fields during schema transformations.
- Adjusted test cases to validate the removal of these fields both at root and nested levels.
- Expanded unsupported schema keywords to include `$comment` and `enumDescriptions` for Gemini compatibility.

Closes: #3512
2026-06-20 00:22:08 +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
ae6c5eaea5 feat(runtime): add support for gpt-image-1.5 and direct image API proxying
- Introduced the `gpt-image-2` model in Codex built-ins and updated visibility logic in the registry.
- Added direct proxy support for OpenAI image generation and editing endpoints.
- Implemented new execution paths for `/images/generations` and `/images/edit`, ensuring seamless handling for both JSON and multipart payloads.
- Expanded test coverage to validate the new model and direct proxy features, including streaming scenarios and error handling.
2026-06-19 00:06:12 +08:00
sususu98
ec8c2c2913 test(antigravity): cover invalid-signature replay cache clear
Add executor httptest for upstream 400 clearing HOME reasoning replay
items, and a whitespace call_id matcher regression test for replay
filtering.
2026-06-18 22:31:50 +08:00
sususu98
c55157dc2e fix(antigravity): PR review replay scope, signature merge, and tool keys
- Derive replay session from generateStableSessionID when sessionId is absent
- Merge cached thoughtSignature into existing functionCall by call id
- Allow filter to pass function_call_part when only signature replay is needed
- Include native functionCall id in replay dedupe keys
- Add unit tests for signature merge, stable scope, and parallel tool ids
2026-06-18 20:29:44 +08:00
sususu98
ef19f5fc81 fix(antigravity): address review on replay call_id and args parsing
Trim call_id once for matching-function-response checks; use args.Value()
in synthetic model functionCall insertion; guard functionResponse lookup
when call_id is empty.
2026-06-18 19:52:54 +08:00
sususu98
b17d29ad35 fix(antigravity): insert replayed functionCall before matching functionResponse
When HOME replay restores a cached function_call_part and the request
already contains the matching functionResponse, insert a synthetic
role=model content with functionCall (and thoughtSignature) immediately
before that response content instead of writing into the same index.

Add regression tests for user/model functionResponse shapes.
2026-06-18 19:50:46 +08:00
sususu98
292456a884 feat(antigravity): HOME reasoning replay for Gemini models
Add executor-scoped replay cache aligned with Codex HOME replay:
Scope, observe SSE/non-stream responses, store normalized thought_signature
and function_call_part items, apply on the next streamGenerateContent
request, and invalidate on invalid signature responses.

Gemini/flash/agent models use HOME replay; native per-part signature
replay is not wired on upstream/dev. Wire non-stream and stream paths
in antigravity_executor and purge expired entries from signature_cache.

Includes unit tests and HOME-provider-replay documentation.
2026-06-18 19:50:28 +08:00
sususu98
62c4b377dd Revert "feat(antigravity): HOME reasoning replay for Gemini models"
This reverts commit 365e8fc2ca.
2026-06-18 16:02:50 +08:00
sususu98
365e8fc2ca feat(antigravity): HOME reasoning replay for Gemini models
Add executor-scoped replay cache aligned with Codex HOME replay:
Scope, observe SSE/non-stream responses, store normalized thought_signature
and function_call_part items, apply on the next streamGenerateContent
request, and invalidate on invalid signature responses.

Gemini/flash/agent models use HOME replay; native per-part signature
replay is not wired on upstream/dev. Wire non-stream and stream paths
in antigravity_executor and purge expired entries from signature_cache.

Includes unit tests and HOME-provider-replay documentation.
2026-06-18 14:37:11 +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
96a8b0cfe2 feat(executor): normalize reasoning text events and enhance handling logic
- Introduced `xaiNormalizeReasoningSummaryData` and related functions to normalize `reasoning_text` events into `reasoning_summary` shapes for standardization.
- Updated WebSocket and streaming logic to process normalized reasoning summary events correctly.
- Enhanced tests to validate normalization, order of events, and output structure in both stream and non-stream scenarios.
2026-06-17 13:00:00 +08:00
sususu98
c296790801 feat(misc): align Antigravity runtime UA with agy CLI version sources
Use the agy CLI User-Agent family (antigravity/cli/{version} darwin/arm64)
on CPA macOS/arm64 hosts instead of the legacy hub-style antigravity/{version}
string. Resolve the cached version from the CLI auto-updater manifest
(darwin_arm64.json), then the GCS latest pointer, then antigravity-cli GCS
prefix listing, with fallback 1.0.8 when all sources fail.

Update AntigravityUserAgent helpers and executor default UA comment to match.
2026-06-17 10:30:52 +08:00
Luis Pater
b9d024af49 feat(executor): handle usage limit errors and enhance retry logic
- Added `isCodexUsageLimitError` to detect and handle `usage_limit_reached` errors from Codex responses.
- Updated `newCodexStatusErr` to treat usage limit errors as HTTP 429 with proper `RetryAfter` handling.
- Enhanced test coverage to validate usage limit error handling, including reset time parsing and retry behavior.

Closes: #2886
2026-06-17 07:19:02 +08:00
Luis Pater
8fad0d0325 feat(config+executor): add global Claude cloak mode toggle and improve credential fallback logic
- Introduced `disable-claude-cloak-mode` configuration to globally disable Claude cloak mode with credential-level overrides.
- Enhanced `getCloakConfigFromAuth` to support fallback to metadata for cloak settings.
- Updated cloak configuration precedence logic, integrating global, credential, and default modes.
- Updated config and watcher diff handling to include `disable-claude-cloak-mode`.

Closes: #2789
2026-06-16 13:03:16 +08:00
Luis Pater
844b855974 feat(executor): sanitize web search tool domains to meet Anthropic requirements
- Added `sanitizeClaudeWebSearchDomains` to remove empty `allowed_domains` and `blocked_domains` fields for built-in web_search tools, addressing ambiguity errors from Anthropic.
- Integrated domain sanitization into the Claude message preparation pipeline.
- Added test cases to validate correct handling of empty and non-empty domain fields across various tool types.

Closes: #2681
2026-06-16 03:29:44 +08:00
Luis Pater
f33bc56bb9 feat(websockets): add transcript state tracking and compaction trigger support
- Added methods for managing and tracking WebSocket transcript state, including recording, prepending, and replacing transcript inputs.
- Implemented `executeCompactionTriggerFromWebsocketContext` to support compaction triggers using recorded transcript context.
- Enhanced upstream-downstream ID mapping with additional utilities and state synchronization.
- Expanded test coverage to validate transcript state management, compaction payload generation, and WebSocket response handling.
2026-06-15 10:41:35 +08:00