nirium-cli 1.0.1

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.
Files changed (3) hide show
  1. package/README.md +72 -0
  2. package/bin/nirium.js +219 -0
  3. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # nirium-cli
2
+
3
+ Scaffold Stellar agent projects — including one that charges for itself.
4
+
5
+ ```bash
6
+ npm install -g nirium-cli
7
+ ```
8
+
9
+ ## Charge for your API in five minutes
10
+
11
+ ```bash
12
+ nirium create x402 --name my-paid-api
13
+ cd my-paid-api && npm install
14
+ ```
15
+
16
+ Fill two values in the generated `.env`:
17
+
18
+ | Variable | Where it comes from |
19
+ |---|---|
20
+ | `STELLAR_PAY_TO` | the Stellar account that receives payments (`G...`) |
21
+ | `X402_FACILITATOR_API_KEY` | free at [channels.openzeppelin.com/gen](https://channels.openzeppelin.com/gen) |
22
+
23
+ The API key is not optional. The facilitator rejects unauthenticated servers
24
+ on testnet as well as mainnet, so without it your routes never get as far as
25
+ offering a 402.
26
+
27
+ ```bash
28
+ npm run dev
29
+ ```
30
+
31
+ Everything under `/premium` now bills before it answers. A caller without
32
+ payment gets a 402 carrying the terms; one that pays gets the data, and the
33
+ transfer settles on Stellar before your handler returns. No subscription, no
34
+ card, no invoice, no human in the middle.
35
+
36
+ The generated server is about ten lines, because `x402Serve()` from the
37
+ [`nirium`](https://www.npmjs.com/package/nirium) SDK carries the facilitator
38
+ client, the scheme registration and the route shape.
39
+
40
+ ## Listen to protocol signals
41
+
42
+ ```bash
43
+ nirium create bot --name my-agent # TypeScript
44
+ nirium create bot --name my-agent -t py # Python
45
+ ```
46
+
47
+ Scaffolds a project that connects to a Nirium agent and prints incoming
48
+ signals. Defaults to `https://nirium-agent.fly.dev` (testnet); set
49
+ `NIRIUM_API_URL` and `NIRIUM_API_KEY` in `.env` to point somewhere else.
50
+
51
+ ## Check an agent
52
+
53
+ ```bash
54
+ nirium status
55
+ ```
56
+
57
+ ## Options
58
+
59
+ | Option | Values | Default |
60
+ |---|---|---|
61
+ | `-n, --name <name>` | project directory name | `nirium-bot-v1` |
62
+ | `-t, --template <template>` | `ts` or `py` — `bot` only | `ts` |
63
+
64
+ ## Links
65
+
66
+ - [nirium.xyz](https://nirium.xyz)
67
+ - [TypeScript SDK](https://www.npmjs.com/package/nirium) · [Python SDK](https://pypi.org/project/nirium/)
68
+ - [SDK and examples on GitHub](https://github.com/nirium-protocol/nirium-sdk)
69
+
70
+ ## License
71
+
72
+ Apache 2.0 — Nirium Protocol
package/bin/nirium.js ADDED
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ═══════════════════════════════════════════════════════════════
4
+ // Nirium — Autonomous Agent CLI (v1.0.1)
5
+ // ═══════════════════════════════════════════════════════════════
6
+
7
+ import { Command } from 'commander';
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import { execSync } from 'child_process';
11
+
12
+ const program = new Command();
13
+
14
+ program
15
+ .name('nirium')
16
+ .description('Nirium protocol development tool')
17
+ .version('1.0.1');
18
+
19
+ // --- COMMAND: create bot ---
20
+ program
21
+ .command('create')
22
+ .argument('<type>', 'What to create: x402 (a server that charges) or bot (a signal listener)')
23
+ .option('-n, --name <name>', 'Name of the project', 'nirium-bot-v1')
24
+ .option('-t, --template <template>', 'Language template (ts, py) — bot only', 'ts')
25
+ .description('Scaffold a new Nirium project')
26
+ .action(async (type, options) => {
27
+ if (type !== 'bot' && type !== 'x402') {
28
+ console.error('❌ Error: type must be "x402" (charge for your API) or "bot" (listen to signals).');
29
+ process.exit(1);
30
+ }
31
+
32
+ const targetDir = path.join(process.cwd(), options.name);
33
+
34
+ if (fs.existsSync(targetDir)) {
35
+ console.error(`❌ Error: Directory ${options.name} already exists.`);
36
+ process.exit(1);
37
+ }
38
+
39
+ console.log(type === 'x402'
40
+ ? `\n💸 [Scaffold] Creating x402 paid API: ${options.name}...`
41
+ : `\n🧬 [Scaffold] Creating ${options.template === 'ts' ? 'TypeScript' : 'Python'} bot: ${options.name}...`);
42
+
43
+ fs.mkdirSync(targetDir, { recursive: true });
44
+
45
+ if (type === 'x402') {
46
+ scaffoldX402(targetDir, options.name);
47
+ } else if (options.template === 'ts') {
48
+ scaffoldTS(targetDir, options.name);
49
+ } else {
50
+ scaffoldPY(targetDir, options.name);
51
+ }
52
+
53
+ console.log(`\n✅ Project initialized in ./${options.name}`);
54
+ console.log(`\n🚀 Get started:`);
55
+ console.log(` cd ${options.name}`);
56
+ if (options.template === 'ts') {
57
+ console.log(` npm install`);
58
+ console.log(` npm run dev`);
59
+ } else {
60
+ console.log(` python -m venv venv`);
61
+ console.log(` source venv/bin/activate`);
62
+ console.log(` pip install -r requirements.txt`);
63
+ console.log(` python main.py`);
64
+ }
65
+ });
66
+
67
+ // Un servidor que COBRA, no uno que escucha. Es el camino corto de
68
+ // "instalé algo" a "me pagaron": levantas esto, le pegas con un cliente
69
+ // x402 y el pago se liquida on-chain antes de que salga la respuesta.
70
+ function scaffoldX402(dir, name) {
71
+ const pkgJson = {
72
+ name,
73
+ version: '0.1.0',
74
+ private: true,
75
+ type: 'module',
76
+ scripts: { dev: 'tsx watch src/server.ts', build: 'tsc' },
77
+ dependencies: {
78
+ nirium: '^0.10.0',
79
+ express: '^5.1.0',
80
+ '@x402/express': '^2.17.0',
81
+ '@x402/core': '^2.17.0',
82
+ '@x402/stellar': '^2.17.0',
83
+ tsx: '^4.19.0',
84
+ typescript: '^5.7.0',
85
+ dotenv: '^16.4.5',
86
+ },
87
+ devDependencies: { '@types/node': '^20.19.0', '@types/express': '^5.0.0' },
88
+ };
89
+ fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(pkgJson, null, 2));
90
+
91
+ fs.mkdirSync(path.join(dir, 'src'), { recursive: true });
92
+ fs.writeFileSync(path.join(dir, 'src', 'server.ts'), `
93
+ import express from 'express';
94
+ import { x402Serve } from 'nirium';
95
+ import 'dotenv/config';
96
+
97
+ const app = express();
98
+
99
+ // Todo lo que va debajo de /premium cobra antes de responder.
100
+ // El pago se liquida on-chain: si no pagaron, tu handler nunca corre.
101
+ app.use('/premium', x402Serve({
102
+ payTo: process.env.STELLAR_PAY_TO!, // tu cuenta G...
103
+ facilitatorApiKey: process.env.X402_FACILITATOR_API_KEY!,
104
+ network: (process.env.STELLAR_NETWORK === 'mainnet' ? 'stellar:pubnet' : 'stellar:testnet'),
105
+ routes: {
106
+ 'GET /signals': '$0.02',
107
+ },
108
+ }));
109
+
110
+ app.get('/premium/signals', (_req, res) => {
111
+ res.json({ signals: [{ pair: 'USDC/CETES', edge: '0.42%' }] });
112
+ });
113
+
114
+ app.listen(3000, () => console.log('💸 cobrando en http://localhost:3000/premium/signals'));
115
+ `.trimStart());
116
+
117
+ fs.writeFileSync(path.join(dir, '.env'),
118
+ 'STELLAR_PAY_TO=\n'
119
+ + '# gratis en channels.openzeppelin.com/gen — el facilitador rechaza servidores sin llave\n'
120
+ + 'X402_FACILITATOR_API_KEY=\n'
121
+ + 'STELLAR_NETWORK=testnet\n');
122
+
123
+ fs.writeFileSync(path.join(dir, 'tsconfig.json'), JSON.stringify({
124
+ compilerOptions: {
125
+ target: 'ES2022', module: 'ESNext', moduleResolution: 'bundler',
126
+ strict: true, esModuleInterop: true, skipLibCheck: true, outDir: 'dist',
127
+ },
128
+ include: ['src'],
129
+ }, null, 2));
130
+ }
131
+
132
+ function scaffoldTS(dir, name) {
133
+ const pkgJson = {
134
+ name,
135
+ version: '0.1.0',
136
+ private: true,
137
+ scripts: {
138
+ "dev": "tsx watch src/index.ts",
139
+ "build": "tsc"
140
+ },
141
+ dependencies: {
142
+ "nirium": "^0.10.0",
143
+ "tsx": "^4.19.0",
144
+ "typescript": "^5.7.0",
145
+ "dotenv": "^16.4.5"
146
+ },
147
+ devDependencies: {
148
+ "@types/node": "^20.19.0"
149
+ }
150
+ };
151
+
152
+ fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(pkgJson, null, 2));
153
+ fs.mkdirSync(path.join(dir, 'src'));
154
+
155
+ const indexSrc = `
156
+ import { Agent } from 'nirium';
157
+ import 'dotenv/config';
158
+
159
+ const agent = new Agent({
160
+ baseUrl: process.env.NIRIUM_API_URL || 'https://nirium-agent.fly.dev',
161
+ apiKey: process.env.NIRIUM_API_KEY
162
+ });
163
+
164
+ agent.subscribe((signal) => {
165
+ console.log('🧬 [Signal Received]:', signal.signal_type, signal.pair);
166
+ // Logic to execute on signals...
167
+ });
168
+
169
+ console.log('✅ Listening for Nirium signals...');
170
+ `;
171
+ fs.writeFileSync(path.join(dir, 'src', 'index.ts'), indexSrc);
172
+ fs.writeFileSync(path.join(dir, '.env'), 'NIRIUM_API_URL=https://nirium-agent.fly.dev\nNIRIUM_API_KEY=');
173
+ fs.writeFileSync(path.join(dir, 'tsconfig.json'), JSON.stringify({
174
+ compilerOptions: {
175
+ target: "es2022",
176
+ module: "nodenext",
177
+ strict: true,
178
+ esModuleInterop: true,
179
+ skipLibCheck: true
180
+ }
181
+ }, null, 2));
182
+ }
183
+
184
+ function scaffoldPY(dir, name) {
185
+ const reqs = "nirium>=0.9.0\npython-dotenv>=1.0.0";
186
+ fs.writeFileSync(path.join(dir, 'requirements.txt'), reqs);
187
+
188
+ const mainSrc = `
189
+ import asyncio
190
+ import os
191
+ from nirium import Agent
192
+ from dotenv import load_dotenv
193
+
194
+ load_dotenv()
195
+
196
+ async def main():
197
+ agent = Agent(
198
+ api_url=os.getenv("NIRIUM_API_URL", "https://nirium-agent.fly.dev"),
199
+ api_key=os.getenv("NIRIUM_API_KEY")
200
+ )
201
+
202
+ @agent.on("signal")
203
+ async def handle_signal(signal):
204
+ print(f"🧬 [Signal]: {signal['signal_type']} on {signal['pair']}")
205
+
206
+ @agent.on("connected")
207
+ async def on_connect(data):
208
+ print("✅ Connected to Nirium Neural Loop")
209
+
210
+ await agent.subscribe()
211
+
212
+ if __name__ == "__main__":
213
+ asyncio.run(main())
214
+ `;
215
+ fs.writeFileSync(path.join(dir, 'main.py'), mainSrc);
216
+ fs.writeFileSync(path.join(dir, '.env'), 'NIRIUM_API_URL=https://nirium-agent.fly.dev\nNIRIUM_API_KEY=');
217
+ }
218
+
219
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "nirium-cli",
3
+ "version": "1.0.1",
4
+ "description": "Nirium CLI — scaffold Stellar agent projects and check agent status",
5
+ "main": "bin/nirium.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "nirium": "bin/nirium.js"
9
+ },
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "keywords": [
14
+ "stellar",
15
+ "soroban",
16
+ "x402",
17
+ "ai-agents",
18
+ "nirium",
19
+ "cli"
20
+ ],
21
+ "author": "Nirium Team",
22
+ "license": "Apache-2.0",
23
+ "dependencies": {
24
+ "axios": "^1.13.6",
25
+ "commander": "^11.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^20.19.30",
29
+ "typescript": "^5.0.0"
30
+ },
31
+ "files": [
32
+ "bin",
33
+ "README.md"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/nirium-protocol/nirium-sdk.git"
38
+ },
39
+ "homepage": "https://nirium.xyz",
40
+ "engines": {
41
+ "node": ">=18"
42
+ }
43
+ }