create-mastra 0.0.0-cloud-deployer-for-core-0.19.1-20251001164939 → 0.0.0-cloud-storage-adapter-20251106204059
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 +277 -1
- package/README.md +10 -32
- package/dist/index.js +597 -464
- package/dist/index.js.map +1 -1
- package/dist/starter-files/tools.ts +2 -2
- package/dist/templates/dev.entry.js +2 -45
- package/package.json +8 -8
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 pino from 'pino';
|
|
19
|
-
import pretty from 'pino-pretty';
|
|
20
|
-
import { execa } from 'execa';
|
|
21
18
|
import fsExtra, { readJSON, ensureFile, writeJSON } from 'fs-extra/esm';
|
|
22
19
|
import prettier from 'prettier';
|
|
20
|
+
import { execa } from 'execa';
|
|
21
|
+
import pino from 'pino';
|
|
22
|
+
import pretty from 'pino-pretty';
|
|
23
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
|
}
|
|
@@ -1090,11 +1095,11 @@ var MastraLogger = class {
|
|
|
1090
1095
|
}
|
|
1091
1096
|
trackException(_error) {
|
|
1092
1097
|
}
|
|
1093
|
-
async
|
|
1098
|
+
async listLogs(transportId, params) {
|
|
1094
1099
|
if (!transportId || !this.transports.has(transportId)) {
|
|
1095
1100
|
return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
|
|
1096
1101
|
}
|
|
1097
|
-
return this.transports.get(transportId).
|
|
1102
|
+
return this.transports.get(transportId).listLogs(params) ?? {
|
|
1098
1103
|
logs: [],
|
|
1099
1104
|
total: 0,
|
|
1100
1105
|
page: params?.page ?? 1,
|
|
@@ -1102,7 +1107,7 @@ var MastraLogger = class {
|
|
|
1102
1107
|
hasMore: false
|
|
1103
1108
|
};
|
|
1104
1109
|
}
|
|
1105
|
-
async
|
|
1110
|
+
async listLogsByRunId({
|
|
1106
1111
|
transportId,
|
|
1107
1112
|
runId,
|
|
1108
1113
|
fromDate,
|
|
@@ -1115,7 +1120,7 @@ var MastraLogger = class {
|
|
|
1115
1120
|
if (!transportId || !this.transports.has(transportId) || !runId) {
|
|
1116
1121
|
return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };
|
|
1117
1122
|
}
|
|
1118
|
-
return this.transports.get(transportId).
|
|
1123
|
+
return this.transports.get(transportId).listLogsByRunId({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {
|
|
1119
1124
|
logs: [],
|
|
1120
1125
|
total: 0,
|
|
1121
1126
|
page: page ?? 1,
|
|
@@ -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 fs5.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 fs5.stat(dirPath);
|
|
1229
|
-
return stat.isDirectory();
|
|
1230
|
-
} catch {
|
|
1231
|
-
return false;
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
async function fileExists(filePath) {
|
|
1235
|
-
try {
|
|
1236
|
-
const stat = await fs5.stat(filePath);
|
|
1237
|
-
return stat.isFile();
|
|
1238
|
-
} catch {
|
|
1239
|
-
return false;
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
async function cloneRepositoryWithoutGit(repoUrl, targetPath) {
|
|
1243
|
-
await fs5.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 fs5.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 fs5.readFile(packageJsonPath, "utf-8");
|
|
1269
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
1270
|
-
packageJson.name = projectName;
|
|
1271
|
-
await fs5.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 fs5.access(packageJsonPath);
|
|
1415
|
-
} catch {
|
|
1416
|
-
return "No package.json file found in the current directory";
|
|
1417
|
-
}
|
|
1418
|
-
const packageJson = JSON.parse(await fs5.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 fs5.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 fs5.readFile("package.json", "utf-8"));
|
|
1442
|
-
packageJson.scripts = {
|
|
1443
|
-
...packageJson.scripts,
|
|
1444
|
-
...scripts
|
|
1445
|
-
};
|
|
1446
|
-
await fs5.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
|
-
|
|
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);
|
|
1574
1402
|
});
|
|
1575
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
|
});
|
|
@@ -1629,10 +1457,10 @@ 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 (
|
|
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) {
|
|
1636
1464
|
console.info(`${outputFilePath} already exists`);
|
|
1637
1465
|
return false;
|
|
1638
1466
|
}
|
|
@@ -1640,14 +1468,14 @@ var FileService = class {
|
|
|
1640
1468
|
return true;
|
|
1641
1469
|
}
|
|
1642
1470
|
async setupEnvFile({ dbUrl }) {
|
|
1643
|
-
const envPath =
|
|
1471
|
+
const envPath = path.join(process.cwd(), ".env.development");
|
|
1644
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,19 +1525,44 @@ 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({
|
|
1535
|
+
id: 'weather-agent',
|
|
1742
1536
|
name: 'Weather Agent',
|
|
1743
1537
|
instructions: \`${instructions}\`,
|
|
1744
|
-
model: ${
|
|
1538
|
+
model: ${modelString},
|
|
1745
1539
|
${addExampleTool ? "tools: { weatherTool }," : ""}
|
|
1540
|
+
${addScorers ? `scorers: {
|
|
1541
|
+
toolCallAppropriateness: {
|
|
1542
|
+
scorer: scorers.toolCallAppropriatenessScorer,
|
|
1543
|
+
sampling: {
|
|
1544
|
+
type: 'ratio',
|
|
1545
|
+
rate: 1,
|
|
1546
|
+
},
|
|
1547
|
+
},
|
|
1548
|
+
completeness: {
|
|
1549
|
+
scorer: scorers.completenessScorer,
|
|
1550
|
+
sampling: {
|
|
1551
|
+
type: 'ratio',
|
|
1552
|
+
rate: 1,
|
|
1553
|
+
},
|
|
1554
|
+
},
|
|
1555
|
+
translation: {
|
|
1556
|
+
scorer: scorers.translationScorer,
|
|
1557
|
+
sampling: {
|
|
1558
|
+
type: 'ratio',
|
|
1559
|
+
rate: 1,
|
|
1560
|
+
},
|
|
1561
|
+
},
|
|
1562
|
+
},` : ""}
|
|
1746
1563
|
memory: new Memory({
|
|
1747
1564
|
storage: new LibSQLStore({
|
|
1565
|
+
id: "memory-storage",
|
|
1748
1566
|
url: "file:../mastra.db", // path is relative to the .mastra/output directory
|
|
1749
1567
|
})
|
|
1750
1568
|
})
|
|
@@ -1754,8 +1572,8 @@ export const weatherAgent = new Agent({
|
|
|
1754
1572
|
parser: "typescript",
|
|
1755
1573
|
singleQuote: true
|
|
1756
1574
|
});
|
|
1757
|
-
await
|
|
1758
|
-
await
|
|
1575
|
+
await fs4.writeFile(destPath, "");
|
|
1576
|
+
await fs4.writeFile(destPath, formattedContent);
|
|
1759
1577
|
}
|
|
1760
1578
|
async function writeWorkflowSample(destPath) {
|
|
1761
1579
|
const content = `import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
@@ -1948,20 +1766,115 @@ export { weatherWorkflow };`;
|
|
|
1948
1766
|
semi: true,
|
|
1949
1767
|
singleQuote: true
|
|
1950
1768
|
});
|
|
1951
|
-
await
|
|
1769
|
+
await fs4.writeFile(destPath, formattedContent);
|
|
1952
1770
|
}
|
|
1953
1771
|
async function writeToolSample(destPath) {
|
|
1954
1772
|
const fileService = new FileService();
|
|
1955
1773
|
await fileService.copyStarterFile("tools.ts", destPath);
|
|
1956
1774
|
}
|
|
1775
|
+
async function writeScorersSample(llmProvider, destPath) {
|
|
1776
|
+
const modelString = getModelIdentifier(llmProvider);
|
|
1777
|
+
const content = `import { z } from 'zod';
|
|
1778
|
+
import { createToolCallAccuracyScorerCode } from '@mastra/evals/scorers/prebuilt';
|
|
1779
|
+
import { createCompletenessScorer } from '@mastra/evals/scorers/prebuilt';
|
|
1780
|
+
import { getAssistantMessageFromRunOutput, getUserMessageFromRunInput } from '@mastra/evals/scorers/utils';
|
|
1781
|
+
import { createScorer } from '@mastra/core/evals';
|
|
1782
|
+
|
|
1783
|
+
export const toolCallAppropriatenessScorer = createToolCallAccuracyScorerCode({
|
|
1784
|
+
expectedTool: 'weatherTool',
|
|
1785
|
+
strictMode: false,
|
|
1786
|
+
});
|
|
1787
|
+
|
|
1788
|
+
export const completenessScorer = createCompletenessScorer();
|
|
1789
|
+
|
|
1790
|
+
// Custom LLM-judged scorer: evaluates if non-English locations are translated appropriately
|
|
1791
|
+
export const translationScorer = createScorer({
|
|
1792
|
+
id: 'translation-quality-scorer',
|
|
1793
|
+
name: 'Translation Quality',
|
|
1794
|
+
description: 'Checks that non-English location names are translated and used correctly',
|
|
1795
|
+
type: 'agent',
|
|
1796
|
+
judge: {
|
|
1797
|
+
model: ${modelString},
|
|
1798
|
+
instructions:
|
|
1799
|
+
'You are an expert evaluator of translation quality for geographic locations. ' +
|
|
1800
|
+
'Determine whether the user text mentions a non-English location and whether the assistant correctly uses an English translation of that location. ' +
|
|
1801
|
+
'Be lenient with transliteration differences and diacritics. ' +
|
|
1802
|
+
'Return only the structured JSON matching the provided schema.',
|
|
1803
|
+
},
|
|
1804
|
+
})
|
|
1805
|
+
.preprocess(({ run }) => {
|
|
1806
|
+
const userText = getUserMessageFromRunInput(run.input) || '';
|
|
1807
|
+
const assistantText = getAssistantMessageFromRunOutput(run.output) || '';
|
|
1808
|
+
return { userText, assistantText };
|
|
1809
|
+
})
|
|
1810
|
+
.analyze({
|
|
1811
|
+
description: 'Extract location names and detect language/translation adequacy',
|
|
1812
|
+
outputSchema: z.object({
|
|
1813
|
+
nonEnglish: z.boolean(),
|
|
1814
|
+
translated: z.boolean(),
|
|
1815
|
+
confidence: z.number().min(0).max(1).default(1),
|
|
1816
|
+
explanation: z.string().default(''),
|
|
1817
|
+
}),
|
|
1818
|
+
createPrompt: ({ results }) => \`
|
|
1819
|
+
You are evaluating if a weather assistant correctly handled translation of a non-English location.
|
|
1820
|
+
User text:
|
|
1821
|
+
"""
|
|
1822
|
+
\${results.preprocessStepResult.userText}
|
|
1823
|
+
"""
|
|
1824
|
+
Assistant response:
|
|
1825
|
+
"""
|
|
1826
|
+
\${results.preprocessStepResult.assistantText}
|
|
1827
|
+
"""
|
|
1828
|
+
Tasks:
|
|
1829
|
+
1) Identify if the user mentioned a location that appears non-English.
|
|
1830
|
+
2) If non-English, check whether the assistant used a correct English translation of that location in its response.
|
|
1831
|
+
3) Be lenient with transliteration differences (e.g., accents/diacritics).
|
|
1832
|
+
Return JSON with fields:
|
|
1833
|
+
{
|
|
1834
|
+
"nonEnglish": boolean,
|
|
1835
|
+
"translated": boolean,
|
|
1836
|
+
"confidence": number, // 0-1
|
|
1837
|
+
"explanation": string
|
|
1838
|
+
}
|
|
1839
|
+
\`,
|
|
1840
|
+
})
|
|
1841
|
+
.generateScore(({ results }) => {
|
|
1842
|
+
const r = (results as any)?.analyzeStepResult || {};
|
|
1843
|
+
if (!r.nonEnglish) return 1; // If not applicable, full credit
|
|
1844
|
+
if (r.translated) return Math.max(0, Math.min(1, 0.7 + 0.3 * (r.confidence ?? 1)));
|
|
1845
|
+
return 0; // Non-English but not translated
|
|
1846
|
+
})
|
|
1847
|
+
.generateReason(({ results, score }) => {
|
|
1848
|
+
const r = (results as any)?.analyzeStepResult || {};
|
|
1849
|
+
return \`Translation scoring: nonEnglish=\${r.nonEnglish ?? false}, translated=\${r.translated ?? false}, confidence=\${r.confidence ?? 0}. Score=\${score}. \${r.explanation ?? ''}\`;
|
|
1850
|
+
});
|
|
1851
|
+
|
|
1852
|
+
export const scorers = {
|
|
1853
|
+
toolCallAppropriatenessScorer,
|
|
1854
|
+
completenessScorer,
|
|
1855
|
+
translationScorer,
|
|
1856
|
+
};`;
|
|
1857
|
+
const formattedContent = await prettier.format(content, {
|
|
1858
|
+
parser: "typescript",
|
|
1859
|
+
singleQuote: true
|
|
1860
|
+
});
|
|
1861
|
+
await fs4.writeFile(destPath, formattedContent);
|
|
1862
|
+
}
|
|
1957
1863
|
async function writeCodeSampleForComponents(llmprovider, component, destPath, importComponents) {
|
|
1958
1864
|
switch (component) {
|
|
1959
1865
|
case "agents":
|
|
1960
|
-
return writeAgentSample(
|
|
1866
|
+
return writeAgentSample(
|
|
1867
|
+
llmprovider,
|
|
1868
|
+
destPath,
|
|
1869
|
+
importComponents.includes("tools"),
|
|
1870
|
+
importComponents.includes("scorers")
|
|
1871
|
+
);
|
|
1961
1872
|
case "tools":
|
|
1962
1873
|
return writeToolSample(destPath);
|
|
1963
1874
|
case "workflows":
|
|
1964
1875
|
return writeWorkflowSample(destPath);
|
|
1876
|
+
case "scorers":
|
|
1877
|
+
return writeScorersSample(llmprovider, destPath);
|
|
1965
1878
|
default:
|
|
1966
1879
|
return "";
|
|
1967
1880
|
}
|
|
@@ -1974,46 +1887,55 @@ var writeIndexFile = async ({
|
|
|
1974
1887
|
dirPath,
|
|
1975
1888
|
addAgent,
|
|
1976
1889
|
addExample,
|
|
1977
|
-
addWorkflow
|
|
1890
|
+
addWorkflow,
|
|
1891
|
+
addScorers
|
|
1978
1892
|
}) => {
|
|
1979
1893
|
const indexPath = dirPath + "/index.ts";
|
|
1980
|
-
const destPath =
|
|
1894
|
+
const destPath = path.join(indexPath);
|
|
1981
1895
|
try {
|
|
1982
|
-
await
|
|
1896
|
+
await fs4.writeFile(destPath, "");
|
|
1983
1897
|
const filteredExports = [
|
|
1984
1898
|
addWorkflow ? `workflows: { weatherWorkflow },` : "",
|
|
1985
|
-
addAgent ? `agents: { weatherAgent },` : ""
|
|
1899
|
+
addAgent ? `agents: { weatherAgent },` : "",
|
|
1900
|
+
addScorers ? `scorers: { toolCallAppropriatenessScorer, completenessScorer, translationScorer },` : ""
|
|
1986
1901
|
].filter(Boolean);
|
|
1987
1902
|
if (!addExample) {
|
|
1988
|
-
await
|
|
1903
|
+
await fs4.writeFile(
|
|
1989
1904
|
destPath,
|
|
1990
1905
|
`
|
|
1991
|
-
import { Mastra } from '@mastra/core';
|
|
1906
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
1992
1907
|
|
|
1993
1908
|
export const mastra = new Mastra()
|
|
1994
1909
|
`
|
|
1995
1910
|
);
|
|
1996
1911
|
return;
|
|
1997
1912
|
}
|
|
1998
|
-
await
|
|
1913
|
+
await fs4.writeFile(
|
|
1999
1914
|
destPath,
|
|
2000
1915
|
`
|
|
2001
1916
|
import { Mastra } from '@mastra/core/mastra';
|
|
2002
1917
|
import { PinoLogger } from '@mastra/loggers';
|
|
2003
1918
|
import { LibSQLStore } from '@mastra/libsql';
|
|
1919
|
+
import { Observability } from '@mastra/observability';
|
|
2004
1920
|
${addWorkflow ? `import { weatherWorkflow } from './workflows/weather-workflow';` : ""}
|
|
2005
1921
|
${addAgent ? `import { weatherAgent } from './agents/weather-agent';` : ""}
|
|
1922
|
+
${addScorers ? `import { toolCallAppropriatenessScorer, completenessScorer, translationScorer } from './scorers/weather-scorer';` : ""}
|
|
2006
1923
|
|
|
2007
1924
|
export const mastra = new Mastra({
|
|
2008
1925
|
${filteredExports.join("\n ")}
|
|
2009
1926
|
storage: new LibSQLStore({
|
|
2010
|
-
|
|
1927
|
+
id: "mastra-storage",
|
|
1928
|
+
// stores observability, scores, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
2011
1929
|
url: ":memory:",
|
|
2012
1930
|
}),
|
|
2013
1931
|
logger: new PinoLogger({
|
|
2014
1932
|
name: 'Mastra',
|
|
2015
1933
|
level: 'info',
|
|
2016
1934
|
}),
|
|
1935
|
+
observability: new Observability({
|
|
1936
|
+
// Enables DefaultExporter and CloudExporter for tracing
|
|
1937
|
+
default: { enabled: true },
|
|
1938
|
+
}),
|
|
2017
1939
|
});
|
|
2018
1940
|
`
|
|
2019
1941
|
);
|
|
@@ -2021,7 +1943,6 @@ export const mastra = new Mastra({
|
|
|
2021
1943
|
throw err;
|
|
2022
1944
|
}
|
|
2023
1945
|
};
|
|
2024
|
-
yoctoSpinner({ text: "Installing Mastra core dependencies\n" });
|
|
2025
1946
|
var getAPIKey = async (provider) => {
|
|
2026
1947
|
let key = "OPENAI_API_KEY";
|
|
2027
1948
|
switch (provider) {
|
|
@@ -2044,20 +1965,18 @@ var getAPIKey = async (provider) => {
|
|
|
2044
1965
|
return key;
|
|
2045
1966
|
}
|
|
2046
1967
|
};
|
|
2047
|
-
var writeAPIKey = async ({
|
|
2048
|
-
|
|
2049
|
-
apiKey = "your-api-key"
|
|
2050
|
-
}) => {
|
|
1968
|
+
var writeAPIKey = async ({ provider, apiKey }) => {
|
|
1969
|
+
const envFileName = apiKey ? ".env" : ".env.example";
|
|
2051
1970
|
const key = await getAPIKey(provider);
|
|
2052
|
-
const escapedKey =
|
|
2053
|
-
const escapedApiKey =
|
|
2054
|
-
await
|
|
1971
|
+
const escapedKey = shellQuote2.quote([key]);
|
|
1972
|
+
const escapedApiKey = shellQuote2.quote([apiKey ? apiKey : "your-api-key"]);
|
|
1973
|
+
await exec(`echo ${escapedKey}=${escapedApiKey} >> ${envFileName}`);
|
|
2055
1974
|
};
|
|
2056
1975
|
var createMastraDir = async (directory) => {
|
|
2057
1976
|
let dir = directory.trim().split("/").filter((item) => item !== "");
|
|
2058
|
-
const dirPath =
|
|
1977
|
+
const dirPath = path.join(process.cwd(), ...dir, "mastra");
|
|
2059
1978
|
try {
|
|
2060
|
-
await
|
|
1979
|
+
await fs4.access(dirPath);
|
|
2061
1980
|
return { ok: false };
|
|
2062
1981
|
} catch {
|
|
2063
1982
|
await fsExtra.ensureDir(dirPath);
|
|
@@ -2072,8 +1991,19 @@ var writeCodeSample = async (dirPath, component, llmProvider, importComponents)
|
|
|
2072
1991
|
throw err;
|
|
2073
1992
|
}
|
|
2074
1993
|
};
|
|
2075
|
-
var
|
|
2076
|
-
|
|
1994
|
+
var LLM_PROVIDERS = [
|
|
1995
|
+
{ value: "openai", label: "OpenAI", hint: "recommended" },
|
|
1996
|
+
{ value: "anthropic", label: "Anthropic" },
|
|
1997
|
+
{ value: "groq", label: "Groq" },
|
|
1998
|
+
{ value: "google", label: "Google" },
|
|
1999
|
+
{ value: "cerebras", label: "Cerebras" },
|
|
2000
|
+
{ value: "mistral", label: "Mistral" }
|
|
2001
|
+
];
|
|
2002
|
+
var interactivePrompt = async (args2 = {}) => {
|
|
2003
|
+
const { skip = {}, options: { showBanner = true } = {} } = args2;
|
|
2004
|
+
if (showBanner) {
|
|
2005
|
+
Ie(color2.inverse(" Mastra Init "));
|
|
2006
|
+
}
|
|
2077
2007
|
const mastraProject = await Ce(
|
|
2078
2008
|
{
|
|
2079
2009
|
directory: () => he({
|
|
@@ -2081,20 +2011,15 @@ var interactivePrompt = async () => {
|
|
|
2081
2011
|
placeholder: "src/",
|
|
2082
2012
|
defaultValue: "src/"
|
|
2083
2013
|
}),
|
|
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
|
-
]
|
|
2014
|
+
llmProvider: () => skip?.llmProvider ? void 0 : ve({
|
|
2015
|
+
message: "Select a default provider:",
|
|
2016
|
+
options: LLM_PROVIDERS
|
|
2094
2017
|
}),
|
|
2095
2018
|
llmApiKey: async ({ results: { llmProvider } }) => {
|
|
2019
|
+
if (skip?.llmApiKey) return void 0;
|
|
2020
|
+
const llmName = LLM_PROVIDERS.find((p6) => p6.value === llmProvider)?.label || "provider";
|
|
2096
2021
|
const keyChoice = await ve({
|
|
2097
|
-
message: `Enter your ${
|
|
2022
|
+
message: `Enter your ${llmName} API key?`,
|
|
2098
2023
|
options: [
|
|
2099
2024
|
{ value: "skip", label: "Skip for now", hint: "default" },
|
|
2100
2025
|
{ value: "enter", label: "Enter API key" }
|
|
@@ -2104,7 +2029,10 @@ var interactivePrompt = async () => {
|
|
|
2104
2029
|
if (keyChoice === "enter") {
|
|
2105
2030
|
return he({
|
|
2106
2031
|
message: "Enter your API key:",
|
|
2107
|
-
placeholder: "sk-..."
|
|
2032
|
+
placeholder: "sk-...",
|
|
2033
|
+
validate: (value) => {
|
|
2034
|
+
if (value.length === 0) return "API key cannot be empty";
|
|
2035
|
+
}
|
|
2108
2036
|
});
|
|
2109
2037
|
}
|
|
2110
2038
|
return void 0;
|
|
@@ -2114,7 +2042,7 @@ var interactivePrompt = async () => {
|
|
|
2114
2042
|
const cursorIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`cursor`);
|
|
2115
2043
|
const vscodeIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`vscode`);
|
|
2116
2044
|
const editor = await ve({
|
|
2117
|
-
message: `Make your
|
|
2045
|
+
message: `Make your IDE into a Mastra expert? (Installs Mastra's MCP server)`,
|
|
2118
2046
|
options: [
|
|
2119
2047
|
{ value: "skip", label: "Skip for now", hint: "default" },
|
|
2120
2048
|
{
|
|
@@ -2158,19 +2086,19 @@ Note: you will need to go into Cursor Settings -> MCP Settings and manually enab
|
|
|
2158
2086
|
);
|
|
2159
2087
|
}
|
|
2160
2088
|
if (editor === `cursor-global`) {
|
|
2161
|
-
const
|
|
2089
|
+
const confirm = await ve({
|
|
2162
2090
|
message: `Global install will add/update ${cursorGlobalMCPConfigPath} and make the Mastra docs MCP server available in all your Cursor projects. Continue?`,
|
|
2163
2091
|
options: [
|
|
2164
2092
|
{ value: "yes", label: "Yes, I understand" },
|
|
2165
2093
|
{ value: "skip", label: "No, skip for now" }
|
|
2166
2094
|
]
|
|
2167
2095
|
});
|
|
2168
|
-
if (
|
|
2096
|
+
if (confirm !== `yes`) {
|
|
2169
2097
|
return void 0;
|
|
2170
2098
|
}
|
|
2171
2099
|
}
|
|
2172
2100
|
if (editor === `windsurf`) {
|
|
2173
|
-
const
|
|
2101
|
+
const confirm = await ve({
|
|
2174
2102
|
message: `Windsurf only supports a global MCP config (at ${windsurfGlobalMCPConfigPath}) is it ok to add/update that global config?
|
|
2175
2103
|
This means the Mastra docs MCP server will be available in all your Windsurf projects.`,
|
|
2176
2104
|
options: [
|
|
@@ -2178,7 +2106,7 @@ This means the Mastra docs MCP server will be available in all your Windsurf pro
|
|
|
2178
2106
|
{ value: "skip", label: "No, skip for now" }
|
|
2179
2107
|
]
|
|
2180
2108
|
});
|
|
2181
|
-
if (
|
|
2109
|
+
if (confirm !== `yes`) {
|
|
2182
2110
|
return void 0;
|
|
2183
2111
|
}
|
|
2184
2112
|
}
|
|
@@ -2194,17 +2122,198 @@ This means the Mastra docs MCP server will be available in all your Windsurf pro
|
|
|
2194
2122
|
);
|
|
2195
2123
|
return mastraProject;
|
|
2196
2124
|
};
|
|
2125
|
+
function getPackageManager() {
|
|
2126
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
2127
|
+
const execPath = process.env.npm_execpath || "";
|
|
2128
|
+
if (userAgent.includes("yarn")) {
|
|
2129
|
+
return "yarn";
|
|
2130
|
+
}
|
|
2131
|
+
if (userAgent.includes("pnpm")) {
|
|
2132
|
+
return "pnpm";
|
|
2133
|
+
}
|
|
2134
|
+
if (userAgent.includes("npm")) {
|
|
2135
|
+
return "npm";
|
|
2136
|
+
}
|
|
2137
|
+
if (execPath.includes("yarn")) {
|
|
2138
|
+
return "yarn";
|
|
2139
|
+
}
|
|
2140
|
+
if (execPath.includes("pnpm")) {
|
|
2141
|
+
return "pnpm";
|
|
2142
|
+
}
|
|
2143
|
+
if (execPath.includes("npm")) {
|
|
2144
|
+
return "npm";
|
|
2145
|
+
}
|
|
2146
|
+
return "npm";
|
|
2147
|
+
}
|
|
2148
|
+
var logger = createLogger(false);
|
|
2149
|
+
function createLogger(debug = false) {
|
|
2150
|
+
return new PinoLogger({
|
|
2151
|
+
name: "Mastra CLI",
|
|
2152
|
+
level: debug ? "debug" : "info"
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
var exec2 = util.promisify(child_process.exec);
|
|
2156
|
+
async function cloneTemplate(options) {
|
|
2157
|
+
const { template, projectName, targetDir } = options;
|
|
2158
|
+
const projectPath = targetDir ? path.resolve(targetDir, projectName) : path.resolve(projectName);
|
|
2159
|
+
const spinner4 = yoctoSpinner({ text: `Cloning template "${template.title}"...` }).start();
|
|
2160
|
+
try {
|
|
2161
|
+
if (await directoryExists(projectPath)) {
|
|
2162
|
+
spinner4.error(`Directory ${projectName} already exists`);
|
|
2163
|
+
throw new Error(`Directory ${projectName} already exists`);
|
|
2164
|
+
}
|
|
2165
|
+
await cloneRepositoryWithoutGit(template.githubUrl, projectPath);
|
|
2166
|
+
await updatePackageJson(projectPath, projectName);
|
|
2167
|
+
const envExamplePath = path.join(projectPath, ".env.example");
|
|
2168
|
+
if (await fileExists(envExamplePath)) {
|
|
2169
|
+
await fs4.copyFile(envExamplePath, path.join(projectPath, ".env"));
|
|
2170
|
+
}
|
|
2171
|
+
spinner4.success(`Template "${template.title}" cloned successfully to ${projectName}`);
|
|
2172
|
+
return projectPath;
|
|
2173
|
+
} catch (error) {
|
|
2174
|
+
spinner4.error(`Failed to clone template: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2175
|
+
throw error;
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
async function directoryExists(dirPath) {
|
|
2179
|
+
try {
|
|
2180
|
+
const stat = await fs4.stat(dirPath);
|
|
2181
|
+
return stat.isDirectory();
|
|
2182
|
+
} catch {
|
|
2183
|
+
return false;
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
async function fileExists(filePath) {
|
|
2187
|
+
try {
|
|
2188
|
+
const stat = await fs4.stat(filePath);
|
|
2189
|
+
return stat.isFile();
|
|
2190
|
+
} catch {
|
|
2191
|
+
return false;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
async function cloneRepositoryWithoutGit(repoUrl, targetPath) {
|
|
2195
|
+
await fs4.mkdir(targetPath, { recursive: true });
|
|
2196
|
+
try {
|
|
2197
|
+
const degitRepo = repoUrl.replace("https://github.com/", "");
|
|
2198
|
+
const degitCommand = shellQuote2.quote(["npx", "degit", degitRepo, targetPath]);
|
|
2199
|
+
await exec2(degitCommand, {
|
|
2200
|
+
cwd: process.cwd()
|
|
2201
|
+
});
|
|
2202
|
+
} catch {
|
|
2203
|
+
try {
|
|
2204
|
+
const gitCommand = shellQuote2.quote(["git", "clone", repoUrl, targetPath]);
|
|
2205
|
+
await exec2(gitCommand, {
|
|
2206
|
+
cwd: process.cwd()
|
|
2207
|
+
});
|
|
2208
|
+
const gitDir = path.join(targetPath, ".git");
|
|
2209
|
+
if (await directoryExists(gitDir)) {
|
|
2210
|
+
await fs4.rm(gitDir, { recursive: true, force: true });
|
|
2211
|
+
}
|
|
2212
|
+
} catch (gitError) {
|
|
2213
|
+
throw new Error(`Failed to clone repository: ${gitError instanceof Error ? gitError.message : "Unknown error"}`);
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
async function updatePackageJson(projectPath, projectName) {
|
|
2218
|
+
const packageJsonPath = path.join(projectPath, "package.json");
|
|
2219
|
+
try {
|
|
2220
|
+
const packageJsonContent = await fs4.readFile(packageJsonPath, "utf-8");
|
|
2221
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
2222
|
+
packageJson.name = projectName;
|
|
2223
|
+
await fs4.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf-8");
|
|
2224
|
+
} catch (error) {
|
|
2225
|
+
logger.warn(`Could not update package.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
async function installDependencies(projectPath, packageManager) {
|
|
2229
|
+
const spinner4 = yoctoSpinner({ text: "Installing dependencies..." }).start();
|
|
2230
|
+
try {
|
|
2231
|
+
const pm = packageManager || getPackageManager();
|
|
2232
|
+
const installCommand = shellQuote2.quote([pm, "install"]);
|
|
2233
|
+
await exec2(installCommand, {
|
|
2234
|
+
cwd: projectPath
|
|
2235
|
+
});
|
|
2236
|
+
spinner4.success("Dependencies installed successfully");
|
|
2237
|
+
} catch (error) {
|
|
2238
|
+
spinner4.error(`Failed to install dependencies: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2239
|
+
throw error;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
var TEMPLATES_API_URL = process.env.MASTRA_TEMPLATES_API_URL || "https://mastra.ai/api/templates.json";
|
|
2243
|
+
async function loadTemplates() {
|
|
2244
|
+
try {
|
|
2245
|
+
const response = await fetch(TEMPLATES_API_URL);
|
|
2246
|
+
if (!response.ok) {
|
|
2247
|
+
throw new Error(`Failed to fetch templates: ${response.statusText}`);
|
|
2248
|
+
}
|
|
2249
|
+
const templates = await response.json();
|
|
2250
|
+
return templates;
|
|
2251
|
+
} catch (error) {
|
|
2252
|
+
console.error("Error loading templates:", error);
|
|
2253
|
+
throw new Error("Failed to load templates. Please check your internet connection and try again.");
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
function pluralize(count, singular, plural) {
|
|
2257
|
+
return count === 1 ? singular : plural || `${singular}s`;
|
|
2258
|
+
}
|
|
2259
|
+
async function selectTemplate(templates) {
|
|
2260
|
+
const choices = templates.map((template) => {
|
|
2261
|
+
const parts = [];
|
|
2262
|
+
if (template.agents?.length) {
|
|
2263
|
+
parts.push(`${template.agents.length} ${pluralize(template.agents.length, "agent")}`);
|
|
2264
|
+
}
|
|
2265
|
+
if (template.tools?.length) {
|
|
2266
|
+
parts.push(`${template.tools.length} ${pluralize(template.tools.length, "tool")}`);
|
|
2267
|
+
}
|
|
2268
|
+
if (template.workflows?.length) {
|
|
2269
|
+
parts.push(`${template.workflows.length} ${pluralize(template.workflows.length, "workflow")}`);
|
|
2270
|
+
}
|
|
2271
|
+
if (template.mcp?.length) {
|
|
2272
|
+
parts.push(`${template.mcp.length} ${pluralize(template.mcp.length, "MCP server")}`);
|
|
2273
|
+
}
|
|
2274
|
+
if (template.networks?.length) {
|
|
2275
|
+
parts.push(`${template.networks.length} ${pluralize(template.networks.length, "agent network")}`);
|
|
2276
|
+
}
|
|
2277
|
+
return {
|
|
2278
|
+
value: template,
|
|
2279
|
+
label: template.title,
|
|
2280
|
+
hint: parts.join(", ") || "Template components"
|
|
2281
|
+
};
|
|
2282
|
+
});
|
|
2283
|
+
const selected = await ve({
|
|
2284
|
+
message: "Select a template:",
|
|
2285
|
+
options: choices
|
|
2286
|
+
});
|
|
2287
|
+
if (pD(selected)) {
|
|
2288
|
+
return null;
|
|
2289
|
+
}
|
|
2290
|
+
return selected;
|
|
2291
|
+
}
|
|
2292
|
+
function findTemplateByName(templates, templateName) {
|
|
2293
|
+
let template = templates.find((t) => t.slug === templateName);
|
|
2294
|
+
if (template) return template;
|
|
2295
|
+
const slugWithPrefix = `template-${templateName}`;
|
|
2296
|
+
template = templates.find((t) => t.slug === slugWithPrefix);
|
|
2297
|
+
if (template) return template;
|
|
2298
|
+
template = templates.find((t) => t.title.toLowerCase() === templateName.toLowerCase());
|
|
2299
|
+
if (template) return template;
|
|
2300
|
+
return null;
|
|
2301
|
+
}
|
|
2302
|
+
function getDefaultProjectName(template) {
|
|
2303
|
+
return template.slug.replace(/^template-/, "");
|
|
2304
|
+
}
|
|
2197
2305
|
var s = Y();
|
|
2198
|
-
var exec3 = util.promisify(child_process.exec);
|
|
2199
2306
|
var init = async ({
|
|
2200
|
-
directory,
|
|
2201
|
-
addExample = false,
|
|
2307
|
+
directory = "src/",
|
|
2202
2308
|
components,
|
|
2203
2309
|
llmProvider = "openai",
|
|
2204
2310
|
llmApiKey,
|
|
2205
|
-
|
|
2311
|
+
addExample = false,
|
|
2312
|
+
configureEditorWithDocsMCP,
|
|
2313
|
+
versionTag
|
|
2206
2314
|
}) => {
|
|
2207
2315
|
s.start("Initializing Mastra");
|
|
2316
|
+
const packageVersionTag = versionTag ? `@${versionTag}` : "";
|
|
2208
2317
|
try {
|
|
2209
2318
|
const result = await createMastraDir(directory);
|
|
2210
2319
|
if (!result.ok) {
|
|
@@ -2217,7 +2326,8 @@ var init = async ({
|
|
|
2217
2326
|
dirPath,
|
|
2218
2327
|
addExample,
|
|
2219
2328
|
addWorkflow: components.includes("workflows"),
|
|
2220
|
-
addAgent: components.includes("agents")
|
|
2329
|
+
addAgent: components.includes("agents"),
|
|
2330
|
+
addScorers: components.includes("scorers")
|
|
2221
2331
|
}),
|
|
2222
2332
|
...components.map((component) => createComponentsDir(dirPath, component)),
|
|
2223
2333
|
writeAPIKey({ provider: llmProvider, apiKey: llmApiKey })
|
|
@@ -2231,24 +2341,26 @@ var init = async ({
|
|
|
2231
2341
|
const depService = new DepsService();
|
|
2232
2342
|
const needsLibsql = await depService.checkDependencies(["@mastra/libsql"]) !== `ok`;
|
|
2233
2343
|
if (needsLibsql) {
|
|
2234
|
-
await depService.installPackages([
|
|
2344
|
+
await depService.installPackages([`@mastra/libsql${packageVersionTag}`]);
|
|
2235
2345
|
}
|
|
2236
2346
|
const needsMemory = components.includes(`agents`) && await depService.checkDependencies(["@mastra/memory"]) !== `ok`;
|
|
2237
2347
|
if (needsMemory) {
|
|
2238
|
-
await depService.installPackages([
|
|
2348
|
+
await depService.installPackages([`@mastra/memory${packageVersionTag}`]);
|
|
2239
2349
|
}
|
|
2240
2350
|
const needsLoggers = await depService.checkDependencies(["@mastra/loggers"]) !== `ok`;
|
|
2241
2351
|
if (needsLoggers) {
|
|
2242
|
-
await depService.installPackages([
|
|
2352
|
+
await depService.installPackages([`@mastra/loggers${packageVersionTag}`]);
|
|
2353
|
+
}
|
|
2354
|
+
const needsObservability = await depService.checkDependencies(["@mastra/observability"]) !== `ok`;
|
|
2355
|
+
if (needsObservability) {
|
|
2356
|
+
await depService.installPackages([`@mastra/observability${packageVersionTag}`]);
|
|
2357
|
+
}
|
|
2358
|
+
const needsEvals = components.includes(`scorers`) && await depService.checkDependencies(["@mastra/evals"]) !== `ok`;
|
|
2359
|
+
if (needsEvals) {
|
|
2360
|
+
await depService.installPackages([`@mastra/evals${packageVersionTag}`]);
|
|
2243
2361
|
}
|
|
2244
2362
|
}
|
|
2245
2363
|
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
2364
|
if (configureEditorWithDocsMCP) {
|
|
2253
2365
|
await installMastraDocsMCPServer({
|
|
2254
2366
|
editor: configureEditorWithDocsMCP,
|
|
@@ -2275,10 +2387,10 @@ var init = async ({
|
|
|
2275
2387
|
return { success: false };
|
|
2276
2388
|
}
|
|
2277
2389
|
};
|
|
2278
|
-
var
|
|
2390
|
+
var exec3 = util.promisify(child_process.exec);
|
|
2279
2391
|
var execWithTimeout = async (command, timeoutMs) => {
|
|
2280
2392
|
try {
|
|
2281
|
-
const promise =
|
|
2393
|
+
const promise = exec3(command, { killSignal: "SIGTERM" });
|
|
2282
2394
|
if (!timeoutMs) {
|
|
2283
2395
|
return await promise;
|
|
2284
2396
|
}
|
|
@@ -2326,23 +2438,39 @@ async function installMastraDependency(pm, dependency, versionTag, isDev, timeou
|
|
|
2326
2438
|
var createMastraProject = async ({
|
|
2327
2439
|
projectName: name,
|
|
2328
2440
|
createVersionTag,
|
|
2329
|
-
timeout
|
|
2441
|
+
timeout,
|
|
2442
|
+
llmProvider,
|
|
2443
|
+
llmApiKey,
|
|
2444
|
+
needsInteractive
|
|
2330
2445
|
}) => {
|
|
2331
2446
|
Ie(color2.inverse(" Mastra Create "));
|
|
2332
2447
|
const projectName = name ?? await he({
|
|
2333
2448
|
message: "What do you want to name your project?",
|
|
2334
2449
|
placeholder: "my-mastra-app",
|
|
2335
|
-
defaultValue: "my-mastra-app"
|
|
2450
|
+
defaultValue: "my-mastra-app",
|
|
2451
|
+
validate: (value) => {
|
|
2452
|
+
if (value.length === 0) return "Project name cannot be empty";
|
|
2453
|
+
if (fs3__default__default.existsSync(value)) {
|
|
2454
|
+
return `A directory named "${value}" already exists. Please choose a different name.`;
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2336
2457
|
});
|
|
2337
2458
|
if (pD(projectName)) {
|
|
2338
2459
|
xe("Operation cancelled");
|
|
2339
2460
|
process.exit(0);
|
|
2340
2461
|
}
|
|
2462
|
+
let result;
|
|
2463
|
+
if (needsInteractive) {
|
|
2464
|
+
result = await interactivePrompt({
|
|
2465
|
+
options: { showBanner: false },
|
|
2466
|
+
skip: { llmProvider: llmProvider !== void 0, llmApiKey: llmApiKey !== void 0 }
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2341
2469
|
const s2 = Y();
|
|
2342
2470
|
try {
|
|
2343
2471
|
s2.start("Creating project");
|
|
2344
2472
|
try {
|
|
2345
|
-
await
|
|
2473
|
+
await fs4.mkdir(projectName);
|
|
2346
2474
|
} catch (error) {
|
|
2347
2475
|
if (error instanceof Error && "code" in error && error.code === "EEXIST") {
|
|
2348
2476
|
s2.stop(`A directory named "${projectName}" already exists. Please choose a different name.`);
|
|
@@ -2357,9 +2485,9 @@ var createMastraProject = async ({
|
|
|
2357
2485
|
const installCommand = getPackageManagerAddCommand(pm);
|
|
2358
2486
|
s2.message("Initializing project structure");
|
|
2359
2487
|
try {
|
|
2360
|
-
await
|
|
2361
|
-
await
|
|
2362
|
-
await
|
|
2488
|
+
await exec3(`npm init -y`);
|
|
2489
|
+
await exec3(`npm pkg set type="module"`);
|
|
2490
|
+
await exec3(`npm pkg set engines.node=">=20.9.0"`);
|
|
2363
2491
|
const depsService = new DepsService();
|
|
2364
2492
|
await depsService.addScriptsToPackageJson({
|
|
2365
2493
|
dev: "mastra dev",
|
|
@@ -2374,9 +2502,9 @@ var createMastraProject = async ({
|
|
|
2374
2502
|
s2.stop("Project structure created");
|
|
2375
2503
|
s2.start(`Installing ${pm} dependencies`);
|
|
2376
2504
|
try {
|
|
2377
|
-
await
|
|
2378
|
-
await
|
|
2379
|
-
await
|
|
2505
|
+
await exec3(`${pm} ${installCommand} zod@^4`);
|
|
2506
|
+
await exec3(`${pm} ${installCommand} typescript @types/node --save-dev`);
|
|
2507
|
+
await exec3(`echo '{
|
|
2380
2508
|
"compilerOptions": {
|
|
2381
2509
|
"target": "ES2022",
|
|
2382
2510
|
"module": "ES2022",
|
|
@@ -2398,15 +2526,15 @@ var createMastraProject = async ({
|
|
|
2398
2526
|
);
|
|
2399
2527
|
}
|
|
2400
2528
|
s2.stop(`${pm} dependencies installed`);
|
|
2401
|
-
s2.start("Installing
|
|
2529
|
+
s2.start("Installing Mastra CLI");
|
|
2402
2530
|
const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
|
|
2403
2531
|
try {
|
|
2404
2532
|
await installMastraDependency(pm, "mastra", versionTag, true, timeout);
|
|
2405
2533
|
} catch (error) {
|
|
2406
2534
|
throw new Error(`Failed to install Mastra CLI: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2407
2535
|
}
|
|
2408
|
-
s2.stop("
|
|
2409
|
-
s2.start("Installing dependencies");
|
|
2536
|
+
s2.stop("Mastra CLI installed");
|
|
2537
|
+
s2.start("Installing Mastra dependencies");
|
|
2410
2538
|
try {
|
|
2411
2539
|
await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
|
|
2412
2540
|
await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
|
|
@@ -2419,21 +2547,21 @@ var createMastraProject = async ({
|
|
|
2419
2547
|
s2.stop("Mastra dependencies installed");
|
|
2420
2548
|
s2.start("Adding .gitignore");
|
|
2421
2549
|
try {
|
|
2422
|
-
await
|
|
2423
|
-
await
|
|
2424
|
-
await
|
|
2425
|
-
await
|
|
2426
|
-
await
|
|
2427
|
-
await
|
|
2428
|
-
await
|
|
2429
|
-
await
|
|
2550
|
+
await exec3(`echo output.txt >> .gitignore`);
|
|
2551
|
+
await exec3(`echo node_modules >> .gitignore`);
|
|
2552
|
+
await exec3(`echo dist >> .gitignore`);
|
|
2553
|
+
await exec3(`echo .mastra >> .gitignore`);
|
|
2554
|
+
await exec3(`echo .env.development >> .gitignore`);
|
|
2555
|
+
await exec3(`echo .env >> .gitignore`);
|
|
2556
|
+
await exec3(`echo *.db >> .gitignore`);
|
|
2557
|
+
await exec3(`echo *.db-* >> .gitignore`);
|
|
2430
2558
|
} catch (error) {
|
|
2431
2559
|
throw new Error(`Failed to create .gitignore: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2432
2560
|
}
|
|
2433
2561
|
s2.stop(".gitignore added");
|
|
2434
2562
|
Se("Project created successfully");
|
|
2435
2563
|
console.info("");
|
|
2436
|
-
return { projectName };
|
|
2564
|
+
return { projectName, result };
|
|
2437
2565
|
} catch (error) {
|
|
2438
2566
|
s2.stop();
|
|
2439
2567
|
const errorMessage = error instanceof Error ? error.message : "An unexpected error occurred";
|
|
@@ -2446,19 +2574,23 @@ var create = async (args2) => {
|
|
|
2446
2574
|
await createFromTemplate({ ...args2, injectedAnalytics: args2.analytics });
|
|
2447
2575
|
return;
|
|
2448
2576
|
}
|
|
2449
|
-
const
|
|
2577
|
+
const needsInteractive = args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0;
|
|
2578
|
+
const { projectName, result } = await createMastraProject({
|
|
2450
2579
|
projectName: args2?.projectName,
|
|
2451
2580
|
createVersionTag: args2?.createVersionTag,
|
|
2452
|
-
timeout: args2?.timeout
|
|
2581
|
+
timeout: args2?.timeout,
|
|
2582
|
+
llmProvider: args2?.llmProvider,
|
|
2583
|
+
llmApiKey: args2?.llmApiKey,
|
|
2584
|
+
needsInteractive
|
|
2453
2585
|
});
|
|
2454
2586
|
const directory = args2.directory || "src/";
|
|
2455
|
-
if (
|
|
2456
|
-
const result = await interactivePrompt();
|
|
2587
|
+
if (needsInteractive && result) {
|
|
2457
2588
|
await init({
|
|
2458
2589
|
...result,
|
|
2459
2590
|
llmApiKey: result?.llmApiKey,
|
|
2460
|
-
components: ["agents", "tools", "workflows"],
|
|
2461
|
-
addExample: true
|
|
2591
|
+
components: ["agents", "tools", "workflows", "scorers"],
|
|
2592
|
+
addExample: true,
|
|
2593
|
+
versionTag: args2.createVersionTag
|
|
2462
2594
|
});
|
|
2463
2595
|
postCreate({ projectName });
|
|
2464
2596
|
return;
|
|
@@ -2470,7 +2602,8 @@ var create = async (args2) => {
|
|
|
2470
2602
|
llmProvider,
|
|
2471
2603
|
addExample,
|
|
2472
2604
|
llmApiKey,
|
|
2473
|
-
configureEditorWithDocsMCP: args2.mcpServer
|
|
2605
|
+
configureEditorWithDocsMCP: args2.mcpServer,
|
|
2606
|
+
versionTag: args2.createVersionTag
|
|
2474
2607
|
});
|
|
2475
2608
|
postCreate({ projectName });
|
|
2476
2609
|
};
|
|
@@ -2573,16 +2706,16 @@ async function createFromTemplate(args2) {
|
|
|
2573
2706
|
selectedTemplate = selected;
|
|
2574
2707
|
} else if (args2.template && typeof args2.template === "string") {
|
|
2575
2708
|
if (isGitHubUrl(args2.template)) {
|
|
2576
|
-
const
|
|
2577
|
-
|
|
2709
|
+
const spinner4 = Y();
|
|
2710
|
+
spinner4.start("Validating GitHub repository...");
|
|
2578
2711
|
const validation = await validateGitHubProject(args2.template);
|
|
2579
2712
|
if (!validation.isValid) {
|
|
2580
|
-
|
|
2713
|
+
spinner4.stop("Validation failed");
|
|
2581
2714
|
M.error("This does not appear to be a valid Mastra project:");
|
|
2582
2715
|
validation.errors.forEach((error) => M.error(` - ${error}`));
|
|
2583
2716
|
throw new Error("Invalid Mastra project");
|
|
2584
2717
|
}
|
|
2585
|
-
|
|
2718
|
+
spinner4.stop("Valid Mastra project \u2713");
|
|
2586
2719
|
selectedTemplate = await createFromGitHubUrl(args2.template);
|
|
2587
2720
|
} else {
|
|
2588
2721
|
const templates = await loadTemplates();
|
|
@@ -2641,7 +2774,7 @@ async function createFromTemplate(args2) {
|
|
|
2641
2774
|
async function getPackageVersion() {
|
|
2642
2775
|
const __filename = fileURLToPath(import.meta.url);
|
|
2643
2776
|
const __dirname = dirname(__filename);
|
|
2644
|
-
const pkgJsonPath =
|
|
2777
|
+
const pkgJsonPath = path.join(__dirname, "..", "package.json");
|
|
2645
2778
|
const content = await fsExtra$1.readJSON(pkgJsonPath);
|
|
2646
2779
|
return content.version;
|
|
2647
2780
|
}
|
|
@@ -2679,7 +2812,7 @@ program.version(`${version}`, "-v, --version").description(`create-mastra ${vers
|
|
|
2679
2812
|
program.name("create-mastra").description("Create a new Mastra project").argument("[project-name]", "Directory name of the project").option(
|
|
2680
2813
|
"-p, --project-name <string>",
|
|
2681
2814
|
"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(
|
|
2815
|
+
).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
2816
|
"--template [template-name]",
|
|
2684
2817
|
"Create project from a template (use template name, public GitHub URL, or leave blank to select from list)"
|
|
2685
2818
|
).action(async (projectNameArg, args) => {
|
|
@@ -2687,7 +2820,7 @@ program.name("create-mastra").description("Create a new Mastra project").argumen
|
|
|
2687
2820
|
const timeout = args?.timeout ? args?.timeout === true ? 6e4 : parseInt(args?.timeout, 10) : void 0;
|
|
2688
2821
|
if (args.default) {
|
|
2689
2822
|
await create({
|
|
2690
|
-
components: ["agents", "tools", "workflows"],
|
|
2823
|
+
components: ["agents", "tools", "workflows", "scorers"],
|
|
2691
2824
|
llmProvider: "openai",
|
|
2692
2825
|
addExample: true,
|
|
2693
2826
|
createVersionTag,
|
|
@@ -2703,7 +2836,7 @@ program.name("create-mastra").description("Create a new Mastra project").argumen
|
|
|
2703
2836
|
components: args.components ? args.components.split(",") : [],
|
|
2704
2837
|
llmProvider: args.llm,
|
|
2705
2838
|
addExample: args.example,
|
|
2706
|
-
llmApiKey: args
|
|
2839
|
+
llmApiKey: args.llmApiKey,
|
|
2707
2840
|
createVersionTag,
|
|
2708
2841
|
timeout,
|
|
2709
2842
|
projectName,
|