MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / _verify_ui_state_settings

Function _verify_ui_state_settings

browser_utils/models/ui_state.py:16–94  ·  view source on GitHub ↗

Verify if the UI state settings are correct. Args: page: Playwright page object. req_id: Request ID for logging. Returns: dict: A dictionary containing the validation result.

(page: AsyncPage, req_id: str = "unknown")

Source from the content-addressed store, hash-verified

14
15
16async def _verify_ui_state_settings(page: AsyncPage, req_id: str = "unknown") -> dict:
17 """
18 Verify if the UI state settings are correct.
19
20 Args:
21 page: Playwright page object.
22 req_id: Request ID for logging.
23
24 Returns:
25 dict: A dictionary containing the validation result.
26 """
27 # Don't set lifecycle phase names as request IDs - they appear as ghost prefixes
28 # Only set actual request IDs (7-char alphanumerics)
29 if req_id not in ("initial", "set_mod", "set_model", "reload", "unknown", ""):
30 set_request_id(req_id)
31 try:
32 logger.debug("[State] Verifying UI state...")
33
34 # Get current localStorage settings
35 prefs_str = await page.evaluate(
36 "() => localStorage.getItem('aiStudioUserPreference')"
37 )
38
39 if not prefs_str:
40 logger.warning("localStorage.aiStudioUserPreference does not exist")
41 return {
42 "exists": False,
43 "isAdvancedOpen": None,
44 "areToolsOpen": None,
45 "needsUpdate": True,
46 "error": "localStorage not found",
47 }
48
49 try:
50 prefs = json.loads(prefs_str)
51 is_advanced_open = prefs.get("isAdvancedOpen")
52 are_tools_open = prefs.get("areToolsOpen")
53
54 # Check if update is needed
55 needs_update = (is_advanced_open is not True) or (
56 are_tools_open is not True
57 )
58
59 result = {
60 "exists": True,
61 "isAdvancedOpen": is_advanced_open,
62 "areToolsOpen": are_tools_open,
63 "needsUpdate": needs_update,
64 "prefs": prefs,
65 }
66
67 if needs_update:
68 logger.debug(
69 f"[State] State mismatch: adv={is_advanced_open}, tools={are_tools_open} (update needed)"
70 )
71 # No log needed when state is correct
72 return result
73

Calls 5

set_request_idFunction · 0.90
debugMethod · 0.80
warningMethod · 0.80
errorMethod · 0.80
getMethod · 0.45