2474 Commits

Author SHA1 Message Date
Luis Pater
e7a185962d feat(api): add request body decoding with Content-Encoding support
- Introduced `ReadRequestBody` helper function to support decoding request bodies based on "Content-Encoding" (e.g., `zstd`).
- Replaced `c.GetRawData()` with `ReadRequestBody` across handlers to enable decoding.
- Added test case to validate `zstd` decoding for compact responses.
v7.0.8
2026-05-16 12:19:32 +08:00
Luis Pater
30a8824b64 fix(gitstore): adjust garbage collection to run after push operation
- Updated `maybeRunGC` to accept `repoDir` instead of `repo`.
- Moved garbage collection trigger to occur after the push step for improved reliability.
- Added a test to validate the sequence of push and GC operations.

Closes: #3373
2026-05-16 04:55:44 +08:00
Luis Pater
9d01c80d33 feat(redis): implement Pub/Sub support for usage tracking
- Added Redis Pub/Sub capability to broadcast usage updates to subscribed clients.
- Enhanced `redisqueue` with subscriber management and message broadcasting.
- Updated tests to validate Pub/Sub message handling, subscription behavior, and fallback to the queue after unsubscribing.
- Integrated `project_id` parsing into auth-files logic to include project identifiers in metadata.

Closes: #3027
2026-05-16 00:38:43 +08:00
Luis Pater
1d529c3ce4 feat(redis): implement Pub/Sub support for usage tracking
- Added Redis Pub/Sub capability to broadcast usage updates to subscribed clients.
- Enhanced `redisqueue` with subscriber management and message broadcasting.
- Updated tests to validate Pub/Sub message handling, subscription behavior, and fallback to the queue after unsubscribing.
- Integrated `project_id` parsing into auth-files logic to include project identifiers in metadata.
v7.0.7
2026-05-15 21:59:43 +08:00
Luis Pater
229d03a690 feat(auth): add support for disabling auth via metadata
- Added logic to set `auth.Disabled` and update `auth.Status` to `StatusDisabled` when `disabled` metadata is provided and true.
- Updated `objectstore`, `gitstore`, and `postgresstore` implementations to handle the new metadata attribute.

Closes: #2651
2026-05-15 03:59:25 +08:00
Luis Pater
3a9fb3780e fix(home): implement home dispatch headers and enhance Gemini model handling v7.0.6 2026-05-14 03:01:55 +08:00
Luis Pater
437aa87c9b feat(api): add dynamic handler for Gemini models with home integration
- Introduced `geminiModelsHandler` to dynamically route Gemini model requests based on home configuration.
- Added `handleHomeGeminiModels` and `loadHomeModelEntries` to support home-specific Gemini model handling.
- Refactored and centralized error handling logic for improved maintainability.
- Enhanced response formatting with `formatHomeGeminiModels` for consistent output structure.
2026-05-14 02:27:23 +08:00
Luis Pater
bcbb94906c feat(client): add cluster node failover and improve reconnection handling
- Introduced cluster node management with `clusterNode` and `clusterNodesEnvelope` types.
- Added failover handling for reconnection failures with configurable threshold (`homeReconnectFailoverThreshold`).
- Implemented node switching and dynamic cluster target updates.
- Enhanced Redis client management with centralized locking for concurrency safety.
- Updated configuration refresh logic to prioritize the best cluster node.
- Improved debug logging for reconnect failures and node switching.
v7.0.5
2026-05-14 00:21:31 +08:00
Luis Pater
6bfcb0ce79 feat(auth): improve unauthorized error handling for refresh and auto-refresh
- Added `isUnauthorizedError` and `hasUnauthorizedAuthFailure` to classify and handle unauthorized errors.
- Introduced `refreshErrorFromError` to map errors to standardized unauthorized responses.
- Modified refresh logic to stop auto-refresh retries for unauthorized errors.
- Updated tests to verify unauthorized error handling and refresh retry prevention.
v7.0.4
2026-05-13 02:59:46 +08:00
Luis Pater
bd8c05a830 feat(usage): add support for detailed token breakdown in usage tracking
- Introduced `CacheReadTokens` and `CacheCreationTokens` to enhance token breakdown.
- Refactored `parseClaudeUsageNode` for cleaner and reusable logic.
- Adjusted helpers and updated token calculations to align with the new fields.
v7.0.3
2026-05-12 11:59:07 +08:00
Luis Pater
041ccf0195 Merge pull request #3303 from lihan3238/fix-3267
fix(api): prevent idle TCP connections from blocking the accept loop
2026-05-11 08:43:00 +08:00
Luis Pater
1fca942b9c Merge remote-tracking branch 'origin/pr/3239' v7.0.2 2026-05-10 20:43:35 +08:00
lihan3238
c5596e0925 fix(api): clear sniff deadline before entering Redis handler
Clear the 10s read deadline before calling handleRedisConnection so
that authenticated Redis clients are not disconnected by an i/o timeout
after 10 seconds of idle time. HTTP paths already clear the deadline
after routing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 15:43:58 +08:00
Luis Pater
5e5b1bce35 feat(config): add detailed logging for home config changes
- Introduced `logHomeConfigChanges` to compare old and new configs, logging detected differences.
- Leveraged `diff.BuildConfigChangeDetails` for structured change detection.
- Adjusted logging behavior to enable debug-level logs dynamically when required.
2026-05-10 15:28:49 +08:00
Luis Pater
15ac7fb932 refactor(auth): simplify home auth session management and remove ref counting
- Consolidated `homeRuntimeAuths` to store a map of session-scoped auth maps, replacing `homeRuntimeAuthSessions` and `homeRuntimeAuthRefs`.
- Adjusted session cleanup logic to directly remove session-scoped auths without reference counting.
- Added `GetExecutionSessionAuthByID` to retrieve auths scoped to a specific execution session.
- Updated tests to reflect the new session-scoped caching behavior.
v7.0.1
2026-05-10 15:21:33 +08:00
Luis Pater
8300ee8bbe feat(auth): enhance home auth session reuse with scoped caching and ref counting
- Added `homeRuntimeAuthSessions` and `homeRuntimeAuthRefs` for scoped caching of home auths per session.
- Updated `pickNextViaHome` to prevent reuse of already-tried pinned auths during session retries.
- Implemented reference counting for shared auths across multiple sessions to improve memory management.
- Enhanced session cleanup logic to clear cached auths only when all referencing sessions are closed.
- Added unit tests to validate scoped caching, retry logic, and session cleanup behavior.
2026-05-10 14:00:13 +08:00
Luis Pater
dc1cc7f115 feat(auth): add websocket session reuse for home auths with caching support
- Introduced `homeRuntimeAuths` to cache home auths for websocket session reuse.
- Updated `pickNextViaHome` to prioritize cached auths for pinned websocket sessions.
- Implemented automatic clearing of cached home auths when home mode is disabled.
- Added unit tests to validate caching behavior, clearing logic, and fallback scenarios.
2026-05-10 13:39:14 +08:00
lihan3238
28dfcae350 fix(api): prevent idle TCP connections from blocking the accept loop
Move per-connection protocol detection (TLS handshake, reader.Peek) out
of the accept loop and into a per-connection goroutine. An idle TCP
connection that never sends bytes would previously block Peek(1)
indefinitely, preventing all subsequent connections from being accepted
and making the management/API server unresponsive.

Closes #3267
2026-05-10 03:23:29 +08:00
Luis Pater
a44e5eb1ab Merge branch 'v7' into dev v7.0.0 2026-05-10 02:33:42 +08:00
Luis Pater
67fb4eb98e feat(auth): add shouldReturnLastErrorOnPickFailure helper and improve error handling in home mode
- Introduced `shouldReturnLastErrorOnPickFailure` to streamline error return logic during provider selection.
- Added `isHomeRequestRetryExceededError` for better home-specific error classification.
- Updated fallback conditions to enhance error handling clarity in `pickNextMixed`.
2026-05-10 02:09:53 +08:00
Luis Pater
66c3dae06b feat(home): implement count for home auth dispatch requests and enable usage statistics
- Added `count` attribute to `homeAuthCount` requests to improve home message batching.
- Enabled usage statistics for home mode by default and added config-level enforcement.
- Adjusted failure logging to include detailed metadata in `UsageReporter`.
- Updated multiple executors to pass error details to `PublishFailure` for better debugging.
- Enhanced unit tests to validate `count` behavior and usage statistics enforcement across components.
2026-05-10 01:30:43 +08:00
Luis Pater
1abf8625d8 feat(logging): add home request-log forwarding support
- Introduced `SetHomeEnabled` to enable/disable request-log forwarding to the home control plane.
- Implemented `forwardRequestLogToHome` for non-streaming logs and `homeStreamingLogWriter` for real-time streaming logs.
- Enhanced `FileRequestLogger` to bypass local logging when home forwarding is enabled.
- Updated server configuration to dynamically toggle home request-log forwarding based on changes.
- Added corresponding unit tests to ensure correct forwarding behavior and fallback mechanisms.
2026-05-09 23:39:59 +08:00
Luis Pater
3cbd587b2c Merge pull request #3283 from wuchulonly/fix/responses-ws-tool-output-context
Fix Responses WebSocket tool output context repair
2026-05-09 21:08:43 +08:00
Luis Pater
41f4ee7c7d feat(auth): enhance auth index generation with improved file path handling
- Updated `EnsureIndex` logic to incorporate absolute and cleaned file paths when generating auth indexes.
- Refined metadata handling to include OAuth type in auth index seed.
- Improved compatibility for `json` file paths as sources in auth attributes.
- Added unit tests to validate correct auth index behavior for various path and type scenarios.
2026-05-09 21:03:11 +08:00
Luis Pater
c69ff49758 feat(auth): add support for persisting disabled flag in token storage
- Updated `FileTokenStore` and related stores (`objectstore`, `gitstore`, `postgresstore`) to include the `disabled` flag in metadata for token storage.
- Adjusted `Auth` metadata handling to initialize empty maps when absent.
- Refined logic in `auto_refresh_loop` and `conductor` to exclude `disabled` tokens from refresh checks.
- Added comprehensive unit tests to verify proper handling of the `disabled` flag in storage and retrieval operations.
2026-05-09 19:48:42 +08:00
Luis Pater
68fddaa319 Merge pull request #3292 from lihan3238/fix-3272
fix: apply default auth-dir when config value is empty
2026-05-09 17:34:05 +08:00
Luis Pater
09ac8a1165 Merge pull request #3221 from mochenya/main
fix(executor): ignore null OpenAI stream usage chunks
2026-05-09 11:53:26 +08:00
Luis Pater
0dcb8bd714 refactor(cliproxy): remove ClaudeCodeSessionAffinity support and simplify session affinity logic 2026-05-09 10:51:49 +08:00
Luis Pater
0f0fcd2304 feat(config): add per-auth disable_cooling override support
- Introduced `disable_cooling` metadata field for fine-grained control over cooldown scheduling.
- Updated `Auth` object to include `Metadata` with conditional logic for handling empty states.
- Added YAML configuration support for `disable_cooling` in API key definitions across providers.
- Enhanced unit tests to validate `disable_cooling` behavior in various scenarios.
2026-05-09 10:51:27 +08:00
Luis Pater
c67096b687 feat(server): add support for loading configuration from a remote home control plane
- Introduced `-home` and `-home-password` flags for specifying home control plane address and authentication.
- Implemented fetching and parsing configuration from the home control plane when `-home` is used.
- Adjusted server configuration handling to bypass local config files when loading from home.
- Ensured compatibility with cloud deploy mode and validation of home configurations.
2026-05-09 07:14:44 +08:00
Luis Pater
1721994111 feat(management): expose additional OAuth and configuration helpers
- Added new helper methods for OAuth session management (`RegisterOAuthSession`, `CompleteOAuthSession`, etc.).
- Introduced `WriteConfig` for persisting management configurations.
- Exported `Handler` type and `NewHandler` constructors for SDK consumers.
2026-05-09 00:23:45 +08:00
lihan3238
4cbe172934 refactor: extract DefaultAuthDir constant per review feedback 2026-05-08 22:28:38 +08:00
lihan3238
4071fdef84 fix: apply default auth-dir when config value is empty
When auth-dir is not specified in config.yaml, ResolveAuthDir returns
an empty string which causes os.MkdirAll to fail with no path. Use
the documented default ~/.cli-proxy-api instead.

Fixes #3272
2026-05-08 21:47:41 +08:00
Codex
c883114a4d fix responses websocket tool output context 2026-05-08 05:12:30 +00:00
Luis Pater
e50cabac4b chore: upgrade CLIProxyAPI dependency to v7 across the project
- Updated all references from v6 to v7 for `github.com/router-for-me/CLIProxyAPI`.
- Ensured consistency in imports within core libraries, tests, and integration tests.
- Added missing tests for new features in Redis Protocol integration.
2026-05-08 11:46:46 +08:00
Luis Pater
785b00c312 Merge pull request #3237 from seakee/docs/add-cpa-manager-usage-statistics
docs: add CPA-Manager to usage statistics recommendations
v6.10.9
2026-05-07 09:32:32 +08:00
Luis Pater
a034cf8b8d Merge pull request #3247 from edlsh/fix/amp-thread-actors-route
fix(amp): proxy thread actors route
2026-05-07 09:31:16 +08:00
edlsh
01171742a6 fix(amp): proxy thread actors route 2026-05-06 13:12:35 -04:00
Luis Pater
fb08b92402 feat(executor): add upstream disconnect handling for Codex WebSocket sessions
- Introduced `UpstreamDisconnectChan` for Codex WebSocket sessions to notify downstream connections of upstream disconnections.
- Implemented `notifyUpstreamDisconnect` to signal errors and close channels on disconnect events.
- Added integration tests to validate WebSocket session behavior on upstream disconnect.
- Updated OpenAI WebSocket response handlers to properly close connections upon upstream disconnect notifications.
2026-05-06 22:09:33 +08:00
AhDEV
a09a16e8f6 Merge branch 'router-for-me:main' into my-fix 2026-05-06 16:41:14 +08:00
seakee
ad3f4f2ce5 📝 docs(readme): add CPA-Manager usage statistics recommendation
Add CPA-Manager to the Usage Statistics recommendations across English, Chinese, and Japanese READMEs.

Highlight request-level monitoring, cost estimation, LiteLLM price sync, SQLite persistence, and Codex account-pool operations for multi-account maintenance.
2026-05-06 15:49:57 +08:00
songyu
17a1f53c47 fix:openai 2 kimi error Continuous function_call
连续的function_call 转换 tool_calls
2026-05-06 14:37:18 +08:00
Luis Pater
ed1458aa6d chore(docs): update sponsor details in README
- Replaced sponsor `z.ai` with `PackyCode` and updated related descriptions, images, and links in `README.md`, `README_CN.md`, and `README_JA.md`.
- Removed outdated sponsor entries for `Poixe AI` in all README files.
- Added new image assets for PackyCode (`packycode-cn.png` and `packycode-en.png`).
2026-05-06 00:41:50 +08:00
mochenya
99dfbaef61 fix(executor): ignore null OpenAI stream usage chunks
- Added validation so OpenAI-style usage parsing only accepts object payloads with token fields.
- Prevented streaming usage:null chunks from publishing zero-token records before the final usage chunk arrives.
- Reused the shared OpenAI-style parser for stream usage to support both chat completions and responses token field names.
- Added tests covering null usage chunks and input/output token usage fields in streaming responses.
2026-05-05 12:31:33 +08:00
Luis Pater
da6c599efd refactor(management): rename GetUsage to GetUsageQueue and update routes/tests
- Renamed handler and test methods for better clarity on functionality.
- Updated route from `/v0/management/usage` to `/v0/management/usage-queue`.
- Adjusted integration and unit tests to reflect new naming and routes.
v6.10.8
2026-05-05 03:02:25 +08:00
Luis Pater
61b39d49bd feat(management): add usage record retrieval endpoint
- Implemented `/v0/management/usage` endpoint for fetching queued usage records from Redis.
- Included validation for `count` parameter to ensure positive integers.
- Added unit tests for queue retrieval and validation, with authentication validation in integration tests.
- Updated management routing to include the new endpoint.
2026-05-05 02:53:04 +08:00
Luis Pater
ba5d8ca733 feat(usage): add support for requested model alias handling
- Introduced methods for setting and retrieving model aliases in execution and usage contexts.
- Enhanced `UsageReporter` and related structures to include client-requested aliases.
- Updated tests to validate alias propagation and ensure correct usage reporting.
- Adjusted metadata handling in CLIProxyAPI executors to address alias integration.
v6.10.7
2026-05-05 01:47:53 +08:00
Luis Pater
28b4b19e7e Merge pull request #3208 from kdcokenny/codex-websocket-protocol-parity
Align Codex websocket protocol semantics
2026-05-05 01:29:19 +08:00
Luis Pater
bdc424007e Merge pull request #2896 from edlsh/fix/oauth-tool-rename-per-request-map
fix(amp): smart-mode tool name fixes + deep-mode response repair
v6.10.6
2026-05-05 00:58:39 +08:00
Luis Pater
e4a93c02c5 fix(executor): enhance parsing of OpenAI stream data lines
- Added trimming for stream input lines to prevent processing of unnecessary whitespace.
- Improved handling of unsupported prefixes and malformed JSON responses, ensuring errors are recorded and propagated appropriately.

Fixed: #2690
v6.10.5
2026-05-04 23:42:26 +08:00