Initialize the ScriptRunner with enhanced state management. Args: session_id: Unique identifier for this session send_message_callback: Async callback to send messages to frontend initial_states: Initial widget states if any
(
self,
session_id: str,
send_message_callback: Callable,
initial_states: dict | None = None,
)
| 30 | |
| 31 | class ScriptRunner: |
| 32 | def __init__( |
| 33 | self, |
| 34 | session_id: str, |
| 35 | send_message_callback: Callable, |
| 36 | initial_states: dict | None = None, |
| 37 | ): |
| 38 | """Initialize the ScriptRunner with enhanced state management. |
| 39 | |
| 40 | Args: |
| 41 | session_id: Unique identifier for this session |
| 42 | send_message_callback: Async callback to send messages to frontend |
| 43 | initial_states: Initial widget states if any |
| 44 | """ |
| 45 | self.session_id = session_id |
| 46 | self._send_message_callback = send_message_callback |
| 47 | self.script_path: str | None = None |
| 48 | self.widget_states = initial_states or {} |
| 49 | self._state = ScriptState.INITIAL |
| 50 | self._last_run_time = 0 |
| 51 | self._run_count = 0 |
| 52 | self._lock = threading.Lock() |
| 53 | self._script_globals = {} |
| 54 | |
| 55 | from .service import PreswaldService # deferred import to avoid cyclic dependency |
| 56 | self._service = PreswaldService.get_instance() |
| 57 | |
| 58 | logger.info(f"[ScriptRunner] Initialized with session_id: {session_id}") |
| 59 | if initial_states: |
| 60 | logger.info(f"[ScriptRunner] Loaded initial states: {initial_states}") |
| 61 | |
| 62 | async def send_message(self, msg: dict): |
| 63 | """Send a message to the frontend.""" |
nothing calls this directly
no test coverage detected