furu 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none">
2
+ <rect width="32" height="32" rx="6" fill="#166534"/>
3
+ <path d="M8 10h4v12H8V10zm6 0h4v12h-4V10zm6 0h4v12h-4V10z" fill="#86efac"/>
4
+ <circle cx="10" cy="13" r="1.5" fill="#22c55e"/>
5
+ <circle cx="16" cy="16" r="1.5" fill="#22c55e"/>
6
+ <circle cx="22" cy="19" r="1.5" fill="#22c55e"/>
7
+ </svg>
8
+
9
+
10
+
@@ -0,0 +1,22 @@
1
+ <!doctype html>
2
+ <html lang="en" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Furu Dashboard</title>
8
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
9
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
10
+ <link
11
+ href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500&display=swap"
12
+ rel="stylesheet"
13
+ />
14
+ <script type="module" crossorigin src="/assets/index-DDv_TYB_.js"></script>
15
+ <link rel="stylesheet" crossorigin href="/assets/index-CbdDfSOZ.css">
16
+ </head>
17
+ <body>
18
+ <div id="root"></div>
19
+ </body>
20
+ </html>
21
+
22
+
furu/dashboard/main.py ADDED
@@ -0,0 +1,134 @@
1
+ """Main FastAPI application with static file serving and CLI."""
2
+
3
+ import importlib.resources
4
+ from pathlib import Path
5
+
6
+ import typer
7
+ import uvicorn
8
+ from fastapi import FastAPI
9
+ from fastapi.middleware.cors import CORSMiddleware
10
+ from fastapi.responses import FileResponse
11
+ from fastapi.staticfiles import StaticFiles
12
+
13
+ from .api.routes import router as api_router
14
+
15
+
16
+ def get_frontend_dir() -> Path:
17
+ """Get frontend dist directory, works for installed package and development."""
18
+ # Try importlib.resources (installed package)
19
+ ref = importlib.resources.files("furu.dashboard").joinpath("frontend/dist")
20
+ with importlib.resources.as_file(ref) as path:
21
+ if path.exists() and (path / "index.html").exists():
22
+ return path
23
+
24
+ # Fallback to relative path (development)
25
+ dev_path = Path(__file__).parent / "frontend" / "dist"
26
+ if dev_path.exists() and (dev_path / "index.html").exists():
27
+ return dev_path
28
+
29
+ raise FileNotFoundError(
30
+ "Frontend dist directory not found. Run 'make frontend-build' to build the frontend."
31
+ )
32
+
33
+
34
+ def create_app(*, serve_frontend: bool = False) -> FastAPI:
35
+ """Create and configure the FastAPI application."""
36
+ app = FastAPI(
37
+ title="Furu Dashboard",
38
+ description="Monitoring dashboard for Furu experiments",
39
+ version="0.1.0",
40
+ )
41
+
42
+ # CORS middleware for development
43
+ app.add_middleware(
44
+ CORSMiddleware, # type: ignore[arg-type]
45
+ allow_origins=["http://localhost:5173"], # Vite dev server
46
+ allow_credentials=True,
47
+ allow_methods=["*"],
48
+ allow_headers=["*"],
49
+ )
50
+
51
+ # Mount API routes
52
+ app.include_router(api_router)
53
+
54
+ # Serve frontend only if explicitly requested
55
+ if serve_frontend:
56
+ frontend_dir = get_frontend_dir()
57
+
58
+ # Mount static assets
59
+ assets_dir = frontend_dir / "assets"
60
+ if assets_dir.exists():
61
+ app.mount("/assets", StaticFiles(directory=assets_dir), name="assets")
62
+
63
+ # SPA catch-all route
64
+ @app.get("/{full_path:path}")
65
+ async def serve_spa(full_path: str) -> FileResponse:
66
+ """Serve the React SPA for all non-API routes."""
67
+ file_path = frontend_dir / full_path
68
+ if file_path.is_file() and not full_path.startswith("api"):
69
+ return FileResponse(file_path)
70
+ return FileResponse(frontend_dir / "index.html")
71
+
72
+ return app
73
+
74
+
75
+ # Default app instance (API only)
76
+ app = create_app()
77
+
78
+ # Lazy-initialized app with frontend (set by serve command)
79
+ _app_with_frontend: FastAPI | None = None
80
+
81
+
82
+ def get_app_with_frontend() -> FastAPI:
83
+ """Get app instance with frontend serving (lazy initialization)."""
84
+ return create_app(serve_frontend=True)
85
+
86
+
87
+ # Create Typer app for CLI
88
+ cli_app = typer.Typer(
89
+ help="Furu Dashboard - Monitor your experiments",
90
+ invoke_without_command=False,
91
+ no_args_is_help=True,
92
+ )
93
+
94
+
95
+ @cli_app.command()
96
+ def serve(
97
+ host: str = typer.Option("0.0.0.0", "--host", "-h", help="Host to bind to"),
98
+ port: int = typer.Option(8000, "--port", "-p", help="Port to bind to"),
99
+ reload: bool = typer.Option(False, "--reload", "-r", help="Enable auto-reload"),
100
+ ) -> None:
101
+ """Start the dashboard server with React frontend."""
102
+ # Create the app with frontend at runtime, not import time
103
+ global _app_with_frontend
104
+ _app_with_frontend = get_app_with_frontend()
105
+ uvicorn.run(
106
+ "furu.dashboard.main:_app_with_frontend",
107
+ host=host,
108
+ port=port,
109
+ reload=reload,
110
+ )
111
+
112
+
113
+ @cli_app.command()
114
+ def api(
115
+ host: str = typer.Option("0.0.0.0", "--host", "-h", help="Host to bind to"),
116
+ port: int = typer.Option(8000, "--port", "-p", help="Port to bind to"),
117
+ reload: bool = typer.Option(False, "--reload", "-r", help="Enable auto-reload"),
118
+ ) -> None:
119
+ """Start the API server only (no frontend)."""
120
+ uvicorn.run(
121
+ "furu.dashboard.main:app",
122
+ host=host,
123
+ port=port,
124
+ reload=reload,
125
+ )
126
+
127
+
128
+ def cli() -> None:
129
+ """CLI entry point."""
130
+ cli_app()
131
+
132
+
133
+ if __name__ == "__main__":
134
+ cli()