__init__.py
python
sha256:f99af7b1a7f36c4d537d1c630d4b71fc39222b1255f82e930929e2fc89015e11
fix: relax browse_repo perf budget to 500ms — 200ms was too…
Sonnet 4.6
100 days ago
| 1 | """MuseHub route package. |
| 2 | |
| 3 | Auto-discovers and registers all sub-routers. Registered in ``musehub.main`` as: |
| 4 | |
| 5 | app.include_router(musehub.router, prefix="/api", tags=["musehub"]) |
| 6 | |
| 7 | **Agent instruction — DO NOT EDIT THIS FILE.** |
| 8 | To add a new endpoint group, create a new module in this package that |
| 9 | exposes a ``router = APIRouter(...)`` attribute. It will be picked up |
| 10 | automatically on the next server start. No changes to this file are needed. |
| 11 | |
| 12 | Registration order: |
| 13 | - All modules are registered alphabetically. |
| 14 | - ``repos`` is always last because it declares the ``/{owner}/{repo_slug}`` |
| 15 | wildcard route, which must not shadow any fixed-path routes. |
| 16 | |
| 17 | Auth policy: |
| 18 | - Public repo GET endpoints use ``optional_token`` — unauthenticated |
| 19 | access is allowed for public repos; private repos return 401. |
| 20 | - Write endpoints (POST/PUT/DELETE) always use ``require_valid_token`` |
| 21 | declared on the individual route handler. |
| 22 | """ |
| 23 | |
| 24 | import importlib |
| 25 | import pkgutil |
| 26 | from pathlib import Path |
| 27 | |
| 28 | from fastapi import APIRouter |
| 29 | |
| 30 | router = APIRouter(prefix="") |
| 31 | |
| 32 | _PACKAGE = "musehub.api.routes.musehub" |
| 33 | _HERE = [str(Path(__file__).parent)] |
| 34 | |
| 35 | # Modules registered directly in main.py (with their own prefix/placement) |
| 36 | # must be excluded here to prevent double-registration and duplicate operationIds. |
| 37 | _DIRECT_REGISTERED = { |
| 38 | "discover", # registered in main.py at /api (has /musehub/discover hardcoded) |
| 39 | "sitemap", # registered in main.py at root (sitemap.xml, robots.txt) |
| 40 | "ui_new_repo", # registered in main.py at root (has /musehub/ui hardcoded prefix) |
| 41 | "ui", # registered in main.py at root (router + fixed_router) |
| 42 | "ui_blame", # registered in main.py at root |
| 43 | "ui_repo_settings",# registered in main.py at root (settings + collaborators) |
| 44 | "ui_search", # absorbed into ui_symbols — file deleted |
| 45 | "ui_topics", # registered in main.py at root |
| 46 | "ui_mcp_elicitation", # registered in main.py at root (MCP elicitation UI pages) |
| 47 | "ui_user_profile", # registered in main.py at root |
| 48 | "users", # registered in main.py at /api/musehub (same path as auto-discovery) |
| 49 | "domains", # registered in main.py at /api (domain registry API) |
| 50 | "ui_domains", # registered in main.py at root (domain registry UI pages) |
| 51 | "ui_intel", # registered in main.py at root |
| 52 | "ui_agents", # registered in main.py at root |
| 53 | "ui_releases", # registered in main.py at root |
| 54 | "ui_sessions", # registered in main.py at root |
| 55 | "ui_tree", # registered in main.py at root |
| 56 | "ui_repo", # registered in main.py at root |
| 57 | "ui_commits", # registered in main.py at root |
| 58 | "ui_proposals", # registered in main.py at root |
| 59 | "ui_issues", # registered in main.py at root |
| 60 | "ui_symbols", # registered in main.py at root |
| 61 | "ui_docs", # registered in main.py at root (/muse developer platform docs) |
| 62 | "ui_avatars", # registered in main.py before wildcard /{owner}/{repo_slug} routes |
| 63 | "mists", # registered in main.py at /api (explicit JSON API router) |
| 64 | "social", # registered in main.py at /api (social feed + SSE stream) |
| 65 | } |
| 66 | |
| 67 | # Load every sibling module that exposes a `router` attribute, alphabetically. |
| 68 | # repos goes last to avoid shadowing fixed-path routes with its wildcard. |
| 69 | for _mod_info in sorted( |
| 70 | pkgutil.iter_modules(_HERE), |
| 71 | key=lambda m: (m.name == "repos", m.name), |
| 72 | ): |
| 73 | if _mod_info.name in _DIRECT_REGISTERED: |
| 74 | continue |
| 75 | _mod = importlib.import_module(f"{_PACKAGE}.{_mod_info.name}") |
| 76 | if hasattr(_mod, "router"): |
| 77 | _tag = _mod_info.name.replace("_", " ").title() |
| 78 | router.include_router(_mod.router, tags=[_tag]) |
| 79 | |
| 80 | __all__ = ["router"] |
File History
2 commits
sha256:f99af7b1a7f36c4d537d1c630d4b71fc39222b1255f82e930929e2fc89015e11
fix: relax browse_repo perf budget to 500ms — 200ms was too…
Sonnet 4.6
100 days ago
sha256:763eb2cb8675073b84c19345b27586d2ed939a9aee97c5479b69f502f1a70eff
fix(tests): update test suite to match current implementation
Sonnet 4.6
patch
122 days ago