(
user_id: str,
question: str,
mentions: Any = None,
*,
limit: int = 6,
)
| 4120 | if isinstance(item, dict): |
| 4121 | title = str(item.get("title") or item.get("label") or "").strip() |
| 4122 | node_id = str(item.get("node_id") or item.get("id") or "").strip() |
| 4123 | if title or node_id: |
| 4124 | normalized.append({"title": title, "node_id": node_id}) |
| 4125 | else: |
| 4126 | token = str(item or "").strip() |
| 4127 | if token: |
| 4128 | normalized.append({"title": token, "node_id": ""}) |
| 4129 | return normalized |
| 4130 | |
| 4131 | |
| 4132 | def _resolve_wiki_mentions( |
| 4133 | user_id: str, |
| 4134 | question: str, |
| 4135 | mentions: Any = None, |
| 4136 | *, |
| 4137 | limit: int = 6, |
| 4138 | ) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]], List[Dict[str, str]]]: |
| 4139 | requested = [*_normalize_requested_mentions(mentions), *_extract_question_mentions(question)] |
| 4140 | resolved_nodes: List[Dict[str, Any]] = [] |
| 4141 | resolved_payloads: List[Dict[str, Any]] = [] |
| 4142 | unresolved: List[Dict[str, str]] = [] |
| 4143 | seen_requests: Set[Tuple[str, str]] = set() |
| 4144 | seen_nodes: Set[str] = set() |
| 4145 | |
| 4146 | for request in requested[: max(1, int(limit))]: |
| 4147 | title = str(request.get("title") or "").strip() |
| 4148 | node_id = str(request.get("node_id") or "").strip() |
| 4149 | request_key = (title.lower(), node_id.lower()) |
| 4150 | if request_key in seen_requests: |
| 4151 | continue |
| 4152 | seen_requests.add(request_key) |
| 4153 | |
| 4154 | node: Optional[Dict[str, Any]] = None |
| 4155 | if node_id: |
| 4156 | db_node = wiki_db.get_node(user_id, node_id) |
| 4157 | if _wiki_node_is_visible(db_node): |
| 4158 | node = db_node |
| 4159 | if node is None: |
| 4160 | daily_node = None |
| 4161 | for entry in _daily_note_reading_entries(scope="all", query=title or node_id, limit=8): |
| 4162 | candidate = _daily_note_reading_node(entry) |
| 4163 | if node_id and str(candidate.get("node_id") or "") == node_id: |
| 4164 | daily_node = candidate |
| 4165 | break |
| 4166 | if title and str(candidate.get("title") or "").strip().lower() == title.lower(): |
| 4167 | daily_node = candidate |
| 4168 | break |
| 4169 | if daily_node is None: |
| 4170 | daily_node = candidate |
| 4171 | if daily_node is not None: |
| 4172 | node = daily_node |
| 4173 | if node is None: |
| 4174 | query = title or node_id |
| 4175 | if query: |
| 4176 | hits = wiki_db.search_nodes(user_id, query, limit=5) |
| 4177 | filtered_hits = _filter_wiki_nodes_for_configured_dir(hits) |
| 4178 | if filtered_hits is not None: |
| 4179 | hits = filtered_hits |
no test coverage detected