Fix console registry for cross-module access
- Create separate console_registry module to avoid __main__ vs module import issue - Handler now correctly finds TUI console instance - Response output should now appear in TUI output area Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
161ddee138
commit
abc5902b60
3 changed files with 28 additions and 24 deletions
19
agentserver/console/console_registry.py
Normal file
19
agentserver/console/console_registry.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
"""
|
||||
console_registry.py — Global console reference for handlers.
|
||||
|
||||
This module provides a central place to register and retrieve
|
||||
the active console instance, avoiding Python module import issues.
|
||||
"""
|
||||
|
||||
_console = None
|
||||
|
||||
|
||||
def set_console(console):
|
||||
"""Set the active console instance."""
|
||||
global _console
|
||||
_console = console
|
||||
|
||||
|
||||
def get_console():
|
||||
"""Get the active console instance (or None)."""
|
||||
return _console
|
||||
|
|
@ -126,18 +126,12 @@ async def handle_response_print(payload: ShoutedResponse, metadata: HandlerMetad
|
|||
|
||||
Routes output to the TUI console if available, otherwise prints to stdout.
|
||||
"""
|
||||
console = None
|
||||
try:
|
||||
from run_organism import get_console
|
||||
console = get_console()
|
||||
except ImportError as e:
|
||||
print(f"[DEBUG] ImportError: {e}")
|
||||
from agentserver.console.console_registry import get_console
|
||||
|
||||
if console is not None:
|
||||
if hasattr(console, 'on_response'):
|
||||
console = get_console()
|
||||
|
||||
if console is not None and hasattr(console, 'on_response'):
|
||||
console.on_response("shouter", payload)
|
||||
else:
|
||||
print(f"[DEBUG] console has no on_response: {type(console)}")
|
||||
else:
|
||||
print(f"[DEBUG] console is None, printing to stdout")
|
||||
# Fallback for simple mode or no console
|
||||
print(f"\033[36m[response] {payload.message}\033[0m")
|
||||
|
|
|
|||
|
|
@ -23,20 +23,11 @@ import sys
|
|||
from pathlib import Path
|
||||
|
||||
from agentserver.message_bus import bootstrap
|
||||
|
||||
|
||||
# Global console reference for response handler
|
||||
_console = None
|
||||
|
||||
|
||||
def get_console():
|
||||
"""Get the current console instance."""
|
||||
return _console
|
||||
from agentserver.console.console_registry import set_console
|
||||
|
||||
|
||||
async def run_organism(config_path: str = "config/organism.yaml", use_simple: bool = False):
|
||||
"""Boot organism with TUI console."""
|
||||
global _console
|
||||
|
||||
# Bootstrap the pump
|
||||
pump = await bootstrap(config_path)
|
||||
|
|
@ -48,7 +39,7 @@ async def run_organism(config_path: str = "config/organism.yaml", use_simple: bo
|
|||
if not await console.authenticate():
|
||||
print("Authentication failed.")
|
||||
return
|
||||
_console = None
|
||||
set_console(None)
|
||||
|
||||
pump_task = asyncio.create_task(pump.run())
|
||||
try:
|
||||
|
|
@ -65,7 +56,7 @@ async def run_organism(config_path: str = "config/organism.yaml", use_simple: bo
|
|||
# Use new TUI console
|
||||
from agentserver.console.tui_console import TUIConsole
|
||||
console = TUIConsole(pump)
|
||||
_console = console
|
||||
set_console(console) # Register for handlers to find
|
||||
|
||||
# Start pump in background
|
||||
pump_task = asyncio.create_task(pump.run())
|
||||
|
|
|
|||
Loading…
Reference in a new issue