Commit Graph

2274 Commits

Author SHA1 Message Date
Luis Pater
e5729872fa Merge pull request #4522 from sususu98/fix/responses-ws-continuity 2026-07-23 14:31:41 +08:00
Luis Pater
b30e7d992a Merge branch 'credential-concurrency' into dev
# Conflicts:
#	internal/api/server.go
2026-07-23 13:53:11 +08:00
Luis Pater
3ecd4afe80 feat: add Home credential concurrency support 2026-07-23 13:42:08 +08:00
sususu
840ba5dcc1 fix(xai): preserve compacted websocket transcript state 2026-07-23 13:07:37 +08:00
sususu
e05ae09425 fix(responses): preserve context across websocket transport changes 2026-07-23 13:07:23 +08:00
Luis Pater
f71ec0eb67 feat(server): add support for Codex Alpha Search model routing
- Implemented `codexAlphaSearchSelectionModel` and `codexAlphaSearchModelRouterHost` for dynamic model selection using plugin-based routing.
- Introduced new `codex-alpha-search` source format for model route requests.
- Integrated routing logic into the model selection pipeline to handle Codex Alpha Search requests with fallback mechanisms.
2026-07-22 22:46:10 +08:00
Luis Pater
f3e36f19c0 feat(executor): add Claude input token state handling and token estimation logic
- Introduced `ClaudeInputTokenState` to track and estimate input token usage for Claude message_start events.
- Added `TranslateStreamWithClaudeInputTokens` for token-aware stream translation.
- Updated executors (XAI, Kimi, Gemini) to leverage the new logic.
- Included robust test cases for token counting, JSON validation, and concurrent tokenization scenarios.
2026-07-22 05:21:14 +08:00
Luis Pater
cb110ad4fa perf(executor): improve token counting by introducing countXAIInputTokens
- Refactored token counting logic into a reusable `countXAIInputTokens` function for better readability and maintainability.
- Replaced direct encoder usage with structured input handling, including JSON parsing and segment collection.
- Switched tokenizer from `Cl100kBase` to `O200kBase` to support larger contexts.

Closes: #4492
2026-07-22 04:00:51 +08:00
Luis Pater
3ad6dfe30e perf(translator): optimize tool handling in OpenAI translator requests
- Moved `parallel_tool_calls` and `tool_choice` logic inside conditional handling for `chatCompletionsTools`.
- Eliminated redundant field updates to streamline payload processing.

Closes: #4491
2026-07-22 03:43:50 +08:00
Luis Pater
36b45d57a3 Merge pull request #4083 from seakee/fix/auth-files-filter-by-index
fix(management): filter auth files by name and auth index
2026-07-21 22:06:35 +08:00
KorenKrita
119debe1f2 fix(pluginhost): honor accepted emit results 2026-07-21 19:21:20 +08:00
KorenKrita
3e7e0815aa fix(pluginhost): prevent stream close/send panic (#4480) 2026-07-21 19:08:17 +08:00
sususu98
7329437297 fix(websocket): propagate upstream 1009 without credential fallback (#4444)
Preserve Codex and XAI upstream message-too-big closes across the Responses WebSocket boundary while treating them as request-scoped errors. Prevent CPA reconnect and credential cooldown/fallback, scope close state to the active connection, retain terminal errors under backpressure, and ensure downstream disconnect cleanup cannot wait behind a blocked writer.
2026-07-20 16:18:13 +08:00
Luis Pater
7d2883e745 chore(models): remove obsolete variables and approvals from Codex client models
- Deleted unused `instructions_variables` and `approvals` fields from `codex_client_models.json`.
2026-07-20 15:58:37 +08:00
Luis Pater
53c1e7e2dd perf(util): introduce GetGJSONBytesNoCopy for efficient JSON parsing without data duplication
- Added `GetGJSONBytesNoCopy` in `internal/util` for safe, no-copy JSON parse operations leveraging `unsafe`.
- Replaced `gjson.GetBytes` with the new helper in key payload processing paths (`kimi_executor`, `vertex_payload_helpers`, etc.) to improve performance.
- Added unit tests for behavior validation, including edge cases with empty input.
2026-07-20 15:37:55 +08:00
Luis Pater
8b4fd28c95 perf(executor): replace sjson.SetBytes with optimized helpers for conditional payload updates
- Introduced `SetStringIfDifferent`, `SetBoolIfDifferent`, and similar helpers in `payload_helpers` to avoid unnecessary writes during JSON modifications.
- Simplified message patching in `kimi_executor` for reasoning and tool call adjustments.
- Updated all executors (Gemini, Codex, XAI, Antigravity, etc.) to use the new helpers, enhancing readability and potentially reducing overhead.
- Removed obsolete `filterKimiEmptyAssistantMessages` function in `kimi_executor`.
2026-07-20 13:57:14 +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
fde40c5a0a feat(executor): sanitize and drop overlong encrypted reasoning IDs in Codex input processing
- Updated `SanitizeCodexInputItemIDs` to remove encrypted reasoning items with IDs exceeding the Codex length limit.
- Refactored logic to deterministically shorten other overlong input item IDs, ensuring compliance with the Codex format.
- Added new tests to verify dropping behavior for encrypted reasoning and shortening of lengthy IDs without encrypted content.
2026-07-20 02:02:17 +08:00
Luis Pater
e47ffda75b feat(translator): normalize and extract OpenAI file content with MIME type
- Added `NormalizeOpenAIFileData` utility to parse and validate file content, ensuring proper MIME type handling and base64 extraction.
- Refactored translation logic to use normalized file data for Gemini, Antigravity, and Interactions processors.
- Introduced comprehensive unit tests for both valid and invalid file data scenarios across all translators.

Fixed: #4416
2026-07-19 18:29:05 +08:00
Luis Pater
07f8354912 feat(translator): qualify function names with namespace in OpenAI response handling
- Updated `ConvertOpenAIResponsesRequestToOpenAIChatCompletions` to include namespaces when generating function names for tool calls.
- Added test case to validate namespace qualification logic for function call histories.

Fixed: #4423
2026-07-19 17:52:02 +08:00
Luis Pater
cd98e9d74d feat(translator): handle empty response content for Claude and adjust JSON structure
- Added conditional logic to append `content_block_start` for empty responses, ensuring correct event flow.
- Updated default `responseJSON` structure to use an empty array (`[]`) for the `content` field instead of `null`.

Fixed: #4431
2026-07-19 17:32:54 +08:00
Luis Pater
b7299a3d86 feat(translator): implement output indexing for OpenAI response generation
- Refactored state management to introduce deterministic output indexing for reasoning, messages, and function calls.
- Added new structures `MessageItems` and `ReasoningItems` to aggregate responses with consistent indices.
- Updated OpenAI response generation to include `output_index` for all outputs, ensuring correct order and no gaps.
- Enhanced tests to validate contiguous output indices and response event lifecycle.

Fixed: #4429
2026-07-19 17:15:04 +08:00
Luis Pater
f175c084d3 feat(executor): promote additional_tools to top-level tools in XAI requests
- Added `promoteXAIAdditionalTools` to normalize and migrate `additional_tools` to the top-level `tools` array in XAI request bodies.
- Updated test cases to validate the promotion logic and ensure unsupported `additional_tools` items are excluded from input payloads.

Closes: #4434
2026-07-19 16:32:47 +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
910ab83bb2 Merge pull request #4329 from mazzz1y/perf/executor
perf(translator): build input and messages arrays in a single pass
2026-07-19 04:06:09 +08:00
Luis Pater
0b2ce80fcb fix(auth): update credential filename logic to include account hash
- Modified `CredentialFileName` to incorporate `hashAccountID` for better disambiguation when available.
- Updated fallback behavior to maintain compatibility with legacy email-based filenames.
- Refined test suite to validate scenarios with and without account hash and plan type.

Closes: #4425
2026-07-19 02:19:38 +08:00
Luis Pater
b651a1a8fd feat(redis): add plugin sync timeout and enhance redis options handling
- Introduced dedicated plugin sync operation timeout (`homePluginSyncOperationTimeout`) for improved task handling.
- Added `cloneRedisOptions` function to safely duplicate Redis options and prevent mutation.
- Modified plugin sync to use a dedicated Redis client with independent configurations.
- Enhanced `GetPluginSync` logic to handle cancellation, timeouts, and TLS handshake gracefully.
- Expanded unit tests to validate new Redis client behavior, plugin sync timeouts, and cancellation handling.
2026-07-19 01:41:18 +08:00
Luis Pater
93d74a890a Merge pull request #4419 from mikewong23571/fix/kimi-upstream-model-normalization 2026-07-18 23:29:16 +08:00
Luis Pater
70c4bd78b2 feat(kimi): route Claude requests through Claude executor in Kimi
- Updated Kimi executor to delegate non-streaming and streaming Claude requests to the Claude executor when `SourceFormat` is `claude`.
- Injected `base_url` for Claude API compatibility during delegation.
2026-07-18 23:15:57 +08:00
Luis Pater
bd3841155e fix(models): update Gemini model IDs and metadata for production release
- Removed "Preview" suffix from model IDs, display names, and descriptions.
- Standardized naming conventions for all Gemini 3.x models to reflect production readiness.
2026-07-18 23:02:57 +08:00
Luis Pater
117654317a feat(kimi): migrate Kimi executor to use chat completions path and remove deprecated code
- Updated Kimi executor to route all Claude requests through the OpenAI-compatible chat completions API.
- Removed legacy delegation to Claude executor for non-streaming and streaming execution.
- Enhanced translator integration for request normalization and Kimi model stripping.
- Updated tests to validate chat completions behavior, including upstream request logging, payload transformation, and response handling.
- Deleted Kimi K3[1M] variant and associated metadata.
2026-07-18 22:55:26 +08:00
mikewong23571
8bafd85433 fix(executor): normalize Kimi upstream model ID to canonical k3
Claude Code sends the configured model name (e.g. kimi-k3[1m]) to
CLIProxyAPI. The Kimi executor forwarded this internal ID to Kimi's
https://api.kimi.com/coding endpoint. Kimi treats kimi-k3 and
kimi-k3[1m] as 256K-context models, while only bare k3 supports the
full 1M context window.

Normalize the upstream model by stripping the CLIProxyAPI kimi- prefix
and any Claude Code [1m] suffix while preserving a trailing thinking
suffix (e.g. (1024)), so that requests for kimi-k3, kimi-k3[1m],
kimi-k3(1024), and kimi-k3[1m](1024) are all sent to Kimi as k3 or
k3(1024). This applies to:

- Execute (Claude and OpenAI branches)
- ExecuteStream (Claude and OpenAI branches)
- CountTokens

Validation (using the stored Kimi token):
- GET /v1/models shows k3 with context_length 1048576.
- Direct /v1/messages calls with ~270k input tokens:
  - model=k3 succeeds.
  - model=k3[1m], kimi-k3, kimi-k3[1m] fail with:
    'Your request exceeded model token limit: 262144 (requested: 270014)'.

Add unit tests for normalizeKimiUpstreamModel.

Closes #4418

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 05:33:12 -07:00
Chén Mù
d32a116971 Merge pull request #4408 from router-for-me/plugin
fix(config): rename SyncRevision to AuthRevision in PluginsConfig
2026-07-18 19:38:26 +08:00
Luis Pater
76dc0fdc54 feat(executor): extend applyClaudeHeaders and Kimi executor with additional header support
- Added an `incomingHeaders` argument to `applyClaudeHeaders` to enable external header injection for flexibility.
- Updated Kimi executor to delegate header support to Claude executor, facilitating upstream request logging and beta header forwarding.
- Introduced tests for delegated configuration, header handling, and upstream request/response logging to improve coverage.
2026-07-18 19:36:09 +08:00
Luis Pater
740caabd9e fix(models): correct casing in Kimi K3 model ID 2026-07-18 18:34:33 +08:00
Luis Pater
a28b9f1a00 feat(models): add new Kimi K3 variants and update metadata
- Added a new variant `kimi-k3[1M]` with extended 1M context length support.
- Updated `kimi-k3` metadata: adjusted context length, tokens, and thinking levels.
- Enhanced descriptions to reflect the latest specifications.
2026-07-18 18:25:30 +08:00
hkfires
1e119afefc fix(config): rename SyncRevision to AuthRevision in PluginsConfig 2026-07-18 09:12:29 +08:00
Luis Pater
81d70f5d9f feat(executor): add normalization for parallel tool calls in Codex executors
- Introduced `normalizeCodexWebsocketParallelToolCalls` and `normalizeCodexParallelToolCalls` to enforce consistent `parallel_tool_calls` handling.
- Updated WebSocket and HTTP executor logic to support headers during parallel tool normalization.
- Refactored redundant logic by consolidating normalization routines for improved clarity and maintainability.
2026-07-18 03:58:03 +08:00
Luis Pater
2f80cb9ae8 feat(executor): add root union type normalization and extended tests
- Introduced `normalizeXAIObjectRootUnionBranchTypes` for ensuring object-only branches in root-level unions.
- Updated XAI executor logic to handle additional schema adjustments, ensuring compatibility with stricter validations.
- Extended test coverage to validate schema normalization, including both functional and custom tool scenarios.

Closes: #4397
2026-07-18 03:34:30 +08:00
Luis Pater
baffbe2cc7 feat(executor): implement agent-scoped cache key isolation and enhance replay handling
- Introduced agent-specific cache key isolation to ensure distinct prompt caching across agents.
- Improved reasoning replay handling for Claude models, including cumulative tool turn restoration and validation.
- Enhanced HTTP and WebSocket session consistency during execution scope and cache replay synchronization.
- Added new unit tests and extended coverage for prompt caching, agent isolation, and replay cache functionality.

Closes: #4352
2026-07-18 02:18:09 +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
Luis Pater
fbe116071a feat(websockets): implement active connection tracking for websocket sessions
- Introduced per-connection active channel management for Codex and XAI websocket sessions.
- Enhanced session behavior to support clearing and reassigning active channels tied to specific connections.
- Added support for detecting and detaching stale connections upon session target changes.
- Refactored websocket message handling logic to ensure connection-specific channel consistency.
- Extended test coverage for websocket session behaviors, including reconnections, target switching, and pinned auth transitions.
2026-07-18 00:40:56 +08:00
Luis Pater
1cfe529f32 feat(executor): add ID shortening for overlong Codex input items
- Implemented deterministic shortening of overlong Codex input item IDs to meet 64-character limit.
- Added `SanitizeCodexInputItemIDs` helper for efficient ID shortening in request bodies.
- Updated Codex executor and websocket implementations to utilize the new helper.
- Introduced unit tests to validate ID length restrictions, avoidance of collisions, and deterministic behavior.

Closes: #4401
2026-07-17 23:52:58 +08:00
Luis Pater
f5746a9822 feat(oauth-model-alias): add support for display names in OAuth model aliases
- Introduced `display-name` field for human-readable model names in config and YAML files.
- Updated alias application logic to set and preserve display names during model alias mapping.
- Enhanced tests to validate display name behavior for various scenarios, including forks and upstream preservation.
- Refined `sanitizeOAuthModelAlias` to handle `display-name` with proper trimming and formatting.

Closes: #4398
2026-07-17 23:28:34 +08:00
Luis Pater
366271969a feat(logging): add CPA trace ID middleware and enhance metadata handling
- Introduced CPA trace ID middleware to inject trace IDs in response headers.
- Added support for CPA trace ID generation and validation.
- Updated metadata handling to include stable auth indices and trace ID callbacks for enhanced request tracking.
- Enhanced tests to verify CPA trace ID propagation and reserved header handling across middleware, metadata, and handlers.

Closes: #4370
2026-07-17 22:58:28 +08:00
Luis Pater
9f4f53ca5a fix(xai): update compact request handling to use dedicated base URL
- Switched from `xaiChatBaseURL` to `xaiCompactBaseURL` for compact requests to avoid 404 errors from CLI chat-proxy.
- Updated headers to use standard API headers for compact endpoints.
- Added `xaiCompactBaseURL` helper function for dedicated compact request base URL resolution.
- Adjusted comments to clarify handling of compact and websocket transports.

Closes: #4376
2026-07-17 17:52:53 +08:00
Luis Pater
4231ad6e2a fix(executor): ensure top_p is removed in normalizeClaudeSamplingForUpstream
- Updated `normalizeClaudeSamplingForUpstream` to delete `top_p` from payloads.
- Adjusted test to validate the removal of both `temperature` and `top_p`.

Closes: #4383
2026-07-17 16:43:26 +08:00