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

Function extract_doc_url

agents/reading-agent/main.py:455–485  ·  view source on GitHub ↗

Best-effort extract the document URL from different Feishu response shapes.

(doc_info: Dict[str, Any])

Source from the content-addressed store, hash-verified

453
454def extract_doc_url(doc_info: Dict[str, Any]) -> Optional[str]:
455 """Best-effort extract the document URL from different Feishu response shapes."""
456 if not isinstance(doc_info, dict):
457 return None
458
459 def _valid_url(candidate: Any) -> Optional[str]:
460 text = str(candidate or "").strip()
461 if text.startswith("http://") or text.startswith("https://"):
462 return text
463 return None
464
465 for candidate in (doc_info.get("url"), doc_info.get("doc_url"), doc_info.get("link")):
466 valid = _valid_url(candidate)
467 if valid:
468 return valid
469
470 data = doc_info.get("data")
471 if isinstance(data, dict):
472 for candidate in (data.get("url"), data.get("doc_url"), data.get("link")):
473 valid = _valid_url(candidate)
474 if valid:
475 return valid
476
477 document = data.get("document")
478 if isinstance(document, dict):
479 for candidate in (document.get("url"), document.get("doc_url"), document.get("link")):
480 valid = _valid_url(candidate)
481 if valid:
482 return valid
483
484 return None
485
486
487def extract_doc_token(doc_info: Dict[str, Any]) -> Optional[str]:
488 """Best-effort extract the document token from different Feishu response shapes."""

Callers 2

create_reading_reportFunction · 0.85

Calls 2

_valid_urlFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected