feat(api): implement phase 2 expanded read endpoints

This commit is contained in:
2026-03-11 23:04:42 -04:00
parent e8303b819b
commit 1be576a9a0
4 changed files with 97 additions and 8 deletions

View File

@@ -186,6 +186,22 @@ class ApiHookClient:
"""Retrieves the dedicated MMA engine status."""
return self._make_request('GET', '/api/gui/mma_status') or {}
def get_mma_workers(self) -> dict[str, Any]:
"""Retrieves status for all active MMA workers."""
return self._make_request('GET', '/api/mma/workers') or {}
def get_context_state(self) -> dict[str, Any]:
"""Retrieves the current file and screenshot context state."""
return self._make_request('GET', '/api/context/state') or {}
def get_financial_metrics(self) -> dict[str, Any]:
"""Retrieves token usage and estimated financial cost metrics."""
return self._make_request('GET', '/api/metrics/financial') or {}
def get_system_telemetry(self) -> dict[str, Any]:
"""Retrieves system-level telemetry including thread status and event queue size."""
return self._make_request('GET', '/api/system/telemetry') or {}
def get_node_status(self, node_id: str) -> dict[str, Any]:
"""Retrieves status for a specific node in the MMA DAG."""
return self._make_request('GET', f'/api/mma/node/{node_id}') or {}

View File

@@ -10,6 +10,7 @@ import logging
import websockets
from websockets.asyncio.server import serve
from src import session_logger
from src import cost_tracker
"""
API Hooks - REST API for external automation and state inspection.
@@ -236,6 +237,42 @@ class HookHandler(BaseHTTPRequestHandler):
else:
self.send_response(504)
self.end_headers()
elif self.path == "/api/mma/workers":
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
mma_streams = _get_app_attr(app, "mma_streams", {})
self.wfile.write(json.dumps({"workers": _serialize_for_api(mma_streams)}).encode("utf-8"))
elif self.path == "/api/context/state":
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
files = _get_app_attr(app, "files", [])
screenshots = _get_app_attr(app, "screenshots", [])
self.wfile.write(json.dumps({"files": files, "screenshots": screenshots}).encode("utf-8"))
elif self.path == "/api/metrics/financial":
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
usage = _get_app_attr(app, "mma_tier_usage", {})
metrics = {}
for tier, data in usage.items():
model = data.get("model", "")
in_t = data.get("input", 0)
out_t = data.get("output", 0)
cost = cost_tracker.estimate_cost(model, in_t, out_t)
metrics[tier] = {**data, "estimated_cost": cost}
self.wfile.write(json.dumps({"financial": metrics}).encode("utf-8"))
elif self.path == "/api/system/telemetry":
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
threads = [t.name for t in threading.enumerate()]
queue_size = 0
if _has_app_attr(app, "_api_event_queue"):
queue = _get_app_attr(app, "_api_event_queue")
if queue: queue_size = len(queue)
self.wfile.write(json.dumps({"threads": threads, "event_queue_size": queue_size}).encode("utf-8"))
else:
self.send_response(404)
self.end_headers()