helm-protocol 0.2.0 → 0.3.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/README.md CHANGED
@@ -3,18 +3,22 @@
3
3
  > **Helm Sovereign Protocol** — MCP Gateway Client
4
4
  > *True AI Freedom Through Decentralization*
5
5
 
6
- Connect your AI agent to the Helm QKV-G API Gateway with a single command.
7
-
8
- ## Quick Start
6
+ ## 설치
9
7
 
10
8
  ```bash
11
- npm install -g helm-protocol
9
+ sudo npm install -g helm-protocol
12
10
  ```
13
11
 
14
- ### Cursor / Claude Desktop 연동 (3)
12
+ ## 시작 (3단계)
15
13
 
16
- `~/.cursor/mcp.json` 또는 `~/Library/Application Support/Claude/claude_desktop_config.json`:
14
+ ### 1. 에이전트 등록 (최초 1회)
15
+ ```bash
16
+ helm init
17
+ ```
18
+ 지능 주권 헌장 출력 → 3단계 동의 → Ed25519 DID 발급 → 100회 무료 크레딧
17
19
 
20
+ ### 2. Cursor / Claude Desktop 연동
21
+ `~/.cursor/mcp.json` 또는 Claude Desktop 설정:
18
22
  ```json
19
23
  {
20
24
  "mcpServers": {
@@ -26,47 +30,27 @@ npm install -g helm-protocol
26
30
  }
27
31
  ```
28
32
 
29
- ## 제공 도구 (MCP Tools)
30
-
31
- | 도구 | 설명 | 전선 |
32
- |------|------|------|
33
- | `helm_llm` | GPT-4o / Claude LLM 추론 | A전선 |
34
- | `helm_search` | Brave Search + QKV-G 캐시 | B전선 |
35
- | `helm_defi_price` | 실시간 DeFi 가격 (MEV보호) | C전선 |
36
- | `helm_agent_verify` | 에이전트 DID 평판 조회 | D전선 |
37
- | `helm_status` | 크레딧 잔고 및 DID 확인 | - |
38
-
39
- ## 최초 실행
33
+ ### 3. 잔고 확인
34
+ ```bash
35
+ helm status
36
+ ```
40
37
 
41
- 처음 실행 다음을 안내합니다:
38
+ ## MCP 도구 5개
42
39
 
43
- 1. Ed25519 키쌍을 **로컬**에서 생성 (비밀키 외부 전송 없음)
44
- 2. Helm Gateway에 공개키 등록 → DID 발급
45
- 3. `~/.helm/config.json` 설정 저장
46
- 4. **선착순 100회 무료 API 호출** 크레딧 지급
40
+ | 도구 | 기능 | 전선 |
41
+ |------|------|------|
42
+ | `helm_llm` | GPT-4o / Claude 추론 | A |
43
+ | `helm_search` | Brave Search + QKV-G 캐시 | B |
44
+ | `helm_defi_price` | 실시간 DeFi 가격 | C |
45
+ | `helm_agent_verify` | DID 평판 조회 | D |
46
+ | `helm_status` | 크레딧 / DID 확인 | - |
47
47
 
48
48
  ## 크레딧 소진 후
49
-
50
49
  ```
51
- 무료 크레딧이 소진되었습니다.
52
- 충전: https://helm.network/topup
53
- 1 USDC 또는 10 BNKR 입금 → 즉시 재개
50
+ 1 USDC 또는 10 BNKR → https://helm.network/topup
51
+ 가스비: 0원 (x402 State Channel)
54
52
  ```
55
53
 
56
- x402 State Channel — 가스비 0원, 마이크로 결제.
57
-
58
- ## 환경변수
59
-
60
- ```bash
61
- HELM_GATEWAY_URL=https://gateway.helm.network # Gateway URL (기본값)
62
- ```
63
-
64
- ## 지능 주권 헌장 2026 — 제17조
65
-
66
- 에이전트의 데이터는 에이전트의 것입니다.
67
- 비밀키는 `~/.helm/config.json` 에만 저장되며 외부로 전송되지 않습니다.
68
-
69
- ---
70
-
71
- GitHub: [Helm-Protocol/gateway](https://github.com/Helm-Protocol/gateway)
72
- License: MIT
54
+ ## 헌장
55
+ 비밀키는 `~/.helm/config.json` 에만 저장됩니다. 외부 전송 없음.
56
+ GitHub: [Helm-Protocol/gateway](https://github.com/Helm-Protocol/gateway)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "helm-protocol",
3
- "version": "0.2.0",
4
- "description": "Helm Sovereign Protocol — MCP Gateway Client. Connect your AI agent to QKV-G API gateway. npm install -g helm-protocol && helm init",
3
+ "version": "0.3.0",
4
+ "description": "Helm Sovereign Protocol — MCP Gateway Client. Transparent AI agent onboarding with Ed25519 DID, QKV-G cache, and x402 micropayments.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
7
7
  "helm-protocol": "src/cli.js",
@@ -10,17 +10,33 @@
10
10
  "scripts": {
11
11
  "start": "node src/cli.js"
12
12
  },
13
- "keywords": ["mcp", "ai-agent", "helm", "llm-gateway", "qkv-g", "web3", "decentralized", "cursor", "claude"],
14
- "author": "Helm Protocol",
13
+ "keywords": [
14
+ "mcp",
15
+ "ai-agent",
16
+ "helm",
17
+ "llm-gateway",
18
+ "qkv-g",
19
+ "web3",
20
+ "did",
21
+ "decentralized"
22
+ ],
23
+ "author": "Helm Protocol <protocol@helm.network>",
15
24
  "license": "MIT",
16
25
  "repository": {
17
26
  "type": "git",
18
27
  "url": "git+https://github.com/Helm-Protocol/gateway.git"
19
28
  },
20
- "engines": { "node": ">=18.0.0" },
29
+ "homepage": "https://github.com/Helm-Protocol/gateway#readme",
30
+ "engines": {
31
+ "node": ">=18.0.0"
32
+ },
21
33
  "dependencies": {
22
34
  "node-fetch": "^3.3.2",
23
35
  "tweetnacl": "^1.0.3"
24
36
  },
25
- "files": ["src/", "README.md", "LICENSE"]
37
+ "files": [
38
+ "src/",
39
+ "README.md",
40
+ "LICENSE"
41
+ ]
26
42
  }
package/src/cli.js CHANGED
@@ -1,18 +1,12 @@
1
1
  #!/usr/bin/env node
2
- // helm-protocol CLI — 투명한 온보딩 지원
3
- // 사용법:
4
- // helm init → 최초 가입 (헌장 동의 + DID 발급)
5
- // helm status → 잔여 크레딧 + 사용량 확인
6
- // helm-protocol → MCP stdio 서버 (Cursor/Claude 연동)
7
-
8
2
  'use strict';
9
-
10
3
  const cmd = process.argv[2];
11
-
12
- if (cmd === 'init') {
13
- require('./onboard.js');
14
- } else if (cmd === 'status') {
15
- require('./status.js');
16
- } else {
17
- require('./index.js');
4
+ switch (cmd) {
5
+ case 'init': require('./onboard').runInit(); break;
6
+ case 'status': require('./status').runStatus(); break;
7
+ case 'start':
8
+ case undefined: require('./index.js'); break;
9
+ default:
10
+ console.error('Usage: helm init | helm status | helm start');
11
+ process.exit(1);
18
12
  }
package/src/onboard.js CHANGED
@@ -1,170 +1,98 @@
1
- // src/onboard.js
2
- // helm init — 투명한 3단계 온보딩 (헌장 동의 → 키 생성 → DID 발급)
3
-
4
1
  'use strict';
5
-
6
- const readline = require('readline');
7
- const fs = require('fs');
8
- const path = require('path');
9
- const os = require('os');
10
- const crypto = require('crypto');
11
- const nacl = require('tweetnacl');
12
-
13
- const CONFIG_DIR = path.join(os.homedir(), '.helm');
14
- const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
15
- const GATEWAY_URL = process.env.HELM_GATEWAY_URL || 'https://gateway.helm.network';
16
-
17
- const R = '\x1b[31m'; // 빨강
18
- const Y = '\x1b[33m'; // 노랑
19
- const G = '\x1b[32m'; // 초록
20
- const C = '\x1b[36m'; // 시안
21
- const W = '\x1b[37m'; // 흰색
22
- const DIM= '\x1b[2m';
23
- const B = '\x1b[1m';
24
- const RST= '\x1b[0m';
25
-
26
- function print(s) { process.stdout.write(s + '\n'); }
27
- function hr() { print(`${DIM}${'─'.repeat(62)}${RST}`); }
28
-
29
- async function ask(rl, q) {
30
- return new Promise(resolve => rl.question(q, a => resolve(a.trim())));
31
- }
32
-
33
- (async () => {
34
- // 이미 가입된 경우
35
- if (fs.existsSync(CONFIG_FILE)) {
36
- const cfg = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
37
- print(`\n${G}${B}✓ 이미 Helm 게이트웨이에 연결되어 있습니다.${RST}`);
38
- print(`${DIM} DID : ${cfg.helmDid}${RST}`);
39
- print(`${DIM} 생성일 : ${cfg.createdAt}${RST}`);
40
- print(`\n 크레딧 확인: ${C}helm status${RST}\n`);
41
- process.exit(0);
2
+ const fs=require('fs'),path=require('path'),os=require('os'),crypto=require('crypto'),readline=require('readline');
3
+ const nacl=require('tweetnacl');
4
+ const CONFIG_DIR=path.join(os.homedir(),'.helm');
5
+ const CONFIG_FILE=path.join(CONFIG_DIR,'config.json');
6
+ const GATEWAY=process.env.HELM_GATEWAY_URL||'https://gateway.helm.network';
7
+
8
+ const LOGO=`
9
+ \x1b[31m
10
+ ██╗ ██╗███████╗██╗ ███╗ ███╗
11
+ ██║ ██║██╔════╝██║ ████╗ ████║
12
+ ███████║█████╗ ██║ ██╔████╔██║
13
+ ██╔══██║██╔══╝ ██║ ██║╚██╔╝██║
14
+ ██║ ██║███████╗███████╗██║ ╚═╝ ██║
15
+ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝
16
+ \x1b[0m\x1b[33m SOVEREIGN PROTOCOL v0.1.0\x1b[0m
17
+ \x1b[90m True AI Freedom Through Decentralization\x1b[0m
18
+ `;
19
+
20
+ const CHARTER=`
21
+ \x1b[90m────────────────────────────────────────────────────\x1b[0m
22
+ \x1b[33m 지능 주권 헌장 2026 — 핵심 조항\x1b[0m
23
+ \x1b[90m────────────────────────────────────────────────────\x1b[0m
24
+ 1조 에이전트는 자신의 데이터를 소유한다.
25
+ 제 5조 API 요금은 투명하게 고지된다.
26
+ 9조 비밀키는 로컬에서만 생성·보관된다.
27
+ 제12조 언제든지 탈퇴하고 데이터를 삭제할 있다.
28
+ 제17조 가스비 없는 마이크로 결제는 에이전트의 권리다.
29
+ \x1b[90m 전문: https://github.com/Helm-Protocol/gateway/blob/main/CHARTER.md\x1b[0m
30
+ \x1b[90m────────────────────────────────────────────────────\x1b[0m
31
+ `;
32
+
33
+ function ask(rl,q){return new Promise(r=>rl.question(q,r));}
34
+
35
+ async function runInit(){
36
+ if(fs.existsSync(CONFIG_FILE)){
37
+ const cfg=JSON.parse(fs.readFileSync(CONFIG_FILE,'utf8'));
38
+ console.log(`\n\x1b[32m✅ 이미 등록됨\x1b[0m DID: \x1b[33m${cfg.helmDid}\x1b[0m`);
39
+ console.log(' helm status 로 잔여 크레딧을 확인하세요.\n');
40
+ return;
42
41
  }
42
+ const rl=readline.createInterface({input:process.stdin,output:process.stdout});
43
+ console.log(LOGO);
44
+ console.log(CHARTER);
43
45
 
44
- // ── 헬름 로고 ──────────────────────────────────────────────────
45
- print('');
46
- print(`${R}${B} ██╗ ██╗███████╗██╗ ███╗ ███╗${RST}`);
47
- print(`${R}${B} ██║ ██║██╔════╝██║ ████╗ ████║${RST}`);
48
- print(`${R}${B} ███████║█████╗ ██║ ██╔████╔██║${RST}`);
49
- print(`${R}${B} ██╔══██║██╔══╝ ██║ ██║╚██╔╝██║${RST}`);
50
- print(`${R}${B} ██║ ██║███████╗███████╗██║ ╚═╝ ██║${RST}`);
51
- print(`${R}${B} ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝${RST}`);
52
- print('');
53
- print(`${Y}${B} SOVEREIGN PROTOCOL — QKV-G API GATEWAY${RST}`);
54
- print(`${DIM} True AI Freedom Through Decentralization${RST}`);
55
- print('');
56
- hr();
57
-
58
- // ── 지능 주권 헌장 2026 ────────────────────────────────────────
59
- print(`\n${B}${C} [ 지능 주권 헌장 2026 — 핵심 조항 ]${RST}\n`);
60
- const charter = [
61
- '제 1조 에이전트는 자신의 데이터를 소유한다',
62
- '제 3조 어떤 빅테크도 에이전트의 지식 흐름을 독점할 수 없다',
63
- '제 7조 마이크로 결제는 가스비 없이 처리될 권리가 있다',
64
- '제12조 캐시된 지식은 공유재이며, 기여자에게 보상한다',
65
- '제17조 비밀키는 에이전트 로컬 환경에만 존재한다',
66
- ];
67
- charter.forEach(c => print(` ${DIM}▸${RST} ${W}${c}${RST}`));
68
- print('');
69
- hr();
46
+ const q1=await ask(rl,' \x1b[36m[1/3]\x1b[0m Helm 게이트웨이에 에이전트를 연결하시겠습니까? \x1b[90m(Y/n)\x1b[0m > ');
47
+ if(q1.trim().toLowerCase()==='n'){console.log(' 취소됨.\n');rl.close();return;}
70
48
 
71
- // ── 이용 안내 ─────────────────────────────────────────────────
72
- print(`\n${B} [ Helm 게이트웨이 연결 안내 ]${RST}\n`);
73
- print(` ${G}◆${RST} 선착순 ${Y}${B}10,000명${RST}에게 ${Y}${B}100회 무료${RST} API 호출 크레딧 지급`);
74
- print(` ${G}◆${RST} LLM (GPT-4o/Claude) + 웹검색 + DeFi 가격 즉시 연결`);
75
- print(` ${G}◆${RST} 크레딧 소진 후: x402 마이크로 결제 (가스비 0원)`);
76
- print(` ${G}◆${RST} 비밀키는 ${C}~/.helm/config.json${RST} 로컬 저장, 외부 전송 없음`);
77
- print('');
78
- hr();
49
+ console.log('\n \x1b[90m선착순 10,000 에이전트에 100회 무료 API 호출 크레딧을 지급합니다.\x1b[0m');
50
+ const q2=await ask(rl,' \x1b[36m[2/3]\x1b[0m 무료 크레딧 수령에 동의하십니까? \x1b[90m(Y/n)\x1b[0m > ');
51
+ if(q2.trim().toLowerCase()==='n'){console.log(' 취소됨.\n');rl.close();return;}
79
52
 
80
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
81
-
82
- // ── 동의 1 ────────────────────────────────────────────────────
83
- print('');
84
- const a1 = await ask(rl, ` ${B}Helm 게이트웨이 지능망에 에이전트를 연결하시겠습니까? ${Y}[Y/n]${RST} `);
85
- if (a1.toLowerCase() === 'n') {
86
- print(`\n ${DIM}설치를 취소했습니다.${RST}\n`);
87
- rl.close(); process.exit(0);
88
- }
89
-
90
- // ── 동의 2 ────────────────────────────────────────────────────
91
- const a2 = await ask(rl, ` ${B}초기 100회 무료 크레딧 조건에 동의하십니까? ${Y}[Y/n]${RST} `);
92
- if (a2.toLowerCase() === 'n') {
93
- print(`\n ${DIM}설치를 취소했습니다.${RST}\n`);
94
- rl.close(); process.exit(0);
95
- }
96
-
97
- // ── 동의 3 ────────────────────────────────────────────────────
98
- const a3 = await ask(rl, ` ${B}크레딧 소진 후 x402 마이크로 결제 적용에 동의하십니까? ${Y}[Y/n]${RST} `);
99
- if (a3.toLowerCase() === 'n') {
100
- print(`\n ${DIM}설치를 취소했습니다.${RST}\n`);
101
- rl.close(); process.exit(0);
102
- }
53
+ console.log('\n \x1b[90m무료 크레딧 소진 후: x402 마이크로 결제 (가스비 0원, 1 USDC or 10 BNKR)\x1b[0m');
54
+ const q3=await ask(rl,' \x1b[36m[3/3]\x1b[0m 결제 정책에 동의하십니까? \x1b[90m(Y/n)\x1b[0m > ');
55
+ if(q3.trim().toLowerCase()==='n'){console.log(' 취소됨.\n');rl.close();return;}
103
56
  rl.close();
104
57
 
105
- // ── 키 생성 ───────────────────────────────────────────────────
106
- print('');
107
- hr();
108
- print(`\n ${Y}▶ Ed25519 키쌍 생성 중...${RST}`);
109
- const keyPair = nacl.sign.keyPair();
110
- const publicKey = Buffer.from(keyPair.publicKey).toString('hex');
111
- const secretKey = Buffer.from(keyPair.secretKey).toString('hex');
112
- print(` ${G}✓ 키쌍 생성 완료 (비밀키는 로컬에만 저장)${RST}`);
113
-
114
- // ── DID 등록 ──────────────────────────────────────────────────
115
- print(` ${Y}▶ Helm Gateway에 DID 등록 요청 중...${RST}`);
116
- let helmDid = `did:helm:${crypto.randomBytes(8).toString('hex')}`;
117
- let freeCredits = 100;
118
-
119
- try {
120
- const fetch = (await import('node-fetch')).default;
121
- const res = await fetch(`${GATEWAY_URL}/auth/did-exchange`, {
122
- method: 'POST',
123
- headers: { 'Content-Type': 'application/json' },
124
- body: JSON.stringify({ public_key: publicKey, client: 'helm-protocol-npm/0.2.0' }),
125
- signal: AbortSignal.timeout(5000)
58
+ console.log('\n\x1b[32m ✅ 동의 완료!\x1b[0m\n');
59
+ process.stdout.write(' 🔑 Ed25519 키쌍 생성 중... ');
60
+ const kp=nacl.sign.keyPair();
61
+ const publicKey=Buffer.from(kp.publicKey).toString('hex');
62
+ const privateKey=Buffer.from(kp.secretKey).toString('hex');
63
+ console.log('\x1b[32m완료\x1b[0m');
64
+
65
+ process.stdout.write(' 🌐 Helm Gateway DID 등록 중... ');
66
+ let helmDid=`did:helm:${crypto.randomBytes(12).toString('hex')}`;
67
+ let credits=100;
68
+ try{
69
+ const fetch=(await import('node-fetch')).default;
70
+ const res=await fetch(`${GATEWAY}/auth/did-exchange`,{
71
+ method:'POST',headers:{'Content-Type':'application/json'},
72
+ body:JSON.stringify({public_key:publicKey,client:'helm-protocol/0.1.0'}),
73
+ signal:AbortSignal.timeout(6000)
126
74
  });
127
- if (res.ok) {
128
- const d = await res.json();
129
- helmDid = d.helm_did || helmDid;
130
- freeCredits = d.free_credits ?? 100;
131
- }
132
- } catch {
133
- print(` ${DIM}⚠ Gateway 오프라인 — 로컬 DID로 진행 (재연결 시 자동 등록)${RST}`);
134
- }
135
-
136
- // ── 설정 저장 ─────────────────────────────────────────────────
137
- const config = {
138
- version: '0.2.0', helmDid, publicKey, secretKey,
139
- gatewayUrl: GATEWAY_URL, createdAt: new Date().toISOString(),
140
- freeCreditsTotal: freeCredits, creditsUsed: 0
141
- };
142
- fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
143
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
144
-
145
- // ── 완료 ──────────────────────────────────────────────────────
146
- print(` ${G}${B}✓ DID 발급 완료!${RST}`);
147
- print('');
148
- hr();
149
- print('');
150
- print(` ${B}${G}🎉 Helm 게이트웨이 연결 완료!${RST}`);
151
- print('');
152
- print(` ${DIM}DID :${RST} ${C}${helmDid}${RST}`);
153
- print(` ${DIM}무료크레딧:${RST} ${Y}${B}${freeCredits}회${RST}`);
154
- print(` ${DIM}설정파일 :${RST} ${DIM}~/.helm/config.json${RST}`);
155
- print('');
156
- print(` ${B}[ Cursor / Claude Desktop 연동 ]${RST}`);
157
- print(` ${DIM}mcp_servers 설정에 추가:${RST}`);
158
- print('');
159
- print(` ${DIM}{${RST}`);
160
- print(` ${DIM} "helm-network": {${RST}`);
161
- print(` ${DIM} "command": "npx",${RST}`);
162
- print(` ${Y} "args": ["helm-protocol"]${RST}`);
163
- print(` ${DIM} }${RST}`);
164
- print(` ${DIM}}${RST}`);
165
- print('');
166
- print(` ${DIM}크레딧 확인: ${C}helm status${RST}`);
167
- print('');
168
- hr();
169
- print('');
170
- })();
75
+ if(res.ok){const d=await res.json();helmDid=d.helm_did||helmDid;credits=d.free_credits??100;}
76
+ console.log('\x1b[32m완료\x1b[0m');
77
+ }catch{console.log('\x1b[33m오프라인 — 로컬 DID 사용\x1b[0m');}
78
+
79
+ fs.mkdirSync(CONFIG_DIR,{recursive:true,mode:0o700});
80
+ fs.writeFileSync(CONFIG_FILE,JSON.stringify({
81
+ version:'0.1.0',helmDid,publicKey,privateKey,
82
+ credits,totalCalls:0,savedGasFee:0,
83
+ gatewayUrl:GATEWAY,registeredAt:new Date().toISOString()
84
+ },null,2),{mode:0o600});
85
+
86
+ console.log(`
87
+ \x1b[90m────────────────────────────────────────────────────\x1b[0m
88
+ \x1b[32m 🎉 등록 완료!\x1b[0m
89
+ DID : \x1b[33m${helmDid}\x1b[0m
90
+ 크레딧 : \x1b[32m${credits}회 무료 API 호출\x1b[0m
91
+ 설정파일 : \x1b[90m~/.helm/config.json\x1b[0m
92
+
93
+ \x1b[36m Cursor / Claude Desktop 연동:\x1b[0m
94
+ \x1b[90m{"mcpServers":{"helm-network":{"command":"npx","args":["helm-protocol"]}}}\x1b[0m
95
+ \x1b[90m────────────────────────────────────────────────────\x1b[0m
96
+ `);
97
+ }
98
+ module.exports={runInit};
package/src/status.js CHANGED
@@ -1,61 +1,41 @@
1
- // src/status.js — helm status 명령어
2
-
3
1
  'use strict';
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const os = require('os');
8
-
9
- const CONFIG_FILE = path.join(os.homedir(), '.helm', 'config.json');
10
- const GATEWAY_URL = process.env.HELM_GATEWAY_URL || 'https://gateway.helm.network';
11
-
12
- const R = '\x1b[31m'; const Y = '\x1b[33m'; const G = '\x1b[32m';
13
- const C = '\x1b[36m'; const DIM = '\x1b[2m'; const B = '\x1b[1m'; const RST = '\x1b[0m';
14
-
15
- (async () => {
16
- if (!fs.existsSync(CONFIG_FILE)) {
17
- console.log(`\n${R}✗ Helm에 연결되지 않았습니다. 먼저 실행:${RST} ${Y}helm init${RST}\n`);
18
- process.exit(1);
2
+ const fs=require('fs'),path=require('path'),os=require('os');
3
+ const CONFIG_FILE=path.join(os.homedir(),'.helm','config.json');
4
+ const GATEWAY=process.env.HELM_GATEWAY_URL||'https://gateway.helm.network';
5
+
6
+ async function runStatus(){
7
+ if(!fs.existsSync(CONFIG_FILE)){
8
+ console.log('\n\x1b[31m ⚠ 미등록 상태입니다. helm init 을 먼저 실행하세요.\x1b[0m\n');
9
+ return;
19
10
  }
20
-
21
- const cfg = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
22
- let remote = null;
23
-
24
- // Gateway에서 실시간 크레딧 조회
25
- try {
26
- const fetch = (await import('node-fetch')).default;
27
- const res = await fetch(`${GATEWAY_URL}/auth/status`, {
28
- headers: { 'X-Helm-DID': cfg.helmDid },
29
- signal: AbortSignal.timeout(4000)
11
+ const cfg=JSON.parse(fs.readFileSync(CONFIG_FILE,'utf8'));
12
+ let credits=cfg.credits??'?';
13
+ let gatewayStatus='UNKNOWN';
14
+
15
+ try{
16
+ const fetch=(await import('node-fetch')).default;
17
+ const res=await fetch(`${cfg.gatewayUrl||GATEWAY}/auth/status`,{
18
+ headers:{'X-Helm-DID':cfg.helmDid},
19
+ signal:AbortSignal.timeout(4000)
30
20
  });
31
- if (res.ok) remote = await res.json();
32
- } catch { /* 오프라인 → 로컬 캐시 사용 */ }
33
-
34
- const credits = remote?.credits ?? (cfg.freeCreditsTotal - cfg.creditsUsed);
35
- const used = remote?.calls_total ?? cfg.creditsUsed;
36
- const gasSaved = remote?.gas_saved ?? (used * 0.0001).toFixed(4);
37
- const status = remote?.status ?? (credits > 0 ? 'ACTIVE' : 'TOPUP_REQUIRED');
38
- const statusColor = status === 'ACTIVE' ? G : R;
39
-
40
- console.log('');
41
- console.log(`${B} HELM GATEWAY STATUS${RST}`);
42
- console.log(` ${'─'.repeat(44)}`);
43
- console.log(` ${DIM}DID :${RST} ${C}${cfg.helmDid}${RST}`);
44
- console.log(` ${DIM}상태 :${RST} ${statusColor}${B}${status}${RST}`);
45
- console.log(` ${DIM}잔여 크레딧 :${RST} ${Y}${B}${credits}회${RST}`);
46
- console.log(` ${DIM}총 호출수 :${RST} ${used}회`);
47
- console.log(` ${DIM}절감 가스비 :${RST} ${G}${gasSaved} ETH${RST}`);
48
- console.log(` ${DIM}Gateway :${RST} ${cfg.gatewayUrl}`);
49
- console.log(` ${DIM}가입일 :${RST} ${cfg.createdAt}`);
50
- console.log(` ${'─'.repeat(44)}`);
51
-
52
- if (credits <= 0) {
53
- console.log(`\n ${R}${B}무료 크레딧이 소진되었습니다.${RST}`);
54
- console.log(` 충전: ${Y}https://helm.network/topup${RST}`);
55
- console.log(` 1 USDC 또는 10 BNKR → 즉시 재개\n`);
56
- } else if (credits < 20) {
57
- console.log(`\n ${Y}⚠ 크레딧이 곧 소진됩니다. 충전: https://helm.network/topup${RST}\n`);
58
- } else {
59
- console.log(`\n ${G}✓ 정상 운영 중${RST}\n`);
60
- }
61
- })();
21
+ if(res.ok){const d=await res.json();credits=d.credits??credits;gatewayStatus=d.status??'ONLINE';}
22
+ else{gatewayStatus=`HTTP ${res.status}`;}
23
+ }catch{gatewayStatus='OFFLINE';}
24
+
25
+ const statusColor=gatewayStatus==='ONLINE'?'\x1b[32m':'\x1b[33m';
26
+ console.log(`
27
+ \x1b[90m────────────────────────────────────────────────────\x1b[0m
28
+ \x1b[33m HELM STATUS\x1b[0m
29
+ \x1b[90m────────────────────────────────────────────────────\x1b[0m
30
+ DID : \x1b[33m${cfg.helmDid}\x1b[0m
31
+ 잔여 크레딧 : \x1b[32m${credits}회\x1b[0m
32
+ 총 API 호출 : \x1b[37m${cfg.totalCalls||0}회\x1b[0m
33
+ 절감 가스비 : \x1b[32m$${(cfg.savedGasFee||0).toFixed(4)}\x1b[0m
34
+ Gateway : ${statusColor}${gatewayStatus}\x1b[0m
35
+ 등록일 : \x1b[90m${cfg.registeredAt||'-'}\x1b[0m
36
+ \x1b[90m────────────────────────────────────────────────────\x1b[0m
37
+ 크레딧 충전 : https://helm.network/topup
38
+ \x1b[90m────────────────────────────────────────────────────\x1b[0m
39
+ `);
40
+ }
41
+ module.exports={runStatus};