aixxai 1.6.7 → 1.6.9
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 +4 -2
- package/aixxai-1.6.9.tgz +0 -0
- package/bin/aixx.js +9 -7
- package/package.json +38 -33
- package/src/commands/aci.js +11 -145
- package/src/commands/balance.js +6 -4
- package/src/commands/config.js +68 -68
- package/src/commands/help.js +4 -3
- package/src/commands/install.js +636 -636
- package/src/commands/market.js +232 -0
- package/src/commands/models.js +2 -2
- package/src/commands/recharge.js +1 -1
- package/src/commands/servers.js +122 -122
- package/src/commands/status.js +120 -0
- package/src/commands/test.js +1 -1
- package/src/utils/agentconfig.js +374 -375
- package/src/utils/download.js +147 -147
- package/src/utils/env.js +136 -136
- package/templates/QUICKSTART.md +1 -1
- package/templates/SKILL.md +5 -5
- package/templates/references/account.md +1 -1
- package/templates/references/aixx-shared.md +59 -59
- package/templates/references/apps.md +1 -1
- package/templates/references/chat.md +2 -2
- package/templates/references/data.md +1 -1
- package/templates/references/notify.md +1 -1
- package/templates/references/search.md +1 -1
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIXX CLI - market 命令(1104 公开端点版)
|
|
3
|
+
*
|
|
4
|
+
* 算力行情数据订阅(三档:consumer/bulk/all · 7天全功能试用):
|
|
5
|
+
* aixx market login --token <T> 保存访问令牌
|
|
6
|
+
* aixx market tickers [--usd] 全标的快照
|
|
7
|
+
* aixx market ticker <SYMBOL> 单标的快照
|
|
8
|
+
* aixx market score <SYMBOL> 标的记分卡
|
|
9
|
+
* aixx market history <SYMBOL> [d] 历史点位
|
|
10
|
+
* aixx market detail <SYMBOL> 大宗详情数据包
|
|
11
|
+
* aixx market consumer <SYMBOL> 消费级详情数据包
|
|
12
|
+
* 所有命令支持 --json(脚本管道用)
|
|
13
|
+
*
|
|
14
|
+
* 本命令组为纯数据输出,零 AI 参与;错误一律人话提示。
|
|
15
|
+
* 端点:/api/v1/* 公开命名契约(机读契约见 /api/v1/api-docs.json)。
|
|
16
|
+
*
|
|
17
|
+
* 令牌来源:环境变量 AIXX_MARKET_TOKEN → ~/.aixx/config.json marketToken(兼容读 aciBetaToken)。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
21
|
+
import { homedir } from 'os';
|
|
22
|
+
import { join } from 'path';
|
|
23
|
+
|
|
24
|
+
const BASE = process.env.AIXX_MARKET_BASE_URL || 'https://aixx.ai';
|
|
25
|
+
const FETCH_TIMEOUT = 15000;
|
|
26
|
+
|
|
27
|
+
function configFile() {
|
|
28
|
+
return join(homedir(), '.aixx', 'config.json');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function loadToken() {
|
|
32
|
+
if (process.env.AIXX_MARKET_TOKEN) return process.env.AIXX_MARKET_TOKEN;
|
|
33
|
+
try {
|
|
34
|
+
const f = configFile();
|
|
35
|
+
if (existsSync(f)) {
|
|
36
|
+
const conf = JSON.parse(readFileSync(f, 'utf-8'));
|
|
37
|
+
return conf.marketToken || null;
|
|
38
|
+
}
|
|
39
|
+
} catch (e) { /* 走未配置路径 */ }
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function mFetch(path) {
|
|
44
|
+
const token = loadToken();
|
|
45
|
+
if (!token) {
|
|
46
|
+
console.error('尚未配置访问令牌。');
|
|
47
|
+
console.error('开通: https://www.aixx.vip | 或设置环境变量 AIXX_MARKET_TOKEN');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
const ctrl = new AbortController();
|
|
51
|
+
const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT);
|
|
52
|
+
try {
|
|
53
|
+
const res = await fetch(`${BASE}${path}`, {
|
|
54
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
55
|
+
signal: ctrl.signal,
|
|
56
|
+
});
|
|
57
|
+
if (res.status === 403) {
|
|
58
|
+
console.error('当前订阅档位不包含该数据 —— 如需升级请访问 aixx.ai 或联系客服');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
if (res.status === 404) {
|
|
62
|
+
console.error('未查询到该数据(请核对标的代码,或联系客服确认订阅状态)');
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
if (res.status === 401 || res.status === 403) {
|
|
66
|
+
console.error('令牌无效或已过期,请重新登录: aixx market login --token <T>');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
console.error(`服务暂不可用 (${res.status}),请稍后重试`);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
return await res.json();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error(err?.name === 'AbortError' || err?.name === 'TimeoutError'
|
|
76
|
+
? '连接超时,请检查网络后重试' : '网络异常,请稍后重试');
|
|
77
|
+
process.exit(1);
|
|
78
|
+
} finally {
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function fmtWan(v, usd) {
|
|
84
|
+
if (typeof v !== 'number') return '-';
|
|
85
|
+
const cur = usd ? '$' : '¥';
|
|
86
|
+
return `${cur}${v >= 1 ? v.toFixed(2) + '万' : (v * 10000).toFixed(0)}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function money(v, usd) {
|
|
90
|
+
if (typeof v !== 'number') return '-';
|
|
91
|
+
return (usd ? '$' : '¥') + v;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function printTicker(c, usd) {
|
|
95
|
+
const lo = usd ? c.listing?.lo_usd : c.listing?.lo;
|
|
96
|
+
const hi = usd ? c.listing?.hi_usd : c.listing?.hi;
|
|
97
|
+
const cur = usd ? '$' : '¥';
|
|
98
|
+
console.log(` ${c.symbol} [${c.category || '-'}]`);
|
|
99
|
+
console.log(` 评分: ${c.score?.raw ?? '-'} (${c.score?.grade ?? '-'})`);
|
|
100
|
+
console.log(` 价格带: ${money(lo, usd) === '-' ? cur + '-' : money(lo, usd)} ~ ${money(hi, usd)} (在售 ${c.listing?.count ?? 0})`);
|
|
101
|
+
if (usd && c.msrp_usd_wan != null) console.log(` 发售价: $${c.msrp_usd_wan}万`);
|
|
102
|
+
console.log(` 租金参考: ${usd ? '$' + (c.rental?.usd_hr ?? '-') : '¥' + (c.rental?.cn_hr ?? '-')}/时`);
|
|
103
|
+
console.log('');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function printScore(d) {
|
|
107
|
+
const s = d.scorecard || {};
|
|
108
|
+
console.log(` ${d.symbol} 记分卡`);
|
|
109
|
+
console.log(` 总分: ${s.raw ?? '-'} 等级: ${s.grade ?? '-'}`);
|
|
110
|
+
const dims = s.dims || {};
|
|
111
|
+
const f = s.formula || {};
|
|
112
|
+
const w = f.weights || {};
|
|
113
|
+
console.log(` 回本维度: ${dims.payback ?? '-'} (权重 ${w.payback ?? 40})`);
|
|
114
|
+
console.log(` 涨价维度: ${dims.appreciation ?? '-'} (权重 ${w.appreciation ?? 30})`);
|
|
115
|
+
console.log(` 流通维度: ${dims.liquidity ?? '-'} (权重 ${w.liquidity ?? 30})`);
|
|
116
|
+
console.log(` 版本: ${f.version || '-'}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function market(subArgs) {
|
|
120
|
+
const sub = subArgs[0] || 'help';
|
|
121
|
+
const rest = subArgs.slice(1);
|
|
122
|
+
const asJson = rest.includes('--json');
|
|
123
|
+
const usd = rest.includes('--usd');
|
|
124
|
+
const args = rest.filter((a) => !a.startsWith('--'));
|
|
125
|
+
const q = (p) => (usd ? '?currency=USD&' : '?') + 'pretty=1';
|
|
126
|
+
|
|
127
|
+
if (sub === 'login') {
|
|
128
|
+
const i = rest.indexOf('--token');
|
|
129
|
+
const tok = i >= 0 ? rest[i + 1] : null;
|
|
130
|
+
if (!tok) {
|
|
131
|
+
console.error('用法: aixx market login --token <令牌>');
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
const f = configFile();
|
|
135
|
+
let conf = {};
|
|
136
|
+
try { if (existsSync(f)) conf = JSON.parse(readFileSync(f, 'utf-8')); } catch (e) { conf = {}; }
|
|
137
|
+
conf.marketToken = tok;
|
|
138
|
+
mkdirSync(join(homedir(), '.aixx'), { recursive: true });
|
|
139
|
+
writeFileSync(f, JSON.stringify(conf, null, 2));
|
|
140
|
+
console.log('✓ 令牌已保存');
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (sub === 'tickers') {
|
|
145
|
+
const d = await mFetch(`/api/v1/market/overview${usd ? '?currency=USD' : ''}`);
|
|
146
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
147
|
+
console.log(`AIXX 算力行情 更新: ${d.generated} 标的: ${d.count} 币种: ${d.currency}\n`);
|
|
148
|
+
for (const c of d.cards || []) printTicker(c, usd);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (sub === 'ticker') {
|
|
153
|
+
const sym = (args[0] || '').toUpperCase();
|
|
154
|
+
if (!sym) { console.error('用法: aixx market ticker <SYMBOL>'); process.exit(1); }
|
|
155
|
+
const d = await mFetch(`/api/v1/assets/${encodeURIComponent(sym)}${usd ? '?currency=USD' : ''}`);
|
|
156
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
157
|
+
console.log(`AIXX 算力行情 更新: ${d.generated}`);
|
|
158
|
+
printTicker(d.ticker, d.currency === 'USD');
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (sub === 'score') {
|
|
163
|
+
const sym = (args[0] || '').toUpperCase();
|
|
164
|
+
if (!sym) { console.error('用法: aixx market score <SYMBOL>'); process.exit(1); }
|
|
165
|
+
const d = await mFetch(`/api/v1/assets/${encodeURIComponent(sym)}/aci`);
|
|
166
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
167
|
+
printScore(d);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (sub === 'history') {
|
|
172
|
+
const sym = (args[0] || '').toUpperCase();
|
|
173
|
+
const days = parseInt(args[1] || '30', 10) || 30;
|
|
174
|
+
if (!sym) { console.error('用法: aixx market history <SYMBOL> [天数]'); process.exit(1); }
|
|
175
|
+
const d = await mFetch(`/api/v1/assets/${encodeURIComponent(sym)}/history?days=${days}`);
|
|
176
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
177
|
+
console.log(`AIXX 行情历史 ${d.symbol} 近 ${d.days} 天\n`);
|
|
178
|
+
for (const p of d.points || []) {
|
|
179
|
+
console.log(` ${p.as_of ?? p.generated} ${money(p.listing?.lo, false)} ~ ${money(p.listing?.hi, false)} 评分 ${p.score_raw ?? '-'}`);
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (sub === 'detail') {
|
|
185
|
+
const sym = (args[0] || '').toUpperCase();
|
|
186
|
+
if (!sym) { console.error('用法: aixx market detail <SYMBOL> [--usd]'); process.exit(1); }
|
|
187
|
+
const d = await mFetch(`/api/v1/market/bulk/${encodeURIComponent(sym)}${usd ? '?currency=USD' : ''}`);
|
|
188
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
189
|
+
console.log(`AIXX 行情详情 ${d.symbol} 更新: ${d.generated} 币种: ${d.currency}\n`);
|
|
190
|
+
printTicker(d.ticker, d.currency === 'USD');
|
|
191
|
+
const pts = d.history?.points || [];
|
|
192
|
+
console.log(` 近 ${d.history?.days ?? 0} 天走势${d.history?.truncated ? '(截断)' : ''}:`);
|
|
193
|
+
for (const p of pts.slice(-10)) {
|
|
194
|
+
console.log(` ${p.as_of ?? p.generated} 评分 ${p.score_raw ?? '-'}`);
|
|
195
|
+
}
|
|
196
|
+
const rr = d.rent_regions || [];
|
|
197
|
+
if (rr.length) {
|
|
198
|
+
console.log(`\n 地区租金参考 (USD/时):`);
|
|
199
|
+
console.log(' ' + rr.map((r) => `${r.region} $${r.usd_hr}`).join(' · '));
|
|
200
|
+
}
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (sub === 'consumer') {
|
|
205
|
+
const sym = (args[0] || '').toLowerCase();
|
|
206
|
+
if (!sym) { console.error('用法: aixx market consumer <型号,如 rtx5090>'); process.exit(1); }
|
|
207
|
+
const d = await mFetch(`/api/v1/market/consumer/${encodeURIComponent(sym)}`);
|
|
208
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
209
|
+
console.log(`AIXX 消费级行情 ${d.symbol} 更新: ${d.as_of || d.updated_at || '-'}\n`);
|
|
210
|
+
const retail = d.retail || {};
|
|
211
|
+
for (const [ch, v] of Object.entries(retail)) {
|
|
212
|
+
if (!v || typeof v !== 'object') continue;
|
|
213
|
+
console.log(` ${ch}: 中位 ${money(v.median, false)} 区间 ${money(v.min, false)} ~ ${money(v.max, false)} (${v.n || 0} 条)`);
|
|
214
|
+
}
|
|
215
|
+
const rr = d.rent_regions || [];
|
|
216
|
+
if (rr.length) {
|
|
217
|
+
console.log(`\n 地区租金: ${rr.map((r) => `${r.region || r[0]} ${r.usd_hr || r[1]}`).join(' · ')}`);
|
|
218
|
+
}
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
console.log('用法: aixx market <子命令>');
|
|
223
|
+
console.log(' login --token <T> 保存访问令牌');
|
|
224
|
+
console.log(' tickers [--usd] [--json] 全标的快照');
|
|
225
|
+
console.log(' ticker <SYMBOL> 单标的快照');
|
|
226
|
+
console.log(' score <SYMBOL> 标的记分卡');
|
|
227
|
+
console.log(' history <SYMBOL> [天数] 历史点位');
|
|
228
|
+
console.log(' detail <SYMBOL> [--usd] 大宗详情数据包');
|
|
229
|
+
console.log(' consumer <型号> 消费级详情数据包');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { market };
|
package/src/commands/models.js
CHANGED
|
@@ -10,7 +10,7 @@ import { loadApiKey, maskKey } from '../utils/env.js';
|
|
|
10
10
|
const FETCH_TIMEOUT = 15000;
|
|
11
11
|
|
|
12
12
|
const MODEL_DESC = {
|
|
13
|
-
'deepseek-chat': '
|
|
13
|
+
'deepseek-chat': '低价档',
|
|
14
14
|
'deepseek-v4-pro': 'DeepSeek 旗舰,推理强',
|
|
15
15
|
'deepseek-ai/DeepSeek-V3': 'DeepSeek V3',
|
|
16
16
|
'glm-4-flash': '智谱免费,速度快',
|
|
@@ -112,7 +112,7 @@ export async function models(subArgs) {
|
|
|
112
112
|
|
|
113
113
|
console.log(`\n📊 共 ${modelIds.length} 个模型\n`);
|
|
114
114
|
console.log('💡 选模型小抄:');
|
|
115
|
-
console.log(' - 日常聊天/写文案 →
|
|
115
|
+
console.log(' - 日常聊天/写文案 → glm-4-flash(免费)或 glm-4-air(便宜)');
|
|
116
116
|
console.log(' - 中文写作 → glm-4-plus 或 claude-fable-5');
|
|
117
117
|
console.log(' - 读超长文档 → moonshot-v1-128k');
|
|
118
118
|
console.log(' - 复杂推理/代码 → claude-opus-5 或 gpt-5.6-sol');
|
package/src/commands/recharge.js
CHANGED
|
@@ -125,7 +125,7 @@ export async function recharge(subArgs) {
|
|
|
125
125
|
console.log(`充值后额度即时到账,可直接使用。\n`);
|
|
126
126
|
|
|
127
127
|
console.log('💡 充值提示:');
|
|
128
|
-
console.log(' - 充 $5 用
|
|
128
|
+
console.log(' - 充 $5 用 glm-4-air 能聊 5 万次以上');
|
|
129
129
|
console.log(' - 充 $20 够用 Claude/GPT 跑一个月');
|
|
130
130
|
console.log(' - 推荐码注册的用户充值后推荐人有分润\n');
|
|
131
131
|
}
|
package/src/commands/servers.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AIXX CLI - servers 命令(1022
|
|
3
|
-
*
|
|
4
|
-
* 萬安云服务器货架:开通/查看你的资源。
|
|
5
|
-
* aixx servers list 我已开通的资源
|
|
6
|
-
* aixx servers open <sku> [名字] 开通一件(kv/d1/r2/queues/pages/ai/turnstile...)
|
|
7
|
-
* aixx servers menu 看全部可开通的商品
|
|
8
|
-
*
|
|
9
|
-
* 令牌:环境变量 AIXX_ACI_TOKEN → ~/.aixx/config.json 的 aciBetaToken。
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { existsSync, readFileSync } from 'fs';
|
|
13
|
-
import { homedir } from 'os';
|
|
14
|
-
import { join } from 'path';
|
|
15
|
-
|
|
16
|
-
const BASE = process.env.AIXX_ACI_BASE_URL || 'https://aixx.ai';
|
|
17
|
-
const TIMEOUT = 15000;
|
|
18
|
-
|
|
19
|
-
const MENU = [
|
|
20
|
-
['kv', 'KV 键值存储', '全球读配置库'],
|
|
21
|
-
['d1', 'D1 边缘数据库', 'SQL 数据库'],
|
|
22
|
-
['r2', 'R2 对象存储', '文件桶·出口免费'],
|
|
23
|
-
['queues', '消息队列', '任务排队'],
|
|
24
|
-
['pages', 'Pages 建站', '免费·送全球网址'],
|
|
25
|
-
['ai', 'AI 模型推理', '73个模型即开即用'],
|
|
26
|
-
['turnstile', '人机验证', '免费·无感验证码'],
|
|
27
|
-
['workers', '边缘函数', '候deploy
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
function loadToken() {
|
|
31
|
-
if (process.env.AIXX_ACI_TOKEN) return process.env.AIXX_ACI_TOKEN;
|
|
32
|
-
try {
|
|
33
|
-
const f = join(homedir(), '.aixx', 'config.json');
|
|
34
|
-
if (existsSync(f)) {
|
|
35
|
-
const conf = JSON.parse(readFileSync(f, 'utf-8'));
|
|
36
|
-
if (conf.aciBetaToken) return conf.aciBetaToken;
|
|
37
|
-
}
|
|
38
|
-
} catch (e) { /* fallthrough */ }
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async function api(path, body) {
|
|
43
|
-
const token = loadToken();
|
|
44
|
-
if (!token) {
|
|
45
|
-
console.error('❌
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
const ctrl = new AbortController();
|
|
49
|
-
const timer = setTimeout(() => ctrl.abort(), TIMEOUT);
|
|
50
|
-
try {
|
|
51
|
-
const res = await fetch(`${BASE}${path}`, {
|
|
52
|
-
method: body ? 'POST' : 'GET',
|
|
53
|
-
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
54
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
55
|
-
signal: ctrl.signal,
|
|
56
|
-
});
|
|
57
|
-
if (res.status === 404) {
|
|
58
|
-
console.error('该能力暂不可用');
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
const d = await res.json();
|
|
62
|
-
if (!res.ok || d.ok === false) {
|
|
63
|
-
console.error('操作失败:', d.error || `HTTP ${res.status}`);
|
|
64
|
-
process.exit(1);
|
|
65
|
-
}
|
|
66
|
-
return d;
|
|
67
|
-
} catch (err) {
|
|
68
|
-
console.error(err?.name === 'AbortError' ? '连接超时' : `失败: ${err?.message || err}`);
|
|
69
|
-
process.exit(1);
|
|
70
|
-
} finally {
|
|
71
|
-
clearTimeout(timer);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function printResource(r) {
|
|
76
|
-
for (const [k, v] of Object.entries(r || {})) {
|
|
77
|
-
console.log(` ${k}: ${typeof v === 'object' ? JSON.stringify(v) : v}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export async function servers(subArgs) {
|
|
82
|
-
const sub = subArgs[0] || 'menu';
|
|
83
|
-
|
|
84
|
-
if (sub === 'list') {
|
|
85
|
-
const d = await api('/v1/servers/list');
|
|
86
|
-
console.log(`你的资源(${d.count} 条流水):`);
|
|
87
|
-
for (const it of d.items || []) {
|
|
88
|
-
console.log(` [${it.ts}] ${it.sku} (${it.status}) ${it.name || ''}`);
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (sub === 'open' || sub === 'provision') {
|
|
94
|
-
const sku = subArgs[1];
|
|
95
|
-
const name = subArgs[2] || 'myapp';
|
|
96
|
-
if (!sku) {
|
|
97
|
-
console.error('用法: aixx servers open <sku> [名字] 例: aixx servers open d1 mydb');
|
|
98
|
-
console.error('可开通: ' + MENU.filter(m => !m[2].includes('候')).map(m => m[0]).join('/'));
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
|
-
console.log(`正在开通 ${sku}(萬安全托管,无需注册任何第三方)...`);
|
|
102
|
-
const d = await api('/v1/servers/provision', { sku, name });
|
|
103
|
-
if (d.status === 'pending') {
|
|
104
|
-
console.log(`⏳
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
console.log(`✅ 开通成功!你的 ${sku}:`);
|
|
108
|
-
printResource(d.resource);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (sub === 'menu') {
|
|
113
|
-
console.log('萬安云服务器货架(全部代开通·按量计费·无需注册第三方):');
|
|
114
|
-
for (const [sku, title, desc] of MENU) {
|
|
115
|
-
console.log(` ${sku.padEnd(10)} ${title.padEnd(14)} ${desc}`);
|
|
116
|
-
}
|
|
117
|
-
console.log('\n开通: aixx servers open <sku> [名字]');
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
console.log('用法: aixx servers <list|open|menu>');
|
|
122
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* AIXX CLI - servers 命令(1022 版)
|
|
3
|
+
*
|
|
4
|
+
* 萬安云服务器货架:开通/查看你的资源。
|
|
5
|
+
* aixx servers list 我已开通的资源
|
|
6
|
+
* aixx servers open <sku> [名字] 开通一件(kv/d1/r2/queues/pages/ai/turnstile...)
|
|
7
|
+
* aixx servers menu 看全部可开通的商品
|
|
8
|
+
*
|
|
9
|
+
* 令牌:环境变量 AIXX_ACI_TOKEN → ~/.aixx/config.json 的 aciBetaToken。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { existsSync, readFileSync } from 'fs';
|
|
13
|
+
import { homedir } from 'os';
|
|
14
|
+
import { join } from 'path';
|
|
15
|
+
|
|
16
|
+
const BASE = process.env.AIXX_ACI_BASE_URL || 'https://aixx.ai';
|
|
17
|
+
const TIMEOUT = 15000;
|
|
18
|
+
|
|
19
|
+
const MENU = [
|
|
20
|
+
['kv', 'KV 键值存储', '全球读配置库'],
|
|
21
|
+
['d1', 'D1 边缘数据库', 'SQL 数据库'],
|
|
22
|
+
['r2', 'R2 对象存储', '文件桶·出口免费'],
|
|
23
|
+
['queues', '消息队列', '任务排队'],
|
|
24
|
+
['pages', 'Pages 建站', '免费·送全球网址'],
|
|
25
|
+
['ai', 'AI 模型推理', '73个模型即开即用'],
|
|
26
|
+
['turnstile', '人机验证', '免费·无感验证码'],
|
|
27
|
+
['workers', '边缘函数', '候deploy命令排期'],
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
function loadToken() {
|
|
31
|
+
if (process.env.AIXX_ACI_TOKEN) return process.env.AIXX_ACI_TOKEN;
|
|
32
|
+
try {
|
|
33
|
+
const f = join(homedir(), '.aixx', 'config.json');
|
|
34
|
+
if (existsSync(f)) {
|
|
35
|
+
const conf = JSON.parse(readFileSync(f, 'utf-8'));
|
|
36
|
+
if (conf.aciBetaToken) return conf.aciBetaToken;
|
|
37
|
+
}
|
|
38
|
+
} catch (e) { /* fallthrough */ }
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function api(path, body) {
|
|
43
|
+
const token = loadToken();
|
|
44
|
+
if (!token) {
|
|
45
|
+
console.error('❌ 未配置访问令牌:请设置环境变量 AIXX_ACI_TOKEN');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const ctrl = new AbortController();
|
|
49
|
+
const timer = setTimeout(() => ctrl.abort(), TIMEOUT);
|
|
50
|
+
try {
|
|
51
|
+
const res = await fetch(`${BASE}${path}`, {
|
|
52
|
+
method: body ? 'POST' : 'GET',
|
|
53
|
+
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
54
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
55
|
+
signal: ctrl.signal,
|
|
56
|
+
});
|
|
57
|
+
if (res.status === 404) {
|
|
58
|
+
console.error('该能力暂不可用');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
const d = await res.json();
|
|
62
|
+
if (!res.ok || d.ok === false) {
|
|
63
|
+
console.error('操作失败:', d.error || `HTTP ${res.status}`);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
return d;
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error(err?.name === 'AbortError' ? '连接超时' : `失败: ${err?.message || err}`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
} finally {
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function printResource(r) {
|
|
76
|
+
for (const [k, v] of Object.entries(r || {})) {
|
|
77
|
+
console.log(` ${k}: ${typeof v === 'object' ? JSON.stringify(v) : v}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function servers(subArgs) {
|
|
82
|
+
const sub = subArgs[0] || 'menu';
|
|
83
|
+
|
|
84
|
+
if (sub === 'list') {
|
|
85
|
+
const d = await api('/v1/servers/list');
|
|
86
|
+
console.log(`你的资源(${d.count} 条流水):`);
|
|
87
|
+
for (const it of d.items || []) {
|
|
88
|
+
console.log(` [${it.ts}] ${it.sku} (${it.status}) ${it.name || ''}`);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (sub === 'open' || sub === 'provision') {
|
|
94
|
+
const sku = subArgs[1];
|
|
95
|
+
const name = subArgs[2] || 'myapp';
|
|
96
|
+
if (!sku) {
|
|
97
|
+
console.error('用法: aixx servers open <sku> [名字] 例: aixx servers open d1 mydb');
|
|
98
|
+
console.error('可开通: ' + MENU.filter(m => !m[2].includes('候')).map(m => m[0]).join('/'));
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
console.log(`正在开通 ${sku}(萬安全托管,无需注册任何第三方)...`);
|
|
102
|
+
const d = await api('/v1/servers/provision', { sku, name });
|
|
103
|
+
if (d.status === 'pending') {
|
|
104
|
+
console.log(`⏳ 该商品为人工开通,已登记(${d.note || ''})`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
console.log(`✅ 开通成功!你的 ${sku}:`);
|
|
108
|
+
printResource(d.resource);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (sub === 'menu') {
|
|
113
|
+
console.log('萬安云服务器货架(全部代开通·按量计费·无需注册第三方):');
|
|
114
|
+
for (const [sku, title, desc] of MENU) {
|
|
115
|
+
console.log(` ${sku.padEnd(10)} ${title.padEnd(14)} ${desc}`);
|
|
116
|
+
}
|
|
117
|
+
console.log('\n开通: aixx servers open <sku> [名字]');
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
console.log('用法: aixx servers <list|open|menu>');
|
|
122
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIXX CLI - status 命令(1120 K哥令:身份编号必须给到用户的agent)
|
|
3
|
+
*
|
|
4
|
+
* 一条命令打出自家全貌:
|
|
5
|
+
* aixx status
|
|
6
|
+
* - 安装身份(萬安云编号 + sk key掩码)
|
|
7
|
+
* - 模型余额(cloudpay/balance 官方端点)
|
|
8
|
+
* - 行情数据 API 额度(X-Quota 或 /api/v1/account/usage)
|
|
9
|
+
*
|
|
10
|
+
* 设计给两种读者:人(终端输出)和 agent(同一输出可直接转述)。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { existsSync, readFileSync } from 'fs';
|
|
14
|
+
import { homedir } from 'os';
|
|
15
|
+
import { join } from 'path';
|
|
16
|
+
|
|
17
|
+
const DEFAULT_BASE_URL = 'https://baodan.run/v1';
|
|
18
|
+
const CLOUD_BASE = 'https://console.aixx.ai';
|
|
19
|
+
const DATA_BASE = 'https://www.aixx.vip';
|
|
20
|
+
const FETCH_TIMEOUT = 12000;
|
|
21
|
+
|
|
22
|
+
function loadApiKey() {
|
|
23
|
+
if (process.env.AIXX_API_KEY) return process.env.AIXX_API_KEY;
|
|
24
|
+
try {
|
|
25
|
+
const cfg = JSON.parse(readFileSync(join(homedir(), '.aixx', 'config.json'), 'utf8'));
|
|
26
|
+
if (cfg.AIXX_API_KEY) return cfg.AIXX_API_KEY;
|
|
27
|
+
} catch {}
|
|
28
|
+
try {
|
|
29
|
+
const acc = JSON.parse(readFileSync(join(homedir(), '.aixx', 'account.json'), 'utf8'));
|
|
30
|
+
if (acc.apiKey) return acc.apiKey;
|
|
31
|
+
} catch {}
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function loadIdentity() {
|
|
36
|
+
// 优先 account.json(正式账号),其次 config.json 的裸注册身份(1010方案)
|
|
37
|
+
try {
|
|
38
|
+
const acc = JSON.parse(readFileSync(join(homedir(), '.aixx', 'account.json'), 'utf8'));
|
|
39
|
+
if (acc.username) return { id: acc.username, kind: 'account' };
|
|
40
|
+
} catch {}
|
|
41
|
+
try {
|
|
42
|
+
const cfg = JSON.parse(readFileSync(join(homedir(), '.aixx', 'config.json'), 'utf8'));
|
|
43
|
+
if (cfg.AIXX_USER_ID) return { id: cfg.AIXX_USER_ID, kind: 'naked' };
|
|
44
|
+
} catch {}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function maskKey(k) {
|
|
49
|
+
if (!k) return '(未找到)';
|
|
50
|
+
return k.slice(0, 8) + '…' + k.slice(-4);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function fetchJson(url, headers) {
|
|
54
|
+
const ctrl = new AbortController();
|
|
55
|
+
const t = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT);
|
|
56
|
+
try {
|
|
57
|
+
const r = await fetch(url, { headers: headers || {}, signal: ctrl.signal });
|
|
58
|
+
return await r.json();
|
|
59
|
+
} finally { clearTimeout(t); }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function status() {
|
|
63
|
+
console.log('╔══════════════════════════════════════════╗');
|
|
64
|
+
console.log('║ AIXX 账户全景(aixx status) ║');
|
|
65
|
+
console.log('╚══════════════════════════════════════════╝\n');
|
|
66
|
+
|
|
67
|
+
// 1. 身份
|
|
68
|
+
const id = loadIdentity();
|
|
69
|
+
const apiKey = loadApiKey();
|
|
70
|
+
console.log('── 安装身份 ──');
|
|
71
|
+
if (id) {
|
|
72
|
+
console.log(`🪪 萬安云身份编号:${id.id}${id.kind === 'naked' ? '(裸注册身份)' : ''}`);
|
|
73
|
+
console.log(' 可在个人中心「账号设置 → 绑定安装身份」并入你的账户');
|
|
74
|
+
} else {
|
|
75
|
+
console.log('🪪 未找到本地身份(尚未安装?运行 npx aixxai install)');
|
|
76
|
+
}
|
|
77
|
+
console.log(`🔑 API Key:${maskKey(apiKey)}\n`);
|
|
78
|
+
|
|
79
|
+
// 2. 模型余额(cloudpay/balance 官方端点)
|
|
80
|
+
console.log('── 模型 API 余额 ──');
|
|
81
|
+
if (apiKey) {
|
|
82
|
+
try {
|
|
83
|
+
const b = await fetchJson(`${CLOUD_BASE}/cloudpay/balance?api_key=${encodeURIComponent(apiKey)}`);
|
|
84
|
+
if (b && b.ok) {
|
|
85
|
+
console.log(`💰 余额:$${Number(b.balance_usd).toFixed(2)}(账户 ${b.username})`);
|
|
86
|
+
} else {
|
|
87
|
+
console.log('⚠️ 查询失败:' + ((b && (b.detail || b.message)) || '未知错误'));
|
|
88
|
+
}
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.log('⚠️ 网络异常:' + e.message);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
console.log('(无 key,跳过)');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 3. 行情数据 API 额度(usage 端点,sk key 桥接可查)
|
|
97
|
+
console.log('\n── GPU 行情数据 API ──');
|
|
98
|
+
if (apiKey) {
|
|
99
|
+
try {
|
|
100
|
+
const u = await fetchJson(`${DATA_BASE}/api/v1/account/usage`,
|
|
101
|
+
{ Authorization: `Bearer ${apiKey}` });
|
|
102
|
+
if (u && u.ok) {
|
|
103
|
+
const left = u.free_quota - u.free_used;
|
|
104
|
+
console.log(`📊 档位:${u.tier === 'sub' ? '订阅中' : '免费档'}${u.sub_expires_at ? `(至 ${String(u.sub_expires_at).slice(0, 10)})` : ''}`);
|
|
105
|
+
console.log(`📊 免费额度:剩 ${left} / ${u.free_quota} 次(今日已用 ${u.today_counted})`);
|
|
106
|
+
} else {
|
|
107
|
+
console.log('⚠️ ' + ((u && (u.error || u.message)) || '查询失败'));
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.log('⚠️ 网络异常:' + e.message);
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
console.log('(无 key,跳过)');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.log('\n── 入口 ──');
|
|
117
|
+
console.log('👤 个人中心:https://console.aixx.ai/console-app.html');
|
|
118
|
+
console.log('📈 行情数据:https://aixx.ai/data-api.html');
|
|
119
|
+
console.log('\n(对 AI 说「跑一下 aixx status」即可随时查看本全景)');
|
|
120
|
+
}
|
package/src/commands/test.js
CHANGED