Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
df96044
fix(extraction): stop simple-LLM entity extraction from leaking rules…
jingw2 Sep 14, 2026
02408db
fix(extraction): drop dangling linked_entities references to rule-cat…
jingw2 Sep 15, 2026
81b319f
feat(extraction): chunk long documents at section boundaries before e…
jingw2 Sep 15, 2026
af89421
feat(extraction): auto-select a stronger model for resolution/relatio…
jingw2 Sep 15, 2026
59925cd
feat(extraction): resolve new entities against already-published ones
jingw2 Sep 15, 2026
26a703c
feat(extraction): compute graph connectivity diagnostics after each run
jingw2 Sep 15, 2026
f707b72
feat(extraction): synthesize a profile for hub (high-degree) entities
jingw2 Sep 15, 2026
db90e31
feat(evals): add real precision/recall eval, verify against 4 domains
jingw2 Sep 15, 2026
dbc6e22
fix(extraction): flush session before computing graph diagnostics
jingw2 Sep 15, 2026
f95fa38
feat(extraction): support instance-level relations, fix medical conce…
jingw2 Sep 16, 2026
44f8fe7
fix(extraction): flush concept relations before instance_relations re…
jingw2 Sep 16, 2026
405c485
modify models.py and extraction.py, fix bugs in models
jingw2 Sep 16, 2026
dd10d6d
fix(delete): sweep outbox re-inserts, clean up Neo4j/Chroma/MinIO on …
jingw2 Sep 17, 2026
8addf59
fix(pipeline-mapping): stop treating any 200 response as a passed con…
jingw2 Sep 17, 2026
28f2a9c
fix(curated): delete the legacy v2_curated_datasets mirror row too
jingw2 Sep 17, 2026
c2831aa
fix(ontology): stop the delete-failure messages from suggesting impos…
jingw2 Sep 17, 2026
3b5be6e
fix(security): enforce per-ontology project grants on legacy and v2 r…
jingw2 Nov 13, 2026
8faa937
fix(upload): stream uploads with a hard size bound
jingw2 Nov 13, 2026
8c27560
feat(connections): use saved DB connections as pipeline and refresh s…
jingw2 Nov 13, 2026
4d6080c
fix(models): delete a model on the legacy schema without active_versi…
jingw2 Nov 13, 2026
7d7017e
chore(python): cap supported Python at <3.13
jingw2 Nov 13, 2026
8bf5e51
chore: point in-network Chroma clients at port 8000; README React 19
jingw2 Nov 13, 2026
3b39ad3
test: take the snapshot-freshness clock per test, not at import
jingw2 Nov 13, 2026
cc201c4
refactor(frontend): drop synchronous setState in effects
jingw2 Nov 13, 2026
ceb148f
fix(#37): stop 403s from logging users out
jingw2 Nov 13, 2026
ba5daf5
fix(#38): expose is_dirty so "publish new version" can appear
jingw2 Nov 13, 2026
b185154
fix(#39): name blocked ontologies and the missing data grant
jingw2 Nov 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ MINIO_SECRET_KEY=minioadmin
MINIO_USE_SSL=false

# v2 — ChromaDB
# Docker network uses port 8000; host-side clients use localhost:8001.
CHROMA_HOST=chromadb
CHROMA_PORT=8001

CHROMA_PORT=8000
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ In Ontexus, every ontology is made of these building blocks:

| Layer | Technology |
|---|---|
| Frontend | React 18, TypeScript, Vite, Tailwind CSS, Cytoscape.js |
| Frontend | React 19, TypeScript, Vite, Tailwind CSS, Cytoscape.js |
| Backend | FastAPI, SQLAlchemy, Alembic |
| Metadata DB | SQLite (dev) / PostgreSQL (prod) |
| Object storage | MinIO (optional, local-file fallback) |
Expand Down
21 changes: 18 additions & 3 deletions backend/app/routers/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from sqlalchemy.orm import Session
from app.deps import get_db, get_current_user, require_editor
from app.models.user import User
from app.services.ontology_access import GrantDenied, require_project_grant
from app.services.publication.working_copy import OntologyWorkingCopyService
from app.services.publication.legacy_sync import delete_action_mirror, sync_action_to_v2
from app.models.action import Action
Expand All @@ -10,13 +11,22 @@

router = APIRouter()


def _grant(db: Session, actor: User, ontology_id: str, capability: str) -> dict:
try:
return require_project_grant(db, actor, ontology_id, capability)
except GrantDenied as exc:
raise HTTPException(status_code=404, detail="ONTOLOGY_NOT_FOUND") from exc

@router.get("")
def list_actions(ontology_id: str, db: Session = Depends(get_db), _=Depends(get_current_user)):
def list_actions(ontology_id: str, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
_grant(db, current_user, ontology_id, "read")
items = db.query(Action).filter(Action.ontology_id == ontology_id).all()
return {"data": [ActionOut.model_validate(a).model_dump() for a in items]}

@router.post("", status_code=201)
def create_action(ontology_id: str, body: ActionCreate, db: Session = Depends(get_db), current_user: User = Depends(require_editor)):
_grant(db, current_user, ontology_id, "edit")
def _write():
data = {k: v for k, v in body.model_dump().items() if v is not None}
a = Action(id=str(uuid.uuid4()), ontology_id=ontology_id, **data)
Expand All @@ -29,14 +39,16 @@ def _write():
return OntologyWorkingCopyService.mutate(db, ontology_id=ontology_id, actor_id=current_user.id, operation="action.create", callback=_write)

@router.get("/{action_id}")
def get_action(ontology_id: str, action_id: str, db: Session = Depends(get_db), _=Depends(get_current_user)):
def get_action(ontology_id: str, action_id: str, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
_grant(db, current_user, ontology_id, "read")
a = db.query(Action).filter(Action.id == action_id, Action.ontology_id == ontology_id).first()
if not a:
raise HTTPException(404, "Not found")
return {"data": ActionOut.model_validate(a).model_dump()}

@router.put("/{action_id}")
def update_action(ontology_id: str, action_id: str, body: ActionUpdate, db: Session = Depends(get_db), current_user: User = Depends(require_editor)):
_grant(db, current_user, ontology_id, "edit")
a = db.query(Action).filter(Action.id == action_id, Action.ontology_id == ontology_id).first()
if not a:
raise HTTPException(404, "Not found")
Expand All @@ -51,6 +63,7 @@ def _write():

@router.delete("/{action_id}", status_code=204)
def delete_action(ontology_id: str, action_id: str, db: Session = Depends(get_db), current_user: User = Depends(require_editor)):
_grant(db, current_user, ontology_id, "edit")
a = db.query(Action).filter(Action.id == action_id, Action.ontology_id == ontology_id).first()
if not a:
raise HTTPException(404, "Not found")
Expand All @@ -62,6 +75,7 @@ def _write():

@router.post("/{action_id}/toggle")
def toggle_action(ontology_id: str, action_id: str, db: Session = Depends(get_db), current_user: User = Depends(require_editor)):
_grant(db, current_user, ontology_id, "edit")
a = db.query(Action).filter(Action.id == action_id, Action.ontology_id == ontology_id).first()
if not a:
raise HTTPException(404, "Not found")
Expand All @@ -74,6 +88,7 @@ def _write():


@router.post("/publish")
def publish_actions(ontology_id: str, db: Session = Depends(get_db), _=Depends(require_editor)):
def publish_actions(ontology_id: str, db: Session = Depends(get_db), current_user: User = Depends(require_editor)):
"""Direct tool publication is closed; use the Ontology compiler (P1C)."""
_grant(db, current_user, ontology_id, "edit")
raise HTTPException(status_code=403, detail="PUBLICATION_NOT_ENABLED")
14 changes: 12 additions & 2 deletions backend/app/routers/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
from app.models.ontology import OntologyProject
from app.schemas.audit import AuditRequest, AuditTaskOut
from app.services.publication.extraction_model_port import default_extraction_model_port
from app.models.user import User
from app.services.ontology_access import GrantDenied, require_project_grant
import uuid

router = APIRouter()


@router.post("")
def start_audit(ontology_id: str, body: AuditRequest, db: Session = Depends(get_db), _=Depends(require_editor)):
def start_audit(ontology_id: str, body: AuditRequest, db: Session = Depends(get_db), current_user: User = Depends(require_editor)):
try:
require_project_grant(db, current_user, ontology_id, "edit")
except GrantDenied as exc:
raise HTTPException(status_code=404, detail="ONTOLOGY_NOT_FOUND") from exc
project = db.query(OntologyProject).filter(OntologyProject.id == ontology_id).first()
if not project:
raise HTTPException(404, "Ontology not found")
Expand Down Expand Up @@ -50,7 +56,11 @@ def run_sync():


@router.get("/status")
def get_audit_status(ontology_id: str, task_id: str, db: Session = Depends(get_db), _=Depends(get_current_user)):
def get_audit_status(ontology_id: str, task_id: str, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
try:
require_project_grant(db, current_user, ontology_id, "read")
except GrantDenied as exc:
raise HTTPException(status_code=404, detail="ONTOLOGY_NOT_FOUND") from exc
task = db.query(AuditTask).filter(AuditTask.id == task_id, AuditTask.ontology_id == ontology_id).first()
if not task:
raise HTTPException(404, "Audit task not found")
Expand Down
20 changes: 17 additions & 3 deletions backend/app/routers/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
from app.deps import get_db, get_current_user, require_admin, require_editor
from app.models.entity import Entity
from app.models.user import User
from app.services.ontology_access import GrantDenied, require_project_grant
from app.services.publication.working_copy import OntologyWorkingCopyService
from app.schemas.entity import EntityCreate, EntityUpdate, EntityOut
import uuid

router = APIRouter()


def _grant(db: Session, actor: User, ontology_id: str, capability: str) -> dict:
try:
return require_project_grant(db, actor, ontology_id, capability)
except GrantDenied as exc:
raise HTTPException(status_code=404, detail="ONTOLOGY_NOT_FOUND") from exc

@router.get("")
def list_entities(ontology_id: str, db: Session = Depends(get_db), _=Depends(get_current_user)):
def list_entities(ontology_id: str, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
_grant(db, current_user, ontology_id, "read")
items = db.query(Entity).filter(Entity.ontology_id == ontology_id).all()
return {"data": [EntityOut.model_validate(e).model_dump() for e in items]}

@router.post("", status_code=201)
def create_entity(ontology_id: str, body: EntityCreate, db: Session = Depends(get_db), current_user: User = Depends(require_editor)):
_grant(db, current_user, ontology_id, "edit")
def _write():
data = {k: v for k, v in body.model_dump().items() if v is not None}
e = Entity(id=str(uuid.uuid4()), ontology_id=ontology_id, **data)
Expand All @@ -24,14 +34,16 @@ def _write():
return OntologyWorkingCopyService.mutate(db, ontology_id=ontology_id, actor_id=current_user.id, operation="entity.create", callback=_write)

@router.get("/{entity_id}")
def get_entity(ontology_id: str, entity_id: str, db: Session = Depends(get_db), _=Depends(get_current_user)):
def get_entity(ontology_id: str, entity_id: str, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
_grant(db, current_user, ontology_id, "read")
e = db.query(Entity).filter(Entity.id == entity_id, Entity.ontology_id == ontology_id).first()
if not e:
raise HTTPException(404, "Not found")
return {"data": EntityOut.model_validate(e).model_dump()}

@router.put("/{entity_id}")
def update_entity(ontology_id: str, entity_id: str, body: EntityUpdate, db: Session = Depends(get_db), current_user: User = Depends(require_editor)):
_grant(db, current_user, ontology_id, "edit")
e = db.query(Entity).filter(Entity.id == entity_id, Entity.ontology_id == ontology_id).first()
if not e:
raise HTTPException(404, "Not found")
Expand All @@ -44,6 +56,7 @@ def _write():

@router.delete("/{entity_id}", status_code=204)
def delete_entity(ontology_id: str, entity_id: str, db: Session = Depends(get_db), current_user: User = Depends(require_admin)):
_grant(db, current_user, ontology_id, "edit")
e = db.query(Entity).filter(Entity.id == entity_id, Entity.ontology_id == ontology_id).first()
if not e:
raise HTTPException(404, "Not found")
Expand All @@ -56,9 +69,10 @@ def list_entity_instances(
ontology_id: str,
entity_id: str,
db: Session = Depends(get_db),
_=Depends(get_current_user),
current_user: User = Depends(get_current_user),
):
"""概念实体下挂的行级实例数据(Pipeline Mapping 与简易 LLM 提取共用同一张表)"""
_grant(db, current_user, ontology_id, "read")
from app.models.entity_instance import EntityInstance

entity = db.query(Entity).filter(
Expand Down
7 changes: 6 additions & 1 deletion backend/app/routers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sqlalchemy.orm import Session
from app.deps import get_db, get_current_user
from app.services import export_service
from app.services.ontology_access import GrantDenied, require_project_grant

router = APIRouter()

Expand All @@ -21,8 +22,12 @@ def export_ontology(
ontology_id: str,
format: str = Query("json", pattern="^(json|yaml|csv|ttl|html|cypher|tugraph)$"),
db: Session = Depends(get_db),
_=Depends(get_current_user)
current_user=Depends(get_current_user)
):
try:
require_project_grant(db, current_user, ontology_id, "read")
except GrantDenied as exc:
raise HTTPException(status_code=404, detail="ONTOLOGY_NOT_FOUND") from exc
if format not in FORMAT_MAP:
raise HTTPException(400, f"Unsupported format: {format}")
content_type, ext, fn = FORMAT_MAP[format]
Expand Down
13 changes: 11 additions & 2 deletions backend/app/routers/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
from app.models.ontology import OntologyProject
from app.services.document_service import combine_converted_files
from app.schemas.extraction import ExtractionRequest, ExtractionTaskOut
from app.services.ontology_access import GrantDenied, require_project_grant
import uuid

logger = logging.getLogger(__name__)

router = APIRouter()

@router.post("")
def start_extraction(ontology_id: str, body: ExtractionRequest, db: Session = Depends(get_db), _=Depends(require_editor)):
def start_extraction(ontology_id: str, body: ExtractionRequest, db: Session = Depends(get_db), current_user: User = Depends(require_editor)):
try:
require_project_grant(db, current_user, ontology_id, "edit")
except GrantDenied as exc:
raise HTTPException(status_code=404, detail="ONTOLOGY_NOT_FOUND") from exc
project = db.query(OntologyProject).filter(OntologyProject.id == ontology_id).first()
if not project:
raise HTTPException(404, "Ontology not found")
Expand Down Expand Up @@ -67,7 +72,11 @@ def run_sync():
return {"data": {"task_id": task.id}, "message": "Extraction queued"}

@router.get("/status")
def get_extraction_status(ontology_id: str, task_id: str, db: Session = Depends(get_db), _=Depends(get_current_user)):
def get_extraction_status(ontology_id: str, task_id: str, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
try:
require_project_grant(db, current_user, ontology_id, "read")
except GrantDenied as exc:
raise HTTPException(status_code=404, detail="ONTOLOGY_NOT_FOUND") from exc
task = db.query(ExtractionTask).filter(ExtractionTask.id == task_id, ExtractionTask.ontology_id == ontology_id).first()
if not task:
raise HTTPException(404, "Task not found")
Expand Down
99 changes: 69 additions & 30 deletions backend/app/routers/files.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import os
import uuid
import logging
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File
from sqlalchemy.orm import Session
from app.deps import get_db, get_current_user, require_admin, require_editor
from app.models.file import UploadedFile
from app.models.ontology import OntologyProject
from app.schemas.file import FileOut
from app.services.document_service import convert_document, is_usable_converted_text
from app.services.ontology_access import GrantDenied, require_project_grant
from app.config import settings

router = APIRouter()
logger = logging.getLogger(__name__)

ALLOWED_TYPES = {
"application/pdf", "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
Expand Down Expand Up @@ -39,8 +42,16 @@ def _file_out(f: UploadedFile) -> dict:
).model_dump()


def _grant(db: Session, actor, ontology_id: str, capability: str) -> dict:
try:
return require_project_grant(db, actor, ontology_id, capability)
except GrantDenied as exc:
raise HTTPException(status_code=404, detail="ONTOLOGY_NOT_FOUND") from exc


@router.get("")
def list_files(ontology_id: str, db: Session = Depends(get_db), _=Depends(get_current_user)):
def list_files(ontology_id: str, db: Session = Depends(get_db), current_user=Depends(get_current_user)):
_grant(db, current_user, ontology_id, "read")
files = db.query(UploadedFile).filter(UploadedFile.ontology_id == ontology_id).all()
return {"data": [_file_out(f) for f in files]}

Expand All @@ -49,11 +60,12 @@ async def upload_file(
ontology_id: str,
file: UploadFile = File(...),
db: Session = Depends(get_db),
_=Depends(require_editor)
current_user=Depends(require_editor),
):
_grant(db, current_user, ontology_id, "edit")
project = db.query(OntologyProject).filter(OntologyProject.id == ontology_id).first()
if not project:
raise HTTPException(404, "Ontology not found")
raise HTTPException(404, detail="ONTOLOGY_NOT_FOUND")

ext_name = (file.filename or "").rsplit(".", 1)[-1].lower()
allowed = {e.strip() for e in settings.allowed_upload_extensions.split(",") if e.strip()}
Expand All @@ -67,36 +79,63 @@ async def upload_file(
ext = os.path.splitext(file.filename)[1]
save_path = os.path.join(upload_dir, f"{file_id}{ext}")

content = await file.read()
if len(content) > settings.max_upload_mb * 1024 * 1024:
max_bytes = settings.max_upload_mb * 1024 * 1024
declared_size = getattr(file, "size", None)
if declared_size is not None and declared_size > max_bytes:
raise HTTPException(413, f"文件超过大小限制 {settings.max_upload_mb}MB")
with open(save_path, "wb") as f:
f.write(content)

mime = file.content_type or "application/octet-stream"
conversion = convert_document(save_path, mime)
if not conversion.ok:
if os.path.exists(save_path):
os.remove(save_path)
raise HTTPException(422, conversion.error or "文件转换失败")

db_file = UploadedFile(
id=file_id,
ontology_id=ontology_id,
filename=file.filename,
file_path=save_path,
file_size=len(content),
mime_type=mime,
converted_md=conversion.content,
)
db.add(db_file); db.commit(); db.refresh(db_file)
return {"data": _file_out(db_file)}

committed = False
try:
total_bytes = 0
with open(save_path, "wb") as saved:
while True:
chunk = await file.read(1024 * 1024)
if not chunk:
break
total_bytes += len(chunk)
if total_bytes > max_bytes:
raise HTTPException(413, f"文件超过大小限制 {settings.max_upload_mb}MB")
saved.write(chunk)

mime = file.content_type or "application/octet-stream"
conversion = convert_document(save_path, mime)
if not conversion.ok:
raise HTTPException(422, conversion.error or "文件转换失败")

db_file = UploadedFile(
id=file_id,
ontology_id=ontology_id,
filename=file.filename,
file_path=save_path,
file_size=total_bytes,
mime_type=mime,
converted_md=conversion.content,
)
db.add(db_file)
try:
db.commit()
except Exception:
db.rollback()
raise
committed = True
db.refresh(db_file)
return {"data": _file_out(db_file)}
except Exception:
if not committed and os.path.exists(save_path):
try:
os.remove(save_path)
except OSError:
logger.warning("failed to clean up rejected upload %s", save_path, exc_info=True)
raise

@router.delete("/{file_id}", status_code=204)
def delete_file(ontology_id: str, file_id: str, db: Session = Depends(get_db), _=Depends(require_admin)):
def delete_file(ontology_id: str, file_id: str, db: Session = Depends(get_db), current_user=Depends(require_admin)):
_grant(db, current_user, ontology_id, "edit")
f = db.query(UploadedFile).filter(UploadedFile.id == file_id, UploadedFile.ontology_id == ontology_id).first()
if not f:
raise HTTPException(404, "File not found")
if os.path.exists(f.file_path):
os.remove(f.file_path)
db.delete(f); db.commit()
file_path = f.file_path
db.delete(f)
db.commit()
if os.path.exists(file_path):
os.remove(file_path)
Loading
Loading