pi-lean-host 0.1.1 → 0.2.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 +182 -62
- package/core/api-guide-types.ts +52 -1
- package/core/api-toggle.ts +20 -1
- package/core/auth.ts +186 -0
- package/core/guide-store.ts +0 -26
- package/core/helpers.ts +173 -57
- package/core/local-helpers.ts +2 -1
- package/core/parse-api-guide.ts +316 -55
- package/core/path-template.ts +30 -1
- package/core/secrets-command.ts +338 -0
- package/core/secrets-store.ts +180 -0
- package/core/ssrf-guard.ts +5 -0
- package/core/transport.ts +114 -26
- package/package.json +14 -1
- package/tools/api-fetch.ts +113 -26
- package/tools/api-guide.ts +13 -15
- package/tools/api-learn.ts +16 -19
- package/tools/api-probe.ts +528 -53
- package/tools/utils.ts +21 -0
package/tools/api-learn.ts
CHANGED
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
16
16
|
import { Type } from "@earendil-works/pi-ai";
|
|
17
17
|
import { Text } from "@earendil-works/pi-tui";
|
|
18
|
-
import {
|
|
18
|
+
import { appendFooter, contentText } from "./utils.js";
|
|
19
19
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
20
20
|
import { join } from "node:path";
|
|
21
21
|
import { parseApiGuide } from "../core/parse-api-guide.js";
|
|
22
22
|
import {
|
|
23
23
|
invalidateCache,
|
|
24
24
|
getUserGuidesDir,
|
|
25
|
-
assertSafeDomain,
|
|
26
25
|
findGuidesByDomain,
|
|
27
26
|
} from "../core/guide-store.js";
|
|
27
|
+
import { assertSafeDomain } from "../core/path-template.js";
|
|
28
28
|
|
|
29
29
|
// ═══════════════════════════════════════════════════════════════════
|
|
30
30
|
// Worked example
|
|
@@ -101,8 +101,7 @@ export const apiLearnTool = defineTool({
|
|
|
101
101
|
description:
|
|
102
102
|
"Save or update an API guide for a domain. " +
|
|
103
103
|
"The recipe is written in YAML frontmatter format. " +
|
|
104
|
-
"Call with no params to see the worked example recipe and field reference.
|
|
105
|
-
"Requires /api learn to be active.",
|
|
104
|
+
"Call with no params to see the worked example recipe and field reference.",
|
|
106
105
|
|
|
107
106
|
parameters: Type.Object({
|
|
108
107
|
domain: Type.Optional(
|
|
@@ -146,6 +145,7 @@ export const apiLearnTool = defineTool({
|
|
|
146
145
|
` \`operations[].path\` — path starting with /`,
|
|
147
146
|
"",
|
|
148
147
|
"## Key defaults",
|
|
148
|
+
` \`apiHost\` — base URL. \`path\` is always resolved relative to it — \`joinUrl\` strips a leading \`/\`, so \`/items\` + \`apiHost: https://host/v3\` → \`https://host/v3/items\`. Keep the version in \`apiHost\` (worked-example style) or leave it bare with the version in each \`path\` — pick one per guide; both at once doubles the segment (\`/v3/v3/items\` → 404)`,
|
|
149
149
|
` \`auth\` — omitted → kind: none`,
|
|
150
150
|
` \`verified\` — omitted → today's date`,
|
|
151
151
|
` \`docs\` — optional API documentation URL (http/https); omitted → no docs line`,
|
|
@@ -165,6 +165,13 @@ export const apiLearnTool = defineTool({
|
|
|
165
165
|
` \`passthrough\` — true → forward undeclared caller params onto the query string`,
|
|
166
166
|
` \`parse\` — op-level responseShape override (format/charset) for this operation`,
|
|
167
167
|
"",
|
|
168
|
+
"## Executor semantics",
|
|
169
|
+
" Pagination:",
|
|
170
|
+
` \`pagination.base\` seeds the page param for offset-limit/page styles (caller value wins, then \`base\`, then the param \`default\`); use \`base: 1\` for 1-based offset APIs`,
|
|
171
|
+
` The page-size param is a real knob: caller value → op param \`default\` → \`pagination.pageSize\` → 50`,
|
|
172
|
+
" Auth:",
|
|
173
|
+
` \`requires\` = fail-closed if unprovisioned; \`optional\` = proceeds unauthenticated if absent. Both are names only — values live in the secrets store.`,
|
|
174
|
+
"",
|
|
168
175
|
"Call api-learn({domain: '...', recipe: '...'}) to save the guide, then api-fetch({domain, operation: '...'}) to verify.",
|
|
169
176
|
].join("\n");
|
|
170
177
|
return {
|
|
@@ -181,10 +188,7 @@ export const apiLearnTool = defineTool({
|
|
|
181
188
|
content: [
|
|
182
189
|
{
|
|
183
190
|
type: "text",
|
|
184
|
-
text:
|
|
185
|
-
err instanceof Error
|
|
186
|
-
? err.message
|
|
187
|
-
: `Invalid domain '${domain}'.`,
|
|
191
|
+
text: err instanceof Error ? err.message : `Invalid domain '${domain}'.`,
|
|
188
192
|
},
|
|
189
193
|
],
|
|
190
194
|
details: { error: "invalid_domain", domain },
|
|
@@ -280,8 +284,7 @@ export const apiLearnTool = defineTool({
|
|
|
280
284
|
const opCount = parsed.guide.operations.length;
|
|
281
285
|
const opNames = parsed.guide.operations.map((o) => o.name).join(", ");
|
|
282
286
|
|
|
283
|
-
const warningBlock =
|
|
284
|
-
warnings.length > 0 ? warnings.join("\n") + "\n\n" : "";
|
|
287
|
+
const warningBlock = warnings.length > 0 ? warnings.join("\n") + "\n\n" : "";
|
|
285
288
|
|
|
286
289
|
return {
|
|
287
290
|
content: [
|
|
@@ -295,7 +298,8 @@ export const apiLearnTool = defineTool({
|
|
|
295
298
|
` Verified: ${parsed.guide.verified}\n` +
|
|
296
299
|
`\n` +
|
|
297
300
|
warningBlock +
|
|
298
|
-
`Call api-fetch({domain: "${domain}", operation: "${parsed.guide.operations[0]!.name}"}) to verify
|
|
301
|
+
`Call api-fetch({domain: "${domain}", operation: "${parsed.guide.operations[0]!.name}"}) to verify.` +
|
|
302
|
+
`\n⚠ Direct edits to guide.md are ignored until the next api-learn save (per-session cache). Re-run api-learn to apply changes.`,
|
|
299
303
|
},
|
|
300
304
|
],
|
|
301
305
|
details: {
|
|
@@ -336,13 +340,6 @@ export const apiLearnTool = defineTool({
|
|
|
336
340
|
text = theme.fg("dim", "📝 Worked example");
|
|
337
341
|
}
|
|
338
342
|
|
|
339
|
-
|
|
340
|
-
if (expanded) {
|
|
341
|
-
text += "\n";
|
|
342
|
-
text = renderExpandedText(text, theme, content, 600);
|
|
343
|
-
} else {
|
|
344
|
-
text += `\n${theme.fg("muted", `${content.length} chars (expand)`)}`;
|
|
345
|
-
}
|
|
346
|
-
return new Text(text, 0, 0);
|
|
343
|
+
return new Text(appendFooter(text, expanded, result, theme, 600), 0, 0);
|
|
347
344
|
},
|
|
348
345
|
});
|