MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / _backfill_docs_to_wiki

Function _backfill_docs_to_wiki

deployments/desktop/shared/agents.py:2419–2454  ·  view source on GitHub ↗

Best-effort Wiki ingest for reused reading reports returned by the GUI.

(user_id: str, docs: Iterable[Dict[str, Any]])

Source from the content-addressed store, hash-verified

2417
2418
2419def _resolve_project_path(value: Any) -> Optional[Path]:
2420 raw = str(value or "").strip()
2421 if not raw:
2422 return None
2423 path = Path(raw).expanduser()
2424 if not path.is_absolute():
2425 path = PROJECT_ROOT / path
2426 return path
2427
2428
2429def _backfill_docs_to_wiki(user_id: str, docs: Iterable[Dict[str, Any]]) -> int:
2430 """Best-effort Wiki ingest for reused reading reports returned by the GUI."""
2431 ingest = getattr(reading_agent, "ingest_reading_report_to_wiki", None)
2432 if ingest is None:
2433 return 0
2434
2435 backfilled = 0
2436 for doc in docs or []:
2437 if doc.get("wiki_ingest"):
2438 continue
2439 report_path = _resolve_project_path(doc.get("report_path"))
2440 if not report_path or not report_path.exists() or not report_path.is_file():
2441 continue
2442 try:
2443 raw = report_path.read_text(encoding="utf-8")
2444 metadata, body = _extract_frontmatter(raw)
2445 paper = dict(doc.get("paper") or {})
2446 for key in ("paper_id", "arxiv_id", "doi", "title", "pdf_path", "pdf_url", "publish_date"):
2447 if metadata.get(key) not in (None, "", [], {}) and paper.get(key) in (None, "", [], {}):
2448 paper[key] = metadata.get(key)
2449 result = ingest(
2450 user_id=user_id,
2451 paper=paper,
2452 report_content=body or raw,
2453 report_payload=doc.get("report_payload") or {},
2454 report_path=str(report_path),
2455 doc_url=doc.get("url") or metadata.get("doc_url"),
2456 doc_token=doc.get("doc_token") or metadata.get("doc_token"),
2457 )

Callers 3

create_reading_reportsFunction · 0.85
read_arxivFunction · 0.85
read_local_pdfFunction · 0.85

Calls 3

_resolve_project_pathFunction · 0.85
_extract_frontmatterFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected