pi-lean-host 0.1.0 → 0.1.1
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 +25 -9
- package/core/helpers.ts +10 -1
- package/core/transport.ts +13 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
> SearXNG search, install
|
|
21
21
|
> [`pi-lean-search`](https://www.npmjs.com/package/pi-lean-search).
|
|
22
22
|
|
|
23
|
-
> ⚠️ **Early release (0.1.
|
|
23
|
+
> ⚠️ **Early release (0.1.1).** The API tools here work today, but this is a
|
|
24
24
|
> development preview. The recipe schema, tool surfaces, and guide format are
|
|
25
25
|
> still settling as we test more APIs to finalize the shape — **future
|
|
26
26
|
> compatibility is not guaranteed** until the package reaches lockstep with
|
|
27
|
-
> `pi-lean-dimension` 0.5.0. Guides authored against 0.1.
|
|
27
|
+
> `pi-lean-dimension` 0.5.0. Guides authored against 0.1.x may need revision
|
|
28
28
|
> as the schema firms up.
|
|
29
29
|
|
|
30
30
|
---
|
|
@@ -105,6 +105,21 @@ This kills two whole classes of recurring mistakes before they exist:
|
|
|
105
105
|
bundled recipes are inert, the only code that ever runs is code you
|
|
106
106
|
explicitly placed in your own directory.
|
|
107
107
|
|
|
108
|
+
### Why not just a skill?
|
|
109
|
+
|
|
110
|
+
A skill is prose the agent re-interprets each turn; this plugin is a fixed
|
|
111
|
+
executor it calls through. For a single clean endpoint you call
|
|
112
|
+
occasionally, a few skill lines are the lazier answer. It earns its keep
|
|
113
|
+
where re-derived curl goes wrong — **pagination to exhaustion** (cursor,
|
|
114
|
+
nextLink, OAI-PMH tokens, Wikimedia continuation dicts walked in one call by
|
|
115
|
+
reviewed code), **charset traps** (Latin-1 APIs serving bytes without a
|
|
116
|
+
charset parameter — fixed once in the transport, not re-applied and
|
|
117
|
+
forgotten), and **in-process TypeScript helpers** that transform params or
|
|
118
|
+
responses directly (a skill can only instruct the agent to write and run
|
|
119
|
+
that code). A skill is also always in context; the guide store loads on
|
|
120
|
+
demand. A skill is pure text with no in-process eval, whereas a loaded
|
|
121
|
+
`helper.ts` runs with the agent's privileges.
|
|
122
|
+
|
|
108
123
|
### Three tiers of code, separated by trust
|
|
109
124
|
|
|
110
125
|
| Tier | Where it lives | Who writes it | Ships in tarball? | Trust |
|
|
@@ -485,7 +500,7 @@ Authoring is via `api-learn` in learn mode, or hand-editing the file.
|
|
|
485
500
|
## Pagination Styles
|
|
486
501
|
|
|
487
502
|
`paginate` follows the style declared in the recipe. Six styles cover the
|
|
488
|
-
patterns the bundled
|
|
503
|
+
patterns the bundled 19-recipe spread pressure-tested:
|
|
489
504
|
|
|
490
505
|
| Style | What it sends | Key fields |
|
|
491
506
|
|-------|---------------|------------|
|
|
@@ -542,15 +557,16 @@ you know you're in disambiguation territory.
|
|
|
542
557
|
|
|
543
558
|
## Bundled Reference Recipes
|
|
544
559
|
|
|
545
|
-
The repo ships **
|
|
560
|
+
The repo ships **21 reference recipes** under `api-guides/` (GitHub only —
|
|
546
561
|
**not in the npm tarball, never auto-loaded**). They are inert worked
|
|
547
562
|
examples spanning the no-auth axes the helper set was validated against:
|
|
548
563
|
|
|
549
564
|
```
|
|
550
|
-
api.gbif.org
|
|
551
|
-
boe.es
|
|
552
|
-
en.wikipedia.org-action
|
|
553
|
-
|
|
565
|
+
api.gbif.org api.github.com archive.org archive.org-wayback
|
|
566
|
+
arxiv.org boe.es data-api.ecb.europa.eu datos.gob.es
|
|
567
|
+
earthquake.usgs.gov en.wikipedia.org en.wikipedia.org-action eutils.ncbi.nlm.nih.gov
|
|
568
|
+
gitlab.com loc.gov musicbrainz.org openlibrary.org
|
|
569
|
+
resources.data.gov services.dnb.de web.archive.org www.federalregister.gov
|
|
554
570
|
www.wikidata.org
|
|
555
571
|
```
|
|
556
572
|
|
|
@@ -766,7 +782,7 @@ machine; the package does not aim to make that easy.
|
|
|
766
782
|
> web-tools suite. For the deferred secrets-store track (the two-threat
|
|
767
783
|
> model and the first-keyed-guide build checklist), see
|
|
768
784
|
> [`docs/design/api-secrets-roadmap.md`](docs/design/api-secrets-roadmap.md).
|
|
769
|
-
> For the helper escape-valve policy and the
|
|
785
|
+
> For the helper escape-valve policy and the 19-recipe spread, see
|
|
770
786
|
> [`docs/design/api-helper-escape-valve.md`](docs/design/api-helper-escape-valve.md).
|
|
771
787
|
>
|
|
772
788
|
> License: AGPL-3.0-only
|
package/core/helpers.ts
CHANGED
|
@@ -241,6 +241,9 @@ const xmlParser = new XMLParser({
|
|
|
241
241
|
textNodeName: "#text",
|
|
242
242
|
parseAttributeValue: true,
|
|
243
243
|
trimValues: true,
|
|
244
|
+
// A2: strip element-name prefixes (message:GenericData → GenericData) so
|
|
245
|
+
// itemsPath/totalCountPath use stable local names across XML providers.
|
|
246
|
+
removeNSPrefix: true,
|
|
244
247
|
});
|
|
245
248
|
|
|
246
249
|
/**
|
|
@@ -656,7 +659,13 @@ export async function paginate(
|
|
|
656
659
|
}
|
|
657
660
|
|
|
658
661
|
// Extract items from this page.
|
|
659
|
-
|
|
662
|
+
let pageItems = resolveJsonPath(data, pagCfg.itemsPath);
|
|
663
|
+
// A1: normalize a single XML record (or scalar) into an array so the
|
|
664
|
+
// declared list path always yields an array even with one element
|
|
665
|
+
// (e.g. arXiv max_results=1, PubMed retmax=1 box a single record).
|
|
666
|
+
if (pageItems != null && !Array.isArray(pageItems)) {
|
|
667
|
+
pageItems = [pageItems];
|
|
668
|
+
}
|
|
660
669
|
if (Array.isArray(pageItems)) {
|
|
661
670
|
if (pageItems.length === 0) break; // empty page → exhaustion
|
|
662
671
|
// Apply the post-response transform per item. A throwing transform
|
package/core/transport.ts
CHANGED
|
@@ -182,14 +182,25 @@ function parseMaxAge(headers: Record<string, string>): number | null {
|
|
|
182
182
|
return m ? parseInt(m[1]!, 10) * 1000 : null;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Compute the delay before a retry. Prefers Retry-After: delay-seconds;
|
|
187
|
+
* falls back to parsing an HTTP-date form. If the date is in the past
|
|
188
|
+
* (clock skew / already-expired) or absent, uses exponential backoff —
|
|
189
|
+
* never a negative or zero delay.
|
|
190
|
+
*/
|
|
191
|
+
export function waitForRetry(
|
|
186
192
|
headers: Record<string, string>,
|
|
187
193
|
attempt: number,
|
|
188
194
|
): number {
|
|
189
195
|
const raw = headers["retry-after"];
|
|
190
196
|
if (raw) {
|
|
191
197
|
const secs = parseInt(raw, 10);
|
|
192
|
-
if (!isNaN(secs) && secs > 0) return secs * 1000;
|
|
198
|
+
if (!Number.isNaN(secs) && secs > 0) return secs * 1000;
|
|
199
|
+
const dateMs = Date.parse(raw);
|
|
200
|
+
if (!Number.isNaN(dateMs)) {
|
|
201
|
+
const delta = dateMs - Date.now();
|
|
202
|
+
if (delta > 0) return delta;
|
|
203
|
+
}
|
|
193
204
|
}
|
|
194
205
|
// Exponential backoff: 1s, 2s, 4s, …
|
|
195
206
|
return Math.min(1000 * 2 ** attempt, 30_000);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-lean-host",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Pi
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "REST API client for Pi. A YAML file per API covers endpoints and pagination; the agent calls through a fixed executor so an API encoded once is reusable forever, not re-derived each session. It can probe a live endpoint and write the YAML for you, and a TypeScript file alongside can add custom auth or reshape the request and response freely.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
7
7
|
"pi-extension",
|