Commit Graph

3111 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
285322cd97 Merge branch 'dev' of github.com:router-for-me/CLIProxyAPI into dev v7.2.96 2026-07-23 14:19:15 +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
a661172b1f fix(responses): commit websocket tool cache atomically 2026-07-23 13:07:57 +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
e8ef4d7338 Merge pull request #4249 from sylearn/docs/add-aiusage-showcase
docs: add AIUsage to related projects
2026-07-22 23:51:48 +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.
v7.2.95
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
v7.2.94
2026-07-21 22:06:35 +08:00
Luis Pater
2b4e96212a Merge pull request #4481 from KorenKrita/agent/fix-plugin-stream-bridge-close-race
fix(pluginhost): prevent stream close/send panic
2026-07-21 21:42:09 +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
Luis Pater
db82d65d1c docs(readme): update Kimi model descriptions with K3 details
- Replaced references to K2.6 with K3 across README files (EN, CN, JA).
- Highlighted Kimi K3's capabilities as the world's first open 3T-class model, including 2.8T parameters, native vision, and enhanced context window (1M tokens).
- Updated quickstart links and clarified CLIProxyAPI support information.
2026-07-21 17:16:25 +08:00
hkfires
01f387f447 feat(docker): add plugin volume mapping to docker-compose files v7.2.93 2026-07-21 13:10:17 +08:00
Luis Pater
a007ad69f2 test(websocket): add robust unit tests for tool call handling and reconciliation
- Implemented tests for scenarios involving incomplete, conflicting, and reconciled tool calls in response payloads.
- Enhanced coverage for `restoreResponsesWebsocketCompletionOutput` and `responseCompletedOutputFromPayload` logic.
- Refactored `isCompleteResponsesWebsocketToolCall` to validate string fields in tool calls.
- Improved caching behavior to skip incomplete tool calls and ensure reconciliation logic aligns with expected outputs.

Closes: #4447
2026-07-20 16:47:22 +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.
v7.2.92
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.
v7.2.91
2026-07-20 02:02:17 +08:00
sylearn
c502eba874 docs: clarify CPA process supervision 2026-07-19 19:55:04 +08:00
sylearn
2457e01e87 docs: add AIUsage to related projects 2026-07-19 19:55:04 +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
v7.2.90
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 v7.2.89 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
36ed0ca5ce feat(auth): add explicit handling for count_tokens endpoint errors and enhance model availability logic
- Implemented logic to differentiate between generic and explicit model-not-found errors for the `count_tokens` endpoint.
- Introduced `recordAvailabilityNeutralResult` to ensure models remain active for generic endpoint errors.
- Expanded test coverage to verify behavior for various 404 scenarios, including error propagation and model suspension handling.
- Refactored error-parsing utilities to identify structured and nested model-not-found errors.

Closes: #4410
2026-07-19 03:39:27 +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
58ef846ff0 chore(go): update golang.org/x/sys to v0.47.0 in Claude web search router 2026-07-19 01:42:16 +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 v7.2.88 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.
v7.2.87
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