Skip to content

Commit ac5b234

Browse files
authored
Merge pull request #286 from NikkeTryHard/main
refactor: remove dead code and update documentation
2 parents fdfb089 + 9da1a7b commit ac5b234

27 files changed

Lines changed: 81 additions & 1689 deletions

CONTRIBUTING.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributing to AI Studio Proxy API
2+
3+
Thank you for your interest in contributing! We welcome bug reports, feature requests, and pull requests.
4+
5+
## Getting Started
6+
7+
### Fork & Clone
8+
9+
```bash
10+
git clone https://github.com/YOUR_USERNAME/AIstudioProxyAPI.git
11+
cd AIstudioProxyAPI
12+
```
13+
14+
### Install Dependencies
15+
16+
```bash
17+
# Install Poetry (if not already installed)
18+
curl -sSL https://install.python-poetry.org | python3 -
19+
20+
# Install dependencies
21+
poetry install --with dev
22+
```
23+
24+
### Run the Test Suite
25+
26+
```bash
27+
poetry run pytest
28+
```
29+
30+
## Making Changes
31+
32+
1. **Create a branch**: `git checkout -b feature/your-feature`
33+
2. **Make your changes**
34+
3. **Run checks** before committing:
35+
```bash
36+
poetry run ruff check .
37+
poetry run ruff format .
38+
poetry run pyright
39+
poetry run pytest
40+
```
41+
4. **Commit** using [Conventional Commits](https://www.conventionalcommits.org/):
42+
- `feat:` New feature
43+
- `fix:` Bug fix
44+
- `docs:` Documentation
45+
- `refactor:` Code restructuring
46+
5. **Open a Pull Request**
47+
48+
## Code Style
49+
50+
We use:
51+
52+
- **Ruff** for linting and formatting
53+
- **Pyright** for type checking
54+
- **80% test coverage** minimum for modified files
55+
56+
See [Development Guide](docs/development-guide.md) for detailed coding conventions.
57+
58+
## Reporting Issues
59+
60+
Please include:
61+
62+
- Steps to reproduce
63+
- Expected vs actual behavior
64+
- Python version and OS
65+
- Relevant logs (from `errors_py/` if available)
66+
67+
## Questions?
68+
69+
- Check [Troubleshooting Guide](docs/troubleshooting.md)
70+
- Open a Discussion or Issue
71+
72+
## License
73+
74+
Contributions are licensed under [AGPLv3](LICENSE).

api_utils/auth_manager.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ def mark_profile_failed(self, profile_path: Optional[str] = None) -> None:
7878
"Attempted to mark profile failed but no profile provided or active."
7979
)
8080

81-
def reset_failures(self) -> None:
82-
"""Reset the failure tracking."""
83-
self.failed_profiles.clear()
84-
logger.info("Auth profile failure tracking reset.")
85-
8681

8782
# Global instance
8883
auth_manager = AuthManager()

api_utils/client_connection.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
import asyncio
22
from asyncio import Event, Task
33
from logging import Logger
4-
from typing import Any, Callable, Coroutine, Dict, Protocol, Tuple
4+
from typing import Any, Callable, Coroutine, Dict, Tuple
55

66
from fastapi import HTTPException, Request
77

88
from logging_utils import set_request_id
99
from models import ClientDisconnectedError
1010

1111

12-
class SupportsReceive(Protocol):
13-
"""Protocol for request objects that support _receive method."""
14-
15-
def _receive(self) -> Coroutine[Any, Any, Dict[str, Any]]:
16-
"""Internal method to receive messages from ASGI."""
17-
...
18-
19-
2012
async def check_client_connection(req_id: str, http_request: Request) -> bool:
2113
"""
2214
Checks if the client is still connected.

api_utils/mcp_adapter.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,39 +55,3 @@ async def execute_mcp_tool_with_endpoint(
5555
except Exception:
5656
data = {"raw": resp.text}
5757
return json.dumps(data, ensure_ascii=False)
58-
59-
60-
# Synchronous helpers for use inside threads
61-
def execute_mcp_tool_sync(name: str, params: Dict[str, Any]) -> str:
62-
ep = os.environ.get("MCP_HTTP_ENDPOINT")
63-
if not ep:
64-
raise RuntimeError("MCP_HTTP_ENDPOINT not configured")
65-
url = f"{_normalize_endpoint(ep)}/tools/execute"
66-
payload = {"name": name, "arguments": params}
67-
headers = {"Content-Type": "application/json"}
68-
timeout = float(os.environ.get("MCP_HTTP_TIMEOUT", "15"))
69-
with httpx.Client(timeout=timeout) as client:
70-
resp = client.post(url, json=payload, headers=headers)
71-
resp.raise_for_status()
72-
try:
73-
data = resp.json()
74-
except Exception:
75-
data = {"raw": resp.text}
76-
return json.dumps(data, ensure_ascii=False)
77-
78-
79-
def execute_mcp_tool_with_endpoint_sync(
80-
endpoint: str, name: str, params: Dict[str, Any]
81-
) -> str:
82-
url = f"{_normalize_endpoint(endpoint)}/tools/execute"
83-
payload = {"name": name, "arguments": params}
84-
headers = {"Content-Type": "application/json"}
85-
timeout = float(os.environ.get("MCP_HTTP_TIMEOUT", "15"))
86-
with httpx.Client(timeout=timeout) as client:
87-
resp = client.post(url, json=payload, headers=headers)
88-
resp.raise_for_status()
89-
try:
90-
data = resp.json()
91-
except Exception:
92-
data = {"raw": resp.text}
93-
return json.dumps(data, ensure_ascii=False)

api_utils/response_generators.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ async def gen_sse_from_aux_stream(
5050
full_body_content = ""
5151
data_receiving = False
5252

53-
loop_count = 0
54-
5553
try:
5654
async for raw_data in use_stream_response(req_id):
57-
loop_count += 1
58-
# logger.debug(f"[{req_id}] gen_sse_from_aux_stream loop iteration #{loop_count}")
59-
6055
data_receiving = True
6156

6257
try:

api_utils/server_state.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,6 @@ def clear_debug_logs(self) -> None:
9999
self.console_logs = []
100100
self.network_log = {"requests": [], "responses": []}
101101

102-
def get_server_status(self) -> Dict[str, Any]:
103-
"""Get current server status as a dictionary."""
104-
return {
105-
"is_initializing": self.is_initializing,
106-
"is_playwright_ready": self.is_playwright_ready,
107-
"is_browser_connected": self.is_browser_connected,
108-
"is_page_ready": self.is_page_ready,
109-
"current_model": self.current_ai_studio_model_id,
110-
"queue_size": self.request_queue.qsize() if self.request_queue else 0,
111-
"worker_running": bool(self.worker_task and not self.worker_task.done()),
112-
}
113-
114102

115103
# Global singleton instance
116104
state = ServerState()

browser_utils/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
capture_playwright_state,
66
get_texas_timestamp,
77
save_comprehensive_snapshot,
8-
save_error_snapshot_legacy,
8+
save_error_snapshot_enhanced,
99
)
1010
from .initialization import (
1111
_close_page_logic,
@@ -34,7 +34,6 @@
3434
save_error_snapshot,
3535
)
3636
from .page_controller import PageController
37-
from .script_manager import ScriptManager, script_manager
3837

3938
__all__ = [
4039
# 初始化相关
@@ -60,14 +59,11 @@
6059
"_force_ui_state_settings",
6160
"_force_ui_state_with_retry",
6261
"_verify_and_apply_ui_state",
63-
# 脚本管理相关
64-
"ScriptManager",
65-
"script_manager",
6662
# Page Controller
6763
"PageController",
6864
# Debug utilities (comprehensive error snapshots)
6965
"save_comprehensive_snapshot",
70-
"save_error_snapshot_legacy",
66+
"save_error_snapshot_enhanced",
7167
"get_texas_timestamp",
7268
"capture_dom_structure",
7369
"capture_playwright_state",

browser_utils/debug_utils.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -694,20 +694,3 @@ async def save_error_snapshot_enhanced(
694694
locators=locators,
695695
error_exception=error_exception,
696696
)
697-
698-
699-
async def save_error_snapshot_legacy(error_name: str = "error") -> None:
700-
"""
701-
Legacy error snapshot function for backward compatibility.
702-
703-
DEPRECATED: Use save_error_snapshot_enhanced() or save_comprehensive_snapshot() instead.
704-
705-
Args:
706-
error_name: Error name with optional req_id suffix (e.g., "error_hbfu521")
707-
"""
708-
# Delegate to enhanced function with minimal context
709-
await save_error_snapshot_enhanced(
710-
error_name=error_name,
711-
error_stage="Legacy snapshot call",
712-
additional_context={"legacy_call": True},
713-
)

browser_utils/operations_modules/interactions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ async def _wait_for_response_completion(
349349
edit_button_locator: Locator,
350350
req_id: str,
351351
check_client_disconnected_func: Callable,
352-
current_chat_id: Optional[str],
353352
timeout_ms=RESPONSE_COMPLETION_TIMEOUT,
354353
initial_wait_ms=INITIAL_WAIT_MS_BEFORE_POLLING,
355354
) -> bool:

browser_utils/page_controller_modules/chat.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,6 @@ async def _execute_chat_clear(
290290
else:
291291
raise
292292

293-
await self._check_disconnect(
294-
check_client_disconnected,
295-
f"清空聊天 - 消失检查尝试 {attempt_disappear + 1} 后",
296-
)
297-
298293
async def _dismiss_backdrops(self):
299294
"""尝试关闭可能残留的 cdk 透明遮罩层以避免点击被拦截。"""
300295
try:

0 commit comments

Comments
 (0)