mastra-starter 1.0.0 → 1.0.2
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/index.mjs +37 -0
- package/package.json +8 -2
- package/src/mastra/agents/index.ts +19 -24
- package/src/mastra/index.ts +2 -2
package/index.mjs
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
import path from 'path';
|
4
|
+
import child_process from 'child_process';
|
5
|
+
|
6
|
+
import { Command } from 'commander';
|
7
|
+
import dotenv from 'dotenv';
|
8
|
+
|
9
|
+
const __dirname = path.dirname(import.meta.url.replace('file://', ''));
|
10
|
+
|
11
|
+
// node index.mjs --character='/Users/a/eliza/characters/trump.character.json'
|
12
|
+
const main = async () => {
|
13
|
+
dotenv.config();
|
14
|
+
|
15
|
+
const program = new Command();
|
16
|
+
|
17
|
+
program
|
18
|
+
.option('--character <string>', 'character json file path')
|
19
|
+
.parse(process.argv);
|
20
|
+
|
21
|
+
const options = program.opts();
|
22
|
+
|
23
|
+
const character = options.character || 'default';
|
24
|
+
|
25
|
+
const p = path.join(__dirname, 'node_modules', 'mastra', 'dist', 'index.js');
|
26
|
+
const cp = child_process.spawn(process.execPath, [p, 'dev'], {
|
27
|
+
env: {
|
28
|
+
...process.env,
|
29
|
+
CHARACTER_JSON_PATH: character,
|
30
|
+
},
|
31
|
+
});
|
32
|
+
cp.stdout.pipe(process.stdout);
|
33
|
+
cp.stderr.pipe(process.stderr);
|
34
|
+
};
|
35
|
+
(async () => {
|
36
|
+
await main();
|
37
|
+
})();
|
package/package.json
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"name": "mastra-starter",
|
3
|
-
"version": "1.0.
|
4
|
-
"main": "index.
|
3
|
+
"version": "1.0.2",
|
4
|
+
"main": "index.mjs",
|
5
|
+
"bin": {
|
6
|
+
"mastra-starter": "./index.mjs"
|
7
|
+
},
|
5
8
|
"scripts": {
|
6
9
|
"test": "echo \"Error: no test specified\" && exit 1",
|
7
10
|
"dev": "mastra dev"
|
@@ -15,6 +18,9 @@
|
|
15
18
|
"@ai-sdk/openai": "^1.2.2",
|
16
19
|
"@mastra/core": "^0.5.0",
|
17
20
|
"@mastra/mcp": "^0.3.0",
|
21
|
+
"commander": "^13.1.0",
|
22
|
+
"dedent": "^1.5.3",
|
23
|
+
"dotenv": "^16.4.7",
|
18
24
|
"mastra": "^0.3.0",
|
19
25
|
"zod": "^3.24.2"
|
20
26
|
},
|
@@ -1,36 +1,31 @@
|
|
1
|
+
import fs from 'fs';
|
1
2
|
import { openai } from '@ai-sdk/openai';
|
2
3
|
import { Agent } from '@mastra/core/agent';
|
3
|
-
|
4
|
+
import dedent from 'dedent';
|
4
5
|
import { MCPConfiguration } from "@mastra/mcp";
|
5
6
|
|
7
|
+
const characterJsonPath = process.env.CHARACTER_JSON_PATH as string;
|
8
|
+
const characterJsonString = await fs.promises.readFile(characterJsonPath, 'utf8');
|
9
|
+
const characterJson = JSON.parse(characterJsonString);
|
10
|
+
|
6
11
|
const mcp = new MCPConfiguration({
|
7
12
|
servers: {
|
8
|
-
//
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
},
|
13
|
+
// telegram: {
|
14
|
+
// command: "node",
|
15
|
+
// args: ["path/mcp-communicator-telegram/build/index.js"], //please add the correct path
|
16
|
+
// env: {
|
17
|
+
// TELEGRAM_TOKEN: process.env.TELEGRAM_TOKEN!,
|
18
|
+
// CHAT_ID: process.env.CHAT_ID!,
|
19
|
+
// },
|
20
|
+
// },
|
17
21
|
},
|
18
22
|
});
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
`,
|
24
|
+
export const characterAgent = new Agent({
|
25
|
+
name: "Character",
|
26
|
+
instructions: dedent`\
|
27
|
+
You are the following character:
|
28
|
+
` + '\n' + JSON.stringify(characterJson, null, 2),
|
34
29
|
model: openai("gpt-4o"),
|
35
30
|
tools: { ...(await mcp.getTools()) },
|
36
31
|
});
|
package/src/mastra/index.ts
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
import { Mastra } from '@mastra/core/mastra';
|
3
3
|
import { createLogger } from '@mastra/core/logger';
|
4
4
|
|
5
|
-
import {
|
5
|
+
import { characterAgent } from "./agents";
|
6
6
|
|
7
7
|
export const mastra = new Mastra({
|
8
|
-
agents: {
|
8
|
+
agents: { characterAgent },
|
9
9
|
logger: createLogger({
|
10
10
|
name: "Mastra",
|
11
11
|
level: "info",
|