feat(api): implement phase 3 comprehensive control endpoints
This commit is contained in:
@@ -240,3 +240,21 @@ class ApiHookClient:
|
||||
"""Gets the current patch modal status."""
|
||||
return self._make_request('GET', '/api/patch/status') or {}
|
||||
|
||||
def spawn_mma_worker(self, data: dict) -> dict:
|
||||
return self._make_request('POST', '/api/mma/workers/spawn', data=data) or {}
|
||||
|
||||
def kill_mma_worker(self, worker_id: str) -> dict:
|
||||
return self._make_request('POST', '/api/mma/workers/kill', data={"worker_id": worker_id}) or {}
|
||||
|
||||
def pause_mma_pipeline(self) -> dict:
|
||||
return self._make_request('POST', '/api/mma/pipeline/pause') or {}
|
||||
|
||||
def resume_mma_pipeline(self) -> dict:
|
||||
return self._make_request('POST', '/api/mma/pipeline/resume') or {}
|
||||
|
||||
def inject_context(self, data: dict) -> dict:
|
||||
return self._make_request('POST', '/api/context/inject', data=data) or {}
|
||||
|
||||
def mutate_mma_dag(self, data: dict) -> dict:
|
||||
return self._make_request('POST', '/api/mma/dag/mutate', data=data) or {}
|
||||
|
||||
|
||||
@@ -519,6 +519,90 @@ class HookHandler(BaseHTTPRequestHandler):
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
elif self.path == "/api/mma/workers/spawn":
|
||||
def spawn_worker():
|
||||
try:
|
||||
func = _get_app_attr(app, "_spawn_worker")
|
||||
if func: func(data)
|
||||
except Exception as e:
|
||||
sys.stderr.write(f"[DEBUG] Hook API spawn_worker error: {e}\n")
|
||||
sys.stderr.flush()
|
||||
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": spawn_worker})
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({"status": "queued"}).encode("utf-8"))
|
||||
elif self.path == "/api/mma/workers/kill":
|
||||
def kill_worker():
|
||||
try:
|
||||
worker_id = data.get("worker_id")
|
||||
func = _get_app_attr(app, "_kill_worker")
|
||||
if func: func(worker_id)
|
||||
except Exception as e:
|
||||
sys.stderr.write(f"[DEBUG] Hook API kill_worker error: {e}\n")
|
||||
sys.stderr.flush()
|
||||
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": kill_worker})
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({"status": "queued"}).encode("utf-8"))
|
||||
elif self.path == "/api/mma/pipeline/pause":
|
||||
def pause_pipeline():
|
||||
_set_app_attr(app, "mma_step_mode", True)
|
||||
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": pause_pipeline})
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({"status": "queued"}).encode("utf-8"))
|
||||
elif self.path == "/api/mma/pipeline/resume":
|
||||
def resume_pipeline():
|
||||
_set_app_attr(app, "mma_step_mode", False)
|
||||
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": resume_pipeline})
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({"status": "queued"}).encode("utf-8"))
|
||||
elif self.path == "/api/context/inject":
|
||||
def inject_context():
|
||||
files = _get_app_attr(app, "files")
|
||||
if isinstance(files, list):
|
||||
files.extend(data.get("files", []))
|
||||
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": inject_context})
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({"status": "queued"}).encode("utf-8"))
|
||||
elif self.path == "/api/mma/dag/mutate":
|
||||
def mutate_dag():
|
||||
try:
|
||||
func = _get_app_attr(app, "_mutate_dag")
|
||||
if func: func(data)
|
||||
except Exception as e:
|
||||
sys.stderr.write(f"[DEBUG] Hook API mutate_dag error: {e}\n")
|
||||
sys.stderr.flush()
|
||||
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": mutate_dag})
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({"status": "queued"}).encode("utf-8"))
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
|
||||
Reference in New Issue
Block a user