@livx.cc/agentx 0.99.136 → 0.99.138
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/dist/cli.js +83 -53
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -14922,19 +14922,21 @@ var McpOAuth = class {
|
|
|
14922
14922
|
const verifier = b64url(randomBytes2(32));
|
|
14923
14923
|
const challenge = b64url(createHash2("sha256").update(verifier).digest());
|
|
14924
14924
|
const state = b64url(randomBytes2(16));
|
|
14925
|
-
const { code, redirectUri } = await this.captureCode(meta
|
|
14925
|
+
const { code, redirectUri } = await this.captureCode(meta, clientId, challenge, state);
|
|
14926
14926
|
const tok = await this.exchange(meta.token_endpoint, {
|
|
14927
14927
|
grant_type: "authorization_code",
|
|
14928
14928
|
code,
|
|
14929
14929
|
redirect_uri: redirectUri,
|
|
14930
14930
|
client_id: clientId,
|
|
14931
|
-
code_verifier: verifier
|
|
14931
|
+
code_verifier: verifier,
|
|
14932
|
+
...meta.resource ? { resource: meta.resource } : {}
|
|
14932
14933
|
});
|
|
14933
14934
|
const bundle = {
|
|
14934
14935
|
access_token: tok.access_token,
|
|
14935
14936
|
refresh_token: tok.refresh_token,
|
|
14936
14937
|
expires_at: tok.expires_in ? this.options.now() + tok.expires_in * 1e3 : void 0,
|
|
14937
14938
|
client_id: clientId,
|
|
14939
|
+
resource: meta.resource,
|
|
14938
14940
|
token_endpoint: meta.token_endpoint
|
|
14939
14941
|
};
|
|
14940
14942
|
const store = this.load();
|
|
@@ -14955,7 +14957,8 @@ var McpOAuth = class {
|
|
|
14955
14957
|
const tok = await this.exchange(b.token_endpoint, {
|
|
14956
14958
|
grant_type: "refresh_token",
|
|
14957
14959
|
refresh_token: b.refresh_token,
|
|
14958
|
-
client_id: b.client_id ?? ""
|
|
14960
|
+
client_id: b.client_id ?? "",
|
|
14961
|
+
...b.resource ? { resource: b.resource } : {}
|
|
14959
14962
|
});
|
|
14960
14963
|
b.access_token = tok.access_token;
|
|
14961
14964
|
if (tok.refresh_token) b.refresh_token = tok.refresh_token;
|
|
@@ -14971,20 +14974,42 @@ var McpOAuth = class {
|
|
|
14971
14974
|
return !!this.load()[serverUrl];
|
|
14972
14975
|
}
|
|
14973
14976
|
// -- internals ----------------------------------------------------------------
|
|
14974
|
-
/** Discover the Authorization Server
|
|
14977
|
+
/** Discover the Authorization Server: RFC 9728 Protected Resource Metadata first, then the server's origin. */
|
|
14975
14978
|
async discover(serverUrl) {
|
|
14976
|
-
const origin = new URL(serverUrl)
|
|
14977
|
-
const
|
|
14978
|
-
|
|
14979
|
+
const { origin, pathname } = new URL(serverUrl);
|
|
14980
|
+
const path = pathname === "/" ? "" : pathname;
|
|
14981
|
+
const prm = await this.firstJson(
|
|
14982
|
+
[`${origin}/.well-known/oauth-protected-resource${path}`, `${origin}/.well-known/oauth-protected-resource`],
|
|
14983
|
+
(m) => m?.authorization_servers?.length
|
|
14984
|
+
);
|
|
14985
|
+
const issuer = prm?.authorization_servers?.[0] ?? origin;
|
|
14986
|
+
const { origin: asOrigin, pathname: asPathname } = new URL(issuer);
|
|
14987
|
+
const asPath = asPathname === "/" ? "" : asPathname.replace(/\/$/, "");
|
|
14988
|
+
const candidates = [.../* @__PURE__ */ new Set([
|
|
14989
|
+
`${asOrigin}/.well-known/oauth-authorization-server${asPath}`,
|
|
14990
|
+
// RFC 8414 path insertion
|
|
14991
|
+
`${asOrigin}${asPath}/.well-known/oauth-authorization-server`,
|
|
14992
|
+
// path-suffix servers
|
|
14993
|
+
`${asOrigin}${asPath}/.well-known/openid-configuration`,
|
|
14994
|
+
`${asOrigin}/.well-known/oauth-authorization-server`,
|
|
14995
|
+
`${asOrigin}/.well-known/openid-configuration`
|
|
14996
|
+
])];
|
|
14997
|
+
const meta = await this.firstJson(candidates, (m) => m?.authorization_endpoint && m?.token_endpoint);
|
|
14998
|
+
if (!meta) throw new Error(`could not discover OAuth metadata for ${serverUrl} (tried ${candidates.join(", ")})`);
|
|
14999
|
+
return { ...meta, resource: prm?.resource, scopes: prm?.scopes_supported };
|
|
15000
|
+
}
|
|
15001
|
+
/** First URL whose JSON body passes `valid`; a failed candidate just moves on to the next. */
|
|
15002
|
+
async firstJson(urls, valid) {
|
|
15003
|
+
for (const u of urls) {
|
|
14979
15004
|
try {
|
|
14980
15005
|
const r = await this.options.fetchImpl(u);
|
|
14981
15006
|
if (!r.ok) continue;
|
|
14982
15007
|
const m = await r.json();
|
|
14983
|
-
if (m
|
|
15008
|
+
if (valid(m)) return m;
|
|
14984
15009
|
} catch {
|
|
14985
15010
|
}
|
|
14986
15011
|
}
|
|
14987
|
-
|
|
15012
|
+
return void 0;
|
|
14988
15013
|
}
|
|
14989
15014
|
/** Dynamic Client Registration (RFC 7591) when no client_id was configured and the server supports it. */
|
|
14990
15015
|
async registerClient(meta, serverUrl) {
|
|
@@ -15002,7 +15027,7 @@ var McpOAuth = class {
|
|
|
15002
15027
|
return j.client_id;
|
|
15003
15028
|
}
|
|
15004
15029
|
/** Start a one-route loopback server, open the browser, and resolve with the returned auth code. */
|
|
15005
|
-
captureCode(
|
|
15030
|
+
captureCode(meta, clientId, challenge, state) {
|
|
15006
15031
|
return new Promise((resolve6, reject) => {
|
|
15007
15032
|
const server = createServer((req, res) => {
|
|
15008
15033
|
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
@@ -15027,14 +15052,16 @@ var McpOAuth = class {
|
|
|
15027
15052
|
server.listen(0, "127.0.0.1", async () => {
|
|
15028
15053
|
const port = server.address().port;
|
|
15029
15054
|
redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
15030
|
-
const auth = new URL(
|
|
15055
|
+
const auth = new URL(meta.authorization_endpoint);
|
|
15031
15056
|
auth.searchParams.set("response_type", "code");
|
|
15032
15057
|
auth.searchParams.set("client_id", clientId);
|
|
15033
15058
|
auth.searchParams.set("redirect_uri", redirectUri);
|
|
15034
15059
|
auth.searchParams.set("code_challenge", challenge);
|
|
15035
15060
|
auth.searchParams.set("code_challenge_method", "S256");
|
|
15036
15061
|
auth.searchParams.set("state", state);
|
|
15037
|
-
|
|
15062
|
+
const scope = this.options.scope ?? meta.scopes?.join(" ");
|
|
15063
|
+
if (scope) auth.searchParams.set("scope", scope);
|
|
15064
|
+
if (meta.resource) auth.searchParams.set("resource", meta.resource);
|
|
15038
15065
|
try {
|
|
15039
15066
|
await this.options.openBrowser(auth.toString());
|
|
15040
15067
|
} catch (e) {
|
|
@@ -23183,49 +23210,52 @@ ${out}
|
|
|
23183
23210
|
const q2 = ask.question.replace(/\s+/g, " ").slice(0, 64);
|
|
23184
23211
|
return bold(yellow(`? ${q2}${ask.question.length > 64 ? "\u2026" : ""} \u2039yes/no\u203A `));
|
|
23185
23212
|
};
|
|
23186
|
-
const result = await readMultiline((cont) =>
|
|
23187
|
-
|
|
23188
|
-
|
|
23189
|
-
|
|
23190
|
-
|
|
23191
|
-
|
|
23192
|
-
|
|
23193
|
-
|
|
23194
|
-
|
|
23195
|
-
|
|
23196
|
-
|
|
23197
|
-
|
|
23198
|
-
|
|
23199
|
-
|
|
23200
|
-
|
|
23201
|
-
|
|
23202
|
-
|
|
23203
|
-
|
|
23204
|
-
|
|
23205
|
-
|
|
23206
|
-
|
|
23207
|
-
|
|
23208
|
-
|
|
23209
|
-
|
|
23210
|
-
|
|
23211
|
-
|
|
23212
|
-
|
|
23213
|
-
|
|
23214
|
-
|
|
23215
|
-
|
|
23216
|
-
|
|
23217
|
-
|
|
23218
|
-
|
|
23213
|
+
const result = await readMultiline((cont) => {
|
|
23214
|
+
dispatchPending = false;
|
|
23215
|
+
return editor.readLine({
|
|
23216
|
+
prompt: cont ? contPrompt : livePrompt,
|
|
23217
|
+
suggest,
|
|
23218
|
+
history,
|
|
23219
|
+
classifyPaste,
|
|
23220
|
+
onEmptyPaste: grabClipboardAttachment,
|
|
23221
|
+
onSubmit: () => {
|
|
23222
|
+
dispatchPending = true;
|
|
23223
|
+
},
|
|
23224
|
+
// claim keys buffered behind the Enter (turn isn't active yet)
|
|
23225
|
+
initial: cont ? void 0 : initial,
|
|
23226
|
+
status: computeFooter,
|
|
23227
|
+
vimMode: cfg.editorMode === "vim",
|
|
23228
|
+
statusTickMs: dx ? 1e3 : void 0,
|
|
23229
|
+
// duplex: animate the running-task footer while idle at the prompt
|
|
23230
|
+
// Esc at the idle prompt with workers running → cancel them (CC-style: Esc stops the work).
|
|
23231
|
+
onEscapeIdle: dx ? () => {
|
|
23232
|
+
const running = [...dx.tasks.values()].filter((t) => t.status === "running");
|
|
23233
|
+
if (!running.length) return false;
|
|
23234
|
+
for (const t of running) err("\r\x1B[0J" + yellow(` \u2298 ${dx.cancelTask(t.id)}`) + "\n");
|
|
23235
|
+
return true;
|
|
23236
|
+
} : void 0,
|
|
23237
|
+
onCyclePosture: cyclePosture,
|
|
23238
|
+
onToggleThinking: toggleReasoning,
|
|
23239
|
+
onToggleVerbose: toggleVerbose,
|
|
23240
|
+
onPickModel: async () => {
|
|
23241
|
+
const picked = await pickModel(work.model);
|
|
23242
|
+
if (picked) setModel(picked);
|
|
23243
|
+
return picked;
|
|
23244
|
+
},
|
|
23245
|
+
onStash: (text) => {
|
|
23246
|
+
inputStash.push(text);
|
|
23247
|
+
err(`${green(" \u2713 stashed")} ${dim(`#${inputStash.length}: ${text.slice(0, 50)}${text.length > 50 ? "\u2026" : ""}`)}
|
|
23219
23248
|
`);
|
|
23220
|
-
|
|
23221
|
-
|
|
23222
|
-
|
|
23223
|
-
|
|
23224
|
-
|
|
23249
|
+
},
|
|
23250
|
+
onUnstash: () => {
|
|
23251
|
+
if (!inputStash.length) return void 0;
|
|
23252
|
+
const t = inputStash.pop();
|
|
23253
|
+
err(dim(` \u2191 unstashed${inputStash.length ? ` (${inputStash.length} left)` : ""}
|
|
23225
23254
|
`));
|
|
23226
|
-
|
|
23227
|
-
|
|
23228
|
-
|
|
23255
|
+
return t;
|
|
23256
|
+
}
|
|
23257
|
+
});
|
|
23258
|
+
});
|
|
23229
23259
|
if (result === null) break;
|
|
23230
23260
|
if (result === REWIND) {
|
|
23231
23261
|
prefill = await rewindToMessage();
|