Router for me main - #3
Merged
Merged
Conversation
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 router-for-me#3267
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>
fix(api): prevent idle TCP connections from blocking the accept loop
- 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.
…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.
…ling - 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.
- 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.
- 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: router-for-me#2651
- 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.
- 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: router-for-me#3027
- 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: router-for-me#3373
- 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.
…ff support - Added `zstd` decoding support in request logging, including helper functions to process `Content-Encoding` headers. - Enhanced config diff logic to compare payload-specific rules and track changes in payload configurations. - Added tests to validate `zstd` decoding and payload diff behavior.
Implement Redis integration with TLS support and cluster discovery option
- Added `parseClusterNodesPayload` for streamlined cluster node parsing. - Introduced `handleSubscriptionPayload` to handle Redis channel payloads, including updates for the new `cluster` channel. - Updated subscription logic to process and apply cluster node updates seamlessly.
…tter maintainability and simplicity
- Implemented xAI OAuth2 integration with PKCE (Proof Key for Code Exchange) support. - Added logic for token exchange, refresh, and persistent storage in JSON format. - Created `xai` package with helpers for OAuth discovery, API token handling, and URL building. - Introduced `XAIExecutor` for integrating xAI credentials into runtime HTTP requests. - Added unit tests to validate OAuth flow, token persistence, and endpoint validation.
…nts for image support - Added new xAI Grok image models (`grok-imagine-image`, `grok-imagine-image-quality`) with high-fidelity and aspect ratio configurations. - Extended `isSupportedImagesModel` logic to validate xAI models. - Implemented API request builders for image generation/editing with customizable options (e.g., resolution, aspect ratio, response format). - Enhanced `/v1/images` endpoints to handle xAI model capabilities, including response normalization and model-specific handlers. - Updated unit tests to validate xAI model validation, request structure, and API integration.
- Introduced new xAI `grok-imagine-video` model for video generation with configurable options (e.g., duration, size, resolution). - Implemented video-specific API endpoints (`/v1/videos`, `/v1/videos/generations`, `/v1/videos/edits`, `/v1/videos/extensions`), including request validation and model handling. - Enhanced model registry with `xaiBuiltinVideoModelID` and metadata for video capabilities. - Added unit tests to validate video model support, request structures, and API response handling. - Extended `XAIExecutor` to integrate video generation and retrieval via runtime requests.
- Introduced Codex client models framework in `openai` package. - Added JSON-based model definitions (`codex_client_models.json`) for Codex, including metadata, reasoning levels, and configuration options. - Implemented handlers to load, clone, and build Codex client models with support for visibility overrides and metadata application. - Enabled sorting and prioritization of models based on configuration or runtime criteria. - Added utility functions for managing and validating model attributes.
- Added `normalizeXAIInputReasoningItems` to clean up `input` reasoning items, removing null `content` and `encrypted_content` fields. - Updated `xai_executor` test cases to validate input normalization and reasoning item handling.
- Relocated Codex client model JSON and related logic from `openai` package to `registry` for better modularity. - Updated references to use `registry.GetCodexClientModelsJSON()` in loading logic. - Extended test cases to cover additional field removals (`upgrade`, `availability_nux`).
- Introduced OpenAI-compatible image model support in the API, enabling integration through image generation and editing endpoints. - Added registry type for OpenAIImageModelType to classify and validate compatibility. - Implemented request handling for OpenAI-compatible image models, including JSON and multipart formats. - Enhanced executor methods to support OpenAI-compatible image streaming and non-streaming requests. - Included tests to validate model registration, streaming behavior, and multipart payload formatting.
…erification - Added support for `ClusterID`, `CAFingerprint`, and `EnrollmentSecret` in Home JWT claims. - Implemented CA fingerprint normalization and verification for PEM and file-based certificates. - Improved certificate request validation and error handling. - Updated server-side logic to include `EnrollmentSecret` in certificate requests.
- Updated text formatting with bold emphasis for consistent branding. - Refined wording for VisionCoder's promotion details in Chinese, Japanese, and English README.
…ion failover - Introduced `homeRedisOperationTimeout` and `homeSubscriptionReceiveTimeout` constants for configurable timeouts. - Enhanced Redis connection options with operation timeout settings and failover mechanisms. - Implemented subscription failover logic on heartbeat timeouts to improve resilience. - Updated message handling to support additional Redis event types, including Pong and Subscription.
Added a new section for Codex Switch tool with details.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Add Codex Switch tool to README
- Removed obsolete Redis protocol test cases and helper functions that were no longer relevant due to recent architecture changes. - Streamlined remaining test files to align with updated Redis handling and connection management logic.
- Registered new models: `gemini-3-flash-agent` and `gemini-3.5-flash-low` with detailed specifications. - Includes support for dynamic thinking levels and extended context capabilities.
- Added new reasoning levels: `none`, `minimal`, and `unsupported` to Codex model configurations. - Introduced metadata sanitization and normalization for reasoning levels in API response. - Extended unit tests to cover reasoning levels validation and metadata sanitation logic.
- Added new model `gemini-3.5-flash` to the registry with enhanced intelligence and speed capabilities. - Supports extended thinking levels (`minimal`, `low`, `medium`, `high`) and dynamic adjustments. - Expanded generation methods, including content creation and token counting.
… capabilities - Registered `gemini-3.5-flash` model with dynamic thinking levels and extended token limits. - Supports multiple generation methods, including cached and batch content creation.
- Updated `ConvertClaudeRequestToGemini` to ignore empty `text` entries during processing. - Added unit tests to ensure empty `text` parts are skipped correctly. Closes: router-for-me#3485
Add reasoning_effort to usage event payloads
…eue operations - Added support for advanced RESP commands (`AUTH`, `SUBSCRIBE`, `RPOP`, `LPOP`) with extended functionality. - Implemented queue operations for usage events via `RPOP` and `LPOP` commands. - Introduced subscription handling with new Pub/Sub message features and error handling improvements. - Updated Redis connection logic to enforce authentication requirements and validate inputs. - Expanded related unit tests to cover new scenarios and edge cases.
…roject-id-onboard fix: require antigravity project id
fix: scope antigravity credits fallback gate
…-length-stream-errors-dev fix codex context length stream errors
Add cluster-specific docker-compose configuration for CLIProxyAPI
新增 OIDC(OpenID Connect)认证提供者,支持通过配置文件定义多个 OIDC 登录流程。主要包含以下功能: - 在配置文件中添加 OIDC 配置段,支持定义域名、客户端 ID、授权路径等参数 - 实现 PKCE(Proof Key for Code Exchange)流程增强安全性 - 添加本地 OAuth 回调服务器处理认证响应 - 支持命令行参数 `-oidc-init` 指定使用的 OIDC 配置 - 集成到现有的认证管理器和执行器注册系统中 - 提供令牌刷新机制和持久化存储功能
在 OIDC 登录成功的元数据中记录 OIDC 配置名称,并新增 `ResolveModels` 函数用于从认证元数据或配置中解析对应的模型列表。同时,在服务注册逻辑中为 OIDC 认证类型添加模型注册,使 OIDC 认证用户能够使用配置的模型。
新增 OIDCExecutor 结构体,用于处理通过 OIDC 认证的 LLM 服务请求。它支持标准的 HTTP 请求、流式响应、令牌刷新和令牌计数功能。执行器通过解析认证元数据获取 JWT 令牌和端点 URL,并集成到现有的执行器注册机制中。
- 移除 util.ApplyCustomHeadersFromAttrs 的直接调用,改为通过 oidcHeaders 方法集中获取 OIDC 配置中的头部 - 将公共的 HTTP 请求逻辑提取到 HttpRequest 方法中,减少重复代码 - 移除 Execute 和 ExecuteStream 中冗余的 JWT 存在性检查,统一在 PrepareRequest 中处理认证头 - 简化流式请求的构建过程,集中设置请求头
修复从 tokenData.Expired 解析时间戳时未正确设置 auth.NextRefreshAfter 字段的问题。当 expired 字段非空且能成功解析为 RFC3339 格式时,将其设置为下次刷新的时间点。
添加对ID令牌中过期时间声明的支持,通过解析多个可能的键(如exp、expires_at)来获取过期时间,并在tokenRequest中设置最早的过期时间以确保安全性。新增firstExpiry函数处理不同数据类型的过期时间值。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.