create-mastra 1.38.0 → 1.39.0-alpha.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/api-DAbEWGY3-ZTRQ8XmV.js +1 -0
- package/dist/{api-CV5-CXEm-CueiBLg3.js → api-DG8M2TjL-CZSw6Pfx.js} +2 -2
- package/dist/{client-JZw8MfpM-BPeyQaUL.js → client-CJbCBipg-DxaD1xVo.js} +2 -2
- package/dist/{credentials-CdkRA-3T-Cagpr0K5.js → credentials-B0pa2uVX-zzOgKQac.js} +1 -1
- package/dist/{credentials-HeXP-kY2-89ktsX3S.js → credentials-DM7I1Pu0-DLYSiiHK.js} +88 -38
- package/dist/index.js +1270 -215
- package/package.json +2 -2
- package/dist/api-Cdahi7Yf-BlGW3U7e.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as fetchOrgs } from "./api-DG8M2TjL-CZSw6Pfx.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as createApiClient, s as throwApiError } from "./client-
|
|
2
|
-
// ../cli/dist/api-
|
|
1
|
+
import { i as createApiClient, s as throwApiError } from "./client-CJbCBipg-DxaD1xVo.js";
|
|
2
|
+
// ../cli/dist/api-DG8M2TjL.js
|
|
3
3
|
async function fetchOrgs(token) {
|
|
4
4
|
const { data, error, response } = await createApiClient(token).GET("/v1/auth/orgs");
|
|
5
5
|
if (error) throwApiError("Failed to fetch orgs", response.status, error.detail);
|
|
@@ -386,7 +386,7 @@ function removeTrailingSlash(url) {
|
|
|
386
386
|
if (url.endsWith("/")) return url.substring(0, url.length - 1);
|
|
387
387
|
return url;
|
|
388
388
|
}
|
|
389
|
-
// ../cli/dist/client-
|
|
389
|
+
// ../cli/dist/client-CJbCBipg.js
|
|
390
390
|
const MASTRA_PLATFORM_API_URL = process.env.MASTRA_PLATFORM_API_URL || "https://platform.mastra.ai";
|
|
391
391
|
const MASTRA_PROJECTS_URL = process.env.MASTRA_PROJECTS_URL || "https://projects.mastra.ai";
|
|
392
392
|
/**
|
|
@@ -460,7 +460,7 @@ async function authenticatedFetch(input, init) {
|
|
|
460
460
|
if (response.status !== 401 || !_currentToken) return response;
|
|
461
461
|
if (!_refreshInFlight) _refreshInFlight = (async () => {
|
|
462
462
|
try {
|
|
463
|
-
const { tryRefreshToken, loadCredentials } = await import("./credentials-
|
|
463
|
+
const { tryRefreshToken, loadCredentials } = await import("./credentials-B0pa2uVX-zzOgKQac.js");
|
|
464
464
|
const creds = await loadCredentials();
|
|
465
465
|
if (!creds) throw new Error("No credentials");
|
|
466
466
|
const newToken = await tryRefreshToken(creds);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { i as loadCredentials, s as tryRefreshToken } from "./credentials-
|
|
1
|
+
export { i as loadCredentials, s as tryRefreshToken } from "./credentials-DM7I1Pu0-DLYSiiHK.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as MASTRA_PLATFORM_API_URL } from "./client-
|
|
1
|
+
import { t as MASTRA_PLATFORM_API_URL } from "./client-CJbCBipg-DxaD1xVo.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import "node:path";
|
|
4
4
|
import process$1, { stdin, stdout } from "node:process";
|
|
@@ -1144,7 +1144,7 @@ ${r ? styleText("cyan", S_BAR_END) : ""}
|
|
|
1144
1144
|
}
|
|
1145
1145
|
}
|
|
1146
1146
|
}).prompt();
|
|
1147
|
-
// ../cli/dist/credentials-
|
|
1147
|
+
// ../cli/dist/credentials-DM7I1Pu0.js
|
|
1148
1148
|
const CREDENTIALS_DIR = join(homedir(), ".mastra");
|
|
1149
1149
|
const CREDENTIALS_FILE = join(CREDENTIALS_DIR, "credentials.json");
|
|
1150
1150
|
var LoginCancelledError = class extends Error {
|
|
@@ -1245,7 +1245,10 @@ async function tryRefreshToken(creds, signal) {
|
|
|
1245
1245
|
return null;
|
|
1246
1246
|
}
|
|
1247
1247
|
}
|
|
1248
|
-
function
|
|
1248
|
+
function escapeHtml(text) {
|
|
1249
|
+
return text.replace(/[&<>"']/g, (char) => `&#${char.charCodeAt(0)};`);
|
|
1250
|
+
}
|
|
1251
|
+
function callbackPage({ success, error }) {
|
|
1249
1252
|
const title = success ? "Logged in!" : "Login failed";
|
|
1250
1253
|
return `<!doctype html>
|
|
1251
1254
|
<html lang="en">
|
|
@@ -1287,36 +1290,73 @@ function callbackPage({ success }) {
|
|
|
1287
1290
|
<body>
|
|
1288
1291
|
<div class="container">
|
|
1289
1292
|
<h1>${title}</h1>
|
|
1290
|
-
<p>${success ? "You can close this tab and return to the terminal." : "Missing parameters. Close this tab and try again."}</p>
|
|
1293
|
+
<p>${success ? "You can close this tab and return to the terminal." : error ? `${escapeHtml(error)}. Close this tab and return to the terminal.` : "Missing parameters. Close this tab and try again."}</p>
|
|
1291
1294
|
</div>
|
|
1292
1295
|
</body>
|
|
1293
1296
|
</html>`;
|
|
1294
1297
|
}
|
|
1295
|
-
function
|
|
1298
|
+
function parseCallback(url, state) {
|
|
1299
|
+
if (url.pathname !== "/callback") return null;
|
|
1300
|
+
const error = url.searchParams.get("error");
|
|
1301
|
+
if (error && url.searchParams.get("state") === state) return { error: url.searchParams.get("error_description") || error };
|
|
1302
|
+
const token = url.searchParams.get("token");
|
|
1303
|
+
const userParam = url.searchParams.get("user");
|
|
1304
|
+
const organizationId = url.searchParams.get("org");
|
|
1305
|
+
if (url.searchParams.get("state") !== state || !token || !userParam || !organizationId) return null;
|
|
1306
|
+
try {
|
|
1307
|
+
const user = JSON.parse(decodeURIComponent(userParam));
|
|
1308
|
+
if (typeof user?.email !== "string") return null;
|
|
1309
|
+
return {
|
|
1310
|
+
token,
|
|
1311
|
+
refreshToken: url.searchParams.get("refresh_token"),
|
|
1312
|
+
user,
|
|
1313
|
+
organizationId
|
|
1314
|
+
};
|
|
1315
|
+
} catch {
|
|
1316
|
+
return null;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
/**
|
|
1320
|
+
* Reads the terminal while waiting for the browser. A pasted URL is passed to `onPaste` on Enter: when the
|
|
1321
|
+
* browser runs on another machine, it can't reach the callback server, but its address bar holds the callback.
|
|
1322
|
+
* With `onSkip`, any other key skips the login.
|
|
1323
|
+
*/
|
|
1324
|
+
function listenForInput({ onSkip, onPaste }) {
|
|
1296
1325
|
const stdin = process.stdin;
|
|
1297
1326
|
if (!stdin.isTTY || typeof stdin.setRawMode !== "function") return () => {};
|
|
1298
1327
|
const wasRaw = stdin.isRaw;
|
|
1299
|
-
const
|
|
1328
|
+
const wasFlowing = stdin.readableFlowing === true;
|
|
1300
1329
|
let listening = true;
|
|
1330
|
+
let buffer = "";
|
|
1301
1331
|
const cleanup = () => {
|
|
1302
1332
|
if (!listening) return;
|
|
1303
1333
|
listening = false;
|
|
1304
1334
|
stdin.removeListener("data", handleInput);
|
|
1305
1335
|
if (!wasRaw) stdin.setRawMode(false);
|
|
1306
|
-
if (
|
|
1336
|
+
if (!wasFlowing) stdin.pause();
|
|
1307
1337
|
};
|
|
1308
1338
|
const handleInput = (input) => {
|
|
1309
|
-
const data = typeof input === "string" ?
|
|
1310
|
-
|
|
1311
|
-
|
|
1339
|
+
const data = typeof input === "string" ? input : input.toString("utf8");
|
|
1340
|
+
if (data.includes("")) {
|
|
1341
|
+
cleanup();
|
|
1312
1342
|
process.kill(process.pid, "SIGINT");
|
|
1313
1343
|
return;
|
|
1314
1344
|
}
|
|
1315
|
-
|
|
1345
|
+
buffer += data;
|
|
1346
|
+
if (onSkip && !buffer.startsWith("http")) {
|
|
1347
|
+
cleanup();
|
|
1348
|
+
onSkip();
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
const end = buffer.search(/[\r\n]/);
|
|
1352
|
+
if (end === -1) return;
|
|
1353
|
+
const line = buffer.slice(0, end).trim();
|
|
1354
|
+
buffer = "";
|
|
1355
|
+
if (line) onPaste(line);
|
|
1316
1356
|
};
|
|
1317
1357
|
stdin.setRawMode(true);
|
|
1318
1358
|
stdin.resume();
|
|
1319
|
-
stdin.
|
|
1359
|
+
stdin.on("data", handleInput);
|
|
1320
1360
|
return cleanup;
|
|
1321
1361
|
}
|
|
1322
1362
|
async function loginAttempt(signal, options = {}) {
|
|
@@ -1331,24 +1371,24 @@ async function loginAttempt(signal, options = {}) {
|
|
|
1331
1371
|
});
|
|
1332
1372
|
});
|
|
1333
1373
|
const loginUrl = `${MASTRA_PLATFORM_API_URL}/v1/auth/login?product=cli&cli_port=${port}&state=${state}&source=${options.source ?? "mastra-cli"}`;
|
|
1334
|
-
console.info(` Opening browser
|
|
1335
|
-
console.info(options.skipOnInput ? ` Waiting for browser sign-in. Press any key to skip this step.\n` : ` Waiting for browser sign-in...\n`);
|
|
1374
|
+
console.info(` Opening browser. If it doesn't open, visit:\n ${loginUrl}\n`);
|
|
1336
1375
|
try {
|
|
1337
1376
|
openBrowser(loginUrl);
|
|
1338
1377
|
} catch {
|
|
1339
|
-
console.info(` Could not open browser automatically
|
|
1340
|
-
console.info(` Open this URL manually: ${loginUrl}\n`);
|
|
1378
|
+
console.info(` Could not open browser automatically. Open the URL above.\n`);
|
|
1341
1379
|
if (isWSL()) console.info(` Note: If login times out, ensure localhost forwarding is enabled in your .wslconfig.\n`);
|
|
1342
1380
|
}
|
|
1381
|
+
if (process.stdin.isTTY) console.info(` Signing in on another device? If the page fails to load after sign-in, paste its URL here and press Enter.\n`);
|
|
1382
|
+
console.info(options.skipOnInput ? ` Waiting for browser sign-in. Press any key to skip this step.\n` : ` Waiting for browser sign-in...\n`);
|
|
1343
1383
|
const result = await new Promise((resolve, reject) => {
|
|
1344
1384
|
let settled = false;
|
|
1345
|
-
let
|
|
1385
|
+
let stopListeningForInput = () => {};
|
|
1346
1386
|
const finish = (callback) => {
|
|
1347
1387
|
if (settled) return;
|
|
1348
1388
|
settled = true;
|
|
1349
1389
|
clearTimeout(timeout);
|
|
1350
1390
|
signal?.removeEventListener("abort", handleAbort);
|
|
1351
|
-
|
|
1391
|
+
stopListeningForInput();
|
|
1352
1392
|
server.close(callback);
|
|
1353
1393
|
server.closeAllConnections();
|
|
1354
1394
|
};
|
|
@@ -1363,33 +1403,43 @@ async function loginAttempt(signal, options = {}) {
|
|
|
1363
1403
|
handleAbort();
|
|
1364
1404
|
return;
|
|
1365
1405
|
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
const
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
res.writeHead(400, { "Content-Type": "text/html" });
|
|
1377
|
-
res.end(callbackPage({ success: false }));
|
|
1406
|
+
const settle = (result) => {
|
|
1407
|
+
if ("error" in result) finish(() => reject(/* @__PURE__ */ new Error(`Sign-in failed: ${result.error}.`)));
|
|
1408
|
+
else finish(() => resolve(result));
|
|
1409
|
+
};
|
|
1410
|
+
stopListeningForInput = listenForInput({
|
|
1411
|
+
onSkip: options.skipOnInput ? () => finish(() => reject(new LoginCancelledError())) : void 0,
|
|
1412
|
+
onPaste: (text) => {
|
|
1413
|
+
const result = URL.canParse(text) ? parseCallback(new URL(text), state) : null;
|
|
1414
|
+
if (!result) {
|
|
1415
|
+
console.info(`\n That doesn't look like the sign-in address. Copy the full URL from the browser's address bar and paste it again.\n`);
|
|
1378
1416
|
return;
|
|
1379
1417
|
}
|
|
1380
|
-
|
|
1381
|
-
|
|
1418
|
+
settle(result);
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
server.on("request", (req, res) => {
|
|
1422
|
+
const url = new URL(req.url, `http://localhost:${port}`);
|
|
1423
|
+
if (url.pathname !== "/callback") return;
|
|
1424
|
+
const result = parseCallback(url, state);
|
|
1425
|
+
if (!result || "error" in result) {
|
|
1426
|
+
res.writeHead(400, {
|
|
1382
1427
|
"Content-Type": "text/html",
|
|
1383
1428
|
Connection: "close"
|
|
1384
1429
|
});
|
|
1385
|
-
res.end(callbackPage({
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
refreshToken,
|
|
1389
|
-
user,
|
|
1390
|
-
organizationId: orgId
|
|
1430
|
+
res.end(callbackPage({
|
|
1431
|
+
success: false,
|
|
1432
|
+
error: result?.error
|
|
1391
1433
|
}));
|
|
1434
|
+
if (result) settle(result);
|
|
1435
|
+
return;
|
|
1392
1436
|
}
|
|
1437
|
+
res.writeHead(200, {
|
|
1438
|
+
"Content-Type": "text/html",
|
|
1439
|
+
Connection: "close"
|
|
1440
|
+
});
|
|
1441
|
+
res.end(callbackPage({ success: true }));
|
|
1442
|
+
settle(result);
|
|
1393
1443
|
});
|
|
1394
1444
|
});
|
|
1395
1445
|
const creds = {
|