create-mastra 0.0.0-commonjs-20250227130920

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.
@@ -0,0 +1,102 @@
1
+ import { createTool } from '@mastra/core/tools';
2
+ import { z } from 'zod';
3
+
4
+ interface GeocodingResponse {
5
+ results: {
6
+ latitude: number;
7
+ longitude: number;
8
+ name: string;
9
+ }[];
10
+ }
11
+ interface WeatherResponse {
12
+ current: {
13
+ time: string;
14
+ temperature_2m: number;
15
+ apparent_temperature: number;
16
+ relative_humidity_2m: number;
17
+ wind_speed_10m: number;
18
+ wind_gusts_10m: number;
19
+ weather_code: number;
20
+ };
21
+ }
22
+
23
+ export const weatherTool = createTool({
24
+ id: 'get-weather',
25
+ description: 'Get current weather for a location',
26
+ inputSchema: z.object({
27
+ location: z.string().describe('City name'),
28
+ }),
29
+ outputSchema: z.object({
30
+ temperature: z.number(),
31
+ feelsLike: z.number(),
32
+ humidity: z.number(),
33
+ windSpeed: z.number(),
34
+ windGust: z.number(),
35
+ conditions: z.string(),
36
+ location: z.string(),
37
+ }),
38
+ execute: async ({ context }) => {
39
+ return await getWeather(context.location);
40
+ },
41
+ });
42
+
43
+ const getWeather = async (location: string) => {
44
+ const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
45
+ const geocodingResponse = await fetch(geocodingUrl);
46
+ const geocodingData = (await geocodingResponse.json()) as GeocodingResponse;
47
+
48
+ if (!geocodingData.results?.[0]) {
49
+ throw new Error(`Location '${location}' not found`);
50
+ }
51
+
52
+ const { latitude, longitude, name } = geocodingData.results[0];
53
+
54
+ const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,wind_gusts_10m,weather_code`;
55
+
56
+ const response = await fetch(weatherUrl);
57
+ const data = (await response.json()) as WeatherResponse;
58
+
59
+ return {
60
+ temperature: data.current.temperature_2m,
61
+ feelsLike: data.current.apparent_temperature,
62
+ humidity: data.current.relative_humidity_2m,
63
+ windSpeed: data.current.wind_speed_10m,
64
+ windGust: data.current.wind_gusts_10m,
65
+ conditions: getWeatherCondition(data.current.weather_code),
66
+ location: name,
67
+ };
68
+ };
69
+
70
+ function getWeatherCondition(code: number): string {
71
+ const conditions: Record<number, string> = {
72
+ 0: 'Clear sky',
73
+ 1: 'Mainly clear',
74
+ 2: 'Partly cloudy',
75
+ 3: 'Overcast',
76
+ 45: 'Foggy',
77
+ 48: 'Depositing rime fog',
78
+ 51: 'Light drizzle',
79
+ 53: 'Moderate drizzle',
80
+ 55: 'Dense drizzle',
81
+ 56: 'Light freezing drizzle',
82
+ 57: 'Dense freezing drizzle',
83
+ 61: 'Slight rain',
84
+ 63: 'Moderate rain',
85
+ 65: 'Heavy rain',
86
+ 66: 'Light freezing rain',
87
+ 67: 'Heavy freezing rain',
88
+ 71: 'Slight snow fall',
89
+ 73: 'Moderate snow fall',
90
+ 75: 'Heavy snow fall',
91
+ 77: 'Snow grains',
92
+ 80: 'Slight rain showers',
93
+ 81: 'Moderate rain showers',
94
+ 82: 'Violent rain showers',
95
+ 85: 'Slight snow showers',
96
+ 86: 'Heavy snow showers',
97
+ 95: 'Thunderstorm',
98
+ 96: 'Thunderstorm with slight hail',
99
+ 99: 'Thunderstorm with heavy hail',
100
+ };
101
+ return conditions[code] || 'Unknown';
102
+ }
@@ -0,0 +1,47 @@
1
+ // @ts-ignore
2
+ // @ts-ignore
3
+ import { evaluate } from '@mastra/core/eval';
4
+ import { AvailableHooks, registerHook } from '@mastra/core/hooks';
5
+ import { TABLE_EVALS } from '@mastra/core/storage';
6
+ import { mastra } from '#mastra';
7
+ import { createNodeServer } from '#server';
8
+
9
+ // init storage
10
+ if (mastra.storage) {
11
+ await mastra.storage.init();
12
+ }
13
+
14
+ // @ts-ignore
15
+ await createNodeServer(mastra, { playground: true, swaggerUI: true });
16
+
17
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
18
+ evaluate({
19
+ agentName,
20
+ input,
21
+ metric,
22
+ output,
23
+ runId,
24
+ globalRunId: runId,
25
+ instructions,
26
+ });
27
+ });
28
+
29
+ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
30
+ if (mastra.storage) {
31
+ await mastra.storage.insert({
32
+ tableName: TABLE_EVALS,
33
+ record: {
34
+ input: traceObject.input,
35
+ output: traceObject.output,
36
+ result: JSON.stringify(traceObject.result),
37
+ agent_name: traceObject.agentName,
38
+ metric_name: traceObject.metricName,
39
+ instructions: traceObject.instructions,
40
+ test_info: null,
41
+ global_run_id: traceObject.globalRunId,
42
+ run_id: traceObject.runId,
43
+ created_at: new Date().toISOString(),
44
+ },
45
+ });
46
+ }
47
+ });
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "create-mastra",
3
+ "version": "0.0.0-commonjs-20250227130920",
4
+ "description": "Create Mastra apps with one command",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "create-mastra": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "starter-files",
13
+ "templates"
14
+ ],
15
+ "keywords": [
16
+ "mastra",
17
+ "create",
18
+ "cli",
19
+ "starter",
20
+ "boilerplate",
21
+ "template",
22
+ "init",
23
+ "generator",
24
+ "scaffold",
25
+ "ai",
26
+ "llm",
27
+ "llms",
28
+ "agent",
29
+ "typescript",
30
+ "project"
31
+ ],
32
+ "dependencies": {
33
+ "commander": "^12.0.0",
34
+ "execa": "^9.3.1",
35
+ "fs-extra": "^11.2.0",
36
+ "pino": "^9.6.0",
37
+ "pino-pretty": "^13.0.0",
38
+ "posthog-node": "^4.3.1",
39
+ "prettier": "^3.3.3"
40
+ },
41
+ "devDependencies": {
42
+ "@microsoft/api-extractor": "^7.49.2",
43
+ "@rollup/plugin-commonjs": "^28.0.2",
44
+ "@rollup/plugin-json": "^6.1.0",
45
+ "@rollup/plugin-node-resolve": "^16.0.0",
46
+ "@types/fs-extra": "^11.0.4",
47
+ "@types/node": "^22.13.1",
48
+ "esbuild": "^0.24.2",
49
+ "eslint": "^9.20.1",
50
+ "rollup": "^4.30.1",
51
+ "rollup-plugin-esbuild": "^6.1.1",
52
+ "rollup-plugin-node-externals": "^8.0.0",
53
+ "typescript": "^5.7.3",
54
+ "@internal/lint": "0.0.0",
55
+ "mastra": "^0.0.0-commonjs-20250227130920"
56
+ },
57
+ "engines": {
58
+ "node": ">=20"
59
+ },
60
+ "scripts": {
61
+ "build": "rollup -c",
62
+ "lint": "eslint .",
63
+ "clean": "rm -rf dist && rm -rf node_modules"
64
+ }
65
+ }