Skip to content

Commit bdbc906

Browse files
committed
correct verbose levels from env bb
1 parent a3e8d0b commit bdbc906

File tree

3 files changed

+60
-43
lines changed

3 files changed

+60
-43
lines changed

stagehand/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ async def init(self):
436436
# Create session if we don't have one
437437
if not self.session_id:
438438
await self._create_session() # Uses self._client and api_url
439-
self.logger.debug(
440-
f"Created new Browserbase session via Stagehand server: {self.session_id}"
439+
self.logger.info(
440+
f"Created new Browserbase session. Session ID: {self.session_id}"
441441
)
442442
else:
443-
self.logger.debug(
443+
self.logger.info(
444444
f"Using existing Browserbase session: {self.session_id}"
445445
)
446446

stagehand/logging.py

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -649,58 +649,76 @@ def debug(
649649
self.log(message, level=2, category=category, auxiliary=auxiliary)
650650

651651

652-
# Create a synchronous wrapper for the async default_log_handler
653652
def sync_log_handler(log_data: dict[str, Any]) -> None:
654653
"""
655-
Synchronous wrapper for log handling, doesn't require awaiting.
656-
This avoids the coroutine never awaited warnings.
654+
Enhanced log handler for messages from the Stagehand server.
655+
Uses Rich for pretty printing and JSON formatting.
656+
657+
The log_data structure from the server is:
658+
{
659+
"message": { // This is the actual LogLine object
660+
"message": "...",
661+
"level": 0|1|2,
662+
"category": "...",
663+
"auxiliary": {...}
664+
},
665+
"status": "running"
666+
}
657667
"""
658-
# Extract relevant data from the log message
659-
level = log_data.get("level", 1)
660-
if isinstance(level, str):
661-
level = {"error": 0, "info": 1, "warning": 2, "debug": 2}.get(level.lower(), 1)
662-
663-
message = log_data.get("message", "")
664-
category = log_data.get("category", "")
665-
auxiliary = {}
666-
667-
# Process auxiliary data if present
668-
if "auxiliary" in log_data:
669-
auxiliary = log_data.get("auxiliary", {})
670-
671-
# Convert string representation to actual object if needed
672-
if isinstance(auxiliary, str) and (
673-
auxiliary.startswith("{") or auxiliary.startswith("{'")
674-
):
675-
try:
676-
import ast
668+
try:
669+
# Extract the actual LogLine object from the nested structure
670+
log_line = log_data.get("message", {})
671+
672+
# Handle case where log_data might directly be the LogLine (fallback)
673+
if not isinstance(log_line, dict) or not log_line:
674+
# If message field is not a dict or is empty, treat log_data as the LogLine
675+
log_line = log_data
676+
677+
# Extract data from the LogLine object
678+
level = log_line.get("level", 1)
679+
message = log_line.get("message", "")
680+
category = log_line.get("category", "")
681+
auxiliary = log_line.get("auxiliary", {})
682+
683+
# Handle level conversion if it's a string
684+
if isinstance(level, str):
685+
level = {"error": 0, "info": 1, "warning": 1, "warn": 1, "debug": 2}.get(
686+
level.lower(), 1
687+
)
677688

678-
auxiliary = ast.literal_eval(auxiliary)
679-
except (SyntaxError, ValueError):
680-
# If parsing fails, keep as string
681-
pass
689+
# Ensure level is within valid range
690+
level = max(0, min(2, int(level))) if level is not None else 1
682691

683-
# Create a temporary logger to handle
684-
temp_logger = StagehandLogger(verbose=2, use_rich=True, external_logger=None)
692+
# Handle cases where message might be a complex object
693+
if isinstance(message, dict):
694+
# If message is a dict, convert to string for display
695+
if "message" in message:
696+
# Handle nested message structure
697+
actual_message = message.get("message", "")
698+
if not level and "level" in message:
699+
level = message.get("level", 1)
700+
if not category and "category" in message:
701+
category = message.get("category", "")
702+
message = actual_message
703+
else:
704+
# Convert dict to JSON string
705+
message = json.dumps(message, indent=2)
706+
707+
# Create a temporary logger to handle the message
708+
temp_logger = StagehandLogger(verbose=2, use_rich=True, external_logger=None)
685709

686-
try:
687710
# Use the logger to format and display the message
688-
temp_logger.log(message, level=level, category=category, auxiliary=auxiliary)
711+
temp_logger.log(message, level=level, auxiliary=auxiliary)
712+
689713
except Exception as e:
690714
# Fall back to basic logging if formatting fails
691715
print(f"Error formatting log: {str(e)}")
692-
print(f"Original message: {message}")
693-
if category:
694-
print(f"Category: {category}")
695-
if auxiliary:
696-
print(f"Auxiliary data: {auxiliary}")
716+
print(f"Original log_data: {log_data}")
697717

698718

699719
async def default_log_handler(log_data: dict[str, Any]) -> None:
700720
"""
701-
Enhanced default handler for log messages from the Stagehand server.
702-
Uses Rich for pretty printing and JSON formatting.
703-
704-
This is an async function but calls the synchronous implementation.
721+
Default handler for log messages from the Stagehand server.
722+
This is just a wrapper around sync_log_handler for backward compatibility.
705723
"""
706724
sync_log_handler(log_data)

stagehand/schemas.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ class ObserveOptions(StagehandBaseModel):
193193
..., description="Instruction detailing what the AI should observe."
194194
)
195195
model_name: Optional[str] = None
196-
return_action: Optional[bool] = None
197196
draw_overlay: Optional[bool] = None
198197
dom_settle_timeout_ms: Optional[int] = None
199198
model_client_options: Optional[dict[str, Any]] = None

0 commit comments

Comments
 (0)