mastra-starter 1.0.10 → 1.0.12
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/package.json +1 -1
- package/src/mastra/agents/index.ts +49 -14
- package/util.mjs +9 -3
package/package.json
CHANGED
@@ -17,9 +17,19 @@ const characterJsonString = await fs.promises.readFile(
|
|
17
17
|
);
|
18
18
|
const characterJson = JSON.parse(characterJsonString);
|
19
19
|
|
20
|
+
const cleanName = (name: string) => {
|
21
|
+
return name
|
22
|
+
.replace(/[\/:]+/g, "-")
|
23
|
+
.replace(/[^a-zA-Z0-9_-]/g, "");
|
24
|
+
};
|
25
|
+
|
20
26
|
// sort plugins
|
21
27
|
const { plugins = [] } = characterJson;
|
22
|
-
const {
|
28
|
+
const {
|
29
|
+
http: httpPlugins,
|
30
|
+
npm: npmPlugins,
|
31
|
+
composio: composioPlugins,
|
32
|
+
} = sortPlugins(plugins);
|
23
33
|
|
24
34
|
// resolve npm plugins
|
25
35
|
const servers: Record<string, any> = {};
|
@@ -27,6 +37,18 @@ const pnpmLockYamlPath = path.resolve(rootDir, "pnpm-lock.yaml");
|
|
27
37
|
const pnpmPackageLookup = new PnpmPackageLookup({
|
28
38
|
pnpmLockYamlPath,
|
29
39
|
});
|
40
|
+
|
41
|
+
console.log("Initializing plugin servers...");
|
42
|
+
|
43
|
+
// http plugins
|
44
|
+
for (const pluginSpecifier of httpPlugins) {
|
45
|
+
const pluginName = cleanName(pluginSpecifier)
|
46
|
+
console.log('pluginName', pluginName, pluginSpecifier);
|
47
|
+
servers[pluginName] = {
|
48
|
+
url: new URL(pluginSpecifier),
|
49
|
+
};
|
50
|
+
}
|
51
|
+
// npm plugins
|
30
52
|
for (const pluginSpecifier of npmPlugins) {
|
31
53
|
const npmPackageType = getNpmPackageType(pluginSpecifier);
|
32
54
|
|
@@ -40,7 +62,7 @@ for (const pluginSpecifier of npmPlugins) {
|
|
40
62
|
pluginSpecifier2 =
|
41
63
|
await pnpmPackageLookup.getPackageNameBySpecifier(packageResolvedName);
|
42
64
|
if (!pluginSpecifier2) {
|
43
|
-
|
65
|
+
console.error(
|
44
66
|
`Could not resolve package name for ${JSON.stringify(
|
45
67
|
{
|
46
68
|
pluginSpecifier,
|
@@ -51,6 +73,7 @@ for (const pluginSpecifier of npmPlugins) {
|
|
51
73
|
2
|
52
74
|
)}`
|
53
75
|
);
|
76
|
+
continue;
|
54
77
|
}
|
55
78
|
} else {
|
56
79
|
pluginSpecifier2 = pluginSpecifier;
|
@@ -61,13 +84,10 @@ for (const pluginSpecifier of npmPlugins) {
|
|
61
84
|
const packageJson = JSON.parse(
|
62
85
|
await fs.promises.readFile(packageJsonPath, "utf8")
|
63
86
|
);
|
64
|
-
const pluginName =
|
65
|
-
pluginSpecifier
|
66
|
-
// .replace(/^github:/, "")
|
67
|
-
.replace(/[\/:]+/g, "-")
|
68
|
-
.replace(/[^a-zA-Z0-9_-]/g, "");
|
87
|
+
const pluginName = cleanName(pluginSpecifier)
|
69
88
|
if (!pluginName) {
|
70
|
-
|
89
|
+
console.error(`Could not clean up plugin name for ${pluginSpecifier}`);
|
90
|
+
continue;
|
71
91
|
}
|
72
92
|
if (packageJson.scripts.start) {
|
73
93
|
servers[pluginName] = {
|
@@ -85,7 +105,7 @@ for (const pluginSpecifier of npmPlugins) {
|
|
85
105
|
env: process.env as any,
|
86
106
|
};
|
87
107
|
} else {
|
88
|
-
|
108
|
+
console.error(
|
89
109
|
`No start script or bins found for ${pluginSpecifier} name ${pluginName}`
|
90
110
|
);
|
91
111
|
}
|
@@ -93,15 +113,26 @@ for (const pluginSpecifier of npmPlugins) {
|
|
93
113
|
}
|
94
114
|
|
95
115
|
// mcp tools
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
const
|
116
|
+
console.log("Retrieving MCP tools...");
|
117
|
+
let mcpTools: ToolsInput = {};
|
118
|
+
try {
|
119
|
+
const mcp = new MCPConfiguration({
|
120
|
+
servers,
|
121
|
+
});
|
122
|
+
|
123
|
+
mcpTools = await mcp.getTools();
|
124
|
+
console.log(
|
125
|
+
`Successfully initialized ${Object.keys(mcpTools).length} MCP tools`
|
126
|
+
);
|
127
|
+
} catch (error) {
|
128
|
+
console.error("Error initializing MCP tools:", error);
|
129
|
+
console.log("Continuing with limited functionality...");
|
130
|
+
}
|
100
131
|
|
101
132
|
// composio tools
|
102
133
|
const composioApiKey = process.env.COMPOSIO_API_KEY;
|
103
134
|
const composioAccountId = process.env.COMPOSIO_ACCOUNT_ID;
|
104
|
-
let composioToolset: ToolsInput
|
135
|
+
let composioToolset: ToolsInput = {};
|
105
136
|
if (composioApiKey && composioAccountId) {
|
106
137
|
const composio = new ComposioIntegration({
|
107
138
|
config: {
|
@@ -124,10 +155,12 @@ if (composioApiKey && composioAccountId) {
|
|
124
155
|
}
|
125
156
|
|
126
157
|
// agent
|
158
|
+
console.log("Initializing agent...");
|
127
159
|
const model = createOpenAI({
|
128
160
|
baseURL: process.env.OPENAI_API_URL || "https://api.openai.com/v1",
|
129
161
|
apiKey: process.env.OPENAI_API_KEY,
|
130
162
|
})("gpt-4o");
|
163
|
+
|
131
164
|
export const characterAgent = new Agent({
|
132
165
|
name: "Character",
|
133
166
|
instructions:
|
@@ -143,3 +176,5 @@ export const characterAgent = new Agent({
|
|
143
176
|
...composioToolset,
|
144
177
|
},
|
145
178
|
});
|
179
|
+
|
180
|
+
console.log("Agent initialization completed!");
|
package/util.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import path from "path";
|
2
|
-
import fs from "fs";
|
2
|
+
// import fs from "fs";
|
3
3
|
import child_process from "child_process";
|
4
4
|
import { mkdirp } from "mkdirp";
|
5
5
|
import { rimraf } from "rimraf";
|
@@ -35,24 +35,30 @@ export const runCharacter = async (characterJsonPath, { env = {} } = {}) => {
|
|
35
35
|
};
|
36
36
|
|
37
37
|
export const getPluginType = (plugin) => {
|
38
|
-
if (plugin
|
38
|
+
if (/^https?:\/\//.test(plugin)) {
|
39
|
+
return "http";
|
40
|
+
} else if (plugin.startsWith("composio:")) {
|
39
41
|
return "composio";
|
40
42
|
} else {
|
41
43
|
return "npm";
|
42
44
|
}
|
43
45
|
};
|
44
46
|
export const sortPlugins = (plugins) => {
|
47
|
+
const http = [];
|
45
48
|
const npm = [];
|
46
49
|
const composio = [];
|
47
50
|
for (const plugin of plugins) {
|
48
51
|
const pluginType = getPluginType(plugin);
|
49
|
-
if (pluginType === "
|
52
|
+
if (pluginType === "http") {
|
53
|
+
http.push(plugin);
|
54
|
+
} else if (pluginType === "npm") {
|
50
55
|
npm.push(plugin);
|
51
56
|
} else if (pluginType === "composio") {
|
52
57
|
composio.push(plugin);
|
53
58
|
}
|
54
59
|
}
|
55
60
|
return {
|
61
|
+
http,
|
56
62
|
npm,
|
57
63
|
composio,
|
58
64
|
};
|