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

Callers 2

create_reading_reportFunction · 0.85

Calls 2

_valid_urlFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected