pi-lean-host 0.7.1 → 0.8.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/CHANGELOG.md +146 -0
- package/README.md +229 -235
- package/core/api-guide-types.ts +71 -3
- package/core/api-toggle.ts +6 -3
- package/core/auth.ts +16 -1
- package/core/guide-catalog.ts +9 -3
- package/core/helpers-command.ts +3 -1
- package/core/helpers.ts +458 -17
- package/core/oauth-command.ts +77 -6
- package/core/oauth-flow.ts +31 -18
- package/core/parse-api-guide.ts +198 -18
- package/core/resolve-op.ts +50 -6
- package/core/response-spill.ts +4 -1
- package/core/secrets-store.ts +3 -1
- package/core/staging.ts +3 -3
- package/core/status-hint.ts +2 -3
- package/core/transport.ts +803 -171
- package/core/verify-command.ts +117 -62
- package/docs/migration-v1.md +19 -20
- package/package.json +4 -3
- package/tools/api-fetch.ts +96 -22
- package/tools/api-guide.ts +10 -1
- package/tools/api-learn.ts +6 -2
- package/tools/api-probe.ts +26 -10
- package/tools/api-scaffold.ts +21 -5
- package/tools/api-store.ts +3 -3
- package/tools/oauth-mint.ts +22 -4
package/tools/api-probe.ts
CHANGED
|
@@ -313,7 +313,9 @@ function flatToStaticKeyAuth(
|
|
|
313
313
|
};
|
|
314
314
|
}
|
|
315
315
|
const secretQueryRefs: Record<string, SecretRef> = {};
|
|
316
|
-
for (const [param, secretName] of Object.entries(
|
|
316
|
+
for (const [param, secretName] of Object.entries(
|
|
317
|
+
auth.secretQueryRefs ?? {},
|
|
318
|
+
)) {
|
|
317
319
|
secretQueryRefs[param] = { secret: secretName };
|
|
318
320
|
}
|
|
319
321
|
const secretPathRefs: Record<string, SecretRef> = {};
|
|
@@ -450,7 +452,8 @@ async function resolveProbeAuth(
|
|
|
450
452
|
if (bearer) {
|
|
451
453
|
tokenHeader["authorization"] = bearer;
|
|
452
454
|
rawTokenValue = result.secretValues[0] ?? "";
|
|
453
|
-
} else
|
|
455
|
+
} else
|
|
456
|
+
tokenNote = "oauth2 mint succeeded but produced no bearer header";
|
|
454
457
|
} catch (e) {
|
|
455
458
|
tokenNote = e instanceof Error ? e.message : "oauth2 mint failed";
|
|
456
459
|
}
|
|
@@ -488,7 +491,9 @@ async function resolveProbeAuth(
|
|
|
488
491
|
hasAuthBlock: true,
|
|
489
492
|
headers,
|
|
490
493
|
queryParams: queryRes.queryParams,
|
|
491
|
-
secretHeaderNames: new Set(
|
|
494
|
+
secretHeaderNames: new Set(
|
|
495
|
+
Object.keys(headers).map((h) => h.toLowerCase()),
|
|
496
|
+
),
|
|
492
497
|
secretQueryParamNames: new Set(Object.keys(queryRes.queryParams)),
|
|
493
498
|
pathSecretParams: pathRes.values,
|
|
494
499
|
pathSecretNames: Object.fromEntries(
|
|
@@ -700,7 +705,8 @@ async function fetchOne(
|
|
|
700
705
|
// Redaction closure (not raw values): keeps the
|
|
701
706
|
// transport's option surface value-agnostic; used
|
|
702
707
|
// on cross-domain redirect hops.
|
|
703
|
-
redactPathSecret: (u: string) =>
|
|
708
|
+
redactPathSecret: (u: string) =>
|
|
709
|
+
redactSecretPathValues(u, pathValues),
|
|
704
710
|
}
|
|
705
711
|
: {}),
|
|
706
712
|
}
|
|
@@ -881,7 +887,8 @@ export function emitDraft(
|
|
|
881
887
|
" # unverified — pagination params are guessed from response keys; confirm the API accepts them",
|
|
882
888
|
);
|
|
883
889
|
const markers = shape.paginationMarkers;
|
|
884
|
-
const isPageStyle =
|
|
890
|
+
const isPageStyle =
|
|
891
|
+
markers.includes("page") || markers.includes("per_page");
|
|
885
892
|
const style = isPageStyle ? "page" : "offset-limit";
|
|
886
893
|
// `start` marker ⇒ 1-based row offset (CMC, GBIF) — emit base: 1 so the
|
|
887
894
|
// first page starts at 1, not the 0 default. `offset` ⇒ 0-based, no base.
|
|
@@ -1024,14 +1031,18 @@ export const apiProbeTool = defineTool({
|
|
|
1024
1031
|
Type.Object(
|
|
1025
1032
|
{
|
|
1026
1033
|
secretRefs: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
1027
|
-
secretQueryRefs: Type.Optional(
|
|
1034
|
+
secretQueryRefs: Type.Optional(
|
|
1035
|
+
Type.Record(Type.String(), Type.String()),
|
|
1036
|
+
),
|
|
1028
1037
|
secretPathRefs: Type.Optional(
|
|
1029
1038
|
Type.Record(Type.String(), Type.String(), {
|
|
1030
1039
|
description:
|
|
1031
1040
|
"Path token → secret name for token-in-path APIs (e.g. {token: 'bot_token'} for /bot{token}/getMe). The store value fills {token}; agent-supplied values for the name are dropped and the token is redacted from surfaced URLs.",
|
|
1032
1041
|
}),
|
|
1033
1042
|
),
|
|
1034
|
-
headerPrefixes: Type.Optional(
|
|
1043
|
+
headerPrefixes: Type.Optional(
|
|
1044
|
+
Type.Record(Type.String(), Type.String()),
|
|
1045
|
+
),
|
|
1035
1046
|
useTokenStore: Type.Optional(
|
|
1036
1047
|
Type.Boolean({
|
|
1037
1048
|
description:
|
|
@@ -1040,7 +1051,10 @@ export const apiProbeTool = defineTool({
|
|
|
1040
1051
|
),
|
|
1041
1052
|
grant: Type.Optional(
|
|
1042
1053
|
Type.Union(
|
|
1043
|
-
[
|
|
1054
|
+
[
|
|
1055
|
+
Type.Literal("client_credentials"),
|
|
1056
|
+
Type.Literal("authorization_code"),
|
|
1057
|
+
],
|
|
1044
1058
|
{
|
|
1045
1059
|
description:
|
|
1046
1060
|
"The token slot's grant — token slots are keyed (domain, grant, tokenUrl). Required with useTokenStore; the mint arm always uses client_credentials.",
|
|
@@ -1061,7 +1075,8 @@ export const apiProbeTool = defineTool({
|
|
|
1061
1075
|
),
|
|
1062
1076
|
clientSecret: Type.Optional(
|
|
1063
1077
|
Type.String({
|
|
1064
|
-
description:
|
|
1078
|
+
description:
|
|
1079
|
+
"Mint-on-demand: secrets-store NAME of the client secret.",
|
|
1065
1080
|
}),
|
|
1066
1081
|
),
|
|
1067
1082
|
scopes: Type.Optional(
|
|
@@ -1203,7 +1218,8 @@ export function formatProbeResult(r: ProbeResult): string {
|
|
|
1203
1218
|
lines.push(` shape: ${s.topLevel}`);
|
|
1204
1219
|
if (s.keys.length > 0) lines.push(` keys: ${s.keys.join(", ")}`);
|
|
1205
1220
|
lines.push(` via: ${s.suggestedVia}`);
|
|
1206
|
-
if (s.suggestedItemsPath)
|
|
1221
|
+
if (s.suggestedItemsPath)
|
|
1222
|
+
lines.push(` itemsPath: ${s.suggestedItemsPath}`);
|
|
1207
1223
|
if (s.arrayLen > 0) lines.push(` arrayLen: ${s.arrayLen}`);
|
|
1208
1224
|
if (s.paginationMarkers.length > 0)
|
|
1209
1225
|
lines.push(` pagination markers: ${s.paginationMarkers.join(", ")}`);
|
package/tools/api-scaffold.ts
CHANGED
|
@@ -112,7 +112,9 @@ function mergeVerifySentinels(
|
|
|
112
112
|
// Path tokens owned by secretPathRefs are store-filled — no sentinel.
|
|
113
113
|
const secretPathTokens = secretPathTokenNames(guide.auth);
|
|
114
114
|
for (const op of guide.operations) {
|
|
115
|
-
const sentinels = renderForSentinels(
|
|
115
|
+
const sentinels = renderForSentinels(
|
|
116
|
+
unsatisfiable(op, {}, secretPathTokens),
|
|
117
|
+
);
|
|
116
118
|
if (sentinels.length === 0) continue; // runnable op → no entry
|
|
117
119
|
const entry = merged[op.name] ?? {};
|
|
118
120
|
for (const p of sentinels) {
|
|
@@ -197,7 +199,10 @@ export const apiScaffoldTool = defineTool({
|
|
|
197
199
|
content: [
|
|
198
200
|
{
|
|
199
201
|
type: "text",
|
|
200
|
-
text:
|
|
202
|
+
text:
|
|
203
|
+
err instanceof Error
|
|
204
|
+
? err.message
|
|
205
|
+
: `Invalid domain '${domain}'.`,
|
|
201
206
|
},
|
|
202
207
|
],
|
|
203
208
|
details: { error: "invalid_domain", domain },
|
|
@@ -268,7 +273,12 @@ export const apiScaffoldTool = defineTool({
|
|
|
268
273
|
` api-scaffold never overwrites a staged sibling. Delete the file from /tmp first, then re-call for a fresh scaffold.`,
|
|
269
274
|
},
|
|
270
275
|
],
|
|
271
|
-
details: {
|
|
276
|
+
details: {
|
|
277
|
+
error: "refuse_overwrite",
|
|
278
|
+
domain,
|
|
279
|
+
dirName,
|
|
280
|
+
file: "helper.ts",
|
|
281
|
+
},
|
|
272
282
|
};
|
|
273
283
|
}
|
|
274
284
|
if (verify && existsSync(join(stagedDir, "verify.json"))) {
|
|
@@ -324,7 +334,11 @@ export const apiScaffoldTool = defineTool({
|
|
|
324
334
|
if (verify) {
|
|
325
335
|
verifyPath = join(stagedDir, "verify.json");
|
|
326
336
|
const merged = mergeVerifySentinels(guide, existingVerify);
|
|
327
|
-
writeFileSync(
|
|
337
|
+
writeFileSync(
|
|
338
|
+
verifyPath,
|
|
339
|
+
`${JSON.stringify(merged, null, 2)}\n`,
|
|
340
|
+
"utf-8",
|
|
341
|
+
);
|
|
328
342
|
written.push(verifyPath);
|
|
329
343
|
}
|
|
330
344
|
|
|
@@ -358,7 +372,9 @@ export const apiScaffoldTool = defineTool({
|
|
|
358
372
|
},
|
|
359
373
|
|
|
360
374
|
renderCall(args, theme, _context) {
|
|
361
|
-
const parts: string[] = [
|
|
375
|
+
const parts: string[] = [
|
|
376
|
+
theme.fg("toolTitle", theme.bold("api-scaffold ")),
|
|
377
|
+
];
|
|
362
378
|
parts.push(theme.fg("accent", `"${args.domain}"`));
|
|
363
379
|
if (args.verify && args.helper) parts.push(theme.fg("dim", "🛠"));
|
|
364
380
|
else if (args.verify) parts.push(theme.fg("dim", "🔑"));
|
package/tools/api-store.ts
CHANGED
|
@@ -329,15 +329,15 @@ export const apiStoreTool = defineTool({
|
|
|
329
329
|
content: [
|
|
330
330
|
{
|
|
331
331
|
type: "text",
|
|
332
|
-
text:
|
|
333
|
-
"api-store: store inspection is learn mode only — run /api learn first.",
|
|
332
|
+
text: "api-store: store inspection is learn mode only — run /api learn first.",
|
|
334
333
|
},
|
|
335
334
|
],
|
|
336
335
|
details: { error: "learn_mode_only" },
|
|
337
336
|
};
|
|
338
337
|
}
|
|
339
338
|
|
|
340
|
-
if (domain)
|
|
339
|
+
if (domain)
|
|
340
|
+
return finishDomainReport(resolveProvisionedParentDomain(domain));
|
|
341
341
|
if (apiHost)
|
|
342
342
|
return finishDomainReport(
|
|
343
343
|
resolveProvisionedParentDomain(hostnameOf(apiHost)),
|
package/tools/oauth-mint.ts
CHANGED
|
@@ -148,6 +148,12 @@ export const oauthMintTool = defineTool({
|
|
|
148
148
|
"Redirect URI registered in the user's OAuth app (authorization_code only; default http://127.0.0.1/callback). Some providers constrain the spelling (Twitch: https or localhost; OSM: unencrypted must be 127.0.0.1) — supply the user's registered URI when it differs from the default. Proposed in the combined endpoint-confirm dialog; the human can change it inline there.",
|
|
149
149
|
}),
|
|
150
150
|
),
|
|
151
|
+
authorizeParams: Type.Optional(
|
|
152
|
+
Type.Record(Type.String(), Type.String(), {
|
|
153
|
+
description:
|
|
154
|
+
"Extra authorize-URL query parameters (authorization_code only) — e.g. { access_type: 'offline', prompt: 'consent' } so the provider issues a refresh token. Values are non-secret URL parameters; keys colliding with built-ins (response_type, client_id, redirect_uri, scope, state, code_challenge, code_challenge_method) are rejected.",
|
|
155
|
+
}),
|
|
156
|
+
),
|
|
151
157
|
}),
|
|
152
158
|
|
|
153
159
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
@@ -164,6 +170,7 @@ export const oauthMintTool = defineTool({
|
|
|
164
170
|
| "client_secret_post"
|
|
165
171
|
| "none";
|
|
166
172
|
redirectUri?: string;
|
|
173
|
+
authorizeParams?: Record<string, string>;
|
|
167
174
|
};
|
|
168
175
|
|
|
169
176
|
// H1 — one guard at the top; no degraded half-flow.
|
|
@@ -181,10 +188,15 @@ export const oauthMintTool = defineTool({
|
|
|
181
188
|
clientId: p.clientId,
|
|
182
189
|
...(p.clientSecret === undefined ? {} : { clientSecret: p.clientSecret }),
|
|
183
190
|
...(p.authorizeUrl === undefined ? {} : { authorizeUrl: p.authorizeUrl }),
|
|
184
|
-
...(p.scopes === undefined
|
|
191
|
+
...(p.scopes === undefined
|
|
192
|
+
? {}
|
|
193
|
+
: { scopes: p.scopes.map((s) => s.name) }),
|
|
185
194
|
...(p.tokenEndpointAuthMethod === undefined
|
|
186
195
|
? {}
|
|
187
196
|
: { tokenEndpointAuthMethod: p.tokenEndpointAuthMethod }),
|
|
197
|
+
...(p.authorizeParams === undefined
|
|
198
|
+
? {}
|
|
199
|
+
: { authorizeParams: p.authorizeParams }),
|
|
188
200
|
};
|
|
189
201
|
buildSyntheticOAuth2Auth(fields);
|
|
190
202
|
|
|
@@ -229,7 +241,9 @@ export const oauthMintTool = defineTool({
|
|
|
229
241
|
if (entered === undefined) throw cancelledError(p.domain, fields);
|
|
230
242
|
if (entered !== "") redirectUri = entered;
|
|
231
243
|
}
|
|
232
|
-
} else if (
|
|
244
|
+
} else if (
|
|
245
|
+
!(await confirmTokenUrl(ctx, storeDomain, p.tokenUrl, p.clientId))
|
|
246
|
+
)
|
|
233
247
|
throw cancelledError(p.domain, fields);
|
|
234
248
|
|
|
235
249
|
// Scopes checklist — the human's affirmative grant. No scopes → skip.
|
|
@@ -241,7 +255,9 @@ export const oauthMintTool = defineTool({
|
|
|
241
255
|
p.scopes.map((s) => ({
|
|
242
256
|
value: s.name,
|
|
243
257
|
label: s.name,
|
|
244
|
-
...(s.description === undefined
|
|
258
|
+
...(s.description === undefined
|
|
259
|
+
? {}
|
|
260
|
+
: { description: s.description }),
|
|
245
261
|
})),
|
|
246
262
|
);
|
|
247
263
|
if (picked === undefined) throw cancelledError(p.domain, fields);
|
|
@@ -271,7 +287,9 @@ export const oauthMintTool = defineTool({
|
|
|
271
287
|
} else {
|
|
272
288
|
// Prints the authorize URL + paste prompt (retry loop inside);
|
|
273
289
|
// cancel lands in the OAuthTokenMissingError handler below.
|
|
274
|
-
await mintAuthCodeToken(finalSynthetic, storeDomain, ctx, {
|
|
290
|
+
await mintAuthCodeToken(finalSynthetic, storeDomain, ctx, {
|
|
291
|
+
redirectUri,
|
|
292
|
+
});
|
|
275
293
|
}
|
|
276
294
|
} catch (err) {
|
|
277
295
|
if (err instanceof OAuthTokenMissingError)
|