Create reading reports for selected papers and route them back to the same chat.
(
user_id: str,
selected: Set[int],
papers: List[Dict],
target_id: Optional[str],
use_chat_id: bool,
send_to_feishu: bool,
selection_push_id: Optional[str] = None,
)
| 191 | |
| 192 | |
| 193 | def create_reading_reports_for_selection( |
| 194 | user_id: str, |
| 195 | selected: Set[int], |
| 196 | papers: List[Dict], |
| 197 | target_id: Optional[str], |
| 198 | use_chat_id: bool, |
| 199 | send_to_feishu: bool, |
| 200 | selection_push_id: Optional[str] = None, |
| 201 | ) -> List[Dict[str, Any]]: |
| 202 | """Create reading reports for selected papers and route them back to the same chat.""" |
| 203 | if not selected or not send_to_feishu: |
| 204 | return [] |
| 205 | |
| 206 | paper_ids: List[int] = [] |
| 207 | for paper_num in sorted(selected): |
| 208 | idx = int(paper_num) - 1 |
| 209 | if not (0 <= idx < len(papers)): |
| 210 | continue |
| 211 | paper = papers[idx] |
| 212 | resolved_id = paper.get("id") |
| 213 | paper_ids.append(int(resolved_id) if resolved_id is not None else int(paper_num)) |
| 214 | |
| 215 | reading_agent = importlib.import_module("agents.reading-agent.main") |
| 216 | kwargs: Dict[str, Any] = { |
| 217 | "user_id": user_id, |
| 218 | "paper_ids": paper_ids, |
| 219 | "papers": papers, |
| 220 | "send_to_feishu": True, |
| 221 | "request_metadata": { |
| 222 | "selection_push_id": selection_push_id, |
| 223 | } if selection_push_id else None, |
| 224 | } |
| 225 | |
| 226 | if use_chat_id and target_id: |
| 227 | kwargs["chat_id"] = target_id |
| 228 | elif target_id: |
| 229 | kwargs["feishu_user_id"] = target_id |
| 230 | |
| 231 | return reading_agent.create_reading_report(**kwargs) |
| 232 | |
| 233 | |
| 234 | def parse_user_reply(reply: str, papers: List[Dict] = None) -> Set[int]: |
no test coverage detected