feat(api): Add /api/gui/state endpoint and live_gui integration tests

This commit is contained in:
2026-03-05 10:06:47 -05:00
parent 52838bc500
commit a783ee5165
4 changed files with 65 additions and 1 deletions

View File

@@ -84,6 +84,11 @@ class ApiHookClient:
"""Retrieves current MMA status (track, tickets, tier, etc.)"""
return self._make_request('GET', '/api/gui/mma_status')
def get_gui_state(self) -> dict | None:
"""Retrieves the current GUI state via /api/gui/state."""
resp = self._make_request("GET", "/api/gui/state")
return resp if resp else None
def push_event(self, event_type: str, payload: dict[str, Any]) -> dict[str, Any] | None:
"""Pushes an event to the GUI's AsyncEventQueue via the /api/gui endpoint."""
return self.post_gui({

View File

@@ -165,6 +165,27 @@ class HookHandler(BaseHTTPRequestHandler):
else:
self.send_response(504)
self.end_headers()
elif self.path == '/api/gui/state':
event = threading.Event()
result = {}
def get_state():
try:
gettable = _get_app_attr(app, "_gettable_fields", {})
for key, attr in gettable.items():
result[key] = _get_app_attr(app, attr, None)
finally: event.set()
lock = _get_app_attr(app, "_pending_gui_tasks_lock")
tasks = _get_app_attr(app, "_pending_gui_tasks")
if lock and tasks is not None:
with lock: tasks.append({"action": "custom_callback", "callback": get_state})
if event.wait(timeout=10):
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(json.dumps(result).encode("utf-8"))
else:
self.send_response(504)
self.end_headers()
else:
self.send_response(404)
self.end_headers()

View File

@@ -707,6 +707,13 @@ class AppController:
'manual_approve': 'ui_manual_approve'
}
self._gettable_fields = dict(self._settable_fields)
self._gettable_fields.update({
'ui_focus_agent': 'ui_focus_agent',
'active_discussion': 'active_discussion',
'_track_discussion_active': '_track_discussion_active'
})
self.hook_server = api_hooks.HookServer(app if app else self)
self.hook_server.start()
@@ -1004,6 +1011,15 @@ class AppController:
"""Returns the health status of the API."""
return {"status": "ok"}
@api.get("/api/gui/state", dependencies=[Depends(get_api_key)])
def get_gui_state() -> dict[str, Any]:
"""Returns the current GUI state for specific fields."""
gettable = getattr(self, "_gettable_fields", {})
state = {}
for key, attr in gettable.items():
state[key] = getattr(self, attr, None)
return state
@api.get("/status", dependencies=[Depends(get_api_key)])
def status() -> dict[str, Any]:
"""Returns the current status of the application."""