litloop 1.18.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- litloop/__init__.py +89 -0
- litloop/__main__.py +6 -0
- litloop/_source_hygiene.py +158 -0
- litloop/agents/__init__.py +13 -0
- litloop/agents/client.py +164 -0
- litloop/agents/runner.py +123 -0
- litloop/agents/system.py +54 -0
- litloop/agents/tools.py +142 -0
- litloop/app_server.py +8 -0
- litloop/browser/__init__.py +1 -0
- litloop/browser/backend.py +1009 -0
- litloop/browser/camofox_api.py +368 -0
- litloop/browser/chrome_copy.py +136 -0
- litloop/browser/cloakbrowser_compat.py +72 -0
- litloop/browser/cookies.py +347 -0
- litloop/browser/engine.py +965 -0
- litloop/browser/login.py +636 -0
- litloop/browser/pdf.py +263 -0
- litloop/browser/profile_health.py +167 -0
- litloop/browser/runtime.py +210 -0
- litloop/cache.py +104 -0
- litloop/citations/__init__.py +1 -0
- litloop/citations/bib_import.py +102 -0
- litloop/citations/bibtex_crossref.py +143 -0
- litloop/citations/formats.py +225 -0
- litloop/citations/paper_list.py +200 -0
- litloop/citations/session_export.py +94 -0
- litloop/cli/__init__.py +12 -0
- litloop/cli/_utils.py +267 -0
- litloop/cli/commands.py +1098 -0
- litloop/cli/doctor.py +141 -0
- litloop/cli/main.py +1173 -0
- litloop/cli/web.py +190 -0
- litloop/config.py +413 -0
- litloop/data/VARCON-LICENSE.txt +62 -0
- litloop/data/elements.tsv +119 -0
- litloop/data/institutional_identity_policy.json +165 -0
- litloop/data/publisher_access_catalog.json +969 -0
- litloop/data/publisher_carsi.json +105 -0
- litloop/data/spelling_search.tsv.gz +0 -0
- litloop/data/spelling_us.tsv.gz +0 -0
- litloop/data/webvpn.dat +0 -0
- litloop/data/webvpn.json +603 -0
- litloop/db.py +1922 -0
- litloop/deps.py +128 -0
- litloop/desktop/__init__.py +1 -0
- litloop/desktop/agent_runner.py +537 -0
- litloop/desktop/download_jobs.py +571 -0
- litloop/desktop/error_text.py +192 -0
- litloop/desktop/server.py +999 -0
- litloop/desktop/settings.py +552 -0
- litloop/desktop/translate.py +103 -0
- litloop/diagnostics.py +126 -0
- litloop/download/__init__.py +1 -0
- litloop/download/doi_check.py +44 -0
- litloop/download/fetcher.py +975 -0
- litloop/download/markdown.py +130 -0
- litloop/download/pdf.py +454 -0
- litloop/download/pipeline.py +1166 -0
- litloop/download/progress.py +312 -0
- litloop/download/rename.py +211 -0
- litloop/extractors/__init__.py +0 -0
- litloop/extractors/html_extractor.py +31 -0
- litloop/extractors/pdf_extractor.py +151 -0
- litloop/extractors/publisher_adapters/__init__.py +0 -0
- litloop/extractors/publisher_adapters/acs.py +167 -0
- litloop/extractors/publisher_adapters/elsevier.py +178 -0
- litloop/extractors/publisher_adapters/generic.py +191 -0
- litloop/extractors/publisher_adapters/nature.py +204 -0
- litloop/extractors/publisher_adapters/rsc.py +154 -0
- litloop/extractors/publisher_adapters/tandfonline.py +154 -0
- litloop/extractors/publisher_adapters/wiley.py +160 -0
- litloop/http_utils.py +57 -0
- litloop/identifiers.py +134 -0
- litloop/institutional/__init__.py +1 -0
- litloop/institutional/auth.py +576 -0
- litloop/institutional/carsi_login.py +569 -0
- litloop/institutional/config_adapter.py +63 -0
- litloop/institutional/proxy_check.py +98 -0
- litloop/institutional/remote_assist.py +274 -0
- litloop/institutional/schools.py +102 -0
- litloop/institutional/session_heal.py +73 -0
- litloop/institutional/session_store.py +105 -0
- litloop/log.py +47 -0
- litloop/models.py +269 -0
- litloop/network.py +417 -0
- litloop/optional.py +310 -0
- litloop/publishers/__init__.py +1 -0
- litloop/publishers/access.py +232 -0
- litloop/publishers/pdf_router.py +451 -0
- litloop/publishers/profiles.py +899 -0
- litloop/publishers/strategies/__init__.py +122 -0
- litloop/publishers/strategies/_core.py +2340 -0
- litloop/publishers/strategies/_elsevier_api.py +578 -0
- litloop/publishers/strategies/acm.py +27 -0
- litloop/publishers/strategies/acs.py +42 -0
- litloop/publishers/strategies/aip.py +27 -0
- litloop/publishers/strategies/aps.py +29 -0
- litloop/publishers/strategies/asce.py +28 -0
- litloop/publishers/strategies/base.py +108 -0
- litloop/publishers/strategies/copernicus.py +24 -0
- litloop/publishers/strategies/elsevier.py +66 -0
- litloop/publishers/strategies/generic.py +39 -0
- litloop/publishers/strategies/ieee.py +28 -0
- litloop/publishers/strategies/iop.py +27 -0
- litloop/publishers/strategies/nature.py +27 -0
- litloop/publishers/strategies/oxford.py +27 -0
- litloop/publishers/strategies/registry.py +83 -0
- litloop/publishers/strategies/royalsociety.py +28 -0
- litloop/publishers/strategies/rsc.py +27 -0
- litloop/publishers/strategies/sage.py +30 -0
- litloop/publishers/strategies/science.py +27 -0
- litloop/publishers/strategies/springer.py +34 -0
- litloop/publishers/strategies/tandfonline.py +32 -0
- litloop/publishers/strategies/wiley.py +32 -0
- litloop/publishers/supplementary.py +219 -0
- litloop/quota.py +202 -0
- litloop/search/__init__.py +1 -0
- litloop/search/abstracts.py +291 -0
- litloop/search/deep.py +1216 -0
- litloop/search/quick.py +1102 -0
- litloop/search/scansci_find.py +410 -0
- litloop/search/screening.py +225 -0
- litloop/search/title_to_doi.py +163 -0
- litloop/search/watches.py +124 -0
- litloop/server.py +1731 -0
- litloop/sources/__init__.py +1339 -0
- litloop/sources/_batch.py +529 -0
- litloop/sources/_index.py +221 -0
- litloop/sources/_routes.py +290 -0
- litloop/sources/altcha.py +90 -0
- litloop/sources/arxiv.py +45 -0
- litloop/sources/attempt.py +91 -0
- litloop/sources/carsi.py +74 -0
- litloop/sources/core_api.py +46 -0
- litloop/sources/crossref.py +162 -0
- litloop/sources/elsevier_api.py +620 -0
- litloop/sources/elsevier_check.py +274 -0
- litloop/sources/europepmc.py +81 -0
- litloop/sources/ezproxy.py +317 -0
- litloop/sources/instsci.py +1295 -0
- litloop/sources/libgen.py +116 -0
- litloop/sources/nature.py +39 -0
- litloop/sources/oa_discovery.py +135 -0
- litloop/sources/openaire.py +122 -0
- litloop/sources/openalex.py +100 -0
- litloop/sources/publishers.py +684 -0
- litloop/sources/sage_cn.py +139 -0
- litloop/sources/scibban.py +10 -0
- litloop/sources/scihub.py +1379 -0
- litloop/sources/scihub_domains.py +203 -0
- litloop/sources/scihub_speed.py +187 -0
- litloop/sources/scoring.py +250 -0
- litloop/sources/semantic_scholar.py +146 -0
- litloop/sources/springer_tdm.py +172 -0
- litloop/sources/unpaywall.py +116 -0
- litloop/sources/vpnsci.py +38 -0
- litloop/store.py +264 -0
- litloop/templates/index.html +347 -0
- litloop/terms/__init__.py +1 -0
- litloop/terms/glossary.py +422 -0
- litloop/terms/spelling.py +89 -0
- litloop/terms/text.py +106 -0
- litloop/tor/__init__.py +1 -0
- litloop/tor/embedded.py +371 -0
- litloop/tor/proxy.py +110 -0
- litloop/updates.py +148 -0
- litloop/zotero/__init__.py +1 -0
- litloop/zotero/bridge.py +309 -0
- litloop/zotero/client.py +317 -0
- litloop-1.18.3.dist-info/METADATA +347 -0
- litloop-1.18.3.dist-info/RECORD +176 -0
- litloop-1.18.3.dist-info/WHEEL +5 -0
- litloop-1.18.3.dist-info/entry_points.txt +2 -0
- litloop-1.18.3.dist-info/licenses/LICENSE +197 -0
- litloop-1.18.3.dist-info/top_level.txt +1 -0
litloop/agents/tools.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""The tools the built-in agent may call, and the schemas the model sees.
|
|
2
|
+
|
|
3
|
+
They are thin wrappers over the functions the MCP server exposes, so the app's
|
|
4
|
+
own agent finds the same behaviour (same screening files, same sessions) as an
|
|
5
|
+
external Agent driving LitLoop through MCP.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any, Callable
|
|
11
|
+
|
|
12
|
+
from ..search import deep, screening
|
|
13
|
+
from ..search.quick import search_papers_v2
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _brief(paper: dict[str, Any]) -> dict[str, Any]:
|
|
17
|
+
out = {}
|
|
18
|
+
for key in ("doi", "title", "year", "journal", "cited_by_count", "is_oa", "retracted"):
|
|
19
|
+
if paper.get(key) not in (None, "", []):
|
|
20
|
+
out[key] = paper[key]
|
|
21
|
+
return out
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def search(query: str, limit: int = 10, sort: str | None = None,
|
|
25
|
+
year_from: int | None = None, year_to: int | None = None) -> dict[str, Any]:
|
|
26
|
+
"""Quick search. Returns the papers plus how many were filtered out."""
|
|
27
|
+
stats: dict[str, Any] = {}
|
|
28
|
+
expansions: list[dict[str, Any]] = []
|
|
29
|
+
papers = search_papers_v2(query, limit=min(int(limit or 10), 50), sort=sort,
|
|
30
|
+
year_from=year_from, year_to=year_to,
|
|
31
|
+
stats=stats, expansions=expansions)
|
|
32
|
+
return {"query": query, "count": len(papers), "papers": [_brief(p) for p in papers],
|
|
33
|
+
"filtered": {k: v for k, v in stats.items() if v} or None,
|
|
34
|
+
"glossary": expansions or None}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def deep_search_start(question: str, queries: list[str], seeds: list[str],
|
|
38
|
+
core_terms: list[str] | None = None, criteria: list[str] | None = None,
|
|
39
|
+
must_find: list[str] | None = None, batch_size: int = 20) -> dict[str, Any]:
|
|
40
|
+
"""Build the candidate pool and return the first batch to screen."""
|
|
41
|
+
return deep.start(question, queries, seeds, core_terms or [], criteria=criteria,
|
|
42
|
+
must_find=must_find, batch_size=batch_size)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def deep_search_next(session: str, force: bool = False) -> dict[str, Any]:
|
|
46
|
+
"""Fold the latest ratings in and serve the next batch."""
|
|
47
|
+
return deep.next_batch(session, force=force)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def deep_search_rate(session: str, ratings: list[dict[str, Any]]) -> dict[str, Any]:
|
|
51
|
+
"""Save the agent's ratings for the latest batch by number."""
|
|
52
|
+
return deep.rate(session, ratings)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def deep_search_status(session: str) -> dict[str, Any]:
|
|
56
|
+
"""What this session has read and found so far, and whether stopping is suggested."""
|
|
57
|
+
return deep.status(session)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def screening_save(session: str = "", ratings: list[dict[str, Any]] | None = None,
|
|
61
|
+
question: str = "", criteria: list[str] | None = None) -> dict[str, Any]:
|
|
62
|
+
"""Record ratings ([{"doi", "relevance", "reason"}], relevance one of 高/中/低/不相关).
|
|
63
|
+
|
|
64
|
+
Without ``session`` a new screening session is created, named by ``question``.
|
|
65
|
+
"""
|
|
66
|
+
items = []
|
|
67
|
+
for item in ratings or []:
|
|
68
|
+
doi = str(item.get("doi") or "").strip()
|
|
69
|
+
relevance = str(item.get("relevance") or "").strip()
|
|
70
|
+
if not doi or relevance not in ("高", "中", "低", "不相关"):
|
|
71
|
+
raise ValueError(f"评分不对:{item!r}(要 doi 和 高/中/低/不相关)")
|
|
72
|
+
row = {"doi": doi, "relevance": relevance, "reason": str(item.get("reason") or "")}
|
|
73
|
+
for key in ("title", "year", "journal", "journal_rank", "cited_by_count",
|
|
74
|
+
"abstract_missing", "retracted", "concern"):
|
|
75
|
+
if item.get(key) not in (None, "", []):
|
|
76
|
+
row[key] = item[key]
|
|
77
|
+
items.append(row)
|
|
78
|
+
if not items:
|
|
79
|
+
raise ValueError("没有评分要保存")
|
|
80
|
+
if session:
|
|
81
|
+
question = question or str(screening.load(session).get("question") or "")
|
|
82
|
+
elif not question.strip():
|
|
83
|
+
raise ValueError("保存评分要带 session,或者给 question 当这次筛选的标题")
|
|
84
|
+
saved = screening.save(question, items, criteria=criteria, session=session or None)
|
|
85
|
+
return {"session": saved["session"], "added": saved["added"], "total": saved["total"],
|
|
86
|
+
"by_relevance": saved["by_relevance"]}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
TOOLS: list[dict[str, Any]] = [
|
|
90
|
+
{"name": "search", "description": "快速检索文献,返回 DOI、标题、年份、期刊、被引数。",
|
|
91
|
+
"parameters": {"type": "object", "properties": {
|
|
92
|
+
"query": {"type": "string", "description": "检索式,可用 | 分隔同义词"},
|
|
93
|
+
"limit": {"type": "integer", "description": "最多返回几篇,默认 10"},
|
|
94
|
+
"sort": {"type": "string", "enum": ["cited", "date"], "description": "按被引或时间排序"},
|
|
95
|
+
"year_from": {"type": "integer"}, "year_to": {"type": "integer"}},
|
|
96
|
+
"required": ["query"]}},
|
|
97
|
+
{"name": "deep_search_start", "description": "建候选池并给出第一批待筛文献;需要 4–8 条英文检索词和 1–3 篇种子。",
|
|
98
|
+
"parameters": {"type": "object", "properties": {
|
|
99
|
+
"question": {"type": "string", "description": "用户的研究问题"},
|
|
100
|
+
"queries": {"type": "array", "items": {"type": "string"}},
|
|
101
|
+
"seeds": {"type": "array", "items": {"type": "string"}, "description": "种子 DOI"},
|
|
102
|
+
"core_terms": {"type": "array", "items": {"type": "string"}},
|
|
103
|
+
"criteria": {"type": "array", "items": {"type": "string"}},
|
|
104
|
+
"must_find": {"type": "array", "items": {"type": "string"}},
|
|
105
|
+
"batch_size": {"type": "integer", "description": "每批几篇,默认 20"}},
|
|
106
|
+
"required": ["question", "queries", "seeds"]}},
|
|
107
|
+
{"name": "deep_search_rate", "description": "按编号保存当前批次的深度检索评分:ratings=[{n, relevance, reason}],relevance 为 高/中/低/不相关。",
|
|
108
|
+
"parameters": {"type": "object", "properties": {
|
|
109
|
+
"session": {"type": "string"},
|
|
110
|
+
"ratings": {"type": "array", "items": {"type": "object", "properties": {
|
|
111
|
+
"n": {"type": "integer"}, "relevance": {"type": "string"},
|
|
112
|
+
"reason": {"type": "string"}},
|
|
113
|
+
"required": ["n", "relevance"]}}},
|
|
114
|
+
"required": ["session", "ratings"]}},
|
|
115
|
+
{"name": "deep_search_next", "description": "提交这一批评分后取下一批。",
|
|
116
|
+
"parameters": {"type": "object", "properties": {
|
|
117
|
+
"session": {"type": "string"}, "force": {"type": "boolean"}},
|
|
118
|
+
"required": ["session"]}},
|
|
119
|
+
{"name": "deep_search_status", "description": "看这个会话读到第几篇、找到多少目标、是否建议停止。",
|
|
120
|
+
"parameters": {"type": "object", "properties": {"session": {"type": "string"}},
|
|
121
|
+
"required": ["session"]}},
|
|
122
|
+
{"name": "screening_save", "description": "保存一批评分:每篇给 doi、相关度(高/中/低/不相关)和一句理由。不传 session 会新建会话,这时要传 question。",
|
|
123
|
+
"parameters": {"type": "object", "properties": {
|
|
124
|
+
"session": {"type": "string", "description": "已有的筛选会话;新建时不传"},
|
|
125
|
+
"question": {"type": "string", "description": "新建会话时的标题,通常就是检索问题"},
|
|
126
|
+
"criteria": {"type": "array", "items": {"type": "string"}, "description": "纳入标准"},
|
|
127
|
+
"ratings": {"type": "array", "items": {"type": "object", "properties": {
|
|
128
|
+
"doi": {"type": "string"}, "relevance": {"type": "string"},
|
|
129
|
+
"reason": {"type": "string"}, "title": {"type": "string"},
|
|
130
|
+
"year": {"type": "integer"}, "journal": {"type": "string"}},
|
|
131
|
+
"required": ["doi", "relevance"]}}},
|
|
132
|
+
"required": ["ratings"]}},
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
FUNCTIONS: dict[str, Callable[..., Any]] = {
|
|
136
|
+
"search": search,
|
|
137
|
+
"deep_search_start": deep_search_start,
|
|
138
|
+
"deep_search_rate": deep_search_rate,
|
|
139
|
+
"deep_search_next": deep_search_next,
|
|
140
|
+
"deep_search_status": deep_search_status,
|
|
141
|
+
"screening_save": screening_save,
|
|
142
|
+
}
|
litloop/app_server.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""The old path of the desktop backend, now litloop.desktop.server; kept for installed desktop apps that start python -m litloop.app_server; remove after one release."""
|
|
2
|
+
|
|
3
|
+
from .desktop.server import create_app, main # noqa: F401
|
|
4
|
+
|
|
5
|
+
if __name__ == "__main__":
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
main(sys.argv[1:])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Browser management, engines, cookies, and automation."""
|