feat(backend): deliver Phase 3 document and voice integration
Add authenticated upload, review, retry and knowledge-selection HTTP flows with bounded JSON processing and frozen OCR policy. Preserve Gemini/OpenAI provider selection and fenced lifecycle semantics; retain FAQ preambles and uncertain vision candidates, and expose opt-in uncalibrated voice transport diagnostics. Include frontend integration examples, aligned contracts and deterministic regressions. Validation: 1767 provider-free tests passed; all 404 PostgreSQL scenarios have passing evidence across the documented runs.
This commit is contained in:
+9
-5
@@ -10,6 +10,8 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from app.api.v1.auth import router as auth_router, identity_router
|
||||
from app.api.v1.conversations import router as conversations_router
|
||||
from app.api.v1.live import router as voice_router
|
||||
from app.api.v1.documents import router as documents_router
|
||||
from app.api.v1.knowledge import router as knowledge_router
|
||||
from app.api.v1 import dependencies
|
||||
from app.infrastructure.blocking import blocking, shutdown_pool
|
||||
from app.modules.voice.configuration import VoiceSettings
|
||||
@@ -23,6 +25,7 @@ async def lifespan(app):
|
||||
try:
|
||||
engine = dependencies.get_engine()
|
||||
lifecycle = dependencies.get_lifecycle_service(engine)
|
||||
await blocking(dependencies.prepare_search_tools)
|
||||
await blocking(lifecycle.reconcile_startup)
|
||||
app.state.ready = True
|
||||
yield
|
||||
@@ -67,7 +70,8 @@ app = FastAPI(title='Technical Documentation Assistant API', lifespan=lifespan)
|
||||
app.state.ready = False
|
||||
config = VoiceSettings()
|
||||
app.add_middleware(CORSMiddleware, allow_origins=list(config.trusted_origins), allow_credentials=True,
|
||||
allow_methods=['GET','POST'], allow_headers=['Content-Type','X-CSRF-Token','X-Request-ID'])
|
||||
allow_methods=['GET','POST','PATCH'], allow_headers=['Content-Type','X-CSRF-Token','X-Request-ID','Idempotency-Key'],
|
||||
expose_headers=['X-Request-ID','Idempotency-Replayed'])
|
||||
|
||||
@app.middleware('http')
|
||||
async def transport(request, call_next):
|
||||
@@ -85,16 +89,16 @@ async def transport(request, call_next):
|
||||
result.headers['X-Request-ID'] = request_id
|
||||
return result
|
||||
|
||||
def envelope(request, code, status):
|
||||
def envelope(request, code, status, details=None):
|
||||
return JSONResponse(status_code=status, headers={'Retry-After':'60'} if status == 429 else {}, content={'error': {'code': code,
|
||||
'message': 'Request could not be completed.', 'request_id': getattr(request.state, 'request_id', str(uuid4())),
|
||||
'retryable': status in (429,503)}})
|
||||
'retryable': status in (429,503), **({'details':details} if details else {})}})
|
||||
|
||||
@app.exception_handler(StarletteHTTPException)
|
||||
@app.exception_handler(HTTPException)
|
||||
async def http_error(request, exc):
|
||||
detail = exc.detail if isinstance(exc.detail, dict) else {}
|
||||
return envelope(request, detail.get('code', 'NOT_FOUND' if exc.status_code == 404 else 'REQUEST_FAILED'), exc.status_code)
|
||||
return envelope(request, detail.get('code', 'NOT_FOUND' if exc.status_code == 404 else 'REQUEST_FAILED'), exc.status_code, detail.get('details'))
|
||||
|
||||
@app.exception_handler(RequestValidationError)
|
||||
async def dto_error(request, exc):
|
||||
@@ -104,7 +108,7 @@ async def dto_error(request, exc):
|
||||
async def unexpected_error(request, exc):
|
||||
return envelope(request, 'DEPENDENCY_UNAVAILABLE', 503)
|
||||
|
||||
for router in (auth_router, identity_router, conversations_router, voice_router):
|
||||
for router in (auth_router, identity_router, conversations_router, voice_router, documents_router, knowledge_router):
|
||||
app.include_router(router, prefix='/api/v1')
|
||||
|
||||
@app.get('/health/live')
|
||||
|
||||
Reference in New Issue
Block a user