Commit Graph

700 Commits

Author SHA1 Message Date
Luis Pater
768b4c49fd feat(usage): track generate flag with backward-compatible defaults
Propagate client generate metadata through usage records while keeping
legacy callers that omit the field enabled by default. Preserve an
existing context generate=false when metadata does not set the value,
and normalize omission to true only at publishing boundaries.
2026-07-15 21:30:09 +08:00
Luis Pater
e57416731a feat(logging): add deferred request body capture for error handling
- Introduced `deferredRequestBodyCapture` for spooling and retaining large error-only request bodies for improved logging.
- Enhanced `RequestLoggingMiddleware` to capture request body based on size and error criteria.
- Implemented decompression and truncation for large request bodies with Zstd encoding.
- Added support for deferred API request logging and context tracking.
- Included extensive test coverage for error-specific body capture and serialization behavior.
2026-07-14 23:35:29 +08:00
sususu98
03d58c4402 fix(usage): collapse OpenAI service tier metadata (#4275)
* fix(usage): preserve request service tier metadata

* fix(usage): collapse request tier metadata

* fix(usage): emit only service_tier and response_service_tier

Collapse request tier to service_tier for usage records and queue payloads. Keep RequestServiceTier as a deprecated input-only alias for older plugin callers.
2026-07-14 14:19:13 +08:00
Luis Pater
a9831c841a fix(xai): sync allowed_tools and prune orphaned choices for x_search inject
Normalize and drop tool_choice entries that reference tools removed by
normalizeXAITools before injecting native x_search, then allow x_search in
allowed_tools without duplicates so Grok can select the injected tool.
2026-07-14 05:03:19 +08:00
Luis Pater
423f3d5ff7 feat(xai): add xAI API key support with comprehensive handling and tests
- Introduced `xai-api-key` to configuration for supporting xAI provider integration.
- Added API key operations: creation, updates, deletion, and sanitization.
- Implemented backend enhancements for credential-specific routing, response filtering with model aliasing, and WebSocket handling for xAI services.
- Included extensive test coverage to validate configuration parsing, CRUD operations, and the new functionalities.
- Updated related modules to handle `xai-api-key`, including the watcher, management handlers, and configuration sanitizers.
2026-07-14 04:40:12 +08:00
Luis Pater
a5577cc67d feat(xai): enhance response filtering with client-declared tool support to distinguish internal X Search traces
- Added `clientDeclaredTools` to `xaiInternalXSearchResponseFilter` for improved filtering precision.
- Implemented `collectXAIClientDeclaredToolKeys` to register client-declared tools with effective normalization to function calls.
- Prevented leakage of internal traces (e.g., `xs_call-*`) while preserving client-declared tools with overlapping names.
- Introduced multiple test cases to ensure filter correctness and preserve expected WebSocket response outputs.
- Enhanced completed output handling in response filtering.

Closes: #4282 / PR #4284.
2026-07-14 03:38:29 +08:00
Luis Pater
4fd81f904b Merge pull request #4284 from vvanglro/codex/fix-xai-x-search-history-4282 2026-07-14 01:30:40 +08:00
vvanglro
4651c3705d perf(xai): reuse parsed input array 2026-07-14 00:44:14 +08:00
sususu98
194fbce4b4 fix(executor): strip orphan reasoning ids when store is disabled (#4285)
* fix(executor): strip orphan reasoning ids when store is disabled

Codex backend requires store=false and treats reasoning items with an
id but no usable encrypted_content as store lookups, which 404 with
"Item with id not found". Drop those orphan ids after removing invalid
encrypted_content (and when encrypted_content is already missing),
while preserving ids when store=true.

* fix(executor): skip id delete when reasoning item has no id

Avoid sjson.Delete on encrypted_content drops that never carried an id,
matching the orphan-id path's Exists() guard.
2026-07-14 00:35:48 +08:00
vvanglro
caa93a7fc6 fix(xai): filter internal X search calls 2026-07-14 00:19:49 +08:00
Dmitry R.
7f6d491e70 perf(executor): avoid O(n^2) rebuilds when sanitizing reasoning encrypted_content (#4281)
Previously each dropped encrypted_content re-ran sjson.DeleteBytes on
the whole body/array per item, causing O(n^2) work on inputs with many
reasoning items.

Now the array is walked once, editing only offending items in place
and lazily building a replacement "input" array via strings.Builder.
The builder stays nil (no allocation) when nothing needs sanitizing,
and the array is spliced back with a single SetRawBytes call.
2026-07-14 00:16:05 +08:00
vvanglro
7bb8132817 fix(xai): normalize custom tool call history 2026-07-13 23:45:44 +08:00
Luis Pater
e674f19129 Fix xAI allowed tool namespace choices 2026-07-13 14:58:03 +08:00
Luis Pater
19fb0f0774 Merge pull request #4251 from huahai0202/fix/xai-namespace-tool-routing 2026-07-13 14:48:55 +08:00
huahai0202
4123e27583 fix(xai): handle additional namespace tools 2026-07-13 10:39:39 +08:00
sususu
18d239d567 fix(xai): clear replay after compaction 2026-07-12 23:59:39 +08:00
huahai0202
eb6d169407 fix(xai): qualify namespaced tool choices 2026-07-12 23:58:16 +08:00
sususu
487f8afc98 fix(xai): disable unisolated replay without caller auth 2026-07-12 23:38:11 +08:00
huahai0202
c4eda81b93 fix(xai): address namespace routing review feedback
Use exact namespace separator matching, normalize replay-inserted calls, preserve payloads on JSON update failures, and remove redundant completed-response restoration.
2026-07-12 23:33:53 +08:00
sususu
f1e9347f51 fix(xai): preserve tool-call-only replay batches 2026-07-12 23:19:36 +08:00
huahai0202
0e3a3e6199 fix(xai): preserve namespace tool routing
xAI Responses does not accept namespace tool containers, so the executor flattens nested tools before forwarding them upstream. The original namespace support in 8b3670b8 moved children to the top level but discarded their namespace identity; ca67caf later retained namespace context only for targeted schema simplification.

Qualify flattened names to avoid collisions, normalize namespaced function-call history, and restore name plus namespace on HTTP and WebSocket responses. This keeps Codex MCP routing intact without changing the existing xAI tool_search filtering policy.
2026-07-12 23:16:57 +08:00
sususu
3f875ecd2d fix(xai): avoid ambiguous reasoning replay injection 2026-07-12 23:07:04 +08:00
sususu
dc551b7de5 refactor(xai): remove unused assistant content equal helpers
Drop xaiAssistantMessageContentEqual and xaiAssistantMessagePartValue,
which were left unused after the last-assistant skip path landed.
2026-07-12 22:31:19 +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
0ba5fab529 Merge pull request #4240 from BG-QWQ/fix/xai-cli-user-agent-4233
fix(executor): identify Grok CLI OAuth requests
2026-07-12 20:27:51 +08:00
Luis Pater
6c70996e43 feat(executor): add logging for resolved xAI base URL and enhance test coverage
- Introduced `logXAIResolvedBaseURL` for consistent logging of resolved upstream base URLs.
- Added helper `xaiBaseURLSource` to classify base URL origins (default, CLI chat proxy, custom).
- Enhanced test suite with `TestXAIBaseURLSource` to cover base URL source classification logic.
2026-07-12 17:23:56 +08:00
1502538344
1a0bbe09c6 fix(executor): identify Grok CLI OAuth requests 2026-07-12 16:40:08 +08:00
Luis Pater
2075f77c8e feat(executor): enhance cache_tokens handling and extend parsing logic with alias normalization
- Added support for `cache_read_tokens` and `cache_creation_tokens` aliases across `prompt_tokens_details`, `input_tokens_details`, and other usage details.
- Updated token parsing logic to handle multiple aliases and improve fallback scenarios.
- Extended test coverage for alias normalization, including `cache_write_tokens`, `cacheCreationTokens`, and `cachedContentTokenCount`.
- Improved total token calculation by incorporating conditional read token addition logic.
2026-07-12 03:22:41 +08:00
Luis Pater
e99a2056ba feat(executor): add using_api attribute support for API path toggle and enhance test coverage
- Introduced `using_api` attribute in xAI auth for toggling between official API and CLI chat-proxy paths.
- Updated `xaiChatBaseURL` and `applyXAIChatHeaders` to conditionally apply the appropriate logic based on the `using_api` value.
- Added robust handling of attribute and metadata parsing for `using_api`.
- Extended test suite to cover `using_api` scenarios, including defaults, overrides, and header behaviors.
2026-07-11 12:15:55 +08:00
Luis Pater
aa05fb27f3 feat(executor, handlers): enhance websocket output restoration and compact compaction logic
- Refactored websocket output collection to restore completed events using fallback items and indexed payloads.
- Updated `CodexExecutorCompact` tests to ensure no injection of `image_generation` tools and maintain compact input order.
- Added new tests to validate sustained reasoning, proper output restoration, and compaction replay behavior.
- Improved logic to handle incremental response appends and preserved reasoning continuations.
- Enhanced test coverage for normalization, tool calls, and downstream payload restoration scenarios.

Closes: #4176
2026-07-11 11:42:51 +08:00
Supra4E8C
8c2bf2c24b Merge pull request #4202 from router-for-me/codex/issue-33-service-tier-reporting
feat(usage): report request and response service tiers
2026-07-11 03:12:02 +08:00
Supra4E8C
bc812e5f74 perf(usage): avoid parsing irrelevant stream chunks 2026-07-11 02:42:42 +08:00
Luis Pater
dc162b938e feat(executor): refactor XAI header application logic and extend test coverage
- Extracted `applyXAIDefaultHeaders` and `applyXAICustomHeaders` for cleaner separation of concerns in API header application.
- Updated `applyXAIChatHeaders` to ensure proper header overrides for CLI chat-proxy-specific configurations.
- Added test case to validate custom headers' ability to override CLI chat-proxy defaults.
2026-07-11 02:12:57 +08:00
Luis Pater
3533484a1f feat(executor): add chat-proxy-specific headers and improve base URL handling
- Introduced `xaiChatBaseURL` helper to normalize base URLs for non-media chat requests.
- Added `applyXAIChatHeaders` to handle CLI chat-proxy-specific headers.
- Updated logic to differentiate between default, chat-proxy, and custom gateway base URLs.
- Extended test coverage to validate behavior of headers and base URL handling across scenarios.

Closes: #4182
2026-07-11 02:07:01 +08:00
Supra4E8C
ea20742e77 fix(usage): retain response tier without usage 2026-07-11 01:37:39 +08:00
Supra4E8C
dc4be1674a feat(usage): report request and response service tiers 2026-07-11 00:49:30 +08:00
Supra4E8C
631f7a652c fix(executor): enhance image generation tool handling for responses-lite requests 2026-07-10 18:54:31 +08:00
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