Commit Graph

72 Commits

Author SHA1 Message Date
Wha1eChai
c9c5e7d486 feat(webui): add hot-reload account management with OAuth support 2026-01-08 23:52:31 +08:00
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
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
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
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
Badri Narayanan S
141558dd62 Improve cross-model thinking handling and add gemini-3-flash fallback
- Add gemini-3-flash to MODEL_FALLBACK_MAP for completeness
- Add hasGeminiHistory() to detect Gemini→Claude cross-model switch
- Trigger recovery for Claude only when Gemini history detected
- Remove unnecessary thinking block filtering for Claude-only conversations
- Add comments explaining '.' placeholder usage
- Remove unused filterUnsignedThinkingFromMessages function

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-04 00:11:14 +05:30
Badri Narayanan S
53f8d7f6cc Add debug logging when stripping thinking blocks
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-03 23:29:21 +05:30
Badri Narayanan S
12e427e9d5 Fix needsThinkingRecovery to require tool loop context
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-03 23:24:52 +05:30
Badri Narayanan S
dc65499c49 Preserve valid thinking blocks during recovery
Instead of stripping all thinking blocks during thinking recovery,
now only strips invalid or incompatible blocks. Uses signature cache
to validate family compatibility for cross-model fallback scenarios.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-03 23:17:38 +05:30
Badri Narayanan S
668c7aef26 correct els if condition for state.inToolLoop 2026-01-03 22:38:46 +05:30
Badri Narayanan S
b7286059ee remove targetFamily from analyzeConversationState 2026-01-03 22:13:35 +05:30
Badri Narayanan S
602d6ca0f8 move fallback map to constants 2026-01-03 22:05:16 +05:30
Badri Narayanan S
ac9ec6b358 Signature handling for fallback 2026-01-03 22:01:57 +05:30
Badri Narayanan S
df6625b531 fallback changes from PR #35 2026-01-03 18:01:21 +05:30
Badri Narayanan S
9c4a712a9a Selective fixes from PR #35: Model-specific rate limits & robustness improvements (#37)
* feat: apply local user changes and fixes

* ;D

* Implement OpenAI support, model-specific rate limiting, and robustness fixes

* docs: update pr title

* feat: ensure unique openai models endpoint

* fix: startup banner alignment and removed duplicates

* feat: add model fallback system with --fallback flag

* fix: accounts cli hanging after completion

* feat: add exit option to accounts cli menu

* fix: remove circular dependency warning for fallback flag

* feat: show active modes in banner and hide their flags

* Remove OpenAI compatibility and fallback features from PR #35

Cherry-picked selective fixes from PR #35 while removing:
- OpenAI-compatible API endpoints (/openai/v1/*)
- Model fallback system (fallback-config.js)
- Thinking block skip for Gemini models
- Unnecessary files (pullrequest.md, test-fix.js, test-openai.js)

Retained improvements:
- Network error handling with retry logic
- Model-specific rate limiting
- Enhanced health check with quota info
- CLI fixes (exit option, process.exit)
- Startup banner alignment (debug mode only)

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

Co-Authored-By: Claude <noreply@anthropic.com>

* banner alignment fix

* Refactor: Model-specific rate limits and cleanup deprecated code

- Remove global rate limit fields (isRateLimited, rateLimitResetTime) in favor of model-specific limits (modelRateLimits[modelId])
- Remove deprecated wrapper functions (is429Error, isAuthInvalidError) from handlers
- Filter fetchAvailableModels to only return Claude and Gemini models
- Fix getCurrentStickyAccount() to pass model param after waiting
- Update /account-limits endpoint to show model-specific limits
- Remove multi-account OAuth flow to avoid state mismatch errors

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: show (x/y) limited status in account-limits table

- Status is now "ok" only when all models are available
- Shows "(x/y) limited" when x out of y models are exhausted
- Provides better visibility into partial rate limiting

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

Co-Authored-By: Claude <noreply@anthropic.com>

* docs: update CLAUDE.md with model-specific rate limiting

- Document modelRateLimits[modelId] for per-model rate tracking
- Add isNetworkError() helper to utilities section

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

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: M1noa <minoa@minoa.cat>
Co-authored-by: Minoa <altgithub@minoa.cat>
Co-authored-by: Claude <noreply@anthropic.com>
2026-01-03 15:33:49 +05:30
Badri Narayanan S
2d05dd5b62 Fix: Reset invalid accounts on startup and improve project discovery logging
Fixes #33 - Accounts marked as invalid were permanently stuck because
the isInvalid flag was persisted to disk but never reset on startup.

Changes:
- Reset isInvalid flag for all accounts on server startup, giving them
  a fresh chance to refresh their OAuth tokens
- Add logging for project discovery failures (was silently failing)
- Add success logging when project is discovered
- Add warning message when falling back to default project

Bug introduced in 01cda83 (2025-12-25) when isInvalid persistence was
added without corresponding reset logic on load.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-02 12:34:35 +05:30
Badri Narayanan S
77089e0360 Fix issue where Antigravity auth is not working 2026-01-02 11:47:54 +05:30
Badri Narayanan S
8e4c4bdfd4 Fix accounts cli path 2026-01-02 00:03:43 +05:30
Badri Narayanan S
f02364d4ef refactor: Reorganize src/ into modular folder structure
Split large monolithic files into focused modules:
- cloudcode-client.js (1,107 lines) → src/cloudcode/ (9 files)
- account-manager.js (639 lines) → src/account-manager/ (5 files)
- Move auth files to src/auth/ (oauth, token-extractor, database)
- Move CLI to src/cli/accounts.js

Update all import paths and documentation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-01 15:13:43 +05:30
Badri Narayanan S
1d91bc0d30 Improve logging, rate limiting, and error handling (#29)
* feat: apply local user changes and fixes

* ;D

* Clean up PR #28: Remove duplicate code lines and unnecessary file

- Remove pullrequest.md (PR notes file not needed in repo)
- Fix duplicate lines in account-manager.js:
  - rateLimitResetTime assignment
  - saveToDisk() calls in markRateLimited and markInvalid
  - invalidReason/invalidAt assignments
  - double return statement in discoverProject

Original PR by M2noa: fix sticky accs, 500s, logging updates, and rate limit handling

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

Co-Authored-By: M2noa <226494568+M2noa@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>

* chore: replace console.log with logger methods for consistency

- Replace all console.log calls with logger.warn/debug in:
  - src/cloudcode-client.js (4 places)
  - src/format/thinking-utils.js (7 places)

This ensures consistent logging behavior with the new logger utility,
respecting --debug mode for verbose output.

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

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: M1noa <minoa@minoa.cat>
Co-authored-by: M2noa <226494568+M2noa@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-01-01 14:35:06 +05:30
Badri Narayanan S
d05fb64e29 Fix: Add Windows support for SQLite database access (Issue #23)
Replace CLI-based sqlite3 extraction with better-sqlite3 library:
- Create shared src/db/database.js module for cross-platform SQLite access
- Remove duplicate extractTokenFromDB functions from token-extractor.js and account-manager.js
- Add better-sqlite3 dependency with prebuilt Windows/Mac/Linux binaries
- Improve error handling with specific messages for common issues

Fixes #23

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-30 18:47:05 +05:30
Badri Narayanan S
ead7632eec Fix: Read Image tool not working 2025-12-30 17:01:01 +05:30
Badri Narayanan S
1bf2362e98 chore: remove unused node-fetch dependency from lockfile
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-30 12:12:27 +05:30
Badri Narayanan S
f3f7189cba Updated readme to set hasCompletedOnboarding to true 2025-12-29 17:26:31 +05:30
Badri Narayanan S
2247df24df updated instructions to load environment variables 2025-12-29 14:46:11 +05:30
Badri Narayanan S
17e7cebef1 Merge pull request #13 from jroth1111/split/count-tokens
Add count_tokens stub
2025-12-29 14:18:26 +05:30
gwizz
306a8891c8 Add count_tokens stub endpoint 2025-12-29 10:57:47 +11:00
Badri Narayanan S
426acc494a Implement Gemini signature caching and thinking recovery
- Add in-memory signature cache to restore thoughtSignatures stripped by Claude Code
- Implement thinking recovery logic to handle interrupted tool loops for Gemini
- Enhance schema sanitizer to preserve constraints and enums as description hints
- Update CLAUDE.md with new architecture details

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-28 14:34:03 +05:30
Badri Narayanan S
1eb2329f7c Gemini schema fix and modularize format converter 2025-12-28 03:28:05 +05:30
Badri Narayanan S
21c17d55f3 Removed standard anthropic name mapper as its unnecessary 2025-12-27 19:11:03 +05:30
Badri Narayanan S
937d23a75a Updated config details in readme 2025-12-27 16:40:43 +05:30
Badri Narayanan S
c1e1dbb0ef Added support for Gemini models 2025-12-27 14:09:20 +05:30
Badri Narayanan S
9b7dcf3a6c removing restcting of available models, fixing max tokens issues in test 2025-12-27 12:17:45 +05:30
Badri Narayanan S
f86c4f4d32 updating star history link to no cache 2025-12-26 23:23:12 +05:30
Badri Narayanan S
1dfb47325b docs: add banner image to README
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-26 20:53:54 +05:30
Badri Narayanan S
136535fd52 docs: add Buy Me a Coffee funding link
- Add .github/FUNDING.yml for GitHub Sponsor button
- Add Buy Me a Coffee badge to README

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-26 20:40:38 +05:30
Badri Narayanan S
07a09c1cb9 fallback to load antigravity default account, even if config file exists but with no accounts 2025-12-26 14:54:43 +05:30
Badri Narayanan S
1a9609054f chore: update repo URLs and title after GitHub rename 2025-12-26 01:09:11 +05:30
Badri Narayanan S
5465e91802 docs: add npm badges and rename title to Server 2025-12-26 00:39:20 +05:30
Badri Narayanan S
6504d77279 fix: auto-sync version from release tag in publish workflow 2025-12-26 00:31:15 +05:30
Badri Narayanan S
de873d5057 docs: update README with npm package installation instructions 2025-12-26 00:23:13 +05:30
Badri Narayanan S
277c28c7e3 1.0.2 2025-12-26 00:18:20 +05:30
Badri Narayanan S
e8bfc7ea04 fix: rename bin command to match package name for npx 2025-12-26 00:18:20 +05:30
Badri Narayanan S
6eca4ed792 1.0.1 2025-12-26 00:17:12 +05:30
Badri Narayanan S
5b1340d228 feat: add npm package support with CLI entry point 2025-12-26 00:17:12 +05:30
Badri Narayanan S
4d0e42471a updated correct star history link 2025-12-25 22:08:16 +05:30
Badri Narayanan S
b8677c9f6b feat: show remaining time for rate-limited accounts
Display rate limit remaining duration in Status column (e.g., "limited (1h23m45s)") instead of just "rate-limited"

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-25 22:00:48 +05:30
Badri Narayanan S
9b0b756e72 feat: consolidate /accounts into /account-limits endpoint
- Remove redundant /accounts endpoint
- Enhance /account-limits table output with account status, last used time, and quota reset time
- Filter model list to show only Claude models
- Use local time format for timestamps
- Update documentation (README.md, CLAUDE.md, index.js)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-25 21:55:03 +05:30