-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (58 loc) · 2.15 KB
/
main.py
File metadata and controls
73 lines (58 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""harness-python-react — FastAPI application entry point."""
from __future__ import annotations
import logging
from contextlib import asynccontextmanager
from importlib.metadata import PackageNotFoundError, version
from typing import TYPE_CHECKING
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from src.api.routes import router as v1_router
from src.api.sessions import SessionStore
from src.observability.logging import setup_logging
from src.observability.tracing import (
instrument_fastapi,
instrument_httpx,
setup_tracing,
)
if TYPE_CHECKING:
from collections.abc import AsyncIterator
logger = logging.getLogger(__name__)
def _package_version() -> str:
"""Resolve the running package version, falling back when not installed.
`[tool.uv] package = false` skips installing the workspace as a Python
package, so `importlib.metadata.version()` raises in local dev. Tests +
`uvicorn --reload` should still boot; callers see ``0.0.0+local`` and the
Docker image (which DOES install the package) reports the real value.
"""
try:
return version("harness-python-react")
except PackageNotFoundError:
return "0.0.0+local"
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
"""Application lifespan: initialise process-wide services on startup."""
setup_tracing()
setup_logging()
instrument_httpx()
instrument_fastapi(app)
app.state.session_store = SessionStore()
logger.info("harness-python-react API started (v%s)", _package_version())
yield
logger.info("harness-python-react API stopped")
app = FastAPI(
title="harness-python-react",
description="Production-quality LLM-driven coding harness — backend scaffold.",
version=_package_version(),
lifespan=lifespan,
)
# CORS — wide-open in the scaffold so the Vite dev server on :5173 can hit
# the backend on :8000 without preflight friction. Tighten via config in a
# real deployment.
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=False,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(v1_router)