sync: rebase on CPA v7.0.2 upstream#29
Closed
hpylsy wants to merge 185 commits into
Closed
Conversation
- Simplify project ID selection to always use the backend project ID returned by Gemini onboarding - Update Gemini CLI version from 0.31.0 to 0.34.0 - Add 'terminal' to User-Agent string for better client identification Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ment Both branches assign finalProjectID = responseProjectID, so move the assignment outside the conditional and keep only the logging inside.
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
After a Codex CLI compact, the client sends a full conversation
transcript (with compaction items or assistant messages) as input.
Previously, normalizeResponseSubsequentRequest() unconditionally
merged this with stale lastRequest/lastResponseOutput, breaking
function_call/function_call_output pairings and causing 400 errors
("No tool output found for function call").
Add inputContainsFullTranscript() heuristic that detects compaction
items (type=compaction/compaction_summary) or assistant messages in
the input array, and bypasses the merge when a full transcript is
present.
Fixes router-for-me#2207
Custom headers configured under openai-compatibility (and any other provider passing through applyCustomHeaders) were silently dropped for the Host key, because Go's net/http reads the wire Host from req.Host, not req.Header["Host"]. As a result, virtual-host routed upstreams (e.g. LiteLLM behind an ingress) saw the base-url's host instead of the user-configured override and returned 404. Detect the Host key with http.CanonicalHeaderKey and assign it to req.Host so it is actually written on the wire. Other headers continue to use Header.Set as before. Fixes router-for-me#2833
Addressing the P1 note from the Codex reviewer: applyCustomHeaders is
also called with a synthetic &http.Request{Header: ...} from the
websockets executors (aistudio_executor.go, codex_websockets_executor.go),
which forward only the header map. The previous continue meant a custom
Host was dropped from that map, regressing virtual-host overrides on
those flows. Mirror the value to both r.Host (for real net/http) and
r.Header (for header-map-only consumers).
…ni, Claude, Codex, OpenAI, and Vertex
feat(api): integrate auth index into key retrieval endpoints for Gemi…
…dex-GPT and Codex-Gemini flows - Introduced `LastImageHashByItemID` in Codex-GPT and `LastImageHashByID` in Codex-Gemini for deduplication of generated images. - Added support for handling `partial_image` and `image_generation_call` types, with inline data embedding for Gemini and URL payload conversion for GPT. - Extended unit tests to verify image handling in both streaming and non-streaming modes.
…outer-for-me#2866) Anthropic has moved the 1M-context-window feature to General Availability, so the context-1m-2025-08-07 beta flag is no longer accepted and now causes 400 Bad Request errors when forwarded upstream. Remove the X-CPA-CLAUDE-1M detection and the corresponding injection of the now-invalid beta header. Also drop the unused net/textproto import that was only needed for the header-key lookup.
…remove-obsolete-1m-beta-header fix(executor): drop obsolete context-1m-2025-08-07 beta header
… links - Added VisionCoder sponsorship information to `README.md`, `README_CN.md`, and `README_JA.md`. - Updated external links to include `target="_blank"` for improved user experience. - Added new logo asset `visioncoder.png` for README use.
- Introduced `refreshIneffectiveBackoff` to prevent tight-looping in auto-refresh when token refresh fails to update expiry. - Adjusted refresh logic to apply backoff when `shouldRefresh` evaluates true. Closes: router-for-me#2830
- Refactored `/healthz` handler to support `HEAD` requests alongside `GET`. - Updated tests to include validation for `HEAD` requests with expected status and empty body. Closes: router-for-me#2929
…m-output-backfill fix(codex): backfill streaming response output
…t-host-header fix(util): forward custom Host header to upstream
- Added `GPT-Image-2` as a built-in model to avoid dependency on remote updates for Codex. - Updated model tier functions (`CodexFree`, `CodexTeam`, etc.) to include built-in models via `WithCodexBuiltins`. - Introduced new handlers for image generation and edit operations under `OpenAIAPIHandler`. - Extended tests to validate 503 response for unsupported image model requests.
…AI image handlers
Codex CLI gates the built-in image_generation tool behind
AuthMode::Chatgpt (OAuth only). When clients connect via API key
auth through CPA, the tool is absent from requests, making image
generation unavailable through the reverse proxy.
Changes:
1. Inject image_generation tool (codex_executor.go):
Add ensureImageGenerationTool() that appends
{"type":"image_generation","output_format":"png"} to the tools
array if not already present. Applied to all three execution
paths: Execute, executeCompact, and ExecuteStream.
2. Route aliases for Codex CLI direct access (server.go):
Add /backend-api/codex/responses routes that map to the same
OpenAI Responses API handlers as /v1/responses. This allows
Codex CLI to connect via chatgpt_base_url config while keeping
AuthMode::Chatgpt, which enables the built-in image_generation
tool on the client side.
3. Unit tests (codex_executor_imagegen_test.go):
Cover no-tools, existing tools, already-present, empty array,
and mixed built-in tool scenarios.
…mplify session affinity logic
fix(executor): ignore null OpenAI stream usage chunks
fix: apply default auth-dir when config value is empty
- 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.
…dling - 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.
…s-tool-output-context Fix Responses WebSocket tool output context repair
- 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.
…ble 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.
…ve 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`.
…upport - 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.
…ef 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.
…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.
- 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.
… /v6 -> /v7 Copied 87 CPAP-exclusive paths (12 third-party providers: bt, codearts, codebuddy, codebuddy_ai, copilot, cursor, gitlab, iflow, joycode, kilo, kiro, qoder) plus management UI web assets and provider-specific handlers. Rewrote all /v6 import paths to /v7 (95 files affected). Added 4 provider constants (Kiro, Kilo, CodeArts, JoyCode) to internal/constant/constant.go needed by copied translator init files. Not yet wired into CPA core files — next batch handles registration in main.go, service.go, conductor.go, server.go, model_definitions.go, etc.
- internal/config/config.go: added KiroKey, BTKey, KiroFingerprintConfig structs, KiroFingerprint/KiroPreferredEndpoint/IncognitoBrowser fields, SanitizeKiroKeys/SanitizeBTKeys methods - internal/browser/browser.go: added SetIncognitoMode, IsIncognitoMode, CloseBrowser - internal/registry/model_registry.go: added SupportedEndpoints field to ModelInfo - internal/registry/model_definitions.go: added GetCodeBuddyModels, GetCodeBuddyAIModels, GetBTModels, GetCursorModels, GetGitHubCopilotModels, GetKiroModels, GetAmazonQModels, GetQoderModels, extended GetStaticModelDefinitionsByChannel + LookupStaticModelInfo - internal/tui/client.go: added GetUsage method - internal/api/handlers/management/handler.go: added sdkAuthManager field + SetSDKAuthManager - internal/runtime/executor/helps/token_helpers.go: added CountClaudeChatTokens, CollectOpenAIContent, collectClaudeMessages/Content/Tools, estimateImageTokens - internal/util/gemini_schema.go: added CleanupOrphanedRequiredInTools - sdk/auth/manager.go: added ProviderInfo, providerMetadata, ListProviders, SaveAuth - Fixed ApplyPayloadConfigWithRoot calls (added requestPath arg) in bt/iflow/qoder/compat_helpers Result: go build ./... passes with 0 errors
Replaced with CPAP version that includes Kiro, BT, CodeBuddy, Cursor, GitLab, GitHub Copilot, JoyCode, CodeArts, Qoder, Kilo examples. recent_requests and kiro-quota already in CPA v7.0.2 base (PR router-for-me#24 merged upstream).
- sdk/cliproxy/service.go: added 12 provider cases to registerModelsForAuth switch (kiro, kilo, cursor, github-copilot, codebuddy, codebuddy-ai, codearts, joycode, gitlab, bt, qoder, iflow) - sdk/cliproxy/service.go: added 12 executor registrations (NewKiroExecutor, etc.) Server binary builds successfully. Kiro models should now appear in /v1/models.
… providers - internal/api/server.go: register /kiro-quota route + StartKiroQuotaRefresher - sdk/cliproxy/auth/oauth_model_alias.go: add kiro, github-copilot, gitlab, cursor, codebuddy, codebuddy-ai, codearts, joycode, qoder, kilo, bt, iflow to OAuthModelAliasChannel switch (enables fork aliases in model list)
Ported from CPAP service.go: - fetchKiroModels: fetches models from Kiro API with fallback to static list - extractKiroTokenData: extracts token from auth attributes/metadata - convertKiroAPIModels: converts API response to ModelInfo - normalizeKiroModelID, formatKiroDisplayName: formatting helpers - generateKiroAgenticVariants: creates -agentic model variants Result: 62 models on test server (matches production exactly)
- internal/api/handlers/management/usage.go: added GetUsageStatistics, ExportUsageStatistics, ImportUsageStatistics handlers - internal/api/handlers/management/handler.go: added usageStats field + SetUsageStats - internal/api/server.go: registered /usage, /usage/export, /usage/import routes All 13 acceptance tests pass (models, chat, streaming, images, aliases, management)
|
This pull request targeted The base branch has been automatically changed to |
The usageStats field was added to Handler but never initialized in NewHandler, causing GetUsageStatistics to always return an empty snapshot (total_requests: 0). Now initialized with usage.GetRequestStatistics() global singleton.
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.
What
Rebased CPAP onto CPA v7.0.2 (upstream latest stable). All 12 third-party providers preserved, all CPA v7.0.2 new features gained.
Why
CPAP was forked from CPA ~v6.0.x and never synced back. This caused:
/v1/images/generationsbroken (streaming response path missing image data)Approach
CPA v7.0.2 as base + CPAP extensions ported on top (not a merge — a clean rebase). CPA core code is untouched; CPAP extensions are additive.
All 12 CPAP providers preserved
Kiro, CodeBuddy, CodeBuddy AI, CodeArts, JoyCode, Cursor, GitHub Copilot, GitLab, iFlow, Kilo, BT, Qoder
Including: executors, translators, auth handlers, login commands, model definitions (static + dynamic fetch), management UI web panel, kiro-quota endpoint, usage statistics.
Gained from CPA v7.0.2
/v1/images/generations+/v1/images/editsDisableCoolingper-credential optionapi-key-usagemanagement endpointTesting
13/13 acceptance tests pass on production (154.201.92.23:8317):
Future CPA sync
8 additive commits — minimal rebase conflicts expected.