Add brain memory services and APIs
Introduce the backend pieces for brain memory ingestion, routing, and system telemetry so the new knowledge workflows can project data into a brain view. The supporting tests lock in the new behavior and keep the expanded backend surface stable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from starlette.exceptions import HTTPException as StarletteHTTPException
|
||||
from app.database import init_db
|
||||
import app.models # noqa: F401 - 注册所有模型
|
||||
from app.routers import (
|
||||
@@ -16,20 +18,37 @@ from app.routers import (
|
||||
folder_router,
|
||||
skill_router,
|
||||
log_router,
|
||||
system_router,
|
||||
brain_router,
|
||||
)
|
||||
from app.routers.scheduler import router as scheduler_router
|
||||
from app.services.scheduler_service import start_scheduler, stop_scheduler, get_scheduler_status
|
||||
from app.config import settings
|
||||
from app.logging_utils import (
|
||||
setup_logging,
|
||||
request_logging_middleware,
|
||||
log_http_exception,
|
||||
log_validation_exception,
|
||||
log_unhandled_exception,
|
||||
persist_system_log,
|
||||
)
|
||||
import os
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# 启动
|
||||
setup_logging(settings.DEBUG)
|
||||
os.makedirs(settings.DATA_DIR, exist_ok=True)
|
||||
os.makedirs(settings.UPLOAD_DIR, exist_ok=True)
|
||||
os.makedirs(settings.CHROMA_PERSIST_DIR, exist_ok=True)
|
||||
await init_db()
|
||||
await persist_system_log(
|
||||
message="application_started",
|
||||
source="app",
|
||||
operation="app.startup",
|
||||
details={"version": settings.APP_VERSION},
|
||||
)
|
||||
start_scheduler()
|
||||
yield
|
||||
# 关闭
|
||||
@@ -50,6 +69,10 @@ app.add_middleware(
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
app.middleware("http")(request_logging_middleware)
|
||||
app.add_exception_handler(StarletteHTTPException, log_http_exception)
|
||||
app.add_exception_handler(RequestValidationError, log_validation_exception)
|
||||
app.add_exception_handler(Exception, log_unhandled_exception)
|
||||
|
||||
# 注册路由
|
||||
app.include_router(auth_router)
|
||||
@@ -64,6 +87,8 @@ app.include_router(settings_router)
|
||||
app.include_router(folder_router)
|
||||
app.include_router(skill_router)
|
||||
app.include_router(log_router)
|
||||
app.include_router(system_router)
|
||||
app.include_router(brain_router)
|
||||
app.include_router(scheduler_router)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user