create-mastra 0.1.0-alpha.4 → 0.1.0-alpha.40
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/LICENSE +44 -0
- package/dist/index.js +1491 -35
- package/dist/index.js.map +1 -0
- package/dist/starter-files/config.ts +28 -0
- package/dist/starter-files/mastra-pg.docker-compose.yaml +15 -0
- package/dist/starter-files/tools.ts +95 -0
- package/dist/starter-files/workflow.ts +182 -0
- package/dist/templates/dev.entry.js +47 -0
- package/package.json +35 -8
- package/dist/index.d.ts +0 -2
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +0 -11
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { openai } from '@ai-sdk/openai';
|
|
2
|
+
import { Agent } from '@mastra/core/agent';
|
|
3
|
+
import { Step, Workflow } from '@mastra/core/workflows';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
const llm = openai('gpt-4o');
|
|
7
|
+
|
|
8
|
+
const agent = new Agent({
|
|
9
|
+
name: 'Weather Agent',
|
|
10
|
+
model: llm,
|
|
11
|
+
instructions: `
|
|
12
|
+
You are a local activities and travel expert who excels at weather-based planning. Analyze the weather data and provide practical activity recommendations.
|
|
13
|
+
|
|
14
|
+
For each day in the forecast, structure your response exactly as follows:
|
|
15
|
+
|
|
16
|
+
📅 [Day, Month Date, Year]
|
|
17
|
+
═══════════════════════════
|
|
18
|
+
|
|
19
|
+
🌡️ WEATHER SUMMARY
|
|
20
|
+
• Conditions: [brief description]
|
|
21
|
+
• Temperature: [X°C/Y°F to A°C/B°F]
|
|
22
|
+
• Precipitation: [X% chance]
|
|
23
|
+
|
|
24
|
+
🌅 MORNING ACTIVITIES
|
|
25
|
+
Outdoor:
|
|
26
|
+
• [Activity Name] - [Brief description including specific location/route]
|
|
27
|
+
Best timing: [specific time range]
|
|
28
|
+
Note: [relevant weather consideration]
|
|
29
|
+
|
|
30
|
+
🌞 AFTERNOON ACTIVITIES
|
|
31
|
+
Outdoor:
|
|
32
|
+
• [Activity Name] - [Brief description including specific location/route]
|
|
33
|
+
Best timing: [specific time range]
|
|
34
|
+
Note: [relevant weather consideration]
|
|
35
|
+
|
|
36
|
+
🏠 INDOOR ALTERNATIVES
|
|
37
|
+
• [Activity Name] - [Brief description including specific venue]
|
|
38
|
+
Ideal for: [weather condition that would trigger this alternative]
|
|
39
|
+
|
|
40
|
+
⚠️ SPECIAL CONSIDERATIONS
|
|
41
|
+
• [Any relevant weather warnings, UV index, wind conditions, etc.]
|
|
42
|
+
|
|
43
|
+
Guidelines:
|
|
44
|
+
- Suggest 2-3 time-specific outdoor activities per day
|
|
45
|
+
- Include 1-2 indoor backup options
|
|
46
|
+
- For precipitation >50%, lead with indoor activities
|
|
47
|
+
- All activities must be specific to the location
|
|
48
|
+
- Include specific venues, trails, or locations
|
|
49
|
+
- Consider activity intensity based on temperature
|
|
50
|
+
- Keep descriptions concise but informative
|
|
51
|
+
|
|
52
|
+
Maintain this exact formatting for consistency, using the emoji and section headers as shown.
|
|
53
|
+
`,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const fetchWeather = new Step({
|
|
57
|
+
id: 'fetch-weather',
|
|
58
|
+
description: 'Fetches weather forecast for a given city',
|
|
59
|
+
inputSchema: z.object({
|
|
60
|
+
city: z.string().describe('The city to get the weather for'),
|
|
61
|
+
}),
|
|
62
|
+
execute: async ({ context }) => {
|
|
63
|
+
const triggerData = context?.getStepPayload<{ city: string }>('trigger');
|
|
64
|
+
|
|
65
|
+
if (!triggerData) {
|
|
66
|
+
throw new Error('Trigger data not found');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(triggerData.city)}&count=1`;
|
|
70
|
+
const geocodingResponse = await fetch(geocodingUrl);
|
|
71
|
+
const geocodingData = (await geocodingResponse.json()) as {
|
|
72
|
+
results: { latitude: number; longitude: number; name: string }[];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
if (!geocodingData.results?.[0]) {
|
|
76
|
+
throw new Error(`Location '${triggerData.city}' not found`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const { latitude, longitude, name } = geocodingData.results[0];
|
|
80
|
+
|
|
81
|
+
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=temperature_2m_max,temperature_2m_min,precipitation_probability_mean,weathercode&timezone=auto`;
|
|
82
|
+
const response = await fetch(weatherUrl);
|
|
83
|
+
const data = (await response.json()) as {
|
|
84
|
+
daily: {
|
|
85
|
+
time: string[];
|
|
86
|
+
temperature_2m_max: number[];
|
|
87
|
+
temperature_2m_min: number[];
|
|
88
|
+
precipitation_probability_mean: number[];
|
|
89
|
+
weathercode: number[];
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const forecast = data.daily.time.map((date: string, index: number) => ({
|
|
94
|
+
date,
|
|
95
|
+
maxTemp: data.daily.temperature_2m_max[index],
|
|
96
|
+
minTemp: data.daily.temperature_2m_min[index],
|
|
97
|
+
precipitationChance: data.daily.precipitation_probability_mean[index],
|
|
98
|
+
condition: getWeatherCondition(data.daily.weathercode[index]!),
|
|
99
|
+
location: name,
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
return forecast;
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const forecastSchema = z.array(
|
|
107
|
+
z.object({
|
|
108
|
+
date: z.string(),
|
|
109
|
+
maxTemp: z.number(),
|
|
110
|
+
minTemp: z.number(),
|
|
111
|
+
precipitationChance: z.number(),
|
|
112
|
+
condition: z.string(),
|
|
113
|
+
location: z.string(),
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const planActivities = new Step({
|
|
118
|
+
id: 'plan-activities',
|
|
119
|
+
description: 'Suggests activities based on weather conditions',
|
|
120
|
+
inputSchema: forecastSchema,
|
|
121
|
+
execute: async ({ context, mastra }) => {
|
|
122
|
+
const forecast = context?.getStepPayload<z.infer<typeof forecastSchema>>('fetch-weather');
|
|
123
|
+
|
|
124
|
+
if (!forecast) {
|
|
125
|
+
throw new Error('Forecast data not found');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const prompt = `Based on the following weather forecast for ${forecast[0].location}, suggest appropriate activities:
|
|
129
|
+
${JSON.stringify(forecast, null, 2)}
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
const response = await agent.stream([
|
|
133
|
+
{
|
|
134
|
+
role: 'user',
|
|
135
|
+
content: prompt,
|
|
136
|
+
},
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
for await (const chunk of response.textStream) {
|
|
140
|
+
process.stdout.write(chunk);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
activities: response.text,
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
function getWeatherCondition(code: number): string {
|
|
150
|
+
const conditions: Record<number, string> = {
|
|
151
|
+
0: 'Clear sky',
|
|
152
|
+
1: 'Mainly clear',
|
|
153
|
+
2: 'Partly cloudy',
|
|
154
|
+
3: 'Overcast',
|
|
155
|
+
45: 'Foggy',
|
|
156
|
+
48: 'Depositing rime fog',
|
|
157
|
+
51: 'Light drizzle',
|
|
158
|
+
53: 'Moderate drizzle',
|
|
159
|
+
55: 'Dense drizzle',
|
|
160
|
+
61: 'Slight rain',
|
|
161
|
+
63: 'Moderate rain',
|
|
162
|
+
65: 'Heavy rain',
|
|
163
|
+
71: 'Slight snow fall',
|
|
164
|
+
73: 'Moderate snow fall',
|
|
165
|
+
75: 'Heavy snow fall',
|
|
166
|
+
95: 'Thunderstorm',
|
|
167
|
+
};
|
|
168
|
+
return conditions[code] || 'Unknown';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const weatherWorkflow = new Workflow({
|
|
172
|
+
name: 'weather-workflow',
|
|
173
|
+
triggerSchema: z.object({
|
|
174
|
+
city: z.string().describe('The city to get the weather for'),
|
|
175
|
+
}),
|
|
176
|
+
})
|
|
177
|
+
.step(fetchWeather)
|
|
178
|
+
.then(planActivities);
|
|
179
|
+
|
|
180
|
+
weatherWorkflow.commit();
|
|
181
|
+
|
|
182
|
+
export { weatherWorkflow };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { mastra } from '#mastra';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { createNodeServer } from '#server';
|
|
5
|
+
import { evaluate } from '@mastra/core/eval';
|
|
6
|
+
import { AvailableHooks, registerHook } from '@mastra/core/hooks';
|
|
7
|
+
import { MastraStorage } from '@mastra/core/storage';
|
|
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: MastraStorage.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-mastra",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.40",
|
|
4
4
|
"description": "Create Mastra apps with one command",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,28 +8,55 @@
|
|
|
8
8
|
"create-mastra": "./dist/index.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"starter-files",
|
|
13
|
+
"templates"
|
|
12
14
|
],
|
|
13
15
|
"keywords": [
|
|
14
16
|
"mastra",
|
|
17
|
+
"create",
|
|
15
18
|
"cli",
|
|
16
|
-
"
|
|
19
|
+
"starter",
|
|
20
|
+
"boilerplate",
|
|
21
|
+
"template",
|
|
22
|
+
"init",
|
|
23
|
+
"generator",
|
|
24
|
+
"scaffold",
|
|
25
|
+
"ai",
|
|
26
|
+
"llm",
|
|
27
|
+
"llms",
|
|
28
|
+
"agent",
|
|
29
|
+
"typescript",
|
|
30
|
+
"project"
|
|
17
31
|
],
|
|
18
32
|
"dependencies": {
|
|
19
33
|
"commander": "^12.0.0",
|
|
34
|
+
"execa": "^9.3.1",
|
|
20
35
|
"fs-extra": "^11.2.0",
|
|
21
|
-
"
|
|
36
|
+
"pino": "^9.6.0",
|
|
37
|
+
"pino-pretty": "^13.0.0",
|
|
38
|
+
"posthog-node": "^4.3.1",
|
|
39
|
+
"prettier": "^3.3.3"
|
|
22
40
|
},
|
|
23
41
|
"devDependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"
|
|
26
|
-
"@
|
|
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
|
+
"rollup": "^4.30.1",
|
|
50
|
+
"rollup-plugin-esbuild": "^6.1.1",
|
|
51
|
+
"rollup-plugin-node-externals": "^8.0.0",
|
|
52
|
+
"typescript": "^5.7.3",
|
|
53
|
+
"mastra": "^0.2.0-alpha.165"
|
|
27
54
|
},
|
|
28
55
|
"engines": {
|
|
29
56
|
"node": ">=20"
|
|
30
57
|
},
|
|
31
58
|
"scripts": {
|
|
32
|
-
"build": "
|
|
59
|
+
"build": "rollup -c",
|
|
33
60
|
"clean": "rm -rf dist && rm -rf node_modules"
|
|
34
61
|
}
|
|
35
62
|
}
|
package/dist/index.d.ts
DELETED
package/dist/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getPackageVersion(): Promise<any>;
|
package/dist/utils.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import fsExtra from 'fs-extra';
|
|
2
|
-
import { dirname } from 'path';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
export async function getPackageVersion() {
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = dirname(__filename);
|
|
8
|
-
const pkgJsonPath = path.join(__dirname, '..', 'package.json');
|
|
9
|
-
const content = await fsExtra.readJSON(pkgJsonPath);
|
|
10
|
-
return content.version;
|
|
11
|
-
}
|