Files
hunjing/backend/app/main.py
T
chenxin 40221170ae ✨ feat: WP-02 角色域——完整生命周期、铸魂、内驱力与随缘
- 迁移 6:character(生命周期六态检查约束、起源、现实人物治理标记、道体基线、内驱力)+ character_version(baseline/first_statement/drive_revision/reforging/persona_candidate 五类不可变版本与审核态)
- 创建:手动与随缘(确定性词库组合,同种子同候选、一次一个——不是抽卡);现实人物治理(已故拒绝、未声明授权拒绝)
- 启镜(draft→active + 首个 baseline 版本)与初照自陈(候选→确认归真并入道体)
- 生命周期端点:静修/归藏/复照(归档可恢复、复照不抹历史)+ 死亡两步确认(7 天冷静期可撤销、未满确认 422);非法状态迁移 422
- 铸魂(显式 confirm 强确认,直接更新道体)与人格候选(pending→审核批准才并入道体,不静默覆盖)
- 内驱力编辑:写当前值并落 drive_revision 版本(可追溯,ADR-018)
- 测试 52 项全绿(+8):状态机全路径、随缘确定性、现实人物三例、铸魂确认、候选审核与重复审核 409、跨域 fail-closed
2026-09-10 18:11:15 +08:00

42 lines
1.3 KiB
Python

"""FastAPI 应用工厂。"""
from fastapi import FastAPI
from app.auth.routes import router as auth_router
from app.characters.routes import router as characters_router
from app.conversations.routes import message_router, run_router
from app.conversations.routes import router as conversations_router
from app.core.config import get_settings
from app.core.errors import install_error_handlers
from app.core.middleware import RequestContextMiddleware, configure_logging
from app.db.session import init_engine
def create_app() -> FastAPI:
settings = get_settings()
configure_logging(settings.log_level)
app = FastAPI(
title="Hunjing API",
version="0.1.0",
# 公共契约位于 docs/contracts 与 openapi/;本服务 docs 仅供开发调试。
docs_url="/_dev/docs",
openapi_url="/_dev/openapi.json",
)
install_error_handlers(app)
init_engine(app)
app.add_middleware(RequestContextMiddleware)
app.include_router(auth_router)
app.include_router(conversations_router)
app.include_router(run_router)
app.include_router(message_router)
app.include_router(characters_router)
@app.get("/healthz", tags=["ops"])
async def healthz() -> dict[str, str]:
return {"status": "ok", "env": settings.env}
return app
app = create_app()