create-mastra 0.0.0-pgvector-index-fix-20250905222058 → 0.0.0-playground-studio-cloud-20251031080052
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 +451 -1
- package/README.md +10 -32
- package/dist/index.js +589 -466
- package/dist/index.js.map +1 -1
- package/dist/templates/dev.entry.js +5 -0
- package/package.json +10 -10
- package/dist/templates/scorers/answer-relevancy-scorer.ts +0 -15
- package/dist/templates/scorers/bias-detection-scorer.ts +0 -16
- package/dist/templates/scorers/completeness-scorer.ts +0 -16
- package/dist/templates/scorers/content-similarity-scorer.ts +0 -15
- package/dist/templates/scorers/faithfulness-scorer.ts +0 -21
- package/dist/templates/scorers/hallucination-scorer.ts +0 -21
- package/dist/templates/scorers/keyword-coverage-scorer.ts +0 -15
- package/dist/templates/scorers/textual-difference-scorer.ts +0 -16
- package/dist/templates/scorers/tone-consistency-scorer.ts +0 -16
- package/dist/templates/scorers/toxicity-detection-scorer.ts +0 -16
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
|
-
import * as
|
|
5
|
-
import
|
|
4
|
+
import * as fs3__default from 'node:fs';
|
|
5
|
+
import fs3__default__default, { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
6
|
import os from 'node:os';
|
|
7
|
-
import
|
|
7
|
+
import path, { dirname } from 'node:path';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import { PostHog } from 'posthog-node';
|
|
10
10
|
import util, { stripVTControlCharacters } from 'node:util';
|
|
@@ -12,18 +12,18 @@ import y$1, { stdout, stdin } from 'node:process';
|
|
|
12
12
|
import * as g from 'node:readline';
|
|
13
13
|
import g__default from 'node:readline';
|
|
14
14
|
import { Writable } from 'node:stream';
|
|
15
|
-
import
|
|
15
|
+
import fs4 from 'node:fs/promises';
|
|
16
16
|
import child_process from 'node:child_process';
|
|
17
17
|
import tty from 'node:tty';
|
|
18
|
+
import fsExtra, { readJSON, ensureFile, writeJSON } from 'fs-extra/esm';
|
|
19
|
+
import prettier from 'prettier';
|
|
20
|
+
import { execa } from 'execa';
|
|
18
21
|
import pino from 'pino';
|
|
19
22
|
import pretty from 'pino-pretty';
|
|
20
|
-
import
|
|
21
|
-
import fsExtra2, { readJSON, ensureFile, writeJSON } from 'fs-extra/esm';
|
|
22
|
-
import prettier from 'prettier';
|
|
23
|
-
import fsExtra from 'fs-extra';
|
|
23
|
+
import fsExtra$1 from 'fs-extra';
|
|
24
24
|
|
|
25
25
|
var __filename = fileURLToPath(import.meta.url);
|
|
26
|
-
var __dirname =
|
|
26
|
+
var __dirname = path.dirname(__filename);
|
|
27
27
|
var analyticsInstance = null;
|
|
28
28
|
function getAnalytics() {
|
|
29
29
|
return analyticsInstance;
|
|
@@ -39,7 +39,7 @@ var PosthogAnalytics = class {
|
|
|
39
39
|
host = "https://app.posthog.com"
|
|
40
40
|
}) {
|
|
41
41
|
this.version = version;
|
|
42
|
-
const cliConfigPath =
|
|
42
|
+
const cliConfigPath = path.join(__dirname, "mastra-cli.json");
|
|
43
43
|
if (existsSync(cliConfigPath)) {
|
|
44
44
|
try {
|
|
45
45
|
const { distinctId, sessionId } = JSON.parse(readFileSync(cliConfigPath, "utf-8"));
|
|
@@ -67,7 +67,7 @@ var PosthogAnalytics = class {
|
|
|
67
67
|
}
|
|
68
68
|
writeCliConfig({ distinctId, sessionId }) {
|
|
69
69
|
try {
|
|
70
|
-
writeFileSync(
|
|
70
|
+
writeFileSync(path.join(__dirname, "mastra-cli.json"), JSON.stringify({ distinctId, sessionId }));
|
|
71
71
|
} catch {
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -422,7 +422,7 @@ ${color2.gray(d)} ${t}
|
|
|
422
422
|
`):process.stdout.write(`${w} ${l}
|
|
423
423
|
`),E(),s();};return {start:H,stop:N,message:(m="")=>{l=R(m??l);}}},Ce=async(t,n)=>{const r={},i=Object.keys(t);for(const s of i){const c=t[s],a=await c({results:r})?.catch(l=>{throw l});if(typeof n?.onCancel=="function"&&pD(a)){r[s]="canceled",n.onCancel({results:r});continue}r[s]=a;}return r};
|
|
424
424
|
|
|
425
|
-
var shellQuote
|
|
425
|
+
var shellQuote = {};
|
|
426
426
|
|
|
427
427
|
var quote;
|
|
428
428
|
var hasRequiredQuote;
|
|
@@ -688,16 +688,16 @@ function requireParse () {
|
|
|
688
688
|
var hasRequiredShellQuote;
|
|
689
689
|
|
|
690
690
|
function requireShellQuote () {
|
|
691
|
-
if (hasRequiredShellQuote) return shellQuote
|
|
691
|
+
if (hasRequiredShellQuote) return shellQuote;
|
|
692
692
|
hasRequiredShellQuote = 1;
|
|
693
693
|
|
|
694
|
-
shellQuote
|
|
695
|
-
shellQuote
|
|
696
|
-
return shellQuote
|
|
694
|
+
shellQuote.quote = requireQuote();
|
|
695
|
+
shellQuote.parse = requireParse();
|
|
696
|
+
return shellQuote;
|
|
697
697
|
}
|
|
698
698
|
|
|
699
699
|
var shellQuoteExports = requireShellQuote();
|
|
700
|
-
var
|
|
700
|
+
var shellQuote2 = /*@__PURE__*/getDefaultExportFromCjs(shellQuoteExports);
|
|
701
701
|
|
|
702
702
|
// eslint-disable-next-line no-warning-comments
|
|
703
703
|
// TODO: Use a better method when it's added to Node.js (https://github.com/nodejs/node/pull/40240)
|
|
@@ -724,13 +724,18 @@ const format = (open, close) => {
|
|
|
724
724
|
// Handle nested colors.
|
|
725
725
|
|
|
726
726
|
// We could have done this, but it's too slow (as of Node.js 22).
|
|
727
|
-
// return openCode + string.replaceAll(closeCode, openCode) + closeCode;
|
|
727
|
+
// return openCode + string.replaceAll(closeCode, (close === 22 ? closeCode : '') + openCode) + closeCode;
|
|
728
728
|
|
|
729
729
|
let result = openCode;
|
|
730
730
|
let lastIndex = 0;
|
|
731
731
|
|
|
732
|
+
// SGR 22 resets both bold (1) and dim (2). When we encounter a nested
|
|
733
|
+
// close for styles that use 22, we need to re-open the outer style.
|
|
734
|
+
const reopenOnNestedClose = close === 22;
|
|
735
|
+
const replaceCode = (reopenOnNestedClose ? closeCode : '') + openCode;
|
|
736
|
+
|
|
732
737
|
while (index !== -1) {
|
|
733
|
-
result += string.slice(lastIndex, index) +
|
|
738
|
+
result += string.slice(lastIndex, index) + replaceCode;
|
|
734
739
|
lastIndex = index + closeCode.length;
|
|
735
740
|
index = string.indexOf(closeCode, lastIndex);
|
|
736
741
|
}
|
|
@@ -1173,279 +1178,6 @@ var PinoLogger = class extends MastraLogger {
|
|
|
1173
1178
|
}
|
|
1174
1179
|
};
|
|
1175
1180
|
|
|
1176
|
-
function getPackageManager() {
|
|
1177
|
-
const userAgent = process.env.npm_config_user_agent || "";
|
|
1178
|
-
const execPath = process.env.npm_execpath || "";
|
|
1179
|
-
if (userAgent.includes("yarn")) {
|
|
1180
|
-
return "yarn";
|
|
1181
|
-
}
|
|
1182
|
-
if (userAgent.includes("pnpm")) {
|
|
1183
|
-
return "pnpm";
|
|
1184
|
-
}
|
|
1185
|
-
if (userAgent.includes("npm")) {
|
|
1186
|
-
return "npm";
|
|
1187
|
-
}
|
|
1188
|
-
if (execPath.includes("yarn")) {
|
|
1189
|
-
return "yarn";
|
|
1190
|
-
}
|
|
1191
|
-
if (execPath.includes("pnpm")) {
|
|
1192
|
-
return "pnpm";
|
|
1193
|
-
}
|
|
1194
|
-
if (execPath.includes("npm")) {
|
|
1195
|
-
return "npm";
|
|
1196
|
-
}
|
|
1197
|
-
return "npm";
|
|
1198
|
-
}
|
|
1199
|
-
var logger = new PinoLogger({
|
|
1200
|
-
name: "Mastra CLI",
|
|
1201
|
-
level: "info"
|
|
1202
|
-
});
|
|
1203
|
-
var exec = util.promisify(child_process.exec);
|
|
1204
|
-
async function cloneTemplate(options) {
|
|
1205
|
-
const { template, projectName, targetDir } = options;
|
|
1206
|
-
const projectPath = targetDir ? path3.resolve(targetDir, projectName) : path3.resolve(projectName);
|
|
1207
|
-
const spinner5 = yoctoSpinner({ text: `Cloning template "${template.title}"...` }).start();
|
|
1208
|
-
try {
|
|
1209
|
-
if (await directoryExists(projectPath)) {
|
|
1210
|
-
spinner5.error(`Directory ${projectName} already exists`);
|
|
1211
|
-
throw new Error(`Directory ${projectName} already exists`);
|
|
1212
|
-
}
|
|
1213
|
-
await cloneRepositoryWithoutGit(template.githubUrl, projectPath);
|
|
1214
|
-
await updatePackageJson(projectPath, projectName);
|
|
1215
|
-
const envExamplePath = path3.join(projectPath, ".env.example");
|
|
1216
|
-
if (await fileExists(envExamplePath)) {
|
|
1217
|
-
await fs.copyFile(envExamplePath, path3.join(projectPath, ".env"));
|
|
1218
|
-
}
|
|
1219
|
-
spinner5.success(`Template "${template.title}" cloned successfully to ${projectName}`);
|
|
1220
|
-
return projectPath;
|
|
1221
|
-
} catch (error) {
|
|
1222
|
-
spinner5.error(`Failed to clone template: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1223
|
-
throw error;
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
async function directoryExists(dirPath) {
|
|
1227
|
-
try {
|
|
1228
|
-
const stat = await fs.stat(dirPath);
|
|
1229
|
-
return stat.isDirectory();
|
|
1230
|
-
} catch {
|
|
1231
|
-
return false;
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
async function fileExists(filePath) {
|
|
1235
|
-
try {
|
|
1236
|
-
const stat = await fs.stat(filePath);
|
|
1237
|
-
return stat.isFile();
|
|
1238
|
-
} catch {
|
|
1239
|
-
return false;
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
async function cloneRepositoryWithoutGit(repoUrl, targetPath) {
|
|
1243
|
-
await fs.mkdir(targetPath, { recursive: true });
|
|
1244
|
-
try {
|
|
1245
|
-
const degitRepo = repoUrl.replace("https://github.com/", "");
|
|
1246
|
-
const degitCommand = shellQuote.quote(["npx", "degit", degitRepo, targetPath]);
|
|
1247
|
-
await exec(degitCommand, {
|
|
1248
|
-
cwd: process.cwd()
|
|
1249
|
-
});
|
|
1250
|
-
} catch {
|
|
1251
|
-
try {
|
|
1252
|
-
const gitCommand = shellQuote.quote(["git", "clone", repoUrl, targetPath]);
|
|
1253
|
-
await exec(gitCommand, {
|
|
1254
|
-
cwd: process.cwd()
|
|
1255
|
-
});
|
|
1256
|
-
const gitDir = path3.join(targetPath, ".git");
|
|
1257
|
-
if (await directoryExists(gitDir)) {
|
|
1258
|
-
await fs.rm(gitDir, { recursive: true, force: true });
|
|
1259
|
-
}
|
|
1260
|
-
} catch (gitError) {
|
|
1261
|
-
throw new Error(`Failed to clone repository: ${gitError instanceof Error ? gitError.message : "Unknown error"}`);
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
async function updatePackageJson(projectPath, projectName) {
|
|
1266
|
-
const packageJsonPath = path3.join(projectPath, "package.json");
|
|
1267
|
-
try {
|
|
1268
|
-
const packageJsonContent = await fs.readFile(packageJsonPath, "utf-8");
|
|
1269
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
1270
|
-
packageJson.name = projectName;
|
|
1271
|
-
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf-8");
|
|
1272
|
-
} catch (error) {
|
|
1273
|
-
logger.warn(`Could not update package.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
async function installDependencies(projectPath, packageManager) {
|
|
1277
|
-
const spinner5 = yoctoSpinner({ text: "Installing dependencies..." }).start();
|
|
1278
|
-
try {
|
|
1279
|
-
const pm = packageManager || getPackageManager();
|
|
1280
|
-
const installCommand = shellQuote.quote([pm, "install"]);
|
|
1281
|
-
await exec(installCommand, {
|
|
1282
|
-
cwd: projectPath
|
|
1283
|
-
});
|
|
1284
|
-
spinner5.success("Dependencies installed successfully");
|
|
1285
|
-
} catch (error) {
|
|
1286
|
-
spinner5.error(`Failed to install dependencies: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1287
|
-
throw error;
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
var TEMPLATES_API_URL = process.env.MASTRA_TEMPLATES_API_URL || "https://mastra.ai/api/templates.json";
|
|
1291
|
-
async function loadTemplates() {
|
|
1292
|
-
try {
|
|
1293
|
-
const response = await fetch(TEMPLATES_API_URL);
|
|
1294
|
-
if (!response.ok) {
|
|
1295
|
-
throw new Error(`Failed to fetch templates: ${response.statusText}`);
|
|
1296
|
-
}
|
|
1297
|
-
const templates = await response.json();
|
|
1298
|
-
return templates;
|
|
1299
|
-
} catch (error) {
|
|
1300
|
-
console.error("Error loading templates:", error);
|
|
1301
|
-
throw new Error("Failed to load templates. Please check your internet connection and try again.");
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
function pluralize(count, singular, plural) {
|
|
1305
|
-
return count === 1 ? singular : plural || `${singular}s`;
|
|
1306
|
-
}
|
|
1307
|
-
async function selectTemplate(templates) {
|
|
1308
|
-
const choices = templates.map((template) => {
|
|
1309
|
-
const parts = [];
|
|
1310
|
-
if (template.agents?.length) {
|
|
1311
|
-
parts.push(`${template.agents.length} ${pluralize(template.agents.length, "agent")}`);
|
|
1312
|
-
}
|
|
1313
|
-
if (template.tools?.length) {
|
|
1314
|
-
parts.push(`${template.tools.length} ${pluralize(template.tools.length, "tool")}`);
|
|
1315
|
-
}
|
|
1316
|
-
if (template.workflows?.length) {
|
|
1317
|
-
parts.push(`${template.workflows.length} ${pluralize(template.workflows.length, "workflow")}`);
|
|
1318
|
-
}
|
|
1319
|
-
if (template.mcp?.length) {
|
|
1320
|
-
parts.push(`${template.mcp.length} ${pluralize(template.mcp.length, "MCP server")}`);
|
|
1321
|
-
}
|
|
1322
|
-
if (template.networks?.length) {
|
|
1323
|
-
parts.push(`${template.networks.length} ${pluralize(template.networks.length, "agent network")}`);
|
|
1324
|
-
}
|
|
1325
|
-
return {
|
|
1326
|
-
value: template,
|
|
1327
|
-
label: template.title,
|
|
1328
|
-
hint: parts.join(", ") || "Template components"
|
|
1329
|
-
};
|
|
1330
|
-
});
|
|
1331
|
-
const selected = await ve({
|
|
1332
|
-
message: "Select a template:",
|
|
1333
|
-
options: choices
|
|
1334
|
-
});
|
|
1335
|
-
if (pD(selected)) {
|
|
1336
|
-
return null;
|
|
1337
|
-
}
|
|
1338
|
-
return selected;
|
|
1339
|
-
}
|
|
1340
|
-
function findTemplateByName(templates, templateName) {
|
|
1341
|
-
let template = templates.find((t) => t.slug === templateName);
|
|
1342
|
-
if (template) return template;
|
|
1343
|
-
const slugWithPrefix = `template-${templateName}`;
|
|
1344
|
-
template = templates.find((t) => t.slug === slugWithPrefix);
|
|
1345
|
-
if (template) return template;
|
|
1346
|
-
template = templates.find((t) => t.title.toLowerCase() === templateName.toLowerCase());
|
|
1347
|
-
if (template) return template;
|
|
1348
|
-
return null;
|
|
1349
|
-
}
|
|
1350
|
-
function getDefaultProjectName(template) {
|
|
1351
|
-
return template.slug.replace(/^template-/, "");
|
|
1352
|
-
}
|
|
1353
|
-
function getPackageManagerAddCommand(pm) {
|
|
1354
|
-
switch (pm) {
|
|
1355
|
-
case "npm":
|
|
1356
|
-
return "install --audit=false --fund=false --loglevel=error --progress=false --update-notifier=false";
|
|
1357
|
-
case "yarn":
|
|
1358
|
-
return "add";
|
|
1359
|
-
case "pnpm":
|
|
1360
|
-
return "add --loglevel=error";
|
|
1361
|
-
case "bun":
|
|
1362
|
-
return "add";
|
|
1363
|
-
default:
|
|
1364
|
-
return "add";
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
var DepsService = class {
|
|
1368
|
-
packageManager;
|
|
1369
|
-
constructor() {
|
|
1370
|
-
this.packageManager = this.getPackageManager();
|
|
1371
|
-
}
|
|
1372
|
-
findLockFile(dir) {
|
|
1373
|
-
const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
|
|
1374
|
-
for (const file of lockFiles) {
|
|
1375
|
-
if (fs4__default__default.existsSync(path3.join(dir, file))) {
|
|
1376
|
-
return file;
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
const parentDir = path3.resolve(dir, "..");
|
|
1380
|
-
if (parentDir !== dir) {
|
|
1381
|
-
return this.findLockFile(parentDir);
|
|
1382
|
-
}
|
|
1383
|
-
return null;
|
|
1384
|
-
}
|
|
1385
|
-
getPackageManager() {
|
|
1386
|
-
const lockFile = this.findLockFile(process.cwd());
|
|
1387
|
-
switch (lockFile) {
|
|
1388
|
-
case "pnpm-lock.yaml":
|
|
1389
|
-
return "pnpm";
|
|
1390
|
-
case "package-lock.json":
|
|
1391
|
-
return "npm";
|
|
1392
|
-
case "yarn.lock":
|
|
1393
|
-
return "yarn";
|
|
1394
|
-
case "bun.lock":
|
|
1395
|
-
return "bun";
|
|
1396
|
-
default:
|
|
1397
|
-
return "npm";
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
async installPackages(packages) {
|
|
1401
|
-
const pm = this.packageManager;
|
|
1402
|
-
const installCommand = getPackageManagerAddCommand(pm);
|
|
1403
|
-
const packageList = packages.join(" ");
|
|
1404
|
-
return execa(`${pm} ${installCommand} ${packageList}`, {
|
|
1405
|
-
all: true,
|
|
1406
|
-
shell: true,
|
|
1407
|
-
stdio: "inherit"
|
|
1408
|
-
});
|
|
1409
|
-
}
|
|
1410
|
-
async checkDependencies(dependencies) {
|
|
1411
|
-
try {
|
|
1412
|
-
const packageJsonPath = path3.join(process.cwd(), "package.json");
|
|
1413
|
-
try {
|
|
1414
|
-
await fs.access(packageJsonPath);
|
|
1415
|
-
} catch {
|
|
1416
|
-
return "No package.json file found in the current directory";
|
|
1417
|
-
}
|
|
1418
|
-
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
|
|
1419
|
-
for (const dependency of dependencies) {
|
|
1420
|
-
if (!packageJson.dependencies || !packageJson.dependencies[dependency]) {
|
|
1421
|
-
return `Please install ${dependency} before running this command (${this.packageManager} install ${dependency})`;
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
return "ok";
|
|
1425
|
-
} catch (err) {
|
|
1426
|
-
console.error(err);
|
|
1427
|
-
return "Could not check dependencies";
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
async getProjectName() {
|
|
1431
|
-
try {
|
|
1432
|
-
const packageJsonPath = path3.join(process.cwd(), "package.json");
|
|
1433
|
-
const packageJson = await fs.readFile(packageJsonPath, "utf-8");
|
|
1434
|
-
const pkg = JSON.parse(packageJson);
|
|
1435
|
-
return pkg.name;
|
|
1436
|
-
} catch (err) {
|
|
1437
|
-
throw err;
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
async addScriptsToPackageJson(scripts) {
|
|
1441
|
-
const packageJson = JSON.parse(await fs.readFile("package.json", "utf-8"));
|
|
1442
|
-
packageJson.scripts = {
|
|
1443
|
-
...packageJson.scripts,
|
|
1444
|
-
...scripts
|
|
1445
|
-
};
|
|
1446
|
-
await fs.writeFile("package.json", JSON.stringify(packageJson, null, 2));
|
|
1447
|
-
}
|
|
1448
|
-
};
|
|
1449
1181
|
var args = ["-y", "@mastra/mcp-docs-server"];
|
|
1450
1182
|
var createMcpConfig = (editor) => {
|
|
1451
1183
|
if (editor === "vscode") {
|
|
@@ -1498,19 +1230,19 @@ async function writeMergedConfig(configPath, editor) {
|
|
|
1498
1230
|
spaces: 2
|
|
1499
1231
|
});
|
|
1500
1232
|
}
|
|
1501
|
-
var windsurfGlobalMCPConfigPath =
|
|
1502
|
-
var cursorGlobalMCPConfigPath =
|
|
1503
|
-
|
|
1504
|
-
var vscodeGlobalMCPConfigPath =
|
|
1233
|
+
var windsurfGlobalMCPConfigPath = path.join(os.homedir(), ".codeium", "windsurf", "mcp_config.json");
|
|
1234
|
+
var cursorGlobalMCPConfigPath = path.join(os.homedir(), ".cursor", "mcp.json");
|
|
1235
|
+
path.join(process.cwd(), ".vscode", "mcp.json");
|
|
1236
|
+
var vscodeGlobalMCPConfigPath = path.join(
|
|
1505
1237
|
os.homedir(),
|
|
1506
|
-
process.platform === "win32" ?
|
|
1238
|
+
process.platform === "win32" ? path.join("AppData", "Roaming", "Code", "User", "settings.json") : process.platform === "darwin" ? path.join("Library", "Application Support", "Code", "User", "settings.json") : path.join(".config", "Code", "User", "settings.json")
|
|
1507
1239
|
);
|
|
1508
1240
|
async function installMastraDocsMCPServer({ editor, directory }) {
|
|
1509
1241
|
if (editor === `cursor`) {
|
|
1510
|
-
await writeMergedConfig(
|
|
1242
|
+
await writeMergedConfig(path.join(directory, ".cursor", "mcp.json"), "cursor");
|
|
1511
1243
|
}
|
|
1512
1244
|
if (editor === `vscode`) {
|
|
1513
|
-
await writeMergedConfig(
|
|
1245
|
+
await writeMergedConfig(path.join(directory, ".vscode", "mcp.json"), "vscode");
|
|
1514
1246
|
}
|
|
1515
1247
|
if (editor === `cursor-global`) {
|
|
1516
1248
|
const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
|
|
@@ -1558,25 +1290,121 @@ async function globalMCPIsAlreadyInstalled(editor) {
|
|
|
1558
1290
|
return false;
|
|
1559
1291
|
}
|
|
1560
1292
|
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1293
|
+
function getPackageManagerAddCommand(pm) {
|
|
1294
|
+
switch (pm) {
|
|
1295
|
+
case "npm":
|
|
1296
|
+
return "install --audit=false --fund=false --loglevel=error --progress=false --update-notifier=false";
|
|
1297
|
+
case "yarn":
|
|
1298
|
+
return "add";
|
|
1299
|
+
case "pnpm":
|
|
1300
|
+
return "add --loglevel=error";
|
|
1301
|
+
case "bun":
|
|
1302
|
+
return "add";
|
|
1303
|
+
default:
|
|
1304
|
+
return "add";
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
var DepsService = class {
|
|
1308
|
+
packageManager;
|
|
1309
|
+
constructor() {
|
|
1310
|
+
this.packageManager = this.getPackageManager();
|
|
1311
|
+
}
|
|
1312
|
+
findLockFile(dir) {
|
|
1313
|
+
const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
|
|
1314
|
+
for (const file of lockFiles) {
|
|
1315
|
+
if (fs3__default__default.existsSync(path.join(dir, file))) {
|
|
1316
|
+
return file;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
const parentDir = path.resolve(dir, "..");
|
|
1320
|
+
if (parentDir !== dir) {
|
|
1321
|
+
return this.findLockFile(parentDir);
|
|
1322
|
+
}
|
|
1323
|
+
return null;
|
|
1324
|
+
}
|
|
1325
|
+
getPackageManager() {
|
|
1326
|
+
const lockFile = this.findLockFile(process.cwd());
|
|
1327
|
+
switch (lockFile) {
|
|
1328
|
+
case "pnpm-lock.yaml":
|
|
1329
|
+
return "pnpm";
|
|
1330
|
+
case "package-lock.json":
|
|
1331
|
+
return "npm";
|
|
1332
|
+
case "yarn.lock":
|
|
1333
|
+
return "yarn";
|
|
1334
|
+
case "bun.lock":
|
|
1335
|
+
return "bun";
|
|
1336
|
+
default:
|
|
1337
|
+
return "npm";
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
async installPackages(packages) {
|
|
1341
|
+
const pm = this.packageManager;
|
|
1342
|
+
const installCommand = getPackageManagerAddCommand(pm);
|
|
1343
|
+
const packageList = packages.join(" ");
|
|
1344
|
+
return execa(`${pm} ${installCommand} ${packageList}`, {
|
|
1345
|
+
all: true,
|
|
1346
|
+
shell: true,
|
|
1347
|
+
stdio: "inherit"
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
async checkDependencies(dependencies) {
|
|
1351
|
+
try {
|
|
1352
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
1353
|
+
try {
|
|
1354
|
+
await fs4.access(packageJsonPath);
|
|
1355
|
+
} catch {
|
|
1356
|
+
return "No package.json file found in the current directory";
|
|
1357
|
+
}
|
|
1358
|
+
const packageJson = JSON.parse(await fs4.readFile(packageJsonPath, "utf-8"));
|
|
1359
|
+
for (const dependency of dependencies) {
|
|
1360
|
+
if (!packageJson.dependencies || !packageJson.dependencies[dependency]) {
|
|
1361
|
+
return `Please install ${dependency} before running this command (${this.packageManager} install ${dependency})`;
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
return "ok";
|
|
1365
|
+
} catch (err) {
|
|
1366
|
+
console.error(err);
|
|
1367
|
+
return "Could not check dependencies";
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
async getProjectName() {
|
|
1371
|
+
try {
|
|
1372
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
1373
|
+
const packageJson = await fs4.readFile(packageJsonPath, "utf-8");
|
|
1374
|
+
const pkg = JSON.parse(packageJson);
|
|
1375
|
+
return pkg.name;
|
|
1376
|
+
} catch (err) {
|
|
1377
|
+
throw err;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
async addScriptsToPackageJson(scripts) {
|
|
1381
|
+
const packageJson = JSON.parse(await fs4.readFile("package.json", "utf-8"));
|
|
1382
|
+
packageJson.scripts = {
|
|
1383
|
+
...packageJson.scripts,
|
|
1384
|
+
...scripts
|
|
1385
|
+
};
|
|
1386
|
+
await fs4.writeFile("package.json", JSON.stringify(packageJson, null, 2));
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
var EnvService = class {
|
|
1390
|
+
};
|
|
1391
|
+
var FileEnvService = class extends EnvService {
|
|
1392
|
+
filePath;
|
|
1393
|
+
constructor(filePath) {
|
|
1394
|
+
super();
|
|
1395
|
+
this.filePath = filePath;
|
|
1396
|
+
}
|
|
1397
|
+
readFile(filePath) {
|
|
1398
|
+
return new Promise((resolve, reject) => {
|
|
1399
|
+
fs3__default.readFile(filePath, "utf8", (err, data) => {
|
|
1400
|
+
if (err) reject(err);
|
|
1401
|
+
else resolve(data);
|
|
1402
|
+
});
|
|
1403
|
+
});
|
|
1576
1404
|
}
|
|
1577
1405
|
writeFile({ filePath, data }) {
|
|
1578
1406
|
return new Promise((resolve, reject) => {
|
|
1579
|
-
|
|
1407
|
+
fs3__default.writeFile(filePath, data, "utf8", (err) => {
|
|
1580
1408
|
if (err) reject(err);
|
|
1581
1409
|
else resolve();
|
|
1582
1410
|
});
|
|
@@ -1596,7 +1424,7 @@ var FileEnvService = class extends EnvService {
|
|
|
1596
1424
|
${key}=${value}`;
|
|
1597
1425
|
}
|
|
1598
1426
|
await this.writeFile({ filePath, data });
|
|
1599
|
-
console.
|
|
1427
|
+
console.info(`${key} set to ${value} in ENV file.`);
|
|
1600
1428
|
return data;
|
|
1601
1429
|
}
|
|
1602
1430
|
async getEnvValue(key) {
|
|
@@ -1629,25 +1457,25 @@ var FileService = class {
|
|
|
1629
1457
|
*/
|
|
1630
1458
|
async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
|
|
1631
1459
|
const __filename = fileURLToPath(import.meta.url);
|
|
1632
|
-
const __dirname =
|
|
1633
|
-
const filePath =
|
|
1634
|
-
const fileString =
|
|
1635
|
-
if (
|
|
1636
|
-
console.
|
|
1460
|
+
const __dirname = path.dirname(__filename);
|
|
1461
|
+
const filePath = path.resolve(__dirname, "starter-files", inputFile);
|
|
1462
|
+
const fileString = fs3__default__default.readFileSync(filePath, "utf8");
|
|
1463
|
+
if (fs3__default__default.existsSync(outputFilePath) && !replaceIfExists) {
|
|
1464
|
+
console.info(`${outputFilePath} already exists`);
|
|
1637
1465
|
return false;
|
|
1638
1466
|
}
|
|
1639
|
-
await
|
|
1467
|
+
await fsExtra.outputFile(outputFilePath, fileString);
|
|
1640
1468
|
return true;
|
|
1641
1469
|
}
|
|
1642
1470
|
async setupEnvFile({ dbUrl }) {
|
|
1643
|
-
const envPath =
|
|
1644
|
-
await
|
|
1471
|
+
const envPath = path.join(process.cwd(), ".env.development");
|
|
1472
|
+
await fsExtra.ensureFile(envPath);
|
|
1645
1473
|
const fileEnvService = new FileEnvService(envPath);
|
|
1646
1474
|
await fileEnvService.setEnvValue("DB_URL", dbUrl);
|
|
1647
1475
|
}
|
|
1648
1476
|
getFirstExistingFile(files) {
|
|
1649
1477
|
for (const f of files) {
|
|
1650
|
-
if (
|
|
1478
|
+
if (fs3__default__default.existsSync(f)) {
|
|
1651
1479
|
return f;
|
|
1652
1480
|
}
|
|
1653
1481
|
}
|
|
@@ -1657,66 +1485,31 @@ var FileService = class {
|
|
|
1657
1485
|
filePath,
|
|
1658
1486
|
replacements
|
|
1659
1487
|
}) {
|
|
1660
|
-
let fileContent =
|
|
1488
|
+
let fileContent = fs3__default__default.readFileSync(filePath, "utf8");
|
|
1661
1489
|
replacements.forEach(({ search, replace }) => {
|
|
1662
1490
|
fileContent = fileContent.replaceAll(search, replace);
|
|
1663
1491
|
});
|
|
1664
|
-
|
|
1665
|
-
}
|
|
1666
|
-
};
|
|
1667
|
-
var exec2 = util.promisify(child_process.exec);
|
|
1668
|
-
var getAISDKPackageVersion = (llmProvider) => {
|
|
1669
|
-
switch (llmProvider) {
|
|
1670
|
-
case "cerebras":
|
|
1671
|
-
return "^0.2.14";
|
|
1672
|
-
default:
|
|
1673
|
-
return "^1.0.0";
|
|
1492
|
+
fs3__default__default.writeFileSync(filePath, fileContent);
|
|
1674
1493
|
}
|
|
1675
1494
|
};
|
|
1676
|
-
var
|
|
1677
|
-
|
|
1678
|
-
case "openai":
|
|
1679
|
-
return "@ai-sdk/openai";
|
|
1680
|
-
case "anthropic":
|
|
1681
|
-
return "@ai-sdk/anthropic";
|
|
1682
|
-
case "groq":
|
|
1683
|
-
return "@ai-sdk/groq";
|
|
1684
|
-
case "google":
|
|
1685
|
-
return "@ai-sdk/google";
|
|
1686
|
-
case "cerebras":
|
|
1687
|
-
return "@ai-sdk/cerebras";
|
|
1688
|
-
case "mistral":
|
|
1689
|
-
return "@ai-sdk/mistral";
|
|
1690
|
-
default:
|
|
1691
|
-
return "@ai-sdk/openai";
|
|
1692
|
-
}
|
|
1693
|
-
};
|
|
1694
|
-
var getProviderImportAndModelItem = (llmProvider) => {
|
|
1695
|
-
let providerImport = "";
|
|
1696
|
-
let modelItem = "";
|
|
1495
|
+
var exec = util.promisify(child_process.exec);
|
|
1496
|
+
var getModelIdentifier = (llmProvider) => {
|
|
1697
1497
|
if (llmProvider === "openai") {
|
|
1698
|
-
|
|
1699
|
-
modelItem = `openai('gpt-4o-mini')`;
|
|
1498
|
+
return `'openai/gpt-4o-mini'`;
|
|
1700
1499
|
} else if (llmProvider === "anthropic") {
|
|
1701
|
-
|
|
1702
|
-
modelItem = `anthropic('claude-3-5-sonnet-20241022')`;
|
|
1500
|
+
return `'anthropic/claude-sonnet-4-5-20250929'`;
|
|
1703
1501
|
} else if (llmProvider === "groq") {
|
|
1704
|
-
|
|
1705
|
-
modelItem = `groq('llama-3.3-70b-versatile')`;
|
|
1502
|
+
return `'groq/llama-3.3-70b-versatile'`;
|
|
1706
1503
|
} else if (llmProvider === "google") {
|
|
1707
|
-
|
|
1708
|
-
modelItem = `google('gemini-2.5-pro')`;
|
|
1504
|
+
return `'google/gemini-2.5-pro'`;
|
|
1709
1505
|
} else if (llmProvider === "cerebras") {
|
|
1710
|
-
|
|
1711
|
-
modelItem = `cerebras('llama-3.3-70b')`;
|
|
1506
|
+
return `'cerebras/llama-3.3-70b'`;
|
|
1712
1507
|
} else if (llmProvider === "mistral") {
|
|
1713
|
-
|
|
1714
|
-
modelItem = `mistral('mistral-medium-2508')`;
|
|
1508
|
+
return `'mistral/mistral-medium-2508'`;
|
|
1715
1509
|
}
|
|
1716
|
-
return { providerImport, modelItem };
|
|
1717
1510
|
};
|
|
1718
|
-
async function writeAgentSample(llmProvider, destPath, addExampleTool) {
|
|
1719
|
-
const
|
|
1511
|
+
async function writeAgentSample(llmProvider, destPath, addExampleTool, addScorers) {
|
|
1512
|
+
const modelString = getModelIdentifier(llmProvider);
|
|
1720
1513
|
const instructions = `
|
|
1721
1514
|
You are a helpful weather assistant that provides accurate weather information and can help planning activities based on the weather.
|
|
1722
1515
|
|
|
@@ -1732,17 +1525,40 @@ async function writeAgentSample(llmProvider, destPath, addExampleTool) {
|
|
|
1732
1525
|
${addExampleTool ? "Use the weatherTool to fetch current weather data." : ""}
|
|
1733
1526
|
`;
|
|
1734
1527
|
const content = `
|
|
1735
|
-
${providerImport}
|
|
1736
1528
|
import { Agent } from '@mastra/core/agent';
|
|
1737
1529
|
import { Memory } from '@mastra/memory';
|
|
1738
1530
|
import { LibSQLStore } from '@mastra/libsql';
|
|
1739
1531
|
${addExampleTool ? `import { weatherTool } from '../tools/weather-tool';` : ""}
|
|
1532
|
+
${addScorers ? `import { scorers } from '../scorers/weather-scorer';` : ""}
|
|
1740
1533
|
|
|
1741
1534
|
export const weatherAgent = new Agent({
|
|
1742
1535
|
name: 'Weather Agent',
|
|
1743
1536
|
instructions: \`${instructions}\`,
|
|
1744
|
-
model: ${
|
|
1537
|
+
model: ${modelString},
|
|
1745
1538
|
${addExampleTool ? "tools: { weatherTool }," : ""}
|
|
1539
|
+
${addScorers ? `scorers: {
|
|
1540
|
+
toolCallAppropriateness: {
|
|
1541
|
+
scorer: scorers.toolCallAppropriatenessScorer,
|
|
1542
|
+
sampling: {
|
|
1543
|
+
type: 'ratio',
|
|
1544
|
+
rate: 1,
|
|
1545
|
+
},
|
|
1546
|
+
},
|
|
1547
|
+
completeness: {
|
|
1548
|
+
scorer: scorers.completenessScorer,
|
|
1549
|
+
sampling: {
|
|
1550
|
+
type: 'ratio',
|
|
1551
|
+
rate: 1,
|
|
1552
|
+
},
|
|
1553
|
+
},
|
|
1554
|
+
translation: {
|
|
1555
|
+
scorer: scorers.translationScorer,
|
|
1556
|
+
sampling: {
|
|
1557
|
+
type: 'ratio',
|
|
1558
|
+
rate: 1,
|
|
1559
|
+
},
|
|
1560
|
+
},
|
|
1561
|
+
},` : ""}
|
|
1746
1562
|
memory: new Memory({
|
|
1747
1563
|
storage: new LibSQLStore({
|
|
1748
1564
|
url: "file:../mastra.db", // path is relative to the .mastra/output directory
|
|
@@ -1754,8 +1570,8 @@ export const weatherAgent = new Agent({
|
|
|
1754
1570
|
parser: "typescript",
|
|
1755
1571
|
singleQuote: true
|
|
1756
1572
|
});
|
|
1757
|
-
await
|
|
1758
|
-
await
|
|
1573
|
+
await fs4.writeFile(destPath, "");
|
|
1574
|
+
await fs4.writeFile(destPath, formattedContent);
|
|
1759
1575
|
}
|
|
1760
1576
|
async function writeWorkflowSample(destPath) {
|
|
1761
1577
|
const content = `import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
@@ -1948,44 +1764,139 @@ export { weatherWorkflow };`;
|
|
|
1948
1764
|
semi: true,
|
|
1949
1765
|
singleQuote: true
|
|
1950
1766
|
});
|
|
1951
|
-
await
|
|
1767
|
+
await fs4.writeFile(destPath, formattedContent);
|
|
1952
1768
|
}
|
|
1953
1769
|
async function writeToolSample(destPath) {
|
|
1954
1770
|
const fileService = new FileService();
|
|
1955
1771
|
await fileService.copyStarterFile("tools.ts", destPath);
|
|
1956
1772
|
}
|
|
1773
|
+
async function writeScorersSample(llmProvider, destPath) {
|
|
1774
|
+
const modelString = getModelIdentifier(llmProvider);
|
|
1775
|
+
const content = `import { z } from 'zod';
|
|
1776
|
+
import { createToolCallAccuracyScorerCode } from '@mastra/evals/scorers/code';
|
|
1777
|
+
import { createCompletenessScorer } from '@mastra/evals/scorers/code';
|
|
1778
|
+
import { createScorer } from '@mastra/core/scores';
|
|
1779
|
+
|
|
1780
|
+
export const toolCallAppropriatenessScorer = createToolCallAccuracyScorerCode({
|
|
1781
|
+
expectedTool: 'weatherTool',
|
|
1782
|
+
strictMode: false,
|
|
1783
|
+
});
|
|
1784
|
+
|
|
1785
|
+
export const completenessScorer = createCompletenessScorer();
|
|
1786
|
+
|
|
1787
|
+
// Custom LLM-judged scorer: evaluates if non-English locations are translated appropriately
|
|
1788
|
+
export const translationScorer = createScorer({
|
|
1789
|
+
name: 'Translation Quality',
|
|
1790
|
+
description: 'Checks that non-English location names are translated and used correctly',
|
|
1791
|
+
type: 'agent',
|
|
1792
|
+
judge: {
|
|
1793
|
+
model: ${modelString},
|
|
1794
|
+
instructions:
|
|
1795
|
+
'You are an expert evaluator of translation quality for geographic locations. ' +
|
|
1796
|
+
'Determine whether the user text mentions a non-English location and whether the assistant correctly uses an English translation of that location. ' +
|
|
1797
|
+
'Be lenient with transliteration differences and diacritics. ' +
|
|
1798
|
+
'Return only the structured JSON matching the provided schema.',
|
|
1799
|
+
},
|
|
1800
|
+
})
|
|
1801
|
+
.preprocess(({ run }) => {
|
|
1802
|
+
const userText = (run.input?.inputMessages?.[0]?.content as string) || '';
|
|
1803
|
+
const assistantText = (run.output?.[0]?.content as string) || '';
|
|
1804
|
+
return { userText, assistantText };
|
|
1805
|
+
})
|
|
1806
|
+
.analyze({
|
|
1807
|
+
description: 'Extract location names and detect language/translation adequacy',
|
|
1808
|
+
outputSchema: z.object({
|
|
1809
|
+
nonEnglish: z.boolean(),
|
|
1810
|
+
translated: z.boolean(),
|
|
1811
|
+
confidence: z.number().min(0).max(1).default(1),
|
|
1812
|
+
explanation: z.string().default(''),
|
|
1813
|
+
}),
|
|
1814
|
+
createPrompt: ({ results }) => \`
|
|
1815
|
+
You are evaluating if a weather assistant correctly handled translation of a non-English location.
|
|
1816
|
+
User text:
|
|
1817
|
+
"""
|
|
1818
|
+
\${results.preprocessStepResult.userText}
|
|
1819
|
+
"""
|
|
1820
|
+
Assistant response:
|
|
1821
|
+
"""
|
|
1822
|
+
\${results.preprocessStepResult.assistantText}
|
|
1823
|
+
"""
|
|
1824
|
+
Tasks:
|
|
1825
|
+
1) Identify if the user mentioned a location that appears non-English.
|
|
1826
|
+
2) If non-English, check whether the assistant used a correct English translation of that location in its response.
|
|
1827
|
+
3) Be lenient with transliteration differences (e.g., accents/diacritics).
|
|
1828
|
+
Return JSON with fields:
|
|
1829
|
+
{
|
|
1830
|
+
"nonEnglish": boolean,
|
|
1831
|
+
"translated": boolean,
|
|
1832
|
+
"confidence": number, // 0-1
|
|
1833
|
+
"explanation": string
|
|
1834
|
+
}
|
|
1835
|
+
\`,
|
|
1836
|
+
})
|
|
1837
|
+
.generateScore(({ results }) => {
|
|
1838
|
+
const r = (results as any)?.analyzeStepResult || {};
|
|
1839
|
+
if (!r.nonEnglish) return 1; // If not applicable, full credit
|
|
1840
|
+
if (r.translated) return Math.max(0, Math.min(1, 0.7 + 0.3 * (r.confidence ?? 1)));
|
|
1841
|
+
return 0; // Non-English but not translated
|
|
1842
|
+
})
|
|
1843
|
+
.generateReason(({ results, score }) => {
|
|
1844
|
+
const r = (results as any)?.analyzeStepResult || {};
|
|
1845
|
+
return \`Translation scoring: nonEnglish=\${r.nonEnglish ?? false}, translated=\${r.translated ?? false}, confidence=\${r.confidence ?? 0}. Score=\${score}. \${r.explanation ?? ''}\`;
|
|
1846
|
+
});
|
|
1847
|
+
|
|
1848
|
+
export const scorers = {
|
|
1849
|
+
toolCallAppropriatenessScorer,
|
|
1850
|
+
completenessScorer,
|
|
1851
|
+
translationScorer,
|
|
1852
|
+
};`;
|
|
1853
|
+
const formattedContent = await prettier.format(content, {
|
|
1854
|
+
parser: "typescript",
|
|
1855
|
+
singleQuote: true
|
|
1856
|
+
});
|
|
1857
|
+
await fs4.writeFile(destPath, formattedContent);
|
|
1858
|
+
}
|
|
1957
1859
|
async function writeCodeSampleForComponents(llmprovider, component, destPath, importComponents) {
|
|
1958
1860
|
switch (component) {
|
|
1959
1861
|
case "agents":
|
|
1960
|
-
return writeAgentSample(
|
|
1862
|
+
return writeAgentSample(
|
|
1863
|
+
llmprovider,
|
|
1864
|
+
destPath,
|
|
1865
|
+
importComponents.includes("tools"),
|
|
1866
|
+
importComponents.includes("scorers")
|
|
1867
|
+
);
|
|
1961
1868
|
case "tools":
|
|
1962
1869
|
return writeToolSample(destPath);
|
|
1963
1870
|
case "workflows":
|
|
1964
1871
|
return writeWorkflowSample(destPath);
|
|
1872
|
+
case "scorers":
|
|
1873
|
+
return writeScorersSample(llmprovider, destPath);
|
|
1965
1874
|
default:
|
|
1966
1875
|
return "";
|
|
1967
1876
|
}
|
|
1968
1877
|
}
|
|
1969
1878
|
var createComponentsDir = async (dirPath, component) => {
|
|
1970
1879
|
const componentPath = dirPath + `/${component}`;
|
|
1971
|
-
await
|
|
1880
|
+
await fsExtra.ensureDir(componentPath);
|
|
1972
1881
|
};
|
|
1973
1882
|
var writeIndexFile = async ({
|
|
1974
1883
|
dirPath,
|
|
1975
1884
|
addAgent,
|
|
1976
1885
|
addExample,
|
|
1977
|
-
addWorkflow
|
|
1886
|
+
addWorkflow,
|
|
1887
|
+
addScorers
|
|
1978
1888
|
}) => {
|
|
1979
1889
|
const indexPath = dirPath + "/index.ts";
|
|
1980
|
-
const destPath =
|
|
1890
|
+
const destPath = path.join(indexPath);
|
|
1981
1891
|
try {
|
|
1982
|
-
await
|
|
1892
|
+
await fs4.writeFile(destPath, "");
|
|
1983
1893
|
const filteredExports = [
|
|
1984
1894
|
addWorkflow ? `workflows: { weatherWorkflow },` : "",
|
|
1985
|
-
addAgent ? `agents: { weatherAgent },` : ""
|
|
1895
|
+
addAgent ? `agents: { weatherAgent },` : "",
|
|
1896
|
+
addScorers ? `scorers: { toolCallAppropriatenessScorer, completenessScorer, translationScorer },` : ""
|
|
1986
1897
|
].filter(Boolean);
|
|
1987
1898
|
if (!addExample) {
|
|
1988
|
-
await
|
|
1899
|
+
await fs4.writeFile(
|
|
1989
1900
|
destPath,
|
|
1990
1901
|
`
|
|
1991
1902
|
import { Mastra } from '@mastra/core';
|
|
@@ -1995,7 +1906,7 @@ export const mastra = new Mastra()
|
|
|
1995
1906
|
);
|
|
1996
1907
|
return;
|
|
1997
1908
|
}
|
|
1998
|
-
await
|
|
1909
|
+
await fs4.writeFile(
|
|
1999
1910
|
destPath,
|
|
2000
1911
|
`
|
|
2001
1912
|
import { Mastra } from '@mastra/core/mastra';
|
|
@@ -2003,17 +1914,22 @@ import { PinoLogger } from '@mastra/loggers';
|
|
|
2003
1914
|
import { LibSQLStore } from '@mastra/libsql';
|
|
2004
1915
|
${addWorkflow ? `import { weatherWorkflow } from './workflows/weather-workflow';` : ""}
|
|
2005
1916
|
${addAgent ? `import { weatherAgent } from './agents/weather-agent';` : ""}
|
|
1917
|
+
${addScorers ? `import { toolCallAppropriatenessScorer, completenessScorer, translationScorer } from './scorers/weather-scorer';` : ""}
|
|
2006
1918
|
|
|
2007
1919
|
export const mastra = new Mastra({
|
|
2008
1920
|
${filteredExports.join("\n ")}
|
|
2009
1921
|
storage: new LibSQLStore({
|
|
2010
|
-
// stores
|
|
1922
|
+
// stores observability, scores, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
2011
1923
|
url: ":memory:",
|
|
2012
1924
|
}),
|
|
2013
1925
|
logger: new PinoLogger({
|
|
2014
1926
|
name: 'Mastra',
|
|
2015
1927
|
level: 'info',
|
|
2016
1928
|
}),
|
|
1929
|
+
observability: {
|
|
1930
|
+
// Enables DefaultExporter and CloudExporter for AI tracing
|
|
1931
|
+
default: { enabled: true },
|
|
1932
|
+
},
|
|
2017
1933
|
});
|
|
2018
1934
|
`
|
|
2019
1935
|
);
|
|
@@ -2021,7 +1937,6 @@ export const mastra = new Mastra({
|
|
|
2021
1937
|
throw err;
|
|
2022
1938
|
}
|
|
2023
1939
|
};
|
|
2024
|
-
yoctoSpinner({ text: "Installing Mastra core dependencies\n" });
|
|
2025
1940
|
var getAPIKey = async (provider) => {
|
|
2026
1941
|
let key = "OPENAI_API_KEY";
|
|
2027
1942
|
switch (provider) {
|
|
@@ -2044,23 +1959,21 @@ var getAPIKey = async (provider) => {
|
|
|
2044
1959
|
return key;
|
|
2045
1960
|
}
|
|
2046
1961
|
};
|
|
2047
|
-
var writeAPIKey = async ({
|
|
2048
|
-
|
|
2049
|
-
apiKey = "your-api-key"
|
|
2050
|
-
}) => {
|
|
1962
|
+
var writeAPIKey = async ({ provider, apiKey }) => {
|
|
1963
|
+
const envFileName = apiKey ? ".env" : ".env.example";
|
|
2051
1964
|
const key = await getAPIKey(provider);
|
|
2052
|
-
const escapedKey =
|
|
2053
|
-
const escapedApiKey =
|
|
2054
|
-
await
|
|
1965
|
+
const escapedKey = shellQuote2.quote([key]);
|
|
1966
|
+
const escapedApiKey = shellQuote2.quote([apiKey ? apiKey : "your-api-key"]);
|
|
1967
|
+
await exec(`echo ${escapedKey}=${escapedApiKey} >> ${envFileName}`);
|
|
2055
1968
|
};
|
|
2056
1969
|
var createMastraDir = async (directory) => {
|
|
2057
1970
|
let dir = directory.trim().split("/").filter((item) => item !== "");
|
|
2058
|
-
const dirPath =
|
|
1971
|
+
const dirPath = path.join(process.cwd(), ...dir, "mastra");
|
|
2059
1972
|
try {
|
|
2060
|
-
await
|
|
1973
|
+
await fs4.access(dirPath);
|
|
2061
1974
|
return { ok: false };
|
|
2062
1975
|
} catch {
|
|
2063
|
-
await
|
|
1976
|
+
await fsExtra.ensureDir(dirPath);
|
|
2064
1977
|
return { ok: true, dirPath };
|
|
2065
1978
|
}
|
|
2066
1979
|
};
|
|
@@ -2072,8 +1985,19 @@ var writeCodeSample = async (dirPath, component, llmProvider, importComponents)
|
|
|
2072
1985
|
throw err;
|
|
2073
1986
|
}
|
|
2074
1987
|
};
|
|
2075
|
-
var
|
|
2076
|
-
|
|
1988
|
+
var LLM_PROVIDERS = [
|
|
1989
|
+
{ value: "openai", label: "OpenAI", hint: "recommended" },
|
|
1990
|
+
{ value: "anthropic", label: "Anthropic" },
|
|
1991
|
+
{ value: "groq", label: "Groq" },
|
|
1992
|
+
{ value: "google", label: "Google" },
|
|
1993
|
+
{ value: "cerebras", label: "Cerebras" },
|
|
1994
|
+
{ value: "mistral", label: "Mistral" }
|
|
1995
|
+
];
|
|
1996
|
+
var interactivePrompt = async (args2 = {}) => {
|
|
1997
|
+
const { skip = {}, options: { showBanner = true } = {} } = args2;
|
|
1998
|
+
if (showBanner) {
|
|
1999
|
+
Ie(color2.inverse(" Mastra Init "));
|
|
2000
|
+
}
|
|
2077
2001
|
const mastraProject = await Ce(
|
|
2078
2002
|
{
|
|
2079
2003
|
directory: () => he({
|
|
@@ -2081,20 +2005,15 @@ var interactivePrompt = async () => {
|
|
|
2081
2005
|
placeholder: "src/",
|
|
2082
2006
|
defaultValue: "src/"
|
|
2083
2007
|
}),
|
|
2084
|
-
llmProvider: () => ve({
|
|
2085
|
-
message: "Select default provider:",
|
|
2086
|
-
options:
|
|
2087
|
-
{ value: "openai", label: "OpenAI", hint: "recommended" },
|
|
2088
|
-
{ value: "anthropic", label: "Anthropic" },
|
|
2089
|
-
{ value: "groq", label: "Groq" },
|
|
2090
|
-
{ value: "google", label: "Google" },
|
|
2091
|
-
{ value: "cerebras", label: "Cerebras" },
|
|
2092
|
-
{ value: "mistral", label: "Mistral" }
|
|
2093
|
-
]
|
|
2008
|
+
llmProvider: () => skip?.llmProvider ? void 0 : ve({
|
|
2009
|
+
message: "Select a default provider:",
|
|
2010
|
+
options: LLM_PROVIDERS
|
|
2094
2011
|
}),
|
|
2095
2012
|
llmApiKey: async ({ results: { llmProvider } }) => {
|
|
2013
|
+
if (skip?.llmApiKey) return void 0;
|
|
2014
|
+
const llmName = LLM_PROVIDERS.find((p6) => p6.value === llmProvider)?.label || "provider";
|
|
2096
2015
|
const keyChoice = await ve({
|
|
2097
|
-
message: `Enter your ${
|
|
2016
|
+
message: `Enter your ${llmName} API key?`,
|
|
2098
2017
|
options: [
|
|
2099
2018
|
{ value: "skip", label: "Skip for now", hint: "default" },
|
|
2100
2019
|
{ value: "enter", label: "Enter API key" }
|
|
@@ -2104,7 +2023,10 @@ var interactivePrompt = async () => {
|
|
|
2104
2023
|
if (keyChoice === "enter") {
|
|
2105
2024
|
return he({
|
|
2106
2025
|
message: "Enter your API key:",
|
|
2107
|
-
placeholder: "sk-..."
|
|
2026
|
+
placeholder: "sk-...",
|
|
2027
|
+
validate: (value) => {
|
|
2028
|
+
if (value.length === 0) return "API key cannot be empty";
|
|
2029
|
+
}
|
|
2108
2030
|
});
|
|
2109
2031
|
}
|
|
2110
2032
|
return void 0;
|
|
@@ -2114,7 +2036,7 @@ var interactivePrompt = async () => {
|
|
|
2114
2036
|
const cursorIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`cursor`);
|
|
2115
2037
|
const vscodeIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`vscode`);
|
|
2116
2038
|
const editor = await ve({
|
|
2117
|
-
message: `Make your
|
|
2039
|
+
message: `Make your IDE into a Mastra expert? (Installs Mastra's MCP server)`,
|
|
2118
2040
|
options: [
|
|
2119
2041
|
{ value: "skip", label: "Skip for now", hint: "default" },
|
|
2120
2042
|
{
|
|
@@ -2158,19 +2080,19 @@ Note: you will need to go into Cursor Settings -> MCP Settings and manually enab
|
|
|
2158
2080
|
);
|
|
2159
2081
|
}
|
|
2160
2082
|
if (editor === `cursor-global`) {
|
|
2161
|
-
const
|
|
2083
|
+
const confirm = await ve({
|
|
2162
2084
|
message: `Global install will add/update ${cursorGlobalMCPConfigPath} and make the Mastra docs MCP server available in all your Cursor projects. Continue?`,
|
|
2163
2085
|
options: [
|
|
2164
2086
|
{ value: "yes", label: "Yes, I understand" },
|
|
2165
2087
|
{ value: "skip", label: "No, skip for now" }
|
|
2166
2088
|
]
|
|
2167
2089
|
});
|
|
2168
|
-
if (
|
|
2090
|
+
if (confirm !== `yes`) {
|
|
2169
2091
|
return void 0;
|
|
2170
2092
|
}
|
|
2171
2093
|
}
|
|
2172
2094
|
if (editor === `windsurf`) {
|
|
2173
|
-
const
|
|
2095
|
+
const confirm = await ve({
|
|
2174
2096
|
message: `Windsurf only supports a global MCP config (at ${windsurfGlobalMCPConfigPath}) is it ok to add/update that global config?
|
|
2175
2097
|
This means the Mastra docs MCP server will be available in all your Windsurf projects.`,
|
|
2176
2098
|
options: [
|
|
@@ -2178,7 +2100,7 @@ This means the Mastra docs MCP server will be available in all your Windsurf pro
|
|
|
2178
2100
|
{ value: "skip", label: "No, skip for now" }
|
|
2179
2101
|
]
|
|
2180
2102
|
});
|
|
2181
|
-
if (
|
|
2103
|
+
if (confirm !== `yes`) {
|
|
2182
2104
|
return void 0;
|
|
2183
2105
|
}
|
|
2184
2106
|
}
|
|
@@ -2194,14 +2116,193 @@ This means the Mastra docs MCP server will be available in all your Windsurf pro
|
|
|
2194
2116
|
);
|
|
2195
2117
|
return mastraProject;
|
|
2196
2118
|
};
|
|
2119
|
+
function getPackageManager() {
|
|
2120
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
2121
|
+
const execPath = process.env.npm_execpath || "";
|
|
2122
|
+
if (userAgent.includes("yarn")) {
|
|
2123
|
+
return "yarn";
|
|
2124
|
+
}
|
|
2125
|
+
if (userAgent.includes("pnpm")) {
|
|
2126
|
+
return "pnpm";
|
|
2127
|
+
}
|
|
2128
|
+
if (userAgent.includes("npm")) {
|
|
2129
|
+
return "npm";
|
|
2130
|
+
}
|
|
2131
|
+
if (execPath.includes("yarn")) {
|
|
2132
|
+
return "yarn";
|
|
2133
|
+
}
|
|
2134
|
+
if (execPath.includes("pnpm")) {
|
|
2135
|
+
return "pnpm";
|
|
2136
|
+
}
|
|
2137
|
+
if (execPath.includes("npm")) {
|
|
2138
|
+
return "npm";
|
|
2139
|
+
}
|
|
2140
|
+
return "npm";
|
|
2141
|
+
}
|
|
2142
|
+
var logger = createLogger(false);
|
|
2143
|
+
function createLogger(debug = false) {
|
|
2144
|
+
return new PinoLogger({
|
|
2145
|
+
name: "Mastra CLI",
|
|
2146
|
+
level: debug ? "debug" : "info"
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
var exec2 = util.promisify(child_process.exec);
|
|
2150
|
+
async function cloneTemplate(options) {
|
|
2151
|
+
const { template, projectName, targetDir } = options;
|
|
2152
|
+
const projectPath = targetDir ? path.resolve(targetDir, projectName) : path.resolve(projectName);
|
|
2153
|
+
const spinner4 = yoctoSpinner({ text: `Cloning template "${template.title}"...` }).start();
|
|
2154
|
+
try {
|
|
2155
|
+
if (await directoryExists(projectPath)) {
|
|
2156
|
+
spinner4.error(`Directory ${projectName} already exists`);
|
|
2157
|
+
throw new Error(`Directory ${projectName} already exists`);
|
|
2158
|
+
}
|
|
2159
|
+
await cloneRepositoryWithoutGit(template.githubUrl, projectPath);
|
|
2160
|
+
await updatePackageJson(projectPath, projectName);
|
|
2161
|
+
const envExamplePath = path.join(projectPath, ".env.example");
|
|
2162
|
+
if (await fileExists(envExamplePath)) {
|
|
2163
|
+
await fs4.copyFile(envExamplePath, path.join(projectPath, ".env"));
|
|
2164
|
+
}
|
|
2165
|
+
spinner4.success(`Template "${template.title}" cloned successfully to ${projectName}`);
|
|
2166
|
+
return projectPath;
|
|
2167
|
+
} catch (error) {
|
|
2168
|
+
spinner4.error(`Failed to clone template: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2169
|
+
throw error;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
async function directoryExists(dirPath) {
|
|
2173
|
+
try {
|
|
2174
|
+
const stat = await fs4.stat(dirPath);
|
|
2175
|
+
return stat.isDirectory();
|
|
2176
|
+
} catch {
|
|
2177
|
+
return false;
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
async function fileExists(filePath) {
|
|
2181
|
+
try {
|
|
2182
|
+
const stat = await fs4.stat(filePath);
|
|
2183
|
+
return stat.isFile();
|
|
2184
|
+
} catch {
|
|
2185
|
+
return false;
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
async function cloneRepositoryWithoutGit(repoUrl, targetPath) {
|
|
2189
|
+
await fs4.mkdir(targetPath, { recursive: true });
|
|
2190
|
+
try {
|
|
2191
|
+
const degitRepo = repoUrl.replace("https://github.com/", "");
|
|
2192
|
+
const degitCommand = shellQuote2.quote(["npx", "degit", degitRepo, targetPath]);
|
|
2193
|
+
await exec2(degitCommand, {
|
|
2194
|
+
cwd: process.cwd()
|
|
2195
|
+
});
|
|
2196
|
+
} catch {
|
|
2197
|
+
try {
|
|
2198
|
+
const gitCommand = shellQuote2.quote(["git", "clone", repoUrl, targetPath]);
|
|
2199
|
+
await exec2(gitCommand, {
|
|
2200
|
+
cwd: process.cwd()
|
|
2201
|
+
});
|
|
2202
|
+
const gitDir = path.join(targetPath, ".git");
|
|
2203
|
+
if (await directoryExists(gitDir)) {
|
|
2204
|
+
await fs4.rm(gitDir, { recursive: true, force: true });
|
|
2205
|
+
}
|
|
2206
|
+
} catch (gitError) {
|
|
2207
|
+
throw new Error(`Failed to clone repository: ${gitError instanceof Error ? gitError.message : "Unknown error"}`);
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
async function updatePackageJson(projectPath, projectName) {
|
|
2212
|
+
const packageJsonPath = path.join(projectPath, "package.json");
|
|
2213
|
+
try {
|
|
2214
|
+
const packageJsonContent = await fs4.readFile(packageJsonPath, "utf-8");
|
|
2215
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
2216
|
+
packageJson.name = projectName;
|
|
2217
|
+
await fs4.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf-8");
|
|
2218
|
+
} catch (error) {
|
|
2219
|
+
logger.warn(`Could not update package.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
async function installDependencies(projectPath, packageManager) {
|
|
2223
|
+
const spinner4 = yoctoSpinner({ text: "Installing dependencies..." }).start();
|
|
2224
|
+
try {
|
|
2225
|
+
const pm = packageManager || getPackageManager();
|
|
2226
|
+
const installCommand = shellQuote2.quote([pm, "install"]);
|
|
2227
|
+
await exec2(installCommand, {
|
|
2228
|
+
cwd: projectPath
|
|
2229
|
+
});
|
|
2230
|
+
spinner4.success("Dependencies installed successfully");
|
|
2231
|
+
} catch (error) {
|
|
2232
|
+
spinner4.error(`Failed to install dependencies: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2233
|
+
throw error;
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
var TEMPLATES_API_URL = process.env.MASTRA_TEMPLATES_API_URL || "https://mastra.ai/api/templates.json";
|
|
2237
|
+
async function loadTemplates() {
|
|
2238
|
+
try {
|
|
2239
|
+
const response = await fetch(TEMPLATES_API_URL);
|
|
2240
|
+
if (!response.ok) {
|
|
2241
|
+
throw new Error(`Failed to fetch templates: ${response.statusText}`);
|
|
2242
|
+
}
|
|
2243
|
+
const templates = await response.json();
|
|
2244
|
+
return templates;
|
|
2245
|
+
} catch (error) {
|
|
2246
|
+
console.error("Error loading templates:", error);
|
|
2247
|
+
throw new Error("Failed to load templates. Please check your internet connection and try again.");
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
function pluralize(count, singular, plural) {
|
|
2251
|
+
return count === 1 ? singular : plural || `${singular}s`;
|
|
2252
|
+
}
|
|
2253
|
+
async function selectTemplate(templates) {
|
|
2254
|
+
const choices = templates.map((template) => {
|
|
2255
|
+
const parts = [];
|
|
2256
|
+
if (template.agents?.length) {
|
|
2257
|
+
parts.push(`${template.agents.length} ${pluralize(template.agents.length, "agent")}`);
|
|
2258
|
+
}
|
|
2259
|
+
if (template.tools?.length) {
|
|
2260
|
+
parts.push(`${template.tools.length} ${pluralize(template.tools.length, "tool")}`);
|
|
2261
|
+
}
|
|
2262
|
+
if (template.workflows?.length) {
|
|
2263
|
+
parts.push(`${template.workflows.length} ${pluralize(template.workflows.length, "workflow")}`);
|
|
2264
|
+
}
|
|
2265
|
+
if (template.mcp?.length) {
|
|
2266
|
+
parts.push(`${template.mcp.length} ${pluralize(template.mcp.length, "MCP server")}`);
|
|
2267
|
+
}
|
|
2268
|
+
if (template.networks?.length) {
|
|
2269
|
+
parts.push(`${template.networks.length} ${pluralize(template.networks.length, "agent network")}`);
|
|
2270
|
+
}
|
|
2271
|
+
return {
|
|
2272
|
+
value: template,
|
|
2273
|
+
label: template.title,
|
|
2274
|
+
hint: parts.join(", ") || "Template components"
|
|
2275
|
+
};
|
|
2276
|
+
});
|
|
2277
|
+
const selected = await ve({
|
|
2278
|
+
message: "Select a template:",
|
|
2279
|
+
options: choices
|
|
2280
|
+
});
|
|
2281
|
+
if (pD(selected)) {
|
|
2282
|
+
return null;
|
|
2283
|
+
}
|
|
2284
|
+
return selected;
|
|
2285
|
+
}
|
|
2286
|
+
function findTemplateByName(templates, templateName) {
|
|
2287
|
+
let template = templates.find((t) => t.slug === templateName);
|
|
2288
|
+
if (template) return template;
|
|
2289
|
+
const slugWithPrefix = `template-${templateName}`;
|
|
2290
|
+
template = templates.find((t) => t.slug === slugWithPrefix);
|
|
2291
|
+
if (template) return template;
|
|
2292
|
+
template = templates.find((t) => t.title.toLowerCase() === templateName.toLowerCase());
|
|
2293
|
+
if (template) return template;
|
|
2294
|
+
return null;
|
|
2295
|
+
}
|
|
2296
|
+
function getDefaultProjectName(template) {
|
|
2297
|
+
return template.slug.replace(/^template-/, "");
|
|
2298
|
+
}
|
|
2197
2299
|
var s = Y();
|
|
2198
|
-
var exec3 = util.promisify(child_process.exec);
|
|
2199
2300
|
var init = async ({
|
|
2200
|
-
directory,
|
|
2201
|
-
addExample = false,
|
|
2301
|
+
directory = "src/",
|
|
2202
2302
|
components,
|
|
2203
2303
|
llmProvider = "openai",
|
|
2204
2304
|
llmApiKey,
|
|
2305
|
+
addExample = false,
|
|
2205
2306
|
configureEditorWithDocsMCP
|
|
2206
2307
|
}) => {
|
|
2207
2308
|
s.start("Initializing Mastra");
|
|
@@ -2217,7 +2318,8 @@ var init = async ({
|
|
|
2217
2318
|
dirPath,
|
|
2218
2319
|
addExample,
|
|
2219
2320
|
addWorkflow: components.includes("workflows"),
|
|
2220
|
-
addAgent: components.includes("agents")
|
|
2321
|
+
addAgent: components.includes("agents"),
|
|
2322
|
+
addScorers: components.includes("scorers")
|
|
2221
2323
|
}),
|
|
2222
2324
|
...components.map((component) => createComponentsDir(dirPath, component)),
|
|
2223
2325
|
writeAPIKey({ provider: llmProvider, apiKey: llmApiKey })
|
|
@@ -2241,14 +2343,16 @@ var init = async ({
|
|
|
2241
2343
|
if (needsLoggers) {
|
|
2242
2344
|
await depService.installPackages(["@mastra/loggers"]);
|
|
2243
2345
|
}
|
|
2346
|
+
const needsObservability = await depService.checkDependencies(["@mastra/observability"]) !== `ok`;
|
|
2347
|
+
if (needsObservability) {
|
|
2348
|
+
await depService.installPackages(["@mastra/observability"]);
|
|
2349
|
+
}
|
|
2350
|
+
const needsEvals = components.includes(`scorers`) && await depService.checkDependencies(["@mastra/evals"]) !== `ok`;
|
|
2351
|
+
if (needsEvals) {
|
|
2352
|
+
await depService.installPackages(["@mastra/evals"]);
|
|
2353
|
+
}
|
|
2244
2354
|
}
|
|
2245
2355
|
const key = await getAPIKey(llmProvider || "openai");
|
|
2246
|
-
const aiSdkPackage = getAISDKPackage(llmProvider);
|
|
2247
|
-
const aiSdkPackageVersion = getAISDKPackageVersion(llmProvider);
|
|
2248
|
-
const depsService = new DepsService();
|
|
2249
|
-
const pm = depsService.packageManager;
|
|
2250
|
-
const installCommand = getPackageManagerAddCommand(pm);
|
|
2251
|
-
await exec3(`${pm} ${installCommand} ${aiSdkPackage}@${aiSdkPackageVersion}`);
|
|
2252
2356
|
if (configureEditorWithDocsMCP) {
|
|
2253
2357
|
await installMastraDocsMCPServer({
|
|
2254
2358
|
editor: configureEditorWithDocsMCP,
|
|
@@ -2275,10 +2379,10 @@ var init = async ({
|
|
|
2275
2379
|
return { success: false };
|
|
2276
2380
|
}
|
|
2277
2381
|
};
|
|
2278
|
-
var
|
|
2382
|
+
var exec3 = util.promisify(child_process.exec);
|
|
2279
2383
|
var execWithTimeout = async (command, timeoutMs) => {
|
|
2280
2384
|
try {
|
|
2281
|
-
const promise =
|
|
2385
|
+
const promise = exec3(command, { killSignal: "SIGTERM" });
|
|
2282
2386
|
if (!timeoutMs) {
|
|
2283
2387
|
return await promise;
|
|
2284
2388
|
}
|
|
@@ -2326,23 +2430,39 @@ async function installMastraDependency(pm, dependency, versionTag, isDev, timeou
|
|
|
2326
2430
|
var createMastraProject = async ({
|
|
2327
2431
|
projectName: name,
|
|
2328
2432
|
createVersionTag,
|
|
2329
|
-
timeout
|
|
2433
|
+
timeout,
|
|
2434
|
+
llmProvider,
|
|
2435
|
+
llmApiKey,
|
|
2436
|
+
needsInteractive
|
|
2330
2437
|
}) => {
|
|
2331
2438
|
Ie(color2.inverse(" Mastra Create "));
|
|
2332
2439
|
const projectName = name ?? await he({
|
|
2333
2440
|
message: "What do you want to name your project?",
|
|
2334
2441
|
placeholder: "my-mastra-app",
|
|
2335
|
-
defaultValue: "my-mastra-app"
|
|
2442
|
+
defaultValue: "my-mastra-app",
|
|
2443
|
+
validate: (value) => {
|
|
2444
|
+
if (value.length === 0) return "Project name cannot be empty";
|
|
2445
|
+
if (fs3__default__default.existsSync(value)) {
|
|
2446
|
+
return `A directory named "${value}" already exists. Please choose a different name.`;
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2336
2449
|
});
|
|
2337
2450
|
if (pD(projectName)) {
|
|
2338
2451
|
xe("Operation cancelled");
|
|
2339
2452
|
process.exit(0);
|
|
2340
2453
|
}
|
|
2454
|
+
let result;
|
|
2455
|
+
if (needsInteractive) {
|
|
2456
|
+
result = await interactivePrompt({
|
|
2457
|
+
options: { showBanner: false },
|
|
2458
|
+
skip: { llmProvider: llmProvider !== void 0, llmApiKey: llmApiKey !== void 0 }
|
|
2459
|
+
});
|
|
2460
|
+
}
|
|
2341
2461
|
const s2 = Y();
|
|
2342
2462
|
try {
|
|
2343
2463
|
s2.start("Creating project");
|
|
2344
2464
|
try {
|
|
2345
|
-
await
|
|
2465
|
+
await fs4.mkdir(projectName);
|
|
2346
2466
|
} catch (error) {
|
|
2347
2467
|
if (error instanceof Error && "code" in error && error.code === "EEXIST") {
|
|
2348
2468
|
s2.stop(`A directory named "${projectName}" already exists. Please choose a different name.`);
|
|
@@ -2357,9 +2477,9 @@ var createMastraProject = async ({
|
|
|
2357
2477
|
const installCommand = getPackageManagerAddCommand(pm);
|
|
2358
2478
|
s2.message("Initializing project structure");
|
|
2359
2479
|
try {
|
|
2360
|
-
await
|
|
2361
|
-
await
|
|
2362
|
-
await
|
|
2480
|
+
await exec3(`npm init -y`);
|
|
2481
|
+
await exec3(`npm pkg set type="module"`);
|
|
2482
|
+
await exec3(`npm pkg set engines.node=">=20.9.0"`);
|
|
2363
2483
|
const depsService = new DepsService();
|
|
2364
2484
|
await depsService.addScriptsToPackageJson({
|
|
2365
2485
|
dev: "mastra dev",
|
|
@@ -2374,9 +2494,9 @@ var createMastraProject = async ({
|
|
|
2374
2494
|
s2.stop("Project structure created");
|
|
2375
2495
|
s2.start(`Installing ${pm} dependencies`);
|
|
2376
2496
|
try {
|
|
2377
|
-
await
|
|
2378
|
-
await
|
|
2379
|
-
await
|
|
2497
|
+
await exec3(`${pm} ${installCommand} zod@^4`);
|
|
2498
|
+
await exec3(`${pm} ${installCommand} typescript @types/node --save-dev`);
|
|
2499
|
+
await exec3(`echo '{
|
|
2380
2500
|
"compilerOptions": {
|
|
2381
2501
|
"target": "ES2022",
|
|
2382
2502
|
"module": "ES2022",
|
|
@@ -2398,15 +2518,15 @@ var createMastraProject = async ({
|
|
|
2398
2518
|
);
|
|
2399
2519
|
}
|
|
2400
2520
|
s2.stop(`${pm} dependencies installed`);
|
|
2401
|
-
s2.start("Installing
|
|
2521
|
+
s2.start("Installing Mastra CLI");
|
|
2402
2522
|
const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
|
|
2403
2523
|
try {
|
|
2404
2524
|
await installMastraDependency(pm, "mastra", versionTag, true, timeout);
|
|
2405
2525
|
} catch (error) {
|
|
2406
2526
|
throw new Error(`Failed to install Mastra CLI: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2407
2527
|
}
|
|
2408
|
-
s2.stop("
|
|
2409
|
-
s2.start("Installing dependencies");
|
|
2528
|
+
s2.stop("Mastra CLI installed");
|
|
2529
|
+
s2.start("Installing Mastra dependencies");
|
|
2410
2530
|
try {
|
|
2411
2531
|
await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
|
|
2412
2532
|
await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
|
|
@@ -2419,21 +2539,21 @@ var createMastraProject = async ({
|
|
|
2419
2539
|
s2.stop("Mastra dependencies installed");
|
|
2420
2540
|
s2.start("Adding .gitignore");
|
|
2421
2541
|
try {
|
|
2422
|
-
await
|
|
2423
|
-
await
|
|
2424
|
-
await
|
|
2425
|
-
await
|
|
2426
|
-
await
|
|
2427
|
-
await
|
|
2428
|
-
await
|
|
2429
|
-
await
|
|
2542
|
+
await exec3(`echo output.txt >> .gitignore`);
|
|
2543
|
+
await exec3(`echo node_modules >> .gitignore`);
|
|
2544
|
+
await exec3(`echo dist >> .gitignore`);
|
|
2545
|
+
await exec3(`echo .mastra >> .gitignore`);
|
|
2546
|
+
await exec3(`echo .env.development >> .gitignore`);
|
|
2547
|
+
await exec3(`echo .env >> .gitignore`);
|
|
2548
|
+
await exec3(`echo *.db >> .gitignore`);
|
|
2549
|
+
await exec3(`echo *.db-* >> .gitignore`);
|
|
2430
2550
|
} catch (error) {
|
|
2431
2551
|
throw new Error(`Failed to create .gitignore: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2432
2552
|
}
|
|
2433
2553
|
s2.stop(".gitignore added");
|
|
2434
2554
|
Se("Project created successfully");
|
|
2435
|
-
console.
|
|
2436
|
-
return { projectName };
|
|
2555
|
+
console.info("");
|
|
2556
|
+
return { projectName, result };
|
|
2437
2557
|
} catch (error) {
|
|
2438
2558
|
s2.stop();
|
|
2439
2559
|
const errorMessage = error instanceof Error ? error.message : "An unexpected error occurred";
|
|
@@ -2446,18 +2566,21 @@ var create = async (args2) => {
|
|
|
2446
2566
|
await createFromTemplate({ ...args2, injectedAnalytics: args2.analytics });
|
|
2447
2567
|
return;
|
|
2448
2568
|
}
|
|
2449
|
-
const
|
|
2569
|
+
const needsInteractive = args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0;
|
|
2570
|
+
const { projectName, result } = await createMastraProject({
|
|
2450
2571
|
projectName: args2?.projectName,
|
|
2451
2572
|
createVersionTag: args2?.createVersionTag,
|
|
2452
|
-
timeout: args2?.timeout
|
|
2573
|
+
timeout: args2?.timeout,
|
|
2574
|
+
llmProvider: args2?.llmProvider,
|
|
2575
|
+
llmApiKey: args2?.llmApiKey,
|
|
2576
|
+
needsInteractive
|
|
2453
2577
|
});
|
|
2454
2578
|
const directory = args2.directory || "src/";
|
|
2455
|
-
if (
|
|
2456
|
-
const result = await interactivePrompt();
|
|
2579
|
+
if (needsInteractive && result) {
|
|
2457
2580
|
await init({
|
|
2458
2581
|
...result,
|
|
2459
2582
|
llmApiKey: result?.llmApiKey,
|
|
2460
|
-
components: ["agents", "tools", "workflows"],
|
|
2583
|
+
components: ["agents", "tools", "workflows", "scorers"],
|
|
2461
2584
|
addExample: true
|
|
2462
2585
|
});
|
|
2463
2586
|
postCreate({ projectName });
|
|
@@ -2573,16 +2696,16 @@ async function createFromTemplate(args2) {
|
|
|
2573
2696
|
selectedTemplate = selected;
|
|
2574
2697
|
} else if (args2.template && typeof args2.template === "string") {
|
|
2575
2698
|
if (isGitHubUrl(args2.template)) {
|
|
2576
|
-
const
|
|
2577
|
-
|
|
2699
|
+
const spinner4 = Y();
|
|
2700
|
+
spinner4.start("Validating GitHub repository...");
|
|
2578
2701
|
const validation = await validateGitHubProject(args2.template);
|
|
2579
2702
|
if (!validation.isValid) {
|
|
2580
|
-
|
|
2703
|
+
spinner4.stop("Validation failed");
|
|
2581
2704
|
M.error("This does not appear to be a valid Mastra project:");
|
|
2582
2705
|
validation.errors.forEach((error) => M.error(` - ${error}`));
|
|
2583
2706
|
throw new Error("Invalid Mastra project");
|
|
2584
2707
|
}
|
|
2585
|
-
|
|
2708
|
+
spinner4.stop("Valid Mastra project \u2713");
|
|
2586
2709
|
selectedTemplate = await createFromGitHubUrl(args2.template);
|
|
2587
2710
|
} else {
|
|
2588
2711
|
const templates = await loadTemplates();
|
|
@@ -2641,14 +2764,14 @@ async function createFromTemplate(args2) {
|
|
|
2641
2764
|
async function getPackageVersion() {
|
|
2642
2765
|
const __filename = fileURLToPath(import.meta.url);
|
|
2643
2766
|
const __dirname = dirname(__filename);
|
|
2644
|
-
const pkgJsonPath =
|
|
2645
|
-
const content = await fsExtra.readJSON(pkgJsonPath);
|
|
2767
|
+
const pkgJsonPath = path.join(__dirname, "..", "package.json");
|
|
2768
|
+
const content = await fsExtra$1.readJSON(pkgJsonPath);
|
|
2646
2769
|
return content.version;
|
|
2647
2770
|
}
|
|
2648
2771
|
async function getCreateVersionTag() {
|
|
2649
2772
|
try {
|
|
2650
2773
|
const pkgPath = fileURLToPath(import.meta.resolve("create-mastra/package.json"));
|
|
2651
|
-
const json = await fsExtra.readJSON(pkgPath);
|
|
2774
|
+
const json = await fsExtra$1.readJSON(pkgPath);
|
|
2652
2775
|
const { stdout } = await execa("npm", ["dist-tag", "create-mastra"]);
|
|
2653
2776
|
const tagLine = stdout.split("\n").find((distLine) => distLine.endsWith(`: ${json.version}`));
|
|
2654
2777
|
const tag = tagLine ? tagLine.split(":")[0].trim() : "latest";
|
|
@@ -2672,14 +2795,14 @@ program.version(`${version}`, "-v, --version").description(`create-mastra ${vers
|
|
|
2672
2795
|
analytics.trackCommand({
|
|
2673
2796
|
command: "version"
|
|
2674
2797
|
});
|
|
2675
|
-
console.
|
|
2798
|
+
console.info(`create-mastra ${version}`);
|
|
2676
2799
|
} catch {
|
|
2677
2800
|
}
|
|
2678
2801
|
});
|
|
2679
2802
|
program.name("create-mastra").description("Create a new Mastra project").argument("[project-name]", "Directory name of the project").option(
|
|
2680
2803
|
"-p, --project-name <string>",
|
|
2681
2804
|
"Project name that will be used in package.json and as the project directory name."
|
|
2682
|
-
).option("--default", "Quick start with defaults(src, OpenAI, examples)").option("-c, --components <components>", "Comma-separated list of components (agents, tools, workflows)").option("-l, --llm <model-provider>", "Default model provider (openai, anthropic, groq, google, or cerebras)").option("-k, --llm-api-key <api-key>", "API key for the model provider").option("-e, --example", "Include example code").option("-n, --no-example", "Do not include example code").option("-t, --timeout [timeout]", "Configurable timeout for package installation, defaults to 60000 ms").option("-d, --dir <directory>", "Target directory for Mastra source code (default: src/)").option("-m, --mcp <mcp>", "MCP Server for code editor (cursor, cursor-global, windsurf, vscode)").option(
|
|
2805
|
+
).option("--default", "Quick start with defaults (src, OpenAI, examples)").option("-c, --components <components>", "Comma-separated list of components (agents, tools, workflows, scorers)").option("-l, --llm <model-provider>", "Default model provider (openai, anthropic, groq, google, or cerebras)").option("-k, --llm-api-key <api-key>", "API key for the model provider").option("-e, --example", "Include example code").option("-n, --no-example", "Do not include example code").option("-t, --timeout [timeout]", "Configurable timeout for package installation, defaults to 60000 ms").option("-d, --dir <directory>", "Target directory for Mastra source code (default: src/)").option("-m, --mcp <mcp>", "MCP Server for code editor (cursor, cursor-global, windsurf, vscode)").option(
|
|
2683
2806
|
"--template [template-name]",
|
|
2684
2807
|
"Create project from a template (use template name, public GitHub URL, or leave blank to select from list)"
|
|
2685
2808
|
).action(async (projectNameArg, args) => {
|
|
@@ -2687,7 +2810,7 @@ program.name("create-mastra").description("Create a new Mastra project").argumen
|
|
|
2687
2810
|
const timeout = args?.timeout ? args?.timeout === true ? 6e4 : parseInt(args?.timeout, 10) : void 0;
|
|
2688
2811
|
if (args.default) {
|
|
2689
2812
|
await create({
|
|
2690
|
-
components: ["agents", "tools", "workflows"],
|
|
2813
|
+
components: ["agents", "tools", "workflows", "scorers"],
|
|
2691
2814
|
llmProvider: "openai",
|
|
2692
2815
|
addExample: true,
|
|
2693
2816
|
createVersionTag,
|
|
@@ -2703,7 +2826,7 @@ program.name("create-mastra").description("Create a new Mastra project").argumen
|
|
|
2703
2826
|
components: args.components ? args.components.split(",") : [],
|
|
2704
2827
|
llmProvider: args.llm,
|
|
2705
2828
|
addExample: args.example,
|
|
2706
|
-
llmApiKey: args
|
|
2829
|
+
llmApiKey: args.llmApiKey,
|
|
2707
2830
|
createVersionTag,
|
|
2708
2831
|
timeout,
|
|
2709
2832
|
projectName,
|