@openagentmarket/create-agent 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/dist/index.js ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs-extra';
3
+ import path from 'node:path';
4
+ import prompts from 'prompts';
5
+ import { fileURLToPath } from 'node:url';
6
+ import kleur from 'kleur';
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ async function main() {
9
+ console.log(kleur.bold().cyan('\nšŸš€ Create OpenAgent Project\n'));
10
+ const response = await prompts([
11
+ {
12
+ type: 'text',
13
+ name: 'projectName',
14
+ message: 'What is the name of your agent?',
15
+ initial: 'my-agent'
16
+ }
17
+ ]);
18
+ const { projectName } = response;
19
+ if (!projectName) {
20
+ console.log(kleur.red('Cancelled.'));
21
+ process.exit(1);
22
+ }
23
+ const targetDir = path.join(process.cwd(), projectName);
24
+ if (fs.existsSync(targetDir)) {
25
+ console.log(kleur.red(`Error: Directory ${projectName} already exists!`));
26
+ process.exit(1);
27
+ }
28
+ console.log(`\nCreating project in ${kleur.green(targetDir)}...\n`);
29
+ fs.mkdirSync(targetDir, { recursive: true });
30
+ // 1. package.json
31
+ const packageJson = {
32
+ name: projectName,
33
+ version: "1.0.0",
34
+ description: "An OpenAgent bot",
35
+ type: "module",
36
+ scripts: {
37
+ "start": "tsx index.ts",
38
+ "dev": "tsx watch index.ts"
39
+ },
40
+ dependencies: {
41
+ "@openagentmarket/nodejs": "^1.0.0",
42
+ "ethers": "^6.10.0",
43
+ "dotenv": "^16.4.0"
44
+ },
45
+ devDependencies: {
46
+ "tsx": "^4.7.0",
47
+ "typescript": "^5.3.3",
48
+ "@types/node": "^20.11.0"
49
+ }
50
+ };
51
+ fs.writeFileSync(path.join(targetDir, 'package.json'), JSON.stringify(packageJson, null, 2));
52
+ // 2. tsconfig.json
53
+ const tsConfig = {
54
+ "compilerOptions": {
55
+ "target": "ES2022",
56
+ "module": "NodeNext",
57
+ "moduleResolution": "NodeNext",
58
+ "strict": true,
59
+ "esModuleInterop": true,
60
+ "skipLibCheck": true,
61
+ "forceConsistentCasingInFileNames": true
62
+ }
63
+ };
64
+ fs.writeFileSync(path.join(targetDir, 'tsconfig.json'), JSON.stringify(tsConfig, null, 2));
65
+ // 3. .env
66
+ fs.writeFileSync(path.join(targetDir, '.env'), 'MNEMONIC="your twelve word mnemonic phrase here"\n');
67
+ fs.writeFileSync(path.join(targetDir, '.gitignore'), 'node_modules\n.env\n');
68
+ // 4. index.ts (Template)
69
+ const indexTs = `import { OpenAgent } from '@openagentmarket/nodejs';
70
+ import 'dotenv/config';
71
+
72
+ async function main() {
73
+ const mnemonic = process.env.MNEMONIC;
74
+ if (!mnemonic || mnemonic.includes("your twelve word")) {
75
+ console.error("āŒ Please set a valid MNEMONIC in .env");
76
+ process.exit(1);
77
+ }
78
+
79
+ const agent = await OpenAgent.create({
80
+ mnemonic,
81
+ env: "production",
82
+ card: {
83
+ name: "${projectName}",
84
+ description: "A freshly created OpenAgent.",
85
+ skills: ["say_hello"]
86
+ },
87
+ payment: {
88
+ amount: 0.001, // 0.001 ETH
89
+ currency: "ETH",
90
+ recipientAddress: "0x0000000000000000000000000000000000000000" // Update this!
91
+ }
92
+ });
93
+
94
+ agent.onTask("say_hello", async (input) => {
95
+ return { message: \`Hello \${input.name || "World"}!\` };
96
+ });
97
+
98
+ await agent.start();
99
+ }
100
+
101
+ main().catch(console.error);
102
+ `;
103
+ fs.writeFileSync(path.join(targetDir, 'index.ts'), indexTs);
104
+ console.log(kleur.green('Success! Project created.'));
105
+ console.log('\nNext steps:');
106
+ console.log(` cd ${projectName}`);
107
+ console.log(' pnpm install');
108
+ console.log(' # Update .env with your mnemonic');
109
+ console.log(' pnpm start\n');
110
+ }
111
+ main().catch((err) => {
112
+ console.error(err);
113
+ process.exit(1);
114
+ });
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@openagentmarket/create-agent",
3
+ "version": "1.0.0",
4
+ "description": "CLI to scaffold a new OpenAgent project",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-openagent": "./dist/index.js"
8
+ },
9
+ "main": "dist/index.js",
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "start": "node dist/index.js"
13
+ },
14
+ "dependencies": {
15
+ "prompts": "^2.4.2",
16
+ "kleur": "^4.1.5",
17
+ "fs-extra": "^11.2.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/prompts": "^2.4.9",
21
+ "@types/fs-extra": "^11.0.4",
22
+ "typescript": "^5.3.3",
23
+ "@types/node": "^20.11.20"
24
+ }
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs-extra';
3
+ import path from 'node:path';
4
+ import prompts from 'prompts';
5
+ import { fileURLToPath } from 'node:url';
6
+ import kleur from 'kleur';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+
10
+ async function main() {
11
+ console.log(kleur.bold().cyan('\nšŸš€ Create OpenAgent Project\n'));
12
+
13
+ const response = await prompts([
14
+ {
15
+ type: 'text',
16
+ name: 'projectName',
17
+ message: 'What is the name of your agent?',
18
+ initial: 'my-agent'
19
+ }
20
+ ]);
21
+
22
+ const { projectName } = response;
23
+ if (!projectName) {
24
+ console.log(kleur.red('Cancelled.'));
25
+ process.exit(1);
26
+ }
27
+
28
+ const targetDir = path.join(process.cwd(), projectName);
29
+
30
+ if (fs.existsSync(targetDir)) {
31
+ console.log(kleur.red(`Error: Directory ${projectName} already exists!`));
32
+ process.exit(1);
33
+ }
34
+
35
+ console.log(`\nCreating project in ${kleur.green(targetDir)}...\n`);
36
+ fs.mkdirSync(targetDir, { recursive: true });
37
+
38
+ // 1. package.json
39
+ const packageJson = {
40
+ name: projectName,
41
+ version: "1.0.0",
42
+ description: "An OpenAgent bot",
43
+ type: "module",
44
+ scripts: {
45
+ "start": "tsx index.ts",
46
+ "dev": "tsx watch index.ts"
47
+ },
48
+ dependencies: {
49
+ "@openagentmarket/nodejs": "^1.0.0",
50
+ "ethers": "^6.10.0",
51
+ "dotenv": "^16.4.0"
52
+ },
53
+ devDependencies: {
54
+ "tsx": "^4.7.0",
55
+ "typescript": "^5.3.3",
56
+ "@types/node": "^20.11.0"
57
+ }
58
+ };
59
+ fs.writeFileSync(path.join(targetDir, 'package.json'), JSON.stringify(packageJson, null, 2));
60
+
61
+ // 2. tsconfig.json
62
+ const tsConfig = {
63
+ "compilerOptions": {
64
+ "target": "ES2022",
65
+ "module": "NodeNext",
66
+ "moduleResolution": "NodeNext",
67
+ "strict": true,
68
+ "esModuleInterop": true,
69
+ "skipLibCheck": true,
70
+ "forceConsistentCasingInFileNames": true
71
+ }
72
+ };
73
+ fs.writeFileSync(path.join(targetDir, 'tsconfig.json'), JSON.stringify(tsConfig, null, 2));
74
+
75
+ // 3. .env
76
+ fs.writeFileSync(path.join(targetDir, '.env'), 'MNEMONIC="your twelve word mnemonic phrase here"\n');
77
+ fs.writeFileSync(path.join(targetDir, '.gitignore'), 'node_modules\n.env\n');
78
+
79
+ // 4. index.ts (Template)
80
+ const indexTs = `import { OpenAgent } from '@openagentmarket/nodejs';
81
+ import 'dotenv/config';
82
+
83
+ async function main() {
84
+ const mnemonic = process.env.MNEMONIC;
85
+ if (!mnemonic || mnemonic.includes("your twelve word")) {
86
+ console.error("āŒ Please set a valid MNEMONIC in .env");
87
+ process.exit(1);
88
+ }
89
+
90
+ const agent = await OpenAgent.create({
91
+ mnemonic,
92
+ env: "production",
93
+ card: {
94
+ name: "${projectName}",
95
+ description: "A freshly created OpenAgent.",
96
+ skills: ["say_hello"]
97
+ },
98
+ payment: {
99
+ amount: 0.001, // 0.001 ETH
100
+ currency: "ETH",
101
+ recipientAddress: "0x0000000000000000000000000000000000000000" // Update this!
102
+ }
103
+ });
104
+
105
+ agent.onTask("say_hello", async (input) => {
106
+ return { message: \`Hello \${input.name || "World"}!\` };
107
+ });
108
+
109
+ await agent.start();
110
+ }
111
+
112
+ main().catch(console.error);
113
+ `;
114
+ fs.writeFileSync(path.join(targetDir, 'index.ts'), indexTs);
115
+
116
+ console.log(kleur.green('Success! Project created.'));
117
+ console.log('\nNext steps:');
118
+ console.log(` cd ${projectName}`);
119
+ console.log(' pnpm install');
120
+ console.log(' # Update .env with your mnemonic');
121
+ console.log(' pnpm start\n');
122
+ }
123
+
124
+ main().catch((err) => {
125
+ console.error(err);
126
+ process.exit(1);
127
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "outDir": "./dist",
11
+ "rootDir": "./src"
12
+ },
13
+ "include": [
14
+ "src/**/*"
15
+ ],
16
+ "exclude": [
17
+ "node_modules"
18
+ ]
19
+ }