football-docs 0.15.1 → 0.16.0
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.
- package/README.md +100 -2
- package/data/docs.db +0 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +79 -1
- package/dist/ingest.js +6 -1
- package/dist/papers/arxiv.d.ts +35 -0
- package/dist/papers/arxiv.js +126 -0
- package/dist/papers/core.d.ts +79 -0
- package/dist/papers/core.js +271 -0
- package/dist/papers/crossref.d.ts +8 -0
- package/dist/papers/crossref.js +37 -0
- package/dist/papers/library.d.ts +124 -0
- package/dist/papers/library.js +369 -0
- package/dist/papers/openalex.d.ts +68 -0
- package/dist/papers/openalex.js +150 -0
- package/dist/papers/read.d.ts +48 -0
- package/dist/papers/read.js +367 -0
- package/dist/papers/records.d.ts +77 -0
- package/dist/papers/records.js +204 -0
- package/dist/papers/sportrxiv.d.ts +52 -0
- package/dist/papers/sportrxiv.js +150 -0
- package/dist/papers/text.d.ts +78 -0
- package/dist/papers/text.js +416 -0
- package/dist/papers/tools.d.ts +55 -0
- package/dist/papers/tools.js +327 -0
- package/dist/papers/web.d.ts +85 -0
- package/dist/papers/web.js +381 -0
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +8 -0
- package/docs/firstbeat/api-endpoints.md +2 -0
- package/docs/firstbeat/data-model.md +60 -2
- package/docs/hawkin-dynamics/api-endpoints.md +18 -0
- package/docs/hawkin-dynamics/data-model.md +41 -0
- package/docs/hawkin-dynamics/test-metrics.md +28 -0
- package/docs/statsports/api-access.md +3 -2
- package/docs/statsports/api-endpoints.md +9 -1
- package/docs/statsports/data-model.md +50 -0
- package/docs/statsports/drill-kpi-metrics.md +34 -0
- package/docs/vald/api-endpoints.md +4 -0
- package/docs/vald/dynamo.md +6 -0
- package/docs/vald/forcedecks.md +21 -15
- package/docs/vald/forceframe.md +6 -0
- package/docs/vald/humantrak.md +6 -0
- package/docs/vald/nordbord.md +6 -0
- package/docs/vald/profiles.md +6 -0
- package/docs/vald/smartspeed.md +6 -0
- package/docs/vald/tenants.md +6 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -94,6 +94,14 @@ Add to `claude_desktop_config.json`:
|
|
|
94
94
|
| `compare_providers` | Compare how different providers handle the same concept. |
|
|
95
95
|
| `request_update` | Request a new provider, flag outdated docs, or suggest a better doc source. Queues locally and points to the matching public GitHub issue template. |
|
|
96
96
|
| `resolve_entity` | Map a player, coach, referee, team, competition, season, stage or match to its IDs at every provider through the [Reep register](https://reep.football). Uses a local copy of the free register (`REEP_DUCKDB_PATH`), else the Reep API (`REEP_API_KEY`; keys are issued by hand on request to getintouch+nutmeg@withqwerty.com, with no self-service sign-up), else returns setup steps and a DuckDB query. See [Reep through football-docs](docs/reep/overview.md#using-reep-through-football-docs). |
|
|
97
|
+
| `search_papers` | Search scholarly papers on football analytics and sport science in [OpenAlex](https://openalex.org) (title, abstract and full text), [arXiv](https://arxiv.org) and [SportRxiv](https://sportrxiv.org), and, when asked, your Zotero library. See [Papers and web sources](#papers-and-web-sources). |
|
|
98
|
+
| `get_paper` | Look up one paper by DOI, arXiv ID, OpenAlex ID or Zotero item: authors, date, venue, all IDs, licence, open copies with their licences, abstract and a citation line. |
|
|
99
|
+
| `get_web_source` | Read a public web page or PDF (a blog post, newsletter, club or vendor article, or an author's copy of a paper) as text, with its author, date, licence and Wayback Machine snapshots. Long pages come back by section. |
|
|
100
|
+
| `read_paper` | Read a paper: the full text of an open copy, by section, with its licence; or the outline and short passages of a paper you supplied. Kept in your library, so a second read sends no request. |
|
|
101
|
+
| `match_quote` | Check that a quote appears in a paper or web page: exact, normalised, close (with a score) or none, with the section, page and a W3C text quote selector. |
|
|
102
|
+
| `add_local_paper` | Add a PDF you have to your library, for papers with no open copy. |
|
|
103
|
+
| `forget_paper` | Remove one paper from your library. |
|
|
104
|
+
| `purge_cache` | Delete your whole paper library (needs `confirm: true`). |
|
|
97
105
|
|
|
98
106
|
Provider filters use the indexed provider keys shown by `list_providers`, but common aliases are accepted. Examples: `fbref`, `understat`, `ClubElo`, `football-data.co.uk`, and `engsoccerdata` search `free-sources`; `Sofascore` searches `soccerdata`; `ESPN`, `ESPN FC`, and `espn-soccer` search `espn`; `FMDB` searches `fmdb-pro`; `Transfer Room` searches `transferroom`; `Hudl Wyscout` searches `wyscout`; `Stats Perform` / `Opta F24` / `WhoScored` search `opta`; `Metrica`, `Sportec` / `DFL`, and `TRACAB` search `databallpy`; `Second Spectrum` searches `kloppy`; `Hawk-Eye`, `SciSports`, `Signality`, `Respovision`, `GradientSports` and `OptaVision` search `fast-forward`; `unravel` searches `unravelsports`; `SportRadar API` / `Soccer Extended` search `sportradar`; `Sonra` / `Apex` search `statsports`; `Hawkin` searches `hawkin-dynamics`; `ForceDecks` / `NordBord` / `ForceFrame` search `vald`; `The Sports DB` / `TSDB` search `thesportsdb`; `StatsBomb Open Data` searches `statsbomb`.
|
|
99
107
|
|
|
@@ -123,8 +131,9 @@ there is one. No search queries or other usage data are sent.
|
|
|
123
131
|
|
|
124
132
|
Settings, as environment variables in the server's MCP configuration:
|
|
125
133
|
|
|
126
|
-
- `FOOTBALL_DOCS_DATA=bundled`: use only the index inside the package. No
|
|
127
|
-
no downloads.
|
|
134
|
+
- `FOOTBALL_DOCS_DATA=bundled`: use only the index inside the package. No update
|
|
135
|
+
check, no downloads. (This does not turn off the paper tools; see
|
|
136
|
+
`FOOTBALL_DOCS_PAPERS` under [Papers and web sources](#papers-and-web-sources).)
|
|
128
137
|
- `FOOTBALL_DOCS_DATA=auto`: the default for an installed package. Check daily and
|
|
129
138
|
use the newest valid index.
|
|
130
139
|
- `FOOTBALL_DOCS_DB_PATH=<file>`: use exactly this index file.
|
|
@@ -136,6 +145,93 @@ fails quietly and the server keeps the index it has. Under CI (`CI` set) the che
|
|
|
136
145
|
does not run. A server running from a git checkout defaults to `bundled`, so
|
|
137
146
|
development and tests always use the working tree's docs.
|
|
138
147
|
|
|
148
|
+
## Papers and web sources
|
|
149
|
+
|
|
150
|
+
Many football methods come from papers, and some from blog posts: Karun Singh
|
|
151
|
+
introduced expected threat (xT) in a blog post, not a paper. `search_papers`
|
|
152
|
+
finds papers and the works that cite an idea; a web search finds the original
|
|
153
|
+
post, and `get_web_source` reads it. `get_paper` checks that a reference exists,
|
|
154
|
+
`read_paper` reads it, and `match_quote` checks that a quote is in the source.
|
|
155
|
+
|
|
156
|
+
### Open and paid papers
|
|
157
|
+
|
|
158
|
+
| Paper | How it gets in | What the tools return |
|
|
159
|
+
|---|---|---|
|
|
160
|
+
| Open copy: arXiv, an open repository, an open-access publisher, SportRxiv, a public web page | `read_paper` or `get_web_source` finds and reads it | The full text, by section, with its licence |
|
|
161
|
+
| A paper you have through a subscription or purchase | You download the PDF and call `add_local_paper`, or keep it in Zotero and use its `zotero:` ID | The outline and passages of at most 200 characters (`FOOTBALL_DOCS_PAPERS_PASSAGE_CHARS`, 50 to 1000) |
|
|
162
|
+
|
|
163
|
+
football-docs never logs in to a publisher or a library, never holds your
|
|
164
|
+
credentials or cookies, and does not use publisher text-mining APIs (their terms
|
|
165
|
+
exclude tools like this). When a site answers with a bot check, the tool stops;
|
|
166
|
+
download the paper yourself instead.
|
|
167
|
+
|
|
168
|
+
Zotero: `search_papers` with `sources: ["zotero"]` searches your library, and
|
|
169
|
+
`read_paper` reads an item's PDF. Two ways to connect, tried in this order:
|
|
170
|
+
|
|
171
|
+
1. Zotero on this computer. In Zotero 7, open Settings > Advanced and turn on
|
|
172
|
+
"Allow other applications on this computer to communicate with Zotero". The
|
|
173
|
+
tools then use its local API on port 23119; nothing leaves the machine.
|
|
174
|
+
2. The Zotero web API, for when Zotero is not running here (another machine, a
|
|
175
|
+
cloud session). Create a read-only key at
|
|
176
|
+
[zotero.org/settings/keys](https://www.zotero.org/settings/keys) with access
|
|
177
|
+
to your library and its files, and set `ZOTERO_API_KEY` (and optionally
|
|
178
|
+
`ZOTERO_USER_ID`; without it the tools ask the key). It reads only files kept
|
|
179
|
+
in Zotero's own storage, not linked files; for those it uses Zotero's
|
|
180
|
+
full-text index. The key is sent only to api.zotero.org, never to the file
|
|
181
|
+
storage host.
|
|
182
|
+
|
|
183
|
+
An item saved without its PDF (metadata only) is read by its DOI instead, so
|
|
184
|
+
`read_paper` still returns the open copy when there is one.
|
|
185
|
+
|
|
186
|
+
### Services
|
|
187
|
+
|
|
188
|
+
The tools call public services at run time. Each reply ends with the services
|
|
189
|
+
it asked.
|
|
190
|
+
|
|
191
|
+
| Service | Used for | Limits |
|
|
192
|
+
|---|---|---|
|
|
193
|
+
| OpenAlex | Search (title, abstract and full text); DOI and OpenAlex ID lookups; open copies | 1000 credits a day without a key: a search costs 10, a lookup costs nothing. A free key from [openalex.org/settings/api](https://openalex.org/settings/api) raises it. |
|
|
194
|
+
| arXiv | Search (title, abstract, authors); arXiv ID lookups with the paper's licence; the paper's HTML or PDF | One request every three seconds to the API; the tool waits its turn. |
|
|
195
|
+
| SportRxiv | Search in a local copy of its OAI feed; preprint PDFs | The first search downloads the feed (under 1000 records); after a week, the next search asks only for changes. |
|
|
196
|
+
| Crossref | DOI lookups that OpenAlex does not know | |
|
|
197
|
+
| Wayback Machine | The earliest and latest snapshot of a web page; the archived copy when the live page fails | The tool never asks it to save a page. |
|
|
198
|
+
| The host of an open copy or web page | The text | Bot checks stop the tool. |
|
|
199
|
+
|
|
200
|
+
### Your library
|
|
201
|
+
|
|
202
|
+
- Text the tools read is kept in `$XDG_DATA_HOME/football-docs/papers/` (by
|
|
203
|
+
default `~/.local/share/football-docs/papers/`). On macOS and Linux the folder
|
|
204
|
+
and its files are readable only by you (modes 0700 and 0600); on Windows they
|
|
205
|
+
have the access rules of your user folder. A second read sends no request.
|
|
206
|
+
- `forget_paper` removes one paper; `purge_cache` with `confirm: true` deletes
|
|
207
|
+
the whole library and the SportRxiv copy. Neither touches your own files or
|
|
208
|
+
Zotero.
|
|
209
|
+
- Nothing in the library goes into this repository, `data/docs.db` or a data
|
|
210
|
+
release. A test fails if a cached paper or any PDF is added to the repository.
|
|
211
|
+
- `get_web_source`, `read_paper` and `match_quote` read only public `http` and
|
|
212
|
+
`https` addresses. They refuse names that resolve to loopback, private or
|
|
213
|
+
link-local addresses, also after a redirect.
|
|
214
|
+
- `add_local_paper` reads only PDF files, given by their full path.
|
|
215
|
+
|
|
216
|
+
### Settings
|
|
217
|
+
|
|
218
|
+
As environment variables in the server's MCP configuration:
|
|
219
|
+
|
|
220
|
+
- `FOOTBALL_DOCS_PAPERS=off`: send no paper or web request, including to the
|
|
221
|
+
Zotero web API. Your library, files you add and Zotero on this computer still
|
|
222
|
+
work. The provider-doc tools never
|
|
223
|
+
call these services.
|
|
224
|
+
- `ZOTERO_API_KEY=<key>` and `ZOTERO_USER_ID=<number>`: a read-only Zotero web
|
|
225
|
+
API key, for reading Zotero when the app is not running here. The key can also
|
|
226
|
+
go in the keychain, as for OpenAlex below.
|
|
227
|
+
- `FOOTBALL_DOCS_PAPERS_PASSAGE_CHARS=<n>`: the longest passage returned from a
|
|
228
|
+
paper you supplied, 50 to 1000 characters (default 200).
|
|
229
|
+
- `OPENALEX_API_KEY=<key>`: your OpenAlex key. On macOS and Linux you can keep it
|
|
230
|
+
in the system keychain instead of the environment:
|
|
231
|
+
- macOS: `security add-generic-password -s football-docs -a OPENALEX_API_KEY -w <key>`
|
|
232
|
+
- Linux (needs `secret-tool`, from libsecret): `secret-tool store --label=football-docs service football-docs key OPENALEX_API_KEY`
|
|
233
|
+
- Windows: use the environment variable; the tools do not read Windows Credential Manager.
|
|
234
|
+
|
|
139
235
|
## Example queries
|
|
140
236
|
|
|
141
237
|
- "What is Opta qualifier 214?" (big chance)
|
|
@@ -145,6 +241,8 @@ development and tests always use the working tree's docs.
|
|
|
145
241
|
- "Does SportMonks have xG data?"
|
|
146
242
|
- "What event types does kloppy map to GenericEvent?"
|
|
147
243
|
- "How does SPADL represent a tackle?"
|
|
244
|
+
- "Who introduced expected threat (xT)? Cite the original." (a web search finds the post, `get_web_source` reads it, `match_quote` checks the quote, `search_papers` finds the papers that cite it)
|
|
245
|
+
- "How does VAEP define the value of an action? Quote the paper." (`read_paper` on arXiv 1802.07127, then `match_quote`)
|
|
148
246
|
|
|
149
247
|
## Indexed providers
|
|
150
248
|
|
package/data/docs.db
CHANGED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A Context7-style searchable index of football data provider documentation.
|
|
5
5
|
* Exposes tools for searching docs, listing providers, comparing providers,
|
|
6
|
-
* requesting documentation updates, and resolving football entities
|
|
6
|
+
* requesting documentation updates, and resolving football entities, plus
|
|
7
|
+
* paper and web-source lookups that call public services at run time.
|
|
7
8
|
*
|
|
8
9
|
* Data is stored in a SQLite FTS5 index for fast offline search. Update
|
|
9
10
|
* requests are stored in a separate writable SQLite DB in a user-writable
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A Context7-style searchable index of football data provider documentation.
|
|
5
5
|
* Exposes tools for searching docs, listing providers, comparing providers,
|
|
6
|
-
* requesting documentation updates, and resolving football entities
|
|
6
|
+
* requesting documentation updates, and resolving football entities, plus
|
|
7
|
+
* paper and web-source lookups that call public services at run time.
|
|
7
8
|
*
|
|
8
9
|
* Data is stored in a SQLite FTS5 index for fast offline search. Update
|
|
9
10
|
* requests are stored in a separate writable SQLite DB in a user-writable
|
|
@@ -19,6 +20,7 @@ import { z } from "zod";
|
|
|
19
20
|
import { hardenConnection } from "./data-format.js";
|
|
20
21
|
import { cleanDataDir, dataModeFor, defaultDataDir, IndexChooser } from "./data-source.js";
|
|
21
22
|
import { checkForUpdate } from "./data-update.js";
|
|
23
|
+
import { addLocalPaper, forgetPaper, getPaper, getWebSource, matchQuote, purgeCache, readPaper, SEARCH_SOURCES, searchPapers, } from "./papers/tools.js";
|
|
22
24
|
import { ENTITY_TYPES } from "./reep.js";
|
|
23
25
|
import { openDatabase } from "./sqlite.js";
|
|
24
26
|
import { compareProviders, getProviderDocs, listProviders, requestUpdate, resolveEntity, resolveProviderId, searchDocs, } from "./tools.js";
|
|
@@ -184,6 +186,82 @@ export function createFootballDocsServer() {
|
|
|
184
186
|
.describe("Name to search, at least 3 characters (e.g. 'Declan Rice'). A name match is a shortlist, not an answer."),
|
|
185
187
|
type: z.enum(ENTITY_TYPES).optional().describe("Restrict results to one entity type"),
|
|
186
188
|
}, { readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async (args) => resolveEntity(args));
|
|
189
|
+
server.tool("search_papers", [
|
|
190
|
+
"Search scholarly papers on football analytics and sport science: OpenAlex (title, abstract and full text),",
|
|
191
|
+
"arXiv (title, abstract, authors) and SportRxiv (title, abstract, keywords). Use it to find the paper behind a",
|
|
192
|
+
"method (xG, VAEP, EPV, pitch control) or the works that cite an idea. Use words and \"quoted phrases\";",
|
|
193
|
+
"OpenAlex matches full text, so a hit may cite the idea rather than introduce it. Many methods first appeared",
|
|
194
|
+
"in blog posts or conference papers without a DOI (xT, for example): search the web for those and read them",
|
|
195
|
+
"with get_web_source. The reply names the services asked. FOOTBALL_DOCS_PAPERS=off turns paper lookups off.",
|
|
196
|
+
].join(" "), {
|
|
197
|
+
query: z
|
|
198
|
+
.string()
|
|
199
|
+
.describe('Words and "quoted phrases", optionally with AND / OR / NOT. Examples: \'"expected threat" soccer\', \'"pitch control" Spearman\', \'VAEP action values\''),
|
|
200
|
+
sources: z
|
|
201
|
+
.array(z.enum(SEARCH_SOURCES))
|
|
202
|
+
.optional()
|
|
203
|
+
.describe("Sources to ask. Default: openalex, arxiv and sportrxiv (searched in a local copy of its feed). Add zotero to search the user's own Zotero library (Zotero on this computer, else the Zotero web API with ZOTERO_API_KEY)."),
|
|
204
|
+
max_results: z.number().optional().default(10).describe("Results per source, 1 to 25 (default 10)."),
|
|
205
|
+
year_from: z.number().int().optional().describe("Only papers published in or after this year."),
|
|
206
|
+
year_to: z.number().int().optional().describe("Only papers published in or before this year."),
|
|
207
|
+
}, { readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async (args) => searchPapers(args));
|
|
208
|
+
server.tool("get_paper", [
|
|
209
|
+
"Look up one paper by DOI, arXiv ID, OpenAlex ID, zotero: ID or local: ID: title, authors, date, venue, all IDs, licence, open copies",
|
|
210
|
+
"with their licences, abstract and a citation line. arXiv IDs come from arXiv with the paper's licence; DOIs",
|
|
211
|
+
"from OpenAlex, then SportRxiv or Crossref. Use it to check that a reference exists and says what is claimed.",
|
|
212
|
+
].join(" "), {
|
|
213
|
+
id: z
|
|
214
|
+
.string()
|
|
215
|
+
.describe("A DOI (10.1145/3292500.3330758 or https://doi.org/...), an arXiv ID or URL (1802.07127, arxiv.org/abs/1802.07127), or an OpenAlex ID (W4288278931)."),
|
|
216
|
+
}, { readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async (args) => getPaper(args));
|
|
217
|
+
server.tool("get_web_source", [
|
|
218
|
+
"Read a public web page (blog post, newsletter, club or vendor article) as text, with its author, date,",
|
|
219
|
+
"licence and Wayback Machine snapshots. Use it for methods first published on the web, such as Karun Singh's",
|
|
220
|
+
"xT post, after finding the page with a web search. A page with no date gets the date of its earliest snapshot",
|
|
221
|
+
"as an upper bound. Reads HTML and PDF. Long pages come back by section. The tool stops at bot checks and refuses",
|
|
222
|
+
"local addresses.",
|
|
223
|
+
].join(" "), {
|
|
224
|
+
url: z.string().describe("The page's http(s) URL."),
|
|
225
|
+
section: z
|
|
226
|
+
.number()
|
|
227
|
+
.int()
|
|
228
|
+
.min(0)
|
|
229
|
+
.optional()
|
|
230
|
+
.describe("For a long page, the section number from the outline of an earlier call."),
|
|
231
|
+
}, { readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async (args) => getWebSource(args));
|
|
232
|
+
const paperId = z
|
|
233
|
+
.string()
|
|
234
|
+
.describe("A DOI, arXiv ID, OpenAlex ID, zotero:KEY from search_papers, or local:… from add_local_paper.");
|
|
235
|
+
server.tool("read_paper", [
|
|
236
|
+
"Read a paper's text. Finds an open copy (arXiv, open repositories, open-access publishers, SportRxiv) and returns",
|
|
237
|
+
"it in full, by section, with its licence. For a paper the user supplied (add_local_paper or zotero:), returns",
|
|
238
|
+
"only the outline and passages of at most 200 characters (FOOTBALL_DOCS_PAPERS_PASSAGE_CHARS). The text is kept in",
|
|
239
|
+
"the user's library, so a second call sends no request. It never logs in anywhere and stops at bot checks; when",
|
|
240
|
+
"no open copy can be read it says so and suggests add_local_paper.",
|
|
241
|
+
].join(" "), {
|
|
242
|
+
id: paperId,
|
|
243
|
+
section: z.number().int().min(0).optional().describe("Section number from the outline of an earlier call (open copies only)."),
|
|
244
|
+
query: z.string().optional().describe("Words to find: returns passages that hold all of them, with their section and page."),
|
|
245
|
+
}, { readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async (args) => readPaper(args));
|
|
246
|
+
server.tool("match_quote", [
|
|
247
|
+
"Check that a quote appears in its source: a paper (any ID read_paper takes) or a web page URL. Reports exact,",
|
|
248
|
+
"normalised (same words; case, spacing, quote marks, ligatures or hyphens differ), close (with a similarity",
|
|
249
|
+
"score: quote the source's own words instead) or none, with the section, page and a W3C TextQuoteSelector. Use it",
|
|
250
|
+
"before citing a definition or a claim.",
|
|
251
|
+
].join(" "), {
|
|
252
|
+
source: z.string().describe("A paper ID or an http(s) URL."),
|
|
253
|
+
quote: z.string().min(10).describe("The quote to check, at least 10 characters."),
|
|
254
|
+
}, { readOnlyHint: true, destructiveHint: false, openWorldHint: true }, async (args) => matchQuote(args));
|
|
255
|
+
server.tool("add_local_paper", [
|
|
256
|
+
"Add a PDF the user has (for example a paper from their library's subscription) to their football-docs library.",
|
|
257
|
+
"Only PDF files are read; the text stays on this computer and is never sent anywhere. Returns a local: ID for",
|
|
258
|
+
"read_paper and match_quote, which give only the outline and short passages of such papers.",
|
|
259
|
+
].join(" "), {
|
|
260
|
+
path: z.string().describe("The full path to the PDF, for example /Users/me/Downloads/paper.pdf or ~/Downloads/paper.pdf."),
|
|
261
|
+
id: z.string().optional().describe("The paper's DOI or arXiv ID, to fill in its title and authors. Found in the PDF when omitted."),
|
|
262
|
+
}, { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, async (args) => addLocalPaper(args));
|
|
263
|
+
server.tool("forget_paper", "Remove one paper's text from the user's football-docs library. The user's own file and Zotero are not touched.", { id: paperId }, { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }, async (args) => forgetPaper(args));
|
|
264
|
+
server.tool("purge_cache", "Delete the user's whole football-docs paper library and the SportRxiv copy. Call with confirm: true only when the user asked for it.", { confirm: z.boolean().describe("Must be true to delete.") }, { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }, async (args) => purgeCache(args));
|
|
187
265
|
return server;
|
|
188
266
|
}
|
|
189
267
|
/**
|
package/dist/ingest.js
CHANGED
|
@@ -65,11 +65,16 @@ export function parseFrontmatter(raw) {
|
|
|
65
65
|
}
|
|
66
66
|
return { frontmatter: fm, body };
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Marks a section that scripts/gen_vendor_tables.py rebuilds from specs/. The
|
|
70
|
+
* marker is for maintainers; it is kept out of the index.
|
|
71
|
+
*/
|
|
72
|
+
const GENERATED_MARKER = /^<!-- generated:[a-z0-9-]+ (start|end) -->$/;
|
|
68
73
|
/** Split a markdown file into chunks by ## or ### headings. */
|
|
69
74
|
export function chunkMarkdown(text, provider, category) {
|
|
70
75
|
const { frontmatter, body } = parseFrontmatter(text);
|
|
71
76
|
const chunks = [];
|
|
72
|
-
const lines = body.split("\n");
|
|
77
|
+
const lines = body.split("\n").filter((line) => !GENERATED_MARKER.test(line));
|
|
73
78
|
let currentTitle = `${provider} - ${category}`;
|
|
74
79
|
let currentLines = [];
|
|
75
80
|
for (const line of lines) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* arXiv: metadata search through the query API, and one record with its
|
|
3
|
+
* licence through OAI-PMH. arXiv metadata is CC0. arXiv asks for no more than
|
|
4
|
+
* one request every three seconds, which core.ts enforces.
|
|
5
|
+
*
|
|
6
|
+
* The query API searches titles, abstracts, authors and comments only, not
|
|
7
|
+
* the body of a paper.
|
|
8
|
+
*/
|
|
9
|
+
import { type PaperContext } from "./core.js";
|
|
10
|
+
import type { PaperRecord } from "./records.js";
|
|
11
|
+
/**
|
|
12
|
+
* Turn a free-text query into arXiv's field syntax: every word and quoted
|
|
13
|
+
* phrase is searched in all fields, joined with AND unless the query says
|
|
14
|
+
* OR or NOT.
|
|
15
|
+
*/
|
|
16
|
+
export declare function arxivQuery(query: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* The year of first submission, from the ID's YYMM part. OAI's <created> can
|
|
19
|
+
* hold a later date than the first version (1802.07127 shows 2019-07-10), so
|
|
20
|
+
* the record does not use it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function arxivYear(arxivId: string): number | undefined;
|
|
23
|
+
export type ArxivSearch = {
|
|
24
|
+
records: PaperRecord[];
|
|
25
|
+
total: number;
|
|
26
|
+
};
|
|
27
|
+
export declare function searchArxiv(ctx: PaperContext, query: string, options: {
|
|
28
|
+
limit: number;
|
|
29
|
+
}): Promise<ArxivSearch>;
|
|
30
|
+
/**
|
|
31
|
+
* One arXiv record through OAI-PMH, which also gives the paper's licence and
|
|
32
|
+
* the DOI of the published version. The version suffix is not part of an OAI
|
|
33
|
+
* identifier, so it is dropped for the call and kept in the record.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getArxivRecord(ctx: PaperContext, arxivId: string): Promise<PaperRecord | null>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* arXiv: metadata search through the query API, and one record with its
|
|
3
|
+
* licence through OAI-PMH. arXiv metadata is CC0. arXiv asks for no more than
|
|
4
|
+
* one request every three seconds, which core.ts enforces.
|
|
5
|
+
*
|
|
6
|
+
* The query API searches titles, abstracts, authors and comments only, not
|
|
7
|
+
* the body of a paper.
|
|
8
|
+
*/
|
|
9
|
+
import { DOMParser } from "linkedom";
|
|
10
|
+
import { getText, plainText } from "./core.js";
|
|
11
|
+
const QUERY_API = "https://export.arxiv.org/api/query";
|
|
12
|
+
const OAI_API = "https://oaipmh.arxiv.org/oai";
|
|
13
|
+
function parseXml(text) {
|
|
14
|
+
return new DOMParser().parseFromString(text, "text/xml");
|
|
15
|
+
}
|
|
16
|
+
function all(parent, tag) {
|
|
17
|
+
return Array.from(parent.getElementsByTagName(tag));
|
|
18
|
+
}
|
|
19
|
+
function first(parent, tag) {
|
|
20
|
+
return plainText(parent.getElementsByTagName(tag)[0]?.textContent ?? "");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Turn a free-text query into arXiv's field syntax: every word and quoted
|
|
24
|
+
* phrase is searched in all fields, joined with AND unless the query says
|
|
25
|
+
* OR or NOT.
|
|
26
|
+
*/
|
|
27
|
+
export function arxivQuery(query) {
|
|
28
|
+
const tokens = query.match(/"[^"]+"|\S+/g) ?? [];
|
|
29
|
+
const parts = [];
|
|
30
|
+
let operator = "AND";
|
|
31
|
+
for (const token of tokens) {
|
|
32
|
+
const upper = token.toUpperCase();
|
|
33
|
+
if (upper === "AND" || upper === "OR" || upper === "NOT") {
|
|
34
|
+
operator = upper === "NOT" ? "ANDNOT" : upper;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const term = token.startsWith('"') ? token : token.replace(/[^\p{L}\p{N}.-]/gu, "");
|
|
38
|
+
if (!term || term === '""')
|
|
39
|
+
continue;
|
|
40
|
+
if (parts.length)
|
|
41
|
+
parts.push(operator);
|
|
42
|
+
parts.push(`all:${term}`);
|
|
43
|
+
operator = "AND";
|
|
44
|
+
}
|
|
45
|
+
return parts.join(" ");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The year of first submission, from the ID's YYMM part. OAI's <created> can
|
|
49
|
+
* hold a later date than the first version (1802.07127 shows 2019-07-10), so
|
|
50
|
+
* the record does not use it.
|
|
51
|
+
*/
|
|
52
|
+
export function arxivYear(arxivId) {
|
|
53
|
+
const match = arxivId.match(/^(\d{2})\d{2}\./) ?? arxivId.match(/\/(\d{2})\d{5}/);
|
|
54
|
+
if (!match)
|
|
55
|
+
return undefined;
|
|
56
|
+
const yy = Number(match[1]);
|
|
57
|
+
return yy >= 91 ? 1900 + yy : 2000 + yy;
|
|
58
|
+
}
|
|
59
|
+
function idFromAbsUrl(url) {
|
|
60
|
+
return url.replace(/^https?:\/\/arxiv\.org\/abs\//i, "");
|
|
61
|
+
}
|
|
62
|
+
export async function searchArxiv(ctx, query, options) {
|
|
63
|
+
const searchQuery = arxivQuery(query);
|
|
64
|
+
if (!searchQuery)
|
|
65
|
+
return { records: [], total: 0 };
|
|
66
|
+
const url = new URL(QUERY_API);
|
|
67
|
+
url.searchParams.set("search_query", searchQuery);
|
|
68
|
+
url.searchParams.set("max_results", String(options.limit));
|
|
69
|
+
url.searchParams.set("sortBy", "relevance");
|
|
70
|
+
const feed = parseXml(await getText(ctx, url.href));
|
|
71
|
+
const records = all(feed, "entry").map((entry) => {
|
|
72
|
+
const id = idFromAbsUrl(first(entry, "id"));
|
|
73
|
+
const published = first(entry, "published");
|
|
74
|
+
const doi = first(entry, "arxiv:doi");
|
|
75
|
+
const journal = first(entry, "arxiv:journal_ref");
|
|
76
|
+
return {
|
|
77
|
+
source: "arxiv",
|
|
78
|
+
title: first(entry, "title"),
|
|
79
|
+
authors: all(entry, "author").map((author) => first(author, "name")).filter(Boolean),
|
|
80
|
+
year: published ? Number(published.slice(0, 4)) : undefined,
|
|
81
|
+
date: published ? published.slice(0, 10) : undefined,
|
|
82
|
+
venue: journal || undefined,
|
|
83
|
+
type: "preprint",
|
|
84
|
+
ids: { arxiv: id, doi: doi ? doi.toLowerCase() : undefined },
|
|
85
|
+
url: `https://arxiv.org/abs/${id}`,
|
|
86
|
+
abstract: first(entry, "summary") || undefined,
|
|
87
|
+
openCopies: [{ url: `https://arxiv.org/pdf/${id}`, pdf: true, host: "arXiv" }],
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
return { records, total: Number(first(feed, "opensearch:totalResults")) || records.length };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* One arXiv record through OAI-PMH, which also gives the paper's licence and
|
|
94
|
+
* the DOI of the published version. The version suffix is not part of an OAI
|
|
95
|
+
* identifier, so it is dropped for the call and kept in the record.
|
|
96
|
+
*/
|
|
97
|
+
export async function getArxivRecord(ctx, arxivId) {
|
|
98
|
+
const bare = arxivId.replace(/v\d+$/i, "");
|
|
99
|
+
if (!/^[\w./-]+$/.test(bare))
|
|
100
|
+
return null;
|
|
101
|
+
// Built by hand: the server does not answer when the colons are percent-encoded,
|
|
102
|
+
// which URLSearchParams does.
|
|
103
|
+
const url = `${OAI_API}?verb=GetRecord&identifier=oai:arXiv.org:${bare}&metadataPrefix=arXiv`;
|
|
104
|
+
const doc = parseXml(await getText(ctx, url));
|
|
105
|
+
const record = doc.getElementsByTagName("arXiv")[0];
|
|
106
|
+
if (!record)
|
|
107
|
+
return null;
|
|
108
|
+
const doi = first(record, "doi");
|
|
109
|
+
const journal = first(record, "journal-ref");
|
|
110
|
+
const authors = all(record, "author").map((author) => [first(author, "forenames"), first(author, "keyname")].filter(Boolean).join(" "));
|
|
111
|
+
return {
|
|
112
|
+
source: "arxiv",
|
|
113
|
+
title: first(record, "title"),
|
|
114
|
+
authors,
|
|
115
|
+
year: arxivYear(bare),
|
|
116
|
+
venue: journal || undefined,
|
|
117
|
+
type: "preprint",
|
|
118
|
+
ids: { arxiv: arxivId, doi: doi ? doi.toLowerCase() : undefined },
|
|
119
|
+
url: `https://arxiv.org/abs/${arxivId}`,
|
|
120
|
+
abstract: first(record, "abstract") || undefined,
|
|
121
|
+
licence: first(record, "license") || undefined,
|
|
122
|
+
openCopies: [
|
|
123
|
+
{ url: `https://arxiv.org/pdf/${arxivId}`, pdf: true, host: "arXiv", licence: first(record, "license") || undefined },
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared parts of the paper and web-source tools: the off switch, the local
|
|
3
|
+
* cache folder, API keys, and a fetch that keeps to each service's limits.
|
|
4
|
+
*
|
|
5
|
+
* These tools call public services at run time (OpenAlex, arXiv, SportRxiv,
|
|
6
|
+
* Crossref, the Wayback Machine and the web page asked for). Nothing they fetch
|
|
7
|
+
* goes into the repository, data/docs.db or a data release: metadata the tools
|
|
8
|
+
* keep stays in the user's cache folder.
|
|
9
|
+
*/
|
|
10
|
+
export declare const USER_AGENT = "football-docs (+https://github.com/withqwerty/football-docs)";
|
|
11
|
+
export type Env = Record<string, string | undefined>;
|
|
12
|
+
export type TextContent = {
|
|
13
|
+
type: "text";
|
|
14
|
+
text: string;
|
|
15
|
+
};
|
|
16
|
+
export type ToolResponse = {
|
|
17
|
+
isError?: boolean;
|
|
18
|
+
content: TextContent[];
|
|
19
|
+
};
|
|
20
|
+
export declare function textResult(text: string, isError?: boolean): ToolResponse;
|
|
21
|
+
/** Everything a paper tool touches outside the process. Tests replace each part. */
|
|
22
|
+
export type PaperContext = {
|
|
23
|
+
env: Env;
|
|
24
|
+
fetchImpl: typeof fetch;
|
|
25
|
+
cacheDir: string;
|
|
26
|
+
/** Wait before a call to a service with a minimum interval (arXiv). */
|
|
27
|
+
sleep: (ms: number) => Promise<void>;
|
|
28
|
+
now: () => number;
|
|
29
|
+
/** Look up a key in the system keychain. Returns null when there is none. */
|
|
30
|
+
keychain: (name: string) => Promise<string | null>;
|
|
31
|
+
};
|
|
32
|
+
export type PaperOptions = Partial<PaperContext>;
|
|
33
|
+
/** FOOTBALL_DOCS_PAPERS=off turns every outbound paper and web lookup off. */
|
|
34
|
+
export declare function papersDisabled(env: Env): boolean;
|
|
35
|
+
export declare const DISABLED_MESSAGE: string;
|
|
36
|
+
export declare function defaultCacheDir(env?: Env): string;
|
|
37
|
+
export declare function contextFrom(options?: PaperOptions): PaperContext;
|
|
38
|
+
export declare function ensureCacheDir(dir: string): void;
|
|
39
|
+
export declare function readCacheJson<T>(dir: string, name: string): T | null;
|
|
40
|
+
/** Write through a temporary file, so a crash never leaves half a file. */
|
|
41
|
+
export declare function writeCacheJson(dir: string, name: string, value: unknown): void;
|
|
42
|
+
/**
|
|
43
|
+
* Read a key from the environment, else from the keychain:
|
|
44
|
+
* macOS: security add-generic-password -s football-docs -a NAME -w
|
|
45
|
+
* Linux: secret-tool store --label=football-docs service football-docs key NAME
|
|
46
|
+
*/
|
|
47
|
+
export declare function apiKey(ctx: PaperContext, name: string): Promise<string | null>;
|
|
48
|
+
/** Services asked during one tool call, named in its reply. */
|
|
49
|
+
export declare class ServiceLog {
|
|
50
|
+
private readonly entries;
|
|
51
|
+
ok(service: string, detail?: string): void;
|
|
52
|
+
failed(service: string, reason: string): void;
|
|
53
|
+
get failures(): string[];
|
|
54
|
+
footer(): string;
|
|
55
|
+
}
|
|
56
|
+
export declare class FetchError extends Error {
|
|
57
|
+
readonly status?: number | undefined;
|
|
58
|
+
constructor(message: string, status?: number | undefined);
|
|
59
|
+
}
|
|
60
|
+
/** Forget the per-host timings. Tests only. */
|
|
61
|
+
export declare function resetRateLimits(): void;
|
|
62
|
+
export declare const MAX_RESPONSE_BYTES: number;
|
|
63
|
+
/** Read a body, stopping at maxBytes so one huge page cannot fill memory. */
|
|
64
|
+
export declare function readCapped(response: Response, maxBytes?: number): Promise<Uint8Array>;
|
|
65
|
+
export type GetOptions = {
|
|
66
|
+
headers?: Record<string, string>;
|
|
67
|
+
timeoutMs?: number;
|
|
68
|
+
};
|
|
69
|
+
/** GET a public API. Throws FetchError with the status on a non-2xx reply. */
|
|
70
|
+
export declare function getResponse(ctx: PaperContext, url: string, options?: GetOptions): Promise<Response>;
|
|
71
|
+
export declare function getText(ctx: PaperContext, url: string, options?: GetOptions): Promise<string>;
|
|
72
|
+
export declare function getJson<T>(ctx: PaperContext, url: string, options?: GetOptions): Promise<{
|
|
73
|
+
body: T;
|
|
74
|
+
headers: Headers;
|
|
75
|
+
}>;
|
|
76
|
+
export declare function reason(error: unknown): string;
|
|
77
|
+
/** Strip tags and decode the entities that appear in OAI and API abstracts. */
|
|
78
|
+
export declare function plainText(value: string | undefined | null): string;
|
|
79
|
+
export declare function truncate(text: string, max: number): string;
|