Commit Graph

165 Commits

Author SHA1 Message Date
Wha1eChai
f2f0a7452e merge: integrate upstream/main (v1.2.15) into feature/webui
- Resolved conflict in src/constants.js: kept config-driven approach

- Adopted upstream 10-second cooldown default

- Added MAX_EMPTY_RESPONSE_RETRIES constant from upstream

- Incorporated new test files and GitHub issue templates
2026-01-09 18:08:45 +08:00
Wha1eChai
a914821d49 perf(webui): refactor dashboard modules and optimize API performance 2026-01-09 17:58:09 +08:00
Badri Narayanan S
4c5236d4b3 fix: filter Antigravity system prompt from model responses
- Add [ignore] tags around system instruction to prevent model from
  identifying as "Antigravity" when asked "Who are you?"
- Replace full system instruction with minimal version used by
  CLIProxyAPI/gcli2api to reduce token usage and improve response quality

Fixes #76

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-09 14:10:41 +05:30
Badri Narayanan S
c49d94ae0d chore: add GitHub issue templates for bug reports and feature requests
Adopts issue template pattern from opencode-antigravity-auth:
- Bug report template with [BUG] prefix and 6-item checklist
- Feature request template with [FEATURE] prefix
- Config disables blank issues, adds links to Google Cloud Support, TOS, and Discussions

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-09 13:46:04 +05:30
Wha1eChai
e909ea6fe3 style(webui): refine UI polish and enhance component interactions 2026-01-09 07:54:50 +08:00
Wha1eChai
40a766ded6 feat(webui): Add Models tab and refactor model configuration
- Add standalone Models tab with real-time quota/status display
- Move model identity table from Dashboard to Models tab
- Slim down Dashboard to KPI cards and charts only
- Dashboard charts now use unfiltered data (independent of Models filters)

Settings > Models improvements:
- Remove redundant Alias column (only Mapping is functional)
- Fix column misalignment bug (empty td)
- Add column widths and hidden row opacity styling
- Single row edit constraint (only one Mapping editable at a time)
- showHiddenModels toggle now only affects Settings (not Models tab)
- Update description text to match current functionality

i18n:
- Add 'models' and 'modelsPageDesc' keys (EN/ZH)
- Add 'modelMappingHint' for Claude CLI guidance
- Update 'modelsDesc' to reflect new functionality
2026-01-09 04:39:05 +08:00
Wha1eChai
a4814b8c34 feat(webui): refactor settings architecture and achieve full i18n coverage 2026-01-09 03:04:10 +08:00
ahmed0magdy
e3be630bfb docs: add instructions for running multiple Claude Code instances 2026-01-08 20:41:05 +02:00
Badri Narayanan S
73e5d13f45 Merge pull request #72 from s21v1d9p/fix/optimistic-rate-limit-retry
fix: add optimistic reset for transient 429 rate limit errors
2026-01-08 22:27:01 +05:30
SvDp
45755bfa18 fix: add optimistic reset for transient 429 rate limit errors
Fixes issue #71 - 'No accounts available' error when API returns 429

The Google Cloud Code API can return 429 RESOURCE_EXHAUSTED errors even
when accounts have quota available due to:
- Temporary API load/throttling
- Per-minute request limits (not per-day quota)
- Transient backend issues

This fix adds:
1. A 500ms buffer after waiting for rate limits to expire
2. Optimistic rate limit reset when all accounts appear stuck
3. Retry logic that clears rate limits and tries again

The fix works in conjunction with the server-level optimistic reset
that already exists, providing multiple layers of protection against
false 'No accounts available' errors.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-08 21:31:50 +05:30
Wha1eChai
c9c5e7d486 feat(webui): add hot-reload account management with OAuth support 2026-01-08 23:52:31 +08:00
Badri Narayanan S
5f6ce1b97d Update daily Cloud Code endpoint to production URL
Remove sandbox subdomain from daily-cloudcode-pa endpoint.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-08 20:24:23 +05:30
Wha1eChai
dc9bea1100 feat(webui): comprehensive UI modernization and server configuration enhancements 2026-01-08 22:18:04 +08:00
Wha1eChai
a7aacdb0ae feat(webui): enhance server configuration and dynamic dashboard analytics 2026-01-08 22:15:03 +08:00
Badri Narayanan S
def3d90581 Add [1m] suffix to gemini 2026-01-08 18:30:54 +05:30
Badri Narayanan S
7375a2ef6d chore: add empty response retry test and fix flaky tests
- Add test:emptyretry script and include in test suite
- Fix test-interleaved-thinking: use complex prompt to force thinking
- Fix test-multiturn-thinking-tools: make Turn 2 lenient (thinking optional)
- Fix test-multiturn-thinking-tools-streaming: same lenient approach
- Use TEST_MODELS helper instead of hardcoded model ID

Models may skip thinking on obvious next steps - this is valid behavior.
Tests now only require thinking on first turn to verify signatures work.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-08 17:54:48 +05:30
Badri Narayanan S
a696ed0872 Merge pull request #64 from BrunoMarc/fix/empty-response-retry
fix: add retry mechanism for empty API responses
2026-01-08 17:38:18 +05:30
Badri Narayanan S
040713ed9a Update npx and npm install commands to use @latest
Ensures users always get the latest version when running via npx or global install.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-08 17:13:48 +05:30
Wha1eChai
217053839f feat(webui): Enhance dashboard, global styles, and settings module
## Dashboard Enhancements
- Add Request Volume trend chart with Chart.js line graph
  - Support Family/Model display modes for aggregation levels
  - Show Total/Today/1H usage statistics
  - Hierarchical filter dropdown with Smart select (Top 5 by 24h usage)
  - Persist chart preferences to localStorage
- Improve account health detection logic
  - Core models (sonnet/opus/pro/flash) require >5% quota to be healthy
  - Dynamic quota ring chart supporting any model family
- Unify table styles with standard-table class

## Global Style Refactoring
- Add CSS variable system for theming
  - Space color scale (950/900/850/800/border)
  - Neon accent colors (purple/green/cyan/yellow/red)
  - Text hierarchy (main/dim/muted/bright)
  - Chart palette (16 colors)
- Add unified component classes
  - .view-container for consistent page layouts
  - .section-header/.section-title/.section-desc
  - .standard-table for table styling
- Update scrollbar, nav-item, progress-bar to use theme variables

## Settings Module Extensions
- Add model mapping column in Models tab
- Enhance model selectors with family color indicators
- Support horizontal scroll for tabs on narrow screens
- Add defaultCooldownMs and maxWaitBeforeErrorMs config options

## New Module
- Add src/modules/usage-stats.js for request tracking
  - Track /v1/messages and /v1/chat/completions endpoints
  - Hierarchical storage: { hour: { family: { model: count } } }
  - Auto-save every minute, 30-day retention
  - GET /api/stats/history endpoint for dashboard chart

## Backend Changes
- Add direct account manipulation helpers (bypass AccountManager)
- Add POST /api/config/password endpoint for WebUI password change
- Auto-reload AccountManager after account operations
- Use CSS variables in OAuth callback pages

## Other
- Update .gitignore for runtime data directory
- Add i18n keys for new UI elements (EN/zh_CN)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-08 19:04:43 +08:00
Badri Narayanan S
f34aa50ba4 Antigravity compatibility to fix antigravity usage 2026-01-08 10:24:54 +05:30
BrunoMarc
74cb1689e9 test: add empty response retry test
Adds comprehensive test for the empty response retry mechanism:
- Verifies EmptyResponseError class exists and works correctly
- Tests basic requests still work (no regression)
- Validates error class behavior and detection

All tests pass successfully.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 20:30:45 -03:00
BrunoMarc
1c80c8ba52 fix: address second round code review feedback
Issues found by Claude Opus 4.5 + Gemini 3 Pro:

HIGH PRIORITY FIXES:
- Mark account rate-limited when 429 occurs during retry (was losing resetMs)
- Add exponential backoff between retries (500ms, 1000ms, 2000ms)
- Fix 5xx handling: don't pass error response to streamer, refetch instead
- Use recognizable error messages (429/401) for isRateLimitError/isAuthError

MEDIUM PRIORITY FIXES:
- Refactor while loop to for loop for clearer retry semantics
- Simplify logic flow with early returns

Code review by: Claude Opus 4.5 + Gemini 3 Pro Preview

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 18:21:25 -03:00
BrunoMarc
05cd80ebb5 fix: address code review feedback
- Move MAX_EMPTY_RESPONSE_RETRIES to constants.js for consistency
- Handle 429/401/5xx errors properly during retry fetch
- Use proper message ID format (crypto.randomBytes) instead of Date.now()
- Add crypto import for UUID generation

Code review by: Gemini 3 Pro Preview + Claude Opus 4.5

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 18:16:09 -03:00
BrunoMarc
49480847b6 fix: add retry mechanism for empty API responses
When Claude Code sends requests with large thinking_budget values,
the model may spend all tokens on "thinking" and return empty responses,
causing Claude Code to stop mid-conversation.

This commit adds a retry mechanism that:
- Throws EmptyResponseError instead of emitting fake message on empty response
- Retries up to 2 times before giving up
- Emits fallback message only after all retries are exhausted

Changes:
- src/errors.js: Added EmptyResponseError class and isEmptyResponseError()
- src/cloudcode/sse-streamer.js: Throw error instead of yielding fake message
- src/cloudcode/streaming-handler.js: Added retry loop with fallback

Tested for 6+ hours with 1,884 API requests and 88% recovery rate
on empty responses.

Fixes #61

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 18:11:03 -03:00
Badri Narayanan S
a7ca710249 fix commands bug in readme - replace anthropic api key to anthropic auth token 2026-01-08 01:21:01 +05:30
Badri Narayanan S
7c047a9578 Updated readme to add MCP CLI Flag 2026-01-08 01:19:47 +05:30
Badri Narayanan S
56e5042700 Merge branch 'main' into feature/webui 2026-01-07 02:01:23 +05:30
Badri Narayanan S
992fa700d8 Updated readme to use 2.5 flash lite as the default haiku model 2026-01-07 01:55:49 +05:30
Badri Narayanan S
63fa90c04b set cooldown to 10 seconds 2026-01-07 00:33:42 +05:30
Badri Narayanan S
57ba5f9c1c setting cooldown back to 30 seconds 2026-01-07 00:20:22 +05:30
Badri Narayanan S
e686af2e67 added cross model thinking to npm run test tests 2026-01-06 22:24:57 +05:30
Badri Narayanan S
5b70b7703e Changed default cooldown time to 10 seconds 2026-01-06 22:22:32 +05:30
Badri Narayanan S
84166fdefe Update star history link to correct one 2026-01-06 22:12:19 +05:30
Badri Narayanan S
59d0a92b37 Merge pull request #55 from jgor20/fix/oauth-callback-utf8-encoding
fix(oauth): add UTF-8 encoding to callback HTML pages
2026-01-06 21:49:02 +05:30
Badri Narayanan S
27afdf1e79 Merge pull request #54 from jgor20/feature/auto-rebuild-native-modules
feat: Add automatic native module rebuild on Node.js version mismatch
2026-01-06 21:48:28 +05:30
jgor20
df9b935329 fix(auth): add UTF-8 charset to OAuth callback HTML responses
Ensure proper encoding for international characters in error and success pages
by specifying charset=utf-8 in Content-Type headers and adding meta charset tags.
2026-01-05 01:43:15 +00:00
jgor20
e29cd5fa9d refactor(auth): use NativeModuleError for native module load failures
Replace generic Error instances with NativeModuleError in loadDatabaseModule
to provide more structured error information, including rebuild status and
restart requirements. Update getAuthStatus to re-throw NativeModuleError
instances without wrapping.
2026-01-05 01:20:35 +00:00
jgor20
b90eb63f22 feat(errors): add NativeModuleError for native module version mismatches
Add a new error class to handle native module errors, including version mismatches and rebuild requirements. This supports the auto-rebuild functionality by providing structured error information for rebuild success and restart needs.
2026-01-05 01:20:28 +00:00
jgor20
69b7e130a0 refactor(auth): move clearRequireCache to utils and update import
Remove the local clearRequireCache function from database.js and import it from
utils/native-module-helper.js. Update the function call to pass require.cache
as the second parameter for proper cache clearing.
2026-01-05 01:13:55 +00:00
jgor20
2d4693b4c6 refactor(utils): rename and refactor clearModuleCache to recursively clear dependencies
The function has been renamed to clearRequireCache and updated to recursively
clear the require cache for a module and all its dependencies, preventing
cycles with a visited set. This improves reliability after rebuilding native
modules by ensuring complete cache invalidation. Removed unused createRequire
import as it's no longer needed.
2026-01-05 01:13:45 +00:00
jgor20
02ceeb2ff5 feat(utils): enhance rebuildModule error handling and logging
Add detailed stdout/stderr capture and logging for failed npm rebuild commands to improve troubleshooting. Also log successful rebuild output for debugging purposes.
2026-01-05 01:11:13 +00:00
jgor20
ff188f5cf6 fix(utils): fix cross-platform root detection in findPackageRoot
Improve the findPackageRoot function to correctly detect filesystem root on all platforms by checking if dirname returns the same path, replacing the Unix-specific '/' check.
2026-01-05 01:09:00 +00:00
jgor20
e6027ec5a6 feat: auto-rebuild native modules on Node.js version mismatch
When Node.js is updated, native modules like better-sqlite3 can become
   incompatible due to NODE_MODULE_VERSION differences. This change adds
   automatic detection and rebuild capability:

   - Add native-module-helper.js utility for detecting version errors
   - Lazy-load better-sqlite3 to catch import errors at runtime
   - Automatically run npm rebuild when version mismatch is detected
   - Clear require cache and retry loading after successful rebuild
   - Provide clear instructions if automatic rebuild fails

   Fixes the issue where users running via npx encounter module errors
   after updating Node.js.
2026-01-05 00:43:21 +00:00
Wha1eChai
85f7d3bae7 feat: Add Web UI for account and quota management
## Summary
Add an optional Web UI for managing accounts and monitoring quotas.
WebUI is implemented as a modular plugin with minimal changes to server.js (only 5 lines added).

## New Features
- Dashboard: Real-time model quota visualization with Chart.js
- Accounts: OAuth-based account management (add/enable/disable/refresh/remove)
- Logs: Live server log streaming via SSE with search and level filtering
- Settings: System configuration with 4 tabs
  - Interface: Language (EN/zh_CN), polling interval, log buffer size, display options
  - Claude CLI: Proxy connection config, model selection, alias overrides (~/.claude.json)
  - Models: Model visibility and ordering management
  - Server Info: Runtime info and account config reload

## Technical Changes
- Add src/webui/index.js as modular plugin (all WebUI routes encapsulated)
- Add src/config.js for centralized configuration (~/.config/antigravity-proxy/config.json)
- Add authMiddleware for optional password protection (WEBUI_PASSWORD env var)
- Enhance logger with EventEmitter for SSE log streaming
- Make constants configurable via config.json
- Merge with main v1.2.6 (model fallback, cross-model thinking)
- server.js changes: only 5 lines added to import and mount WebUI module

## Bug Fixes
- Fix Alpine.js $watch error in settings-store.js (not supported in store init)
- Fix "OK" label to "SUCCESS" in logs filter
- Add saveSettings() calls to settings toggles for proper persistence
- Improve Claude CLI config robustness (handle empty/invalid JSON files)
- Add safety check for empty config.env in claude-config component
- Improve config.example.json instructions with clear Windows/macOS/Linux paths

## New Files
- src/webui/index.js - WebUI module with all API routes
- public/ - Complete Web UI frontend (Alpine.js + TailwindCSS + DaisyUI)
- src/config.js - Configuration management
- src/utils/claude-config.js - Claude CLI settings helper
- tests/frontend/ - Frontend test suite

## API Endpoints Added
- GET/POST /api/config - Server configuration
- GET/POST /api/claude/config - Claude CLI configuration
- POST /api/models/config - Model alias/hidden settings
- GET /api/accounts - Account list with status
- POST /api/accounts/:email/toggle - Enable/disable account
- POST /api/accounts/:email/refresh - Refresh account token
- DELETE /api/accounts/:email - Remove account
- GET /api/logs - Log history
- GET /api/logs/stream - Live log streaming (SSE)
- GET /api/auth/url - OAuth URL generation
- GET /oauth/callback - OAuth callback handler

## Backward Compatibility
- Default port remains 8080
- All existing CLI/API functionality unchanged
- WebUI is entirely optional
- Can be disabled by removing mountWebUI() call
2026-01-04 18:35:29 +08:00
Badri Narayanan S
ea3d3ca4a4 format readme for headless server account addition 2026-01-04 14:59:29 +05:30
Badri Narayanan S
3c0a4845d6 Merge pull request #50 from badri-s2001/feature/headless-server
feat: add --no-browser OAuth mode for headless servers
2026-01-04 14:53:08 +05:30
Badri Narayanan S
1628696ca1 fix: correct state destructuring and document headless mode
- Fix extractCodeFromInput destructuring: returns { code, state } not
  { code, extractedState }, so state validation was being bypassed
- Add --no-browser hint to CLI banner for discoverability
- Document --no-browser mode in README.md and CLAUDE.md
- Add test:oauth script to package.json
- Add OAuth test to run-all.cjs test suite

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-04 14:51:05 +05:30
Caixiaopig
573ba57db6 feat: add --no-browser OAuth mode for headless servers
## Feature Description

Enables adding Google accounts on remote servers without a desktop
environment (headless Linux, Docker containers, SSH sessions) where
automatic browser opening is not possible. Users can manually copy the
authorization URL to a device with a browser, complete authentication,
and paste the authorization code back.

## Usage

npm run accounts:add -- --no-browser

## Code Architecture

### New Modules

1. oauth.js - extractCodeFromInput()
   - Parses user input (full callback URL or raw authorization code)
   - Extracts code and state parameters
   - Handles OAuth error responses

2. accounts.js - addAccountNoBrowser()
   - Account addition flow for no-browser mode
   - Displays authorization URL for manual copying
   - Waits for user to paste authorization code
   - Calls extractCodeFromInput to parse input
   - Completes OAuth flow and saves account

3. tests/test-oauth-no-browser.cjs
   - 13 unit tests covering valid URLs, raw codes, error handling, edge cases

### Modified Modules

1. accounts.js - interactiveAdd()
   - Added noBrowser parameter
   - Selects addAccount or addAccountNoBrowser based on mode

2. accounts.js - main()
   - Parses --no-browser CLI argument
   - Updated help information

## User Flow

┌─────────────────────────────────────────────────────────────┐
│                   Headless Server Terminal                   │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │ npm run accounts:add -- --no-browser │
            └─────────────────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │   Display Google OAuth URL       │
            │   (manual copy required)         │
            └─────────────────────────────────┘
                              │
         ┌────────────────────┴────────────────────┐
         │                                         │
         ▼                                         ▼
┌─────────────────┐                    ┌─────────────────────┐
│  Local Browser  │                    │  Phone/Other Device │
│  Open URL       │                    │  Open URL           │
│  Google Sign-in │                    │  Google Sign-in     │
│  Authorize App  │                    │  Authorize App      │
└─────────────────┘                    └─────────────────────┘
         │                                         │
         └────────────────────┬────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │ Browser redirects to localhost   │
            │ (page won't load - this is OK)   │
            │ Copy full URL or code parameter  │
            └─────────────────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │ Return to server terminal        │
            │ Paste URL or authorization code  │
            └─────────────────────────────────┘
                              │
                              ▼
            ┌─────────────────────────────────┐
            │ ✓ Account added successfully     │
            └─────────────────────────────────┘

## Security Considerations

- Supports state parameter validation (when user pastes full URL)
- Warns on state mismatch but allows continuation (manual mode tolerance)
- Authorization code length validation to prevent incorrect input

## Compatibility

- Does not affect existing automatic browser OAuth flow
- All changes are additive, no modifications to upstream logic
- Easy to merge future upstream updates
2026-01-04 14:46:16 +05:30
Badri Narayanan S
d03c79cc39 Merge pull request #41 from badri-s2001/feature/model-fallback
Feature/model fallback
2026-01-04 02:32:32 +05:30
Badri Narayanan S
e0b3f90777 docs: update CLAUDE.md with model fallback and cross-model features
- Add --fallback and --debug startup flags to commands section
- Add test:crossmodel script for cross-model thinking tests
- Document fallback-config.js module in directory structure
- Add Model Fallback section explaining fallback behavior
- Add Cross-Model Thinking Signatures section explaining compatibility
- Update constants section with MODEL_FALLBACK_MAP

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-04 00:19:35 +05:30