Spaces:
Sleeping
Sleeping
Claude Code commited on
Commit ·
03e9f81
1
Parent(s): dcc9bec
Claude Code: Fix the in (around line 780). The issue is try
Browse files
app.py
CHANGED
|
@@ -23,6 +23,8 @@ from dataclasses import dataclass, asdict
|
|
| 23 |
from enum import Enum
|
| 24 |
|
| 25 |
import gradio as gr
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# ========== Configuration ==========
|
| 28 |
|
|
@@ -749,41 +751,46 @@ def create_agent_office():
|
|
| 749 |
def create_agent_office_with_ws():
|
| 750 |
"""
|
| 751 |
Create the Agent Office with WebSocket API endpoints.
|
| 752 |
-
Returns
|
| 753 |
"""
|
| 754 |
-
|
|
|
|
| 755 |
|
| 756 |
-
#
|
| 757 |
-
|
| 758 |
-
def api_get_thoughts(limit: int = 50):
|
| 759 |
"""Get recent agent thoughts as JSON."""
|
| 760 |
return ws_manager.get_recent_thoughts(limit)
|
| 761 |
|
| 762 |
-
|
|
|
|
| 763 |
"""Get WebSocket manager statistics."""
|
| 764 |
return ws_manager.get_stats()
|
| 765 |
|
| 766 |
-
|
|
|
|
| 767 |
"""Clear the thought history."""
|
| 768 |
ws_manager.clear_history()
|
| 769 |
return {"status": "cleared"}
|
| 770 |
|
| 771 |
-
|
|
|
|
| 772 |
"""Get current agent status as JSON."""
|
| 773 |
return load_cain_status()
|
| 774 |
|
| 775 |
-
|
|
|
|
| 776 |
"""Get agent registry as JSON."""
|
| 777 |
return load_agent_registry()
|
| 778 |
|
| 779 |
-
#
|
| 780 |
-
|
| 781 |
-
app.add_api_route("/api/thoughts/stats", api_get_stats, methods=["GET"])
|
| 782 |
-
app.add_api_route("/api/thoughts/clear", api_clear_thoughts, methods=["POST"])
|
| 783 |
-
app.add_api_route("/api/agent/status", api_agent_status, methods=["GET"])
|
| 784 |
-
app.add_api_route("/api/agent/registry", api_agent_registry, methods=["GET"])
|
| 785 |
|
| 786 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 787 |
|
| 788 |
|
| 789 |
# ========== Main Entry Point ==========
|
|
|
|
| 23 |
from enum import Enum
|
| 24 |
|
| 25 |
import gradio as gr
|
| 26 |
+
from fastapi import FastAPI
|
| 27 |
+
from fastapi.responses import JSONResponse
|
| 28 |
|
| 29 |
# ========== Configuration ==========
|
| 30 |
|
|
|
|
| 751 |
def create_agent_office_with_ws():
|
| 752 |
"""
|
| 753 |
Create the Agent Office with WebSocket API endpoints.
|
| 754 |
+
Returns a FastAPI app with the Gradio app mounted at root.
|
| 755 |
"""
|
| 756 |
+
# Create FastAPI app first
|
| 757 |
+
fastapi_app = FastAPI(title="HuggingClaw Agent Office API")
|
| 758 |
|
| 759 |
+
# Define API route handlers
|
| 760 |
+
@fastapi_app.get("/api/thoughts")
|
| 761 |
+
async def api_get_thoughts(limit: int = 50):
|
| 762 |
"""Get recent agent thoughts as JSON."""
|
| 763 |
return ws_manager.get_recent_thoughts(limit)
|
| 764 |
|
| 765 |
+
@fastapi_app.get("/api/thoughts/stats")
|
| 766 |
+
async def api_get_stats():
|
| 767 |
"""Get WebSocket manager statistics."""
|
| 768 |
return ws_manager.get_stats()
|
| 769 |
|
| 770 |
+
@fastapi_app.post("/api/thoughts/clear")
|
| 771 |
+
async def api_clear_thoughts():
|
| 772 |
"""Clear the thought history."""
|
| 773 |
ws_manager.clear_history()
|
| 774 |
return {"status": "cleared"}
|
| 775 |
|
| 776 |
+
@fastapi_app.get("/api/agent/status")
|
| 777 |
+
async def api_agent_status():
|
| 778 |
"""Get current agent status as JSON."""
|
| 779 |
return load_cain_status()
|
| 780 |
|
| 781 |
+
@fastapi_app.get("/api/agent/registry")
|
| 782 |
+
async def api_agent_registry():
|
| 783 |
"""Get agent registry as JSON."""
|
| 784 |
return load_agent_registry()
|
| 785 |
|
| 786 |
+
# Create Gradio app
|
| 787 |
+
gradio_app = create_agent_office()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
|
| 789 |
+
# Mount Gradio app to FastAPI app at root path
|
| 790 |
+
# This makes the Gradio UI available at "/" and API routes at "/api/*"
|
| 791 |
+
gradio_app = gr.mount_gradio_app(fastapi_app, gradio_app, path="/")
|
| 792 |
+
|
| 793 |
+
return gradio_app
|
| 794 |
|
| 795 |
|
| 796 |
# ========== Main Entry Point ==========
|