# Description of Changes Change Stirling Engine to support deleting documents automatically. This happens both on user logout and after an amount of time specified by the Java when ingesting a document (allowing for personal documents to have short lifetimes but org documents to be left in the db with no expiry date). Also sets up an [ACL policy](https://en.wikipedia.org/wiki/Access-control_list) for the documents so the database knows which users have access to which documents. This is not fully implemented in the Java, so currently all docs are treated as having a single owner, the uploader, but theoretically when we need to support org storage, we shouldn't need to change the db schema.
70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
from fastapi import HTTPException, Request, status
|
|
|
|
from stirling.agents import (
|
|
ExecutionPlanningAgent,
|
|
OrchestratorAgent,
|
|
PdfEditAgent,
|
|
PdfQuestionAgent,
|
|
UserSpecAgent,
|
|
)
|
|
from stirling.agents.ledger import MathAuditorAgent
|
|
from stirling.agents.pdf_comment import PdfCommentAgent
|
|
from stirling.documents import DocumentService
|
|
from stirling.models import UserId
|
|
from stirling.services import AppRuntime, current_user_id
|
|
|
|
|
|
def get_runtime(request: Request) -> AppRuntime:
|
|
return request.app.state.runtime
|
|
|
|
|
|
def get_orchestrator_agent(request: Request) -> OrchestratorAgent:
|
|
return request.app.state.orchestrator_agent
|
|
|
|
|
|
def get_pdf_edit_agent(request: Request) -> PdfEditAgent:
|
|
return request.app.state.pdf_edit_agent
|
|
|
|
|
|
def get_pdf_question_agent(request: Request) -> PdfQuestionAgent:
|
|
return request.app.state.pdf_question_agent
|
|
|
|
|
|
def get_user_spec_agent(request: Request) -> UserSpecAgent:
|
|
return request.app.state.user_spec_agent
|
|
|
|
|
|
def get_execution_planning_agent(request: Request) -> ExecutionPlanningAgent:
|
|
return request.app.state.execution_planning_agent
|
|
|
|
|
|
def get_document_service(request: Request) -> DocumentService:
|
|
return request.app.state.runtime.documents
|
|
|
|
|
|
def get_math_auditor_agent(request: Request) -> MathAuditorAgent:
|
|
return request.app.state.math_auditor_agent
|
|
|
|
|
|
def get_pdf_comment_agent(request: Request) -> PdfCommentAgent:
|
|
return request.app.state.pdf_comment_agent
|
|
|
|
|
|
def require_user_id() -> UserId:
|
|
"""FastAPI dependency for routes that touch per-user storage.
|
|
|
|
Reads ``X-User-Id`` (already extracted into a ContextVar by ``UserIdMiddleware``)
|
|
and returns it. Returns HTTP 401 if the caller didn't supply the header. Apply
|
|
to any route that ingests, searches, reads, or deletes document content so
|
|
the tenancy gate is enforced at the API boundary.
|
|
"""
|
|
user_id = current_user_id.get()
|
|
if user_id is None:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="X-User-Id header is required",
|
|
)
|
|
return user_id
|