pi-lean-host 0.7.2 → 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 +3 -2
- 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/core/api-guide-types.ts
CHANGED
|
@@ -19,6 +19,18 @@ import type { Guide } from "./guide-loader.js";
|
|
|
19
19
|
*/
|
|
20
20
|
export const GATHER_ALL_MAX_FALLBACK = 1000;
|
|
21
21
|
|
|
22
|
+
/** A download-class call: a declared `download: true` op, or any call with
|
|
23
|
+
* `saveTo` (explicit caller intent wins — saveTo present ⇒ the download
|
|
24
|
+
* arm runs and parse/errorPath/transform are skipped for this call).
|
|
25
|
+
* The one definition used by both resolve-op (transform-load gate) and
|
|
26
|
+
* the executor (arm dispatch). */
|
|
27
|
+
export function isDownloadClass(
|
|
28
|
+
op: Operation,
|
|
29
|
+
saveTo?: string | undefined,
|
|
30
|
+
): boolean {
|
|
31
|
+
return op.download === true || saveTo !== undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
/**
|
|
23
35
|
* The schema version of the guide recipe format. Enforced by the hard gate:
|
|
24
36
|
* a guide whose schemaVersion is stale (< current) fails to parse and routes
|
|
@@ -119,7 +131,8 @@ export interface OAuth2GrantIssue {
|
|
|
119
131
|
| "noneWithSecret"
|
|
120
132
|
| "ccRequiresSecret"
|
|
121
133
|
| "ccRejectsAuthorizeUrl"
|
|
122
|
-
| "acRequiresAuthorizeUrl"
|
|
134
|
+
| "acRequiresAuthorizeUrl"
|
|
135
|
+
| "authorizeParamsOnCc";
|
|
123
136
|
}
|
|
124
137
|
|
|
125
138
|
/**
|
|
@@ -135,9 +148,15 @@ export function oauth2GrantIssue(fields: {
|
|
|
135
148
|
hasClientSecret: boolean;
|
|
136
149
|
authorizeUrl?: string | undefined;
|
|
137
150
|
tokenEndpointAuthMethod?: OAuth2TokenEndpointAuthMethod | undefined;
|
|
151
|
+
authorizeParams?: Record<string, string> | undefined;
|
|
138
152
|
}): OAuth2GrantIssue | null {
|
|
139
|
-
const {
|
|
140
|
-
|
|
153
|
+
const {
|
|
154
|
+
grant,
|
|
155
|
+
hasClientSecret,
|
|
156
|
+
authorizeUrl,
|
|
157
|
+
tokenEndpointAuthMethod,
|
|
158
|
+
authorizeParams,
|
|
159
|
+
} = fields;
|
|
141
160
|
// tokenEndpointAuthMethod: none sends no client credentials (PKCE public
|
|
142
161
|
// clients) — a declared clientSecret alongside it is a contradiction.
|
|
143
162
|
if (tokenEndpointAuthMethod === "none" && hasClientSecret) {
|
|
@@ -146,12 +165,43 @@ export function oauth2GrantIssue(fields: {
|
|
|
146
165
|
if (grant === "client_credentials") {
|
|
147
166
|
if (!hasClientSecret) return { code: "ccRequiresSecret" };
|
|
148
167
|
if (authorizeUrl !== undefined) return { code: "ccRejectsAuthorizeUrl" };
|
|
168
|
+
if (authorizeParams !== undefined) return { code: "authorizeParamsOnCc" };
|
|
149
169
|
} else if (authorizeUrl === undefined) {
|
|
150
170
|
return { code: "acRequiresAuthorizeUrl" };
|
|
151
171
|
}
|
|
152
172
|
return null;
|
|
153
173
|
}
|
|
154
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Authorize-URL parameters `buildAuthorizeUrl` sets itself — reserved
|
|
177
|
+
* unconditionally. `scope` is a conditional built-in at the URL builder (set
|
|
178
|
+
* only when the auth declares `scopes`), so a collision rule keyed on
|
|
179
|
+
* "parameters it sets" would admit an `authorizeParams: { scope: … }`
|
|
180
|
+
* override on a scope-less guide and silently set a wire scope the
|
|
181
|
+
* granted-scope bookkeeping never records — hence the unconditional
|
|
182
|
+
* reservation. Shared by the guide parser (authoring-time rejection) and
|
|
183
|
+
* `buildAuthorizeUrl` (mint-time throw on every mint path).
|
|
184
|
+
*/
|
|
185
|
+
export const OAUTH2_AUTHORIZE_URL_BUILTINS = [
|
|
186
|
+
"response_type",
|
|
187
|
+
"client_id",
|
|
188
|
+
"redirect_uri",
|
|
189
|
+
"scope",
|
|
190
|
+
"state",
|
|
191
|
+
"code_challenge",
|
|
192
|
+
"code_challenge_method",
|
|
193
|
+
] as const;
|
|
194
|
+
|
|
195
|
+
/** The first `authorizeParams` key colliding with a built-in, or null. */
|
|
196
|
+
export function authorizeParamsBuiltInCollision(
|
|
197
|
+
authorizeParams: Record<string, string>,
|
|
198
|
+
): string | null {
|
|
199
|
+
for (const key of OAUTH2_AUTHORIZE_URL_BUILTINS) {
|
|
200
|
+
if (key in authorizeParams) return key;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
155
205
|
export interface OAuth2Auth {
|
|
156
206
|
kind: "oauth2";
|
|
157
207
|
grant: OAuth2Grant;
|
|
@@ -187,6 +237,14 @@ export interface OAuth2Auth {
|
|
|
187
237
|
tokenEndpointAuthMethod?: OAuth2TokenEndpointAuthMethod;
|
|
188
238
|
/** auth-code only (parser-enforced present iff grant === "authorization_code"). */
|
|
189
239
|
authorizeUrl?: string;
|
|
240
|
+
/**
|
|
241
|
+
* Extra authorize-URL query parameters (authorization_code-only). Exists
|
|
242
|
+
* for mint-time refresh-token availability: Google-class providers issue
|
|
243
|
+
* no refresh token unless the consent requested one (access_type=offline,
|
|
244
|
+
* prompt=consent). Spread into the authorize URL AFTER the built-ins;
|
|
245
|
+
* keys colliding with a built-in are rejected (shared predicate).
|
|
246
|
+
*/
|
|
247
|
+
authorizeParams?: Record<string, string>;
|
|
190
248
|
/** Optional revocation endpoint. */
|
|
191
249
|
revokeUrl?: string;
|
|
192
250
|
}
|
|
@@ -412,6 +470,16 @@ export interface Operation {
|
|
|
412
470
|
* dropped so the agent gets a predictable request, not a silent miss.
|
|
413
471
|
*/
|
|
414
472
|
passthrough?: boolean;
|
|
473
|
+
/**
|
|
474
|
+
* Declares "this op returns a byte stream, not data." Legal only on
|
|
475
|
+
* `restGet` ops and mutually exclusive with `parse`, `transform: true`,
|
|
476
|
+
* `errorPath`, an op-level `pagination` block, and `gatherAllMax` (all
|
|
477
|
+
* parser-enforced) — the download executor skips that machinery by
|
|
478
|
+
* declaration. A flagged op routes through the download arm: the body is
|
|
479
|
+
* streamed to the caller's `saveTo` path and the result is file metadata
|
|
480
|
+
* (`file: { path, bytes, contentType }`), never an inline body.
|
|
481
|
+
*/
|
|
482
|
+
download?: boolean;
|
|
415
483
|
}
|
|
416
484
|
|
|
417
485
|
// ═══════════════════════════════════════════════════════════════════
|
package/core/api-toggle.ts
CHANGED
|
@@ -189,7 +189,9 @@ function handleStatusSubcommand(
|
|
|
189
189
|
} else {
|
|
190
190
|
state = "off";
|
|
191
191
|
}
|
|
192
|
-
const learnFlag = learnOn
|
|
192
|
+
const learnFlag = learnOn
|
|
193
|
+
? `✅ on (${learnToolNames()} available)`
|
|
194
|
+
: "❌ off";
|
|
193
195
|
|
|
194
196
|
const allGuides = loadAllGuides();
|
|
195
197
|
const guideCount = Object.keys(allGuides.guides).length;
|
|
@@ -446,8 +448,9 @@ export default function initApiToggle(pi: ExtensionAPI): void {
|
|
|
446
448
|
|
|
447
449
|
case "off": {
|
|
448
450
|
if (
|
|
449
|
-
!refuseOnAllowlist(
|
|
450
|
-
|
|
451
|
+
!refuseOnAllowlist(
|
|
452
|
+
ctx,
|
|
453
|
+
() => apiToolset.disable(pi, ctx.sessionManager), // cascades learn off via requires
|
|
451
454
|
)
|
|
452
455
|
)
|
|
453
456
|
return;
|
package/core/auth.ts
CHANGED
|
@@ -245,7 +245,11 @@ export function authStatusLine(
|
|
|
245
245
|
const headerRes = resolveSecretHeaders(auth, domain);
|
|
246
246
|
const queryRes = resolveSecretQueryParams(auth, domain);
|
|
247
247
|
const pathRes = resolveSecretPathParams(auth, domain);
|
|
248
|
-
const absentRequired = missingRequiredSecrets(
|
|
248
|
+
const absentRequired = missingRequiredSecrets(
|
|
249
|
+
headerRes,
|
|
250
|
+
queryRes,
|
|
251
|
+
pathRes,
|
|
252
|
+
);
|
|
249
253
|
if (absentRequired.length > 0) {
|
|
250
254
|
return (
|
|
251
255
|
`🔑 auth: requires ${absentRequired.join(", ")} — not provisioned. ` +
|
|
@@ -1011,6 +1015,11 @@ export interface SyntheticOAuth2Fields {
|
|
|
1011
1015
|
authorizeUrl?: string;
|
|
1012
1016
|
scopes?: string[];
|
|
1013
1017
|
tokenEndpointAuthMethod?: OAuth2TokenEndpointAuthMethod;
|
|
1018
|
+
/**
|
|
1019
|
+
* Extra authorize-URL query parameters (authorization_code-only) — mint-time
|
|
1020
|
+
* refresh-token availability (e.g. access_type=offline, prompt=consent).
|
|
1021
|
+
*/
|
|
1022
|
+
authorizeParams?: Record<string, string>;
|
|
1014
1023
|
}
|
|
1015
1024
|
|
|
1016
1025
|
/**
|
|
@@ -1057,6 +1066,7 @@ export function buildSyntheticOAuth2Auth(f: SyntheticOAuth2Fields): OAuth2Auth {
|
|
|
1057
1066
|
hasClientSecret: clientSecret !== undefined,
|
|
1058
1067
|
authorizeUrl: f.authorizeUrl,
|
|
1059
1068
|
tokenEndpointAuthMethod: f.tokenEndpointAuthMethod,
|
|
1069
|
+
authorizeParams: f.authorizeParams,
|
|
1060
1070
|
});
|
|
1061
1071
|
if (issue) {
|
|
1062
1072
|
throw new Error(syntheticGrantIssueMessage(issue.code));
|
|
@@ -1079,6 +1089,9 @@ export function buildSyntheticOAuth2Auth(f: SyntheticOAuth2Fields): OAuth2Auth {
|
|
|
1079
1089
|
if (f.authorizeUrl !== undefined) {
|
|
1080
1090
|
auth.authorizeUrl = f.authorizeUrl;
|
|
1081
1091
|
}
|
|
1092
|
+
if (f.authorizeParams !== undefined) {
|
|
1093
|
+
auth.authorizeParams = f.authorizeParams;
|
|
1094
|
+
}
|
|
1082
1095
|
return auth;
|
|
1083
1096
|
}
|
|
1084
1097
|
|
|
@@ -1094,6 +1107,8 @@ function syntheticGrantIssueMessage(code: OAuth2GrantIssue["code"]): string {
|
|
|
1094
1107
|
return "--authorize-url is only valid with --grant authorization_code (client_credentials is server-to-server).";
|
|
1095
1108
|
case "acRequiresAuthorizeUrl":
|
|
1096
1109
|
return "grant authorization_code requires --authorize-url (the provider's authorization endpoint).";
|
|
1110
|
+
case "authorizeParamsOnCc":
|
|
1111
|
+
return "--authorize-params is authorization_code-only (it customizes the consent-page URL — client_credentials has no authorize URL).";
|
|
1097
1112
|
}
|
|
1098
1113
|
}
|
|
1099
1114
|
|
package/core/guide-catalog.ts
CHANGED
|
@@ -142,7 +142,8 @@ export function loadApiGuidesFromDir(
|
|
|
142
142
|
name,
|
|
143
143
|
{
|
|
144
144
|
field: "shortName",
|
|
145
|
-
expected:
|
|
145
|
+
expected:
|
|
146
|
+
"a shortName that slugs to a non-empty safe directory name",
|
|
146
147
|
found: `"${guide.shortName}"`,
|
|
147
148
|
fix: "Set a valid shortName (lowercase letters, digits, and '-') in the guide's frontmatter.",
|
|
148
149
|
},
|
|
@@ -324,7 +325,9 @@ export function formatApiGuideCatalog(loaded: LoadedApiGuides): string {
|
|
|
324
325
|
}
|
|
325
326
|
for (const { name, guide } of orgless) {
|
|
326
327
|
const domains =
|
|
327
|
-
guide.domains && guide.domains.length > 0
|
|
328
|
+
guide.domains && guide.domains.length > 0
|
|
329
|
+
? guide.domains.join(", ")
|
|
330
|
+
: name;
|
|
328
331
|
lines.push(
|
|
329
332
|
` ${guide.icon} ${guide.shortName} — ${domains} (verified ${guide.verified}, ${guide.operations.length} ops)`,
|
|
330
333
|
);
|
|
@@ -338,7 +341,10 @@ export function formatApiGuideCatalog(loaded: LoadedApiGuides): string {
|
|
|
338
341
|
// render naturally instead of being inlined into the summary line.
|
|
339
342
|
if (mal.error.fix) lines.push(` fix: ${mal.error.fix}`);
|
|
340
343
|
}
|
|
341
|
-
if (
|
|
344
|
+
if (
|
|
345
|
+
Object.keys(loaded.guides).length === 0 &&
|
|
346
|
+
loaded.malformed.length === 0
|
|
347
|
+
) {
|
|
342
348
|
lines.push(" (no guides — call api-learn({domain, dir}) to author one)");
|
|
343
349
|
}
|
|
344
350
|
lines.push("");
|
package/core/helpers-command.ts
CHANGED
|
@@ -79,7 +79,9 @@ export async function handleHelpersSubcommand(
|
|
|
79
79
|
if (source === null) {
|
|
80
80
|
const all = getAllHelpers();
|
|
81
81
|
const known =
|
|
82
|
-
all.length > 0
|
|
82
|
+
all.length > 0
|
|
83
|
+
? ` Known helpers: ${all.join(", ")}.`
|
|
84
|
+
: " No helpers found.";
|
|
83
85
|
ctx.ui.notify(
|
|
84
86
|
`No helper for '${domain}'.${known}\n\n` +
|
|
85
87
|
`Helpers live alongside guides at api-guides/<dirName>/helper.ts.\n` +
|