@inworld/cli 2.0.0 → 2.2.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/dist/cli/inworld-mcp.js +370 -70
- package/dist/index.js +603 -248
- package/package.json +1 -1
package/dist/cli/inworld-mcp.js
CHANGED
|
@@ -62525,7 +62525,7 @@ var init_package = __esm({
|
|
|
62525
62525
|
"package.json"() {
|
|
62526
62526
|
package_default = {
|
|
62527
62527
|
name: "@inworld/cli",
|
|
62528
|
-
version: "2.
|
|
62528
|
+
version: "2.2.0",
|
|
62529
62529
|
type: "module",
|
|
62530
62530
|
main: "dist/index.js",
|
|
62531
62531
|
bin: {
|
|
@@ -62717,7 +62717,7 @@ function gotrueErrorMessage(data, fallback) {
|
|
|
62717
62717
|
}
|
|
62718
62718
|
return fallback;
|
|
62719
62719
|
}
|
|
62720
|
-
async function gotrueToken(authUrl, grantType, body) {
|
|
62720
|
+
async function gotrueToken(authUrl, grantType, body, signal) {
|
|
62721
62721
|
const url = `${authUrl}/token?grant_type=${grantType}`;
|
|
62722
62722
|
const res = await fetch(url, {
|
|
62723
62723
|
method: "POST",
|
|
@@ -62725,7 +62725,8 @@ async function gotrueToken(authUrl, grantType, body) {
|
|
|
62725
62725
|
"Content-Type": "application/json",
|
|
62726
62726
|
[CLIENT_INFO_HEADER]: CLIENT_INFO
|
|
62727
62727
|
},
|
|
62728
|
-
body: JSON.stringify(body)
|
|
62728
|
+
body: JSON.stringify(body),
|
|
62729
|
+
signal
|
|
62729
62730
|
});
|
|
62730
62731
|
const text = await res.text();
|
|
62731
62732
|
let data = {};
|
|
@@ -62819,23 +62820,55 @@ async function startLoopbackReceiver(options) {
|
|
|
62819
62820
|
settle = { resolve: resolve2, reject };
|
|
62820
62821
|
});
|
|
62821
62822
|
let claimed = false;
|
|
62822
|
-
|
|
62823
|
+
let ended = false;
|
|
62824
|
+
let failure2;
|
|
62825
|
+
const redemption = new AbortController();
|
|
62826
|
+
const end = (outcome) => {
|
|
62827
|
+
if (ended) return false;
|
|
62828
|
+
ended = true;
|
|
62823
62829
|
claimed = true;
|
|
62824
|
-
|
|
62830
|
+
if (outcome instanceof Error) {
|
|
62831
|
+
failure2 = outcome;
|
|
62832
|
+
redemption.abort();
|
|
62833
|
+
settle.reject(outcome);
|
|
62834
|
+
} else {
|
|
62835
|
+
settle.resolve(outcome);
|
|
62836
|
+
}
|
|
62837
|
+
return true;
|
|
62838
|
+
};
|
|
62839
|
+
const finish = (redeem, answer = () => {
|
|
62840
|
+
}) => {
|
|
62841
|
+
claimed = true;
|
|
62842
|
+
redeem(redemption.signal).then(
|
|
62843
|
+
// A result after cancel or the timeout is dropped. Ending closes the
|
|
62844
|
+
// listener first, so a browser still waiting gets no result page: its
|
|
62845
|
+
// connection is reset, and `answer` finds it gone.
|
|
62825
62846
|
(tokens) => {
|
|
62826
|
-
|
|
62827
|
-
|
|
62828
|
-
settle.resolve(tokens);
|
|
62847
|
+
end(tokens);
|
|
62848
|
+
answer(signInResultUrl(options.pageUrl, failure2?.message));
|
|
62829
62849
|
},
|
|
62830
62850
|
(error2) => {
|
|
62831
|
-
|
|
62832
|
-
|
|
62833
|
-
});
|
|
62834
|
-
res.end();
|
|
62835
|
-
settle.reject(error2);
|
|
62851
|
+
end(error2);
|
|
62852
|
+
answer(signInResultUrl(options.pageUrl, failure2?.message));
|
|
62836
62853
|
}
|
|
62837
62854
|
);
|
|
62838
62855
|
};
|
|
62856
|
+
const answerWith = (res, status) => {
|
|
62857
|
+
return (location) => {
|
|
62858
|
+
if (res.headersSent || res.destroyed) return;
|
|
62859
|
+
res.writeHead(status, { Location: location });
|
|
62860
|
+
res.end();
|
|
62861
|
+
};
|
|
62862
|
+
};
|
|
62863
|
+
const redeemRedirect = (params) => {
|
|
62864
|
+
const error2 = params.get("error_description") ?? params.get("error");
|
|
62865
|
+
const code = params.get("code");
|
|
62866
|
+
if (error2 || !code) {
|
|
62867
|
+
const msg = error2 ?? "No authorization code in the redirect.";
|
|
62868
|
+
return () => Promise.reject(new Error(msg));
|
|
62869
|
+
}
|
|
62870
|
+
return (signal) => options.redeemCode(code, signal);
|
|
62871
|
+
};
|
|
62839
62872
|
const handler = (req, res) => {
|
|
62840
62873
|
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
62841
62874
|
if (url.pathname !== "/") {
|
|
@@ -62851,14 +62884,7 @@ async function startLoopbackReceiver(options) {
|
|
|
62851
62884
|
res.writeHead(400).end("Unknown sign-in.");
|
|
62852
62885
|
return;
|
|
62853
62886
|
}
|
|
62854
|
-
|
|
62855
|
-
const code = url.searchParams.get("code");
|
|
62856
|
-
if (error2 || !code) {
|
|
62857
|
-
const msg = error2 ?? "No authorization code in the redirect.";
|
|
62858
|
-
finish(res, 302, () => Promise.reject(new Error(msg)));
|
|
62859
|
-
return;
|
|
62860
|
-
}
|
|
62861
|
-
finish(res, 302, () => options.redeemCode(code));
|
|
62887
|
+
finish(redeemRedirect(url.searchParams), answerWith(res, 302));
|
|
62862
62888
|
return;
|
|
62863
62889
|
}
|
|
62864
62890
|
if (req.method === "POST") {
|
|
@@ -62881,7 +62907,10 @@ async function startLoopbackReceiver(options) {
|
|
|
62881
62907
|
res.writeHead(400).end("Missing refresh_token.");
|
|
62882
62908
|
return;
|
|
62883
62909
|
}
|
|
62884
|
-
finish(
|
|
62910
|
+
finish(
|
|
62911
|
+
(signal) => options.redeemRefreshToken(refreshToken, signal),
|
|
62912
|
+
answerWith(res, 303)
|
|
62913
|
+
);
|
|
62885
62914
|
},
|
|
62886
62915
|
() => {
|
|
62887
62916
|
if (!res.headersSent) res.writeHead(413).end();
|
|
@@ -62897,23 +62926,42 @@ async function startLoopbackReceiver(options) {
|
|
|
62897
62926
|
server.listen(options.port, "127.0.0.1", () => resolve2());
|
|
62898
62927
|
});
|
|
62899
62928
|
const { port } = server.address();
|
|
62900
|
-
const timer = setTimeout(
|
|
62901
|
-
(
|
|
62929
|
+
const timer = setTimeout(() => {
|
|
62930
|
+
end(
|
|
62902
62931
|
new Error(
|
|
62903
62932
|
`Sign-in timed out after ${OAUTH_SIGN_IN_TIMEOUT_MS / 6e4} minutes. Run the login again.`
|
|
62904
62933
|
)
|
|
62905
|
-
)
|
|
62906
|
-
|
|
62907
|
-
);
|
|
62934
|
+
);
|
|
62935
|
+
}, OAUTH_SIGN_IN_TIMEOUT_MS);
|
|
62908
62936
|
timer.unref();
|
|
62909
|
-
const
|
|
62910
|
-
|
|
62937
|
+
const loopback = new URL(`http://127.0.0.1:${port}/`);
|
|
62938
|
+
loopback.searchParams.set("state", state);
|
|
62939
|
+
const pasteRedirect = (address) => {
|
|
62940
|
+
if (claimed) return false;
|
|
62941
|
+
let url;
|
|
62942
|
+
try {
|
|
62943
|
+
url = new URL(address.trim());
|
|
62944
|
+
} catch {
|
|
62945
|
+
return false;
|
|
62946
|
+
}
|
|
62947
|
+
if (url.origin !== loopback.origin || url.pathname !== loopback.pathname || !sameSecret(url.searchParams.get("state"), state) || !(url.searchParams.get("code") || url.searchParams.get("error") || url.searchParams.get("error_description"))) {
|
|
62948
|
+
return false;
|
|
62949
|
+
}
|
|
62950
|
+
finish(redeemRedirect(url.searchParams));
|
|
62951
|
+
return true;
|
|
62952
|
+
};
|
|
62953
|
+
const cancel = () => {
|
|
62954
|
+
end(new Error("Sign-in cancelled."));
|
|
62955
|
+
};
|
|
62911
62956
|
return {
|
|
62912
62957
|
state,
|
|
62913
62958
|
port,
|
|
62914
|
-
redirectTo:
|
|
62959
|
+
redirectTo: loopback.toString(),
|
|
62915
62960
|
done,
|
|
62961
|
+
pasteRedirect,
|
|
62962
|
+
cancel,
|
|
62916
62963
|
close: () => {
|
|
62964
|
+
claimed = true;
|
|
62917
62965
|
clearTimeout(timer);
|
|
62918
62966
|
server.close();
|
|
62919
62967
|
server.closeAllConnections?.();
|
|
@@ -62925,13 +62973,18 @@ async function startBrowserSignIn(options) {
|
|
|
62925
62973
|
const receiver = await startLoopbackReceiver({
|
|
62926
62974
|
port: options.port ?? gotrueCallbackPort(),
|
|
62927
62975
|
pageUrl: options.pageUrl,
|
|
62928
|
-
redeemCode: (code) => gotrueToken(
|
|
62929
|
-
|
|
62930
|
-
|
|
62931
|
-
|
|
62932
|
-
|
|
62933
|
-
|
|
62934
|
-
|
|
62976
|
+
redeemCode: (code, signal) => gotrueToken(
|
|
62977
|
+
options.authUrl,
|
|
62978
|
+
"pkce",
|
|
62979
|
+
{ auth_code: code, code_verifier: verifier },
|
|
62980
|
+
signal
|
|
62981
|
+
),
|
|
62982
|
+
redeemRefreshToken: (refreshToken, signal) => gotrueToken(
|
|
62983
|
+
options.authUrl,
|
|
62984
|
+
"refresh_token",
|
|
62985
|
+
{ refresh_token: refreshToken },
|
|
62986
|
+
signal
|
|
62987
|
+
)
|
|
62935
62988
|
});
|
|
62936
62989
|
let url;
|
|
62937
62990
|
if (options.oauthProvider) {
|
|
@@ -62949,7 +63002,12 @@ async function startBrowserSignIn(options) {
|
|
|
62949
63002
|
page.searchParams.set("state", receiver.state);
|
|
62950
63003
|
url = page.toString();
|
|
62951
63004
|
}
|
|
62952
|
-
return {
|
|
63005
|
+
return {
|
|
63006
|
+
url,
|
|
63007
|
+
done: receiver.done.finally(receiver.close),
|
|
63008
|
+
pasteRedirect: receiver.pasteRedirect,
|
|
63009
|
+
cancel: receiver.cancel
|
|
63010
|
+
};
|
|
62953
63011
|
}
|
|
62954
63012
|
var BEARER_TYPE_HEADER, IDENTITY_BEARER_TYPE, IDENTITY_AUTH_TYPE, GOTRUE_OAUTH_PROVIDERS, base64url2, OAUTH_SIGN_IN_TIMEOUT_MS, MAX_FORM_BYTES;
|
|
62955
63013
|
var init_identity = __esm({
|
|
@@ -65223,6 +65281,203 @@ var init_schemas4 = __esm({
|
|
|
65223
65281
|
}
|
|
65224
65282
|
});
|
|
65225
65283
|
|
|
65284
|
+
// src/mcp/auth/second_factor.ts
|
|
65285
|
+
function askHidden(prompt, input = process.stdin, output = process.stdout) {
|
|
65286
|
+
return new Promise((resolve2, reject) => {
|
|
65287
|
+
const raw = Boolean(input.isTTY && input.setRawMode);
|
|
65288
|
+
let typed = "";
|
|
65289
|
+
const finish = (settle) => {
|
|
65290
|
+
input.removeListener("data", onData);
|
|
65291
|
+
input.removeListener("end", onEnd);
|
|
65292
|
+
if (raw) input.setRawMode?.(false);
|
|
65293
|
+
input.pause();
|
|
65294
|
+
output.write("\n");
|
|
65295
|
+
settle();
|
|
65296
|
+
};
|
|
65297
|
+
const onData = (chunk) => {
|
|
65298
|
+
for (const ch of chunk.toString()) {
|
|
65299
|
+
if (ch === "\r" || ch === "\n") return finish(() => resolve2(typed));
|
|
65300
|
+
if (ch === "") {
|
|
65301
|
+
return finish(() => reject(new Error("Sign-in cancelled.")));
|
|
65302
|
+
}
|
|
65303
|
+
if (ch === "" && !typed) {
|
|
65304
|
+
return finish(() => reject(new Error(INPUT_ENDED_MESSAGE)));
|
|
65305
|
+
}
|
|
65306
|
+
if (ch === "\x7F" || ch === "\b") typed = typed.slice(0, -1);
|
|
65307
|
+
else typed += ch;
|
|
65308
|
+
}
|
|
65309
|
+
};
|
|
65310
|
+
const onEnd = () => finish(() => reject(new Error(INPUT_ENDED_MESSAGE)));
|
|
65311
|
+
if (raw) input.setRawMode?.(true);
|
|
65312
|
+
output.write(prompt);
|
|
65313
|
+
input.on("data", onData);
|
|
65314
|
+
input.on("end", onEnd);
|
|
65315
|
+
input.resume();
|
|
65316
|
+
});
|
|
65317
|
+
}
|
|
65318
|
+
function maskEmail(address) {
|
|
65319
|
+
const at = address.lastIndexOf("@");
|
|
65320
|
+
if (at < 1) return "your email address";
|
|
65321
|
+
return `${address[0]}***${address.slice(at)}`;
|
|
65322
|
+
}
|
|
65323
|
+
async function gotrueJson(url, init) {
|
|
65324
|
+
const res = await fetch(url, {
|
|
65325
|
+
method: init.method,
|
|
65326
|
+
headers: {
|
|
65327
|
+
Authorization: `Bearer ${init.accessToken}`,
|
|
65328
|
+
"Content-Type": "application/json",
|
|
65329
|
+
[CLIENT_INFO_HEADER]: CLIENT_INFO
|
|
65330
|
+
},
|
|
65331
|
+
body: init.body === void 0 ? void 0 : JSON.stringify(init.body)
|
|
65332
|
+
});
|
|
65333
|
+
const text = await res.text();
|
|
65334
|
+
let data = {};
|
|
65335
|
+
try {
|
|
65336
|
+
const parsed = text ? JSON.parse(text) : {};
|
|
65337
|
+
if (parsed && typeof parsed === "object") {
|
|
65338
|
+
data = parsed;
|
|
65339
|
+
}
|
|
65340
|
+
} catch {
|
|
65341
|
+
}
|
|
65342
|
+
return { status: res.status, data };
|
|
65343
|
+
}
|
|
65344
|
+
function failure(step, status, data) {
|
|
65345
|
+
return new Error(
|
|
65346
|
+
`${step} failed: ${gotrueErrorMessage(data, `HTTP ${status}`)}`
|
|
65347
|
+
);
|
|
65348
|
+
}
|
|
65349
|
+
function signedInIndependently(accessToken) {
|
|
65350
|
+
const amr = decodeJwtPayload(accessToken)?.amr;
|
|
65351
|
+
return Array.isArray(amr) && amr.some(
|
|
65352
|
+
(entry) => typeof entry === "object" && entry !== null && INDEPENDENT_FIRST_FACTORS.has(
|
|
65353
|
+
String(entry.method)
|
|
65354
|
+
)
|
|
65355
|
+
);
|
|
65356
|
+
}
|
|
65357
|
+
function chooseFactor(factors, accessToken) {
|
|
65358
|
+
const verified = factors.filter((f) => f.status === "verified");
|
|
65359
|
+
if (verified.length === 0) return null;
|
|
65360
|
+
const owed = verified.filter((f) => f.factor_type !== "recovery_code");
|
|
65361
|
+
const totp = owed.find((f) => f.factor_type === "totp");
|
|
65362
|
+
if (totp) return totp;
|
|
65363
|
+
const email2 = owed.find((f) => f.factor_type === "email");
|
|
65364
|
+
const onlyEmail = verified.every((f) => f.factor_type === "email");
|
|
65365
|
+
if (email2 && (onlyEmail || signedInIndependently(accessToken))) return email2;
|
|
65366
|
+
throw new Error(UNSUPPORTED_MESSAGE);
|
|
65367
|
+
}
|
|
65368
|
+
async function stepUpSecondFactor(source, tokens, io) {
|
|
65369
|
+
if (decodeJwtPayload(tokens.idToken)?.aal !== "aal1") return tokens;
|
|
65370
|
+
const accessToken = tokens.idToken;
|
|
65371
|
+
const user = await gotrueJson(`${source.authUrl}/user`, {
|
|
65372
|
+
method: "GET",
|
|
65373
|
+
accessToken
|
|
65374
|
+
});
|
|
65375
|
+
if (!succeeded(user.status)) {
|
|
65376
|
+
throw failure(
|
|
65377
|
+
"Reading the account's second factors",
|
|
65378
|
+
user.status,
|
|
65379
|
+
user.data
|
|
65380
|
+
);
|
|
65381
|
+
}
|
|
65382
|
+
const factor = chooseFactor(
|
|
65383
|
+
Array.isArray(user.data.factors) ? user.data.factors : [],
|
|
65384
|
+
accessToken
|
|
65385
|
+
);
|
|
65386
|
+
if (!factor) return tokens;
|
|
65387
|
+
const interactive = io.interactive ?? (Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY));
|
|
65388
|
+
if (!interactive) throw new Error(NO_TERMINAL_MESSAGE);
|
|
65389
|
+
const ask = io.ask ?? ((prompt2) => askHidden(prompt2));
|
|
65390
|
+
const address = typeof user.data.email === "string" ? user.data.email : tokens.email;
|
|
65391
|
+
const prompt = factor.factor_type === "email" ? `Enter the code we emailed to ${address ? maskEmail(address) : "your email address"}: ` : "Enter the 6-digit code from your authenticator app: ";
|
|
65392
|
+
const factorUrl = `${source.authUrl}/factors/${encodeURIComponent(factor.id)}`;
|
|
65393
|
+
io.print("This account has a second factor.");
|
|
65394
|
+
let wrongCodes = 0;
|
|
65395
|
+
for (let challenges = 0; challenges < MAX_CHALLENGES; challenges++) {
|
|
65396
|
+
const challenge = await gotrueJson(`${factorUrl}/challenge`, {
|
|
65397
|
+
method: "POST",
|
|
65398
|
+
accessToken,
|
|
65399
|
+
body: {}
|
|
65400
|
+
});
|
|
65401
|
+
const challengeId = challenge.data.id;
|
|
65402
|
+
if (!succeeded(challenge.status) || typeof challengeId !== "string") {
|
|
65403
|
+
throw failure(
|
|
65404
|
+
"Starting the second-factor challenge",
|
|
65405
|
+
challenge.status,
|
|
65406
|
+
challenge.data
|
|
65407
|
+
);
|
|
65408
|
+
}
|
|
65409
|
+
if (factor.factor_type === "email") io.print("We emailed you a code.");
|
|
65410
|
+
for (; ; ) {
|
|
65411
|
+
const code = (await ask(prompt)).replace(/\s+/g, "");
|
|
65412
|
+
if (!/^\d+$/.test(code)) {
|
|
65413
|
+
io.print("The code is digits only. Try again.");
|
|
65414
|
+
continue;
|
|
65415
|
+
}
|
|
65416
|
+
const verified = await gotrueJson(`${factorUrl}/verify`, {
|
|
65417
|
+
method: "POST",
|
|
65418
|
+
accessToken,
|
|
65419
|
+
body: { challenge_id: challengeId, code }
|
|
65420
|
+
});
|
|
65421
|
+
if (succeeded(verified.status)) {
|
|
65422
|
+
const { access_token, refresh_token } = verified.data;
|
|
65423
|
+
if (typeof access_token !== "string" || typeof refresh_token !== "string") {
|
|
65424
|
+
throw new Error(
|
|
65425
|
+
"Second-factor verification: response missing access or refresh token"
|
|
65426
|
+
);
|
|
65427
|
+
}
|
|
65428
|
+
const verifiedUser = verified.data.user;
|
|
65429
|
+
return {
|
|
65430
|
+
idToken: access_token,
|
|
65431
|
+
refreshToken: refresh_token,
|
|
65432
|
+
email: verifiedUser?.email ?? tokens.email
|
|
65433
|
+
};
|
|
65434
|
+
}
|
|
65435
|
+
if (verified.data.error_code === "mfa_challenge_expired") {
|
|
65436
|
+
io.print("That code expired. Sending a new one.");
|
|
65437
|
+
break;
|
|
65438
|
+
}
|
|
65439
|
+
if (isWrongCode(verified.status, verified.data)) {
|
|
65440
|
+
if (++wrongCodes >= MAX_CODE_ATTEMPTS) {
|
|
65441
|
+
throw new Error(
|
|
65442
|
+
"Too many incorrect codes. Run `inworld login` to try again."
|
|
65443
|
+
);
|
|
65444
|
+
}
|
|
65445
|
+
io.print("That code is not correct. Try again.");
|
|
65446
|
+
continue;
|
|
65447
|
+
}
|
|
65448
|
+
throw failure(
|
|
65449
|
+
"Second-factor verification",
|
|
65450
|
+
verified.status,
|
|
65451
|
+
verified.data
|
|
65452
|
+
);
|
|
65453
|
+
}
|
|
65454
|
+
}
|
|
65455
|
+
throw new Error(
|
|
65456
|
+
"The second-factor code expired too many times. Run `inworld login` to try again."
|
|
65457
|
+
);
|
|
65458
|
+
}
|
|
65459
|
+
var MAX_CODE_ATTEMPTS, MAX_CHALLENGES, NO_TERMINAL_MESSAGE, UNSUPPORTED_MESSAGE, INPUT_ENDED_MESSAGE, succeeded, isWrongCode, INDEPENDENT_FIRST_FACTORS;
|
|
65460
|
+
var init_second_factor = __esm({
|
|
65461
|
+
"src/mcp/auth/second_factor.ts"() {
|
|
65462
|
+
"use strict";
|
|
65463
|
+
init_client_info();
|
|
65464
|
+
init_identity();
|
|
65465
|
+
MAX_CODE_ATTEMPTS = 5;
|
|
65466
|
+
MAX_CHALLENGES = 5;
|
|
65467
|
+
NO_TERMINAL_MESSAGE = "This account needs a second-factor code; run `inworld login` in an interactive terminal.";
|
|
65468
|
+
UNSUPPORTED_MESSAGE = "This account's second factor cannot be completed in the CLI after this sign-in. Set up an authenticator app in your Inworld account settings and run `inworld login` again, or contact support.";
|
|
65469
|
+
INPUT_ENDED_MESSAGE = "Input ended before a code was entered.";
|
|
65470
|
+
succeeded = (status) => status >= 200 && status < 300;
|
|
65471
|
+
isWrongCode = (status, data) => data.error_code === "mfa_verification_failed" || status === 422 && !data.error_code;
|
|
65472
|
+
INDEPENDENT_FIRST_FACTORS = /* @__PURE__ */ new Set([
|
|
65473
|
+
"password",
|
|
65474
|
+
"sso/saml",
|
|
65475
|
+
"passkey",
|
|
65476
|
+
"web3"
|
|
65477
|
+
]);
|
|
65478
|
+
}
|
|
65479
|
+
});
|
|
65480
|
+
|
|
65226
65481
|
// src/mcp/auth/browser.ts
|
|
65227
65482
|
import { execFile } from "node:child_process";
|
|
65228
65483
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -65243,40 +65498,79 @@ var init_browser = __esm({
|
|
|
65243
65498
|
}
|
|
65244
65499
|
});
|
|
65245
65500
|
|
|
65246
|
-
// src/mcp/
|
|
65501
|
+
// src/mcp/auth/sign_in_prompt.ts
|
|
65247
65502
|
import * as readline from "node:readline";
|
|
65248
|
-
async function
|
|
65249
|
-
|
|
65250
|
-
|
|
65251
|
-
|
|
65252
|
-
|
|
65503
|
+
async function promptForSignIn(signIn, out) {
|
|
65504
|
+
const { url, done, pasteRedirect, cancel } = signIn;
|
|
65505
|
+
const printLink = out.printLink ?? out.print;
|
|
65506
|
+
const printError = out.printError ?? out.print;
|
|
65507
|
+
out.print("Please visit the following URL to authenticate:");
|
|
65508
|
+
printLink(url);
|
|
65509
|
+
out.print("");
|
|
65510
|
+
out.print(
|
|
65511
|
+
"Browser on another machine? Sign in there with Google, GitHub, Microsoft or SSO. It then fails to load an http://127.0.0.1 address: copy that address and paste it here. Email sign-in needs a browser on this machine."
|
|
65512
|
+
);
|
|
65513
|
+
out.print("");
|
|
65514
|
+
const terminal = readline.createInterface({
|
|
65253
65515
|
input: process.stdin,
|
|
65254
|
-
output:
|
|
65516
|
+
output: out.output
|
|
65255
65517
|
});
|
|
65256
|
-
|
|
65257
|
-
|
|
65258
|
-
|
|
65259
|
-
|
|
65260
|
-
);
|
|
65518
|
+
let closed = false;
|
|
65519
|
+
let opened = false;
|
|
65520
|
+
terminal.on("close", () => {
|
|
65521
|
+
closed = true;
|
|
65261
65522
|
});
|
|
65262
|
-
|
|
65263
|
-
()
|
|
65264
|
-
()
|
|
65265
|
-
);
|
|
65266
|
-
const
|
|
65267
|
-
|
|
65268
|
-
|
|
65269
|
-
|
|
65270
|
-
|
|
65271
|
-
|
|
65272
|
-
|
|
65273
|
-
|
|
65274
|
-
|
|
65523
|
+
terminal.on("SIGINT", () => {
|
|
65524
|
+
cancel();
|
|
65525
|
+
terminal.close();
|
|
65526
|
+
});
|
|
65527
|
+
const ask = (prompt) => {
|
|
65528
|
+
if (closed) return;
|
|
65529
|
+
terminal.setPrompt(prompt);
|
|
65530
|
+
terminal.prompt();
|
|
65531
|
+
};
|
|
65532
|
+
terminal.on("line", async (line) => {
|
|
65533
|
+
const address = line.trim();
|
|
65534
|
+
if (!address) {
|
|
65535
|
+
if (!opened) {
|
|
65536
|
+
opened = true;
|
|
65537
|
+
try {
|
|
65538
|
+
await openInBrowser(url);
|
|
65539
|
+
out.print("\u2713 Browser opened");
|
|
65540
|
+
} catch {
|
|
65541
|
+
out.print(
|
|
65542
|
+
"\u26A0 Could not open browser automatically. Please open the URL manually."
|
|
65543
|
+
);
|
|
65544
|
+
}
|
|
65545
|
+
out.print("");
|
|
65546
|
+
out.print("Waiting for authentication...");
|
|
65547
|
+
}
|
|
65548
|
+
ask("Paste the address here if the browser could not load it: ");
|
|
65549
|
+
return;
|
|
65550
|
+
}
|
|
65551
|
+
if (pasteRedirect(address)) {
|
|
65552
|
+
out.print("Finishing sign-in...");
|
|
65553
|
+
terminal.close();
|
|
65554
|
+
return;
|
|
65555
|
+
}
|
|
65556
|
+
printError(
|
|
65557
|
+
"That is not this sign-in's address. Paste the whole address from the browser's address bar; it starts with http://127.0.0.1:"
|
|
65275
65558
|
);
|
|
65276
|
-
|
|
65277
|
-
|
|
65278
|
-
|
|
65559
|
+
ask("Paste the address: ");
|
|
65560
|
+
});
|
|
65561
|
+
ask("Press Enter to open your browser, or paste the address: ");
|
|
65562
|
+
await done.catch(() => {
|
|
65563
|
+
});
|
|
65564
|
+
terminal.close();
|
|
65279
65565
|
}
|
|
65566
|
+
var init_sign_in_prompt = __esm({
|
|
65567
|
+
"src/mcp/auth/sign_in_prompt.ts"() {
|
|
65568
|
+
"use strict";
|
|
65569
|
+
init_browser();
|
|
65570
|
+
}
|
|
65571
|
+
});
|
|
65572
|
+
|
|
65573
|
+
// src/mcp/cli/login.ts
|
|
65280
65574
|
async function runLogin() {
|
|
65281
65575
|
const source = await resolveIdentitySource(PLATFORM_URL);
|
|
65282
65576
|
const oauthProvider = process.env.INWORLD_AUTH_OAUTH_PROVIDER || void 0;
|
|
@@ -65285,14 +65579,19 @@ async function runLogin() {
|
|
|
65285
65579
|
`INWORLD_AUTH_OAUTH_PROVIDER=${oauthProvider} is not supported by inworld-mcp login (use ${GOTRUE_OAUTH_PROVIDERS.join(", ")}, or unset it to choose on the sign-in page).`
|
|
65286
65580
|
);
|
|
65287
65581
|
}
|
|
65288
|
-
const
|
|
65582
|
+
const signIn = await startBrowserSignIn({
|
|
65289
65583
|
authUrl: source.authUrl,
|
|
65290
65584
|
pageUrl: INWORLD_CLI_AUTH_URL,
|
|
65291
65585
|
version: CLI_VERSION,
|
|
65292
65586
|
oauthProvider
|
|
65293
65587
|
});
|
|
65294
|
-
await
|
|
65295
|
-
|
|
65588
|
+
await promptForSignIn(signIn, {
|
|
65589
|
+
print: (line) => console.error(line),
|
|
65590
|
+
output: process.stdout
|
|
65591
|
+
});
|
|
65592
|
+
const tokens = await stepUpSecondFactor(source, await signIn.done, {
|
|
65593
|
+
print: (line) => console.error(line)
|
|
65594
|
+
});
|
|
65296
65595
|
console.error();
|
|
65297
65596
|
console.error("Exchanging for Inworld session...");
|
|
65298
65597
|
const exchanged = await exchangeIdentityToken(tokens.idToken);
|
|
@@ -65329,12 +65628,13 @@ var init_login = __esm({
|
|
|
65329
65628
|
"use strict";
|
|
65330
65629
|
init_dist4();
|
|
65331
65630
|
init_constants6();
|
|
65332
|
-
init_browser();
|
|
65333
65631
|
init_constants5();
|
|
65334
65632
|
init_exchange();
|
|
65335
65633
|
init_identity();
|
|
65336
65634
|
init_paths();
|
|
65635
|
+
init_second_factor();
|
|
65337
65636
|
init_session();
|
|
65637
|
+
init_sign_in_prompt();
|
|
65338
65638
|
}
|
|
65339
65639
|
});
|
|
65340
65640
|
|