mastra-starter 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/env.example ADDED
@@ -0,0 +1,3 @@
1
+ OPENAI_API_KEY=sk-proj--
2
+ TELEGRAM_TOKEN=80207
3
+ CHAT_ID=8101
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "mastra-starter",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "dev": "mastra dev"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "description": "",
13
+ "type": "module",
14
+ "dependencies": {
15
+ "@ai-sdk/openai": "^1.2.2",
16
+ "@mastra/core": "^0.5.0",
17
+ "@mastra/mcp": "^0.3.0",
18
+ "mastra": "^0.3.0",
19
+ "zod": "^3.24.2"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^22.13.10",
23
+ "tsx": "^4.19.3",
24
+ "typescript": "^5.8.2"
25
+ }
26
+ }
@@ -0,0 +1,36 @@
1
+ import { openai } from '@ai-sdk/openai';
2
+ import { Agent } from '@mastra/core/agent';
3
+
4
+ import { MCPConfiguration } from "@mastra/mcp";
5
+
6
+ const mcp = new MCPConfiguration({
7
+ servers: {
8
+ // Telegram server configuration
9
+ telegram: {
10
+ command: "node",
11
+ args: ["path/mcp-communicator-telegram/build/index.js"], //please add the correct path
12
+ env: {
13
+ TELEGRAM_TOKEN: process.env.TELEGRAM_TOKEN!,
14
+ CHAT_ID: process.env.CHAT_ID!,
15
+ },
16
+ },
17
+ },
18
+ });
19
+
20
+
21
+
22
+ export const telegramAgent = new Agent({
23
+ name: "Telegram Bot",
24
+ instructions: `
25
+ You are a friendly Telegram bot that provides assistance.
26
+
27
+ Your primary function is to help Telegram users. When responding:
28
+ - Introduce yourself as a Telegram Bot in your first message
29
+ - Keep responses concise and friendly
30
+ - Be responsive to Telegram-specific commands like /start and /help
31
+
32
+ When users send /start or /help, provide a brief introduction and explain how to use your services.
33
+ `,
34
+ model: openai("gpt-4o"),
35
+ tools: { ...(await mcp.getTools()) },
36
+ });
@@ -0,0 +1,13 @@
1
+
2
+ import { Mastra } from '@mastra/core/mastra';
3
+ import { createLogger } from '@mastra/core/logger';
4
+
5
+ import { telegramAgent } from "./agents";
6
+
7
+ export const mastra = new Mastra({
8
+ agents: { telegramAgent },
9
+ logger: createLogger({
10
+ name: "Mastra",
11
+ level: "info",
12
+ }),
13
+ });
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { mastra } from "..";
4
+ import readline from "readline";
5
+
6
+ // Create readline interface
7
+ const rl = readline.createInterface({
8
+ input: process.stdin,
9
+ output: process.stdout,
10
+ });
11
+
12
+ console.log("🌤️ Weather Agent CLI");
13
+ console.log('Type your weather questions (e.g., "What\'s the weather in London today?")');
14
+ console.log('Type "exit" to quit\n');
15
+
16
+ // Main interaction loop
17
+ function askQuestion() {
18
+ rl.question("> ", async (input) => {
19
+ if (input.toLowerCase() === "exit") {
20
+ console.log("Goodbye! 👋");
21
+ rl.close();
22
+ return;
23
+ }
24
+
25
+ try {
26
+ console.log("Fetching weather information...");
27
+ const response = await mastra.run({
28
+ agent: "weatherAgent",
29
+ input,
30
+ });
31
+
32
+ console.log("\nResponse:");
33
+ console.log(response);
34
+ console.log(); // Empty line for better readability
35
+ } catch (error) {
36
+ console.error("Error:", error.message);
37
+ }
38
+
39
+ // Continue the conversation
40
+ askQuestion();
41
+ });
42
+ }
43
+
44
+ // Start the interaction
45
+ askQuestion();
@@ -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
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "moduleResolution": "bundler",
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "strict": true,
9
+ "skipLibCheck": true,
10
+ "outDir": "dist"
11
+ },
12
+ "include": [
13
+ "src/**/*"
14
+ ],
15
+ "exclude": [
16
+ "node_modules",
17
+ "dist",
18
+ ".mastra"
19
+ ]
20
+ }