Skip to content

Conversation

@kaitranntt
Copy link
Owner

Summary

Adds comprehensive remote CLIProxy routing support enabling CCS to connect to remote CLIProxyAPI servers. This is a major feature for v7.1.

Changes

New Files

  • src/cliproxy/proxy-target-resolver.ts - Central proxy target resolution (local/remote)
  • src/cliproxy/remote-auth-fetcher.ts - Fetch auth status from remote CLIProxyAPI
  • src/web-server/routes/account-routes.ts - Account management endpoints

Remote Routing (Core Feature)

  • src/cliproxy/cliproxy-executor.ts - Load remote config from config.yaml
  • src/cliproxy/config-generator.ts - Add localhost URL rewriting for remote mode
  • src/cliproxy/stats-fetcher.ts - Refactored to use proxy target resolver
  • src/web-server/routes/cliproxy-auth-routes.ts - Branch on remote mode, return 501 for unsupported ops

UI Updates

  • ui/src/components/cliproxy/control-panel-embed.tsx - Dynamic URLs, remote indicator, masked token
  • ui/src/components/cliproxy/provider-editor/* - Remote mode indicator in header
  • ui/src/components/monitoring/proxy-status-widget.tsx - Show remote server info

API Improvements

  • Enhanced error handling with try-catch patterns in all route handlers
  • Fixed route path mismatches
  • Corrected cliproxy account API paths

Documentation

  • README: Add remote CLIProxy section with CLI flags
  • docs/system-architecture.md: Add Remote CLIProxy Flow diagram
  • docs/project-roadmap.md: Add Phase 10 (Remote CLIProxy)
  • docs/code-standards.md: Add Config Priority Pattern

Key Features

  • Protocol-based default ports (443 for HTTPS, 80 for HTTP)
  • Optional auth token (only sends header when configured)
  • Runtime API response validation
  • Localhost URL rewriting for remote proxy mode
  • User model settings respected in remote mode

Test Plan

  • TypeScript compiles without errors
  • ESLint passes
  • All 539 main project tests pass
  • All 99 UI tests pass

kaitranntt and others added 24 commits December 21, 2025 00:42
- add ProxyTarget interface with host, port, protocol, authToken, isRemote
- implement getProxyTarget() to resolve target from unified config
- add buildProxyUrl() and buildProxyHeaders() utilities
- handle optional auth token (empty = no Authorization header)
- Refactor stats-fetcher.ts: 5 functions now use getProxyTarget()
- Add remote-auth-fetcher.ts: fetch auth status from remote /v0/management/auth-files
- Update cliproxy-auth-routes.ts: branch on isRemote for GET routes
- Return 501 for account management in remote mode (unsupported)
- Use React Query to fetch cliproxy_server config
- Build URLs dynamically based on remote/local mode
- Add Globe icon and Remote badge indicator
- Show context-aware error messages for remote failures
- Add runtime API response validation in remote-auth-fetcher
- Add AbortController cleanup to prevent state updates after unmount
- Validate postMessage origin matches iframe src before sending creds
- Mask auth token display (show ***last4) for security
- Reset error/connected state on refresh
- Fix port default to use protocol-based (443 for https, 80 for http)
- Normalize path in buildProxyUrl to ensure leading slash
- Add fallback for undefined email (default to 'Unknown')
- Extract timeout constant (REMOTE_FETCH_TIMEOUT_MS)
- Remove unused RemoteAuthFilesResponse interface
- Add rewriteLocalhostUrls() to detect and rewrite localhost URLs
- Support 127.0.0.1, localhost, 0.0.0.0 patterns
- Update getEffectiveEnvVars() to accept remoteRewriteConfig param
- Auto-rewrite saved settings URLs to remote server at runtime
- Import loadOrCreateUnifiedConfig to access cliproxy_server settings
- Pass remote/local config to resolveProxyConfig() function
- Enables CLI to detect remote mode from user's config.yaml
- Add remote mode detection via cliproxy-server-config query
- Display blue-themed "Remote Proxy" widget when remote enabled
- Show remote host and "Traffic auto-routed" message
- Hide local start/stop/restart controls in remote mode
getRemoteEnvVars was ignoring user settings and always loading
models from base config. Now follows same priority as local mode:
1. Custom settings path (variant configs)
2. User settings file (~/.ccs/{provider}.settings.json)
3. Base config defaults

This fixes the issue where selecting Opus 4.5 in UI resulted in
Gemini 3 preview being loaded when using remote proxy mode.
Shows "Remote" badge with Globe icon and "Traffic auto-routed to
remote server" message when remote CLIProxy mode is active.
- Change /cliproxy/accounts/* to /cliproxy/auth/accounts/*
- Fix 404 errors when managing CLIProxy accounts from dashboard
- Root cause: frontend called wrong endpoints for account management
- Add /usage alias for /cliproxy/stats (frontend compatibility)
- Create account-routes.ts to fix /accounts/accounts double path
- Update index.ts to mount accountRoutes at /accounts
- Remove account code from profile-routes.ts
- Clean up unused imports in profile-routes.ts
- Add try-catch to cliproxy-auth-routes GET /
- Add try-catch to health-routes GET / and POST /fix/:checkId
- Add try-catch to config-routes GET /format and POST /migrate
- Improve error messages with specific context
- All handlers now return 500 with error message on failure
- Add try-catch to all route handlers in settings, variant, config routes
- Implement 5 missing endpoints in cliproxy-stats-routes:
  - GET/PUT /config.yaml for YAML config management
  - GET /auth-files to list auth directory files
  - GET /auth-files/download for file download
  - PUT /models/:provider to update model settings
- All handlers now return proper error messages on failure
fix(api): resolve CLIProxy account management errors
Resolve conflicts in cliproxy-auth-routes.ts by combining:
- Dev's improved error handling with try-catch patterns
- Branch's remote mode routing logic

All 638 tests pass.
feat(cliproxy): add remote CLIProxy routing with dev merge
- README: add remote CLIProxy section with CLI flags and quick setup
- code-standards: add Config Priority Pattern (CLI > ENV > config.yaml)
- codebase-summary: add new remote proxy files, update test counts (638)
- project-overview-pdr: add FR-008 requirement, v7.1 release section
- project-roadmap: add Phase 10 (Remote CLIProxy), mark #142 complete
- system-architecture: add Remote CLIProxy Flow diagram
@kaitranntt kaitranntt merged commit 71008b3 into main Dec 22, 2025
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 7.2.0 🎉

The release is available on:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants