Skip to content

✨ refactor: extensive codebase cleanup, architecture modernization, and critical fixes#14

Merged
MasuRii merged 34 commits intomainfrom
refactor-cleanup-and-thinking-fixes
Dec 22, 2025
Merged

✨ refactor: extensive codebase cleanup, architecture modernization, and critical fixes#14
MasuRii merged 34 commits intomainfrom
refactor-cleanup-and-thinking-fixes

Conversation

@MasuRii
Copy link
Owner

@MasuRii MasuRii commented Dec 22, 2025

✨ refactor: extensive codebase cleanup, architecture modernization, and critical fixes

This PR introduces a comprehensive modernization of the AI Studio Proxy API, featuring a major architecture refactor, a complete frontend overhaul, extensive codebase cleanup, and critical fixes for thinking mode and request processing stability.

📝 Summary

This is a transformative update that streamlines the core architecture by centralizing state management, modernizing the frontend stack to React/Vite, and resolving long-standing stability issues with thinking mode and request hangs. It also completes a full synchronization with the Dec 2025 upstream, including full English localization and restructured documentation.

✨ Changes

🧹 Codebase Cleanup

  • Removed Deprecated Components: Deleted gui_launcher.py and the entire deprecated_javascript_version/ directory, significantly reducing technical debt.
  • Dead Code Elimination: Removed over 800 lines of legacy logic, including the old auth state migration and api_utils/mcp_adapter.py.
  • Systematic Refactor: Automated removal of ~140 unused imports and standardized import formatting across 80+ files using ruff.
  • Documentation Consolidation: Moved documentation from workspace/docs/ to docs/guides/ and cleaned up task archives.

🏗 Core Architecture Modernization

  • Centralized State Management: Refactored server.py to remove legacy proxy logic, moving all shared state to api_utils/server_state.py.
  • Modern Frontend Stack: Replaced the legacy static JS/HTML frontend with a modern React + Vite + TypeScript implementation in static/frontend/.
  • Modular Routing: Modularized API endpoints into dedicated routers in api_utils/routers/, improving maintainability.
  • Improved Initialization: Enhanced the launcher and browser initialization sequence for better reliability on various platforms.

🧠 Thinking Mode & Stability Fixes

  • Strict Mode Compliance: Fixed critical violations in "Thinking Mode" logic that caused unexpected model behavior.
  • Request Resiliency: Resolved hangs in the request processor related to is_disconnected states and sync issues.
  • UI Robustness: Updated selectors and added existence checks for Gemini 3 thinking mode and budget toggles, ensuring compatibility with new AI Studio UI updates.

📚 Documentation & Localization

  • Exhaustive Guides: Introduced a new docs/guides/ structure with comprehensive documentation on architecture, API usage, environment variables, and platform differences.
  • English Localization: Completed full localization of the codebase and documentation into English.
  • Reference Material: Updated README.md and .env.example with detailed instructions and configuration options.

🛑 Shutdown & Reliability

  • Graceful Exit: Implemented a cleaner shutdown procedure to prevent zombie processes and ensure all browser instances are properly terminated.
  • Noise Reduction: Optimized logging to reduce noise while maintaining high visibility into critical operations.

📁 Files Changed

Category Change Type Impact
api_utils/ ♻️ Refactor Moved to centralized state, modularized routers, cleaned up imports.
browser_utils/ 🐛 Fix/Refactor Improved UI resiliency, thinking mode fixes, modularized controller.
static/frontend/ ✨ New Brand new React/Vite frontend.
docs/guides/ 📚 New/Move Restructured and exhaustive documentation.
server.py ♻️ Refactor Removed proxy logic, streamlined entry point.

🧪 Testing Status

  • Automated Tests: Verified existing test suites in tests/launcher/ and tests/api_utils/. Confirmed no regressions were introduced.
  • Manual Verification:
    • Confirmed successful startup and state synchronization using the new server_state module.
    • Verified the new React frontend correctly interfaces with all API endpoints.
    • Tested Gemini 3 models with and without thinking mode to ensure selector resiliency.
    • Verified graceful shutdown on both Windows (Git Bash) and Linux environments.

🔗 Related Issues

  • Sync with upstream Dec 2025.
  • Fixes various stability issues reported with thinking mode budget and request hangs.

⚠️ Breaking Changes

  • State Access: External scripts or old modules relying on server.attribute must now use api_utils.server_state.state.attribute.
  • Frontend Build: The frontend now requires a build step (npm run build in static/frontend) for production deployment, though pre-built assets are managed by the launcher.

Sn0wo2 and others added 30 commits December 7, 2025 23:34
fix: Update selectors for Google AI Studio UI changes and fix test mocks (CJackHwang#278)
…by centralizing definitions and supporting new/old UI structures."
…new tests for selector and grid logger utilities.
…nd prompt handling, alongside refactoring authentication state saving and enhancing logging infrastructure.
…ts for server state and launcher configuration.
…t, and enable standard type checking mode with stricter reports
feat: Logging overhaul, UI selector robustness, and thinking mode support
… its tests, exposing `save_error_snapshot_enhanced` in its place.
refactor: remove dead code and update documentation
Google AI Studio changed the menu item text from 'Upload File' to 'Upload a file'.
Added fallback chain to support both old and new UI versions.
…ty (CJackHwang#292)

* style: remove nested logs and leading spaces from logger output messages

* refactor: Remove leading spaces from log messages for cleaner output.

* fix: improve reliability of chat message input and sending in page controller.

* feat: enhance logging by adding new tags, silencing verbose modules, and improving test coverage for log messages

* refactor: deprecate legacy frontend, add React SPA and modularize routers
…t kill security by restricting PIDs to tracked processes. (CJackHwang#293)
…ng#294)

Updated files:
- advanced-configuration.md: Add SKIP_FRONTEND_BUILD, model_capabilities.json section, port kill security note
- architecture-guide.md: Add model_capabilities.json and all new routers
- development-guide.md: Add Node.js prereq, frontend dev section with npm commands
- env-variables-reference.md: Add SKIP_FRONTEND_BUILD variable
- environment-configuration.md: Add SKIP_FRONTEND_BUILD to startup config
- installation-guide.md: Update Node.js requirement for frontend development
…ang#295)

* docs: comprehensive documentation update for v4.0.3 changes

Updated files:
- advanced-configuration.md: Add SKIP_FRONTEND_BUILD, model_capabilities.json section, port kill security note
- architecture-guide.md: Add model_capabilities.json and all new routers
- development-guide.md: Add Node.js prereq, frontend dev section with npm commands
- env-variables-reference.md: Add SKIP_FRONTEND_BUILD variable
- environment-configuration.md: Add SKIP_FRONTEND_BUILD to startup config
- installation-guide.md: Update Node.js requirement for frontend development

* docs: update and refine various documentation files for improved clarity
- Adopted logic and features from upstream (Centralized State, QueueManager, New Frontend).
- Preserved and restored English translations across all backend modules.
- Localized core components of the new React frontend (static/frontend).
- Fixed circular imports introduced during the merge.
- Audited README and .env.example for branding consistency.
Synchronize with CJackHwang/AIstudioProxyAPI upstream (Dec 2025) while
fully localizing the codebase to English and restoring fork-specific features.

## Upstream Sync
- Merged latest upstream changes including architecture improvements
- Updated browser automation and page controller modules
- Synced configuration and environment variable handling
- Integrated upstream test improvements and coverage enhancements

## Localization (300+ strings across 50+ files)
- Translated all Chinese log messages, comments, and docstrings to English
- Localized error messages and user-facing strings in core modules
- Updated all 18 documentation files to English
- Renamed support_author.jpg (from Chinese filename)
- Ensured consistent English terminology throughout codebase

## Fork Features Restored
- Preserved custom authentication rotation and quota handling logic
- Maintained fork-specific streaming enhancements
- Kept enhanced error handling and recovery mechanisms
- Restored all fork-specific test customizations

## Bug Fixes During Merge
- Resolved merge conflicts in page_controller.py and launch_camoufox.py
- Fixed selector constant references after upstream changes
- Corrected import paths affected by module reorganization
- Addressed CRLF/LF line ending inconsistencies

## Test Status
- 660 tests passing
- 13 pre-existing test failures (unrelated to this sync)
- All localization changes verified against test suite

Files changed: 115 (6,986 insertions, 8,949 deletions)
…ing mode timeouts

- Fixed state shadowing by removing module-level variables in server.py.
- Updated dependencies.py to read directly from the centralized state.
- Resolved queue worker hang by implementing non-blocking client connection checks.
- Integrated robust ThinkingController and simplified thinking selectors.
- Implemented parameter caching for reasoning_effort to avoid redundant UI interactions.
- Fixed NameError bugs for 'logger' and 'pending'.
- Removed legacy/unused QueueManager class to reduce technical debt.
- Ported reliability workarounds (backdrop cleanup, keyboard submission) from stable branch.
Perform a major cleanup and modernization of the repository to improve
maintainability and resolve critical UI interaction issues.

Changes:
- 🏗 Cleanup: Removed deprecated `deprecated/`, `deprecated_javascript_version/`,
  and `workspace/` directories.
- 📚 Docs: Restructured documentation by moving all guides to `docs/guides/` and
  archiving outdated research notes.
- ⚡️ Modernization: Updated `server.py` and `api_utils/app.py` to remove
  legacy proxy logic and streamline the main entry points.
- 🐛 Fix: Resolved 'Thinking Budget' selector issues that caused strict mode
  violations in browser automation.
- 🛑 Reliability: Improved server shutdown and client disconnection logic to
  reduce `CancelledError` noise and ensure clean resource release.
- 🎨 Refactor: Pruned unused imports and legacy helper functions across the
  entire `api_utils` and `browser_utils` modules.
- 🧪 Testing: Updated test suite to reflect architectural changes and ensure
  compatibility with the modernized codebase.

Includes implementation report: docs/reports/refactor/REFACTOR_REPORT_2025-12-22.md
@MasuRii MasuRii merged commit 3860fdc into main Dec 22, 2025
@MasuRii MasuRii deleted the refactor-cleanup-and-thinking-fixes branch January 7, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants