aixxai 1.6.7 → 1.6.8
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/bin/aixx.js +137 -137
- package/package.json +38 -33
- package/src/commands/aci.js +11 -145
- package/src/commands/balance.js +168 -168
- package/src/commands/help.js +45 -45
- package/src/commands/install.js +3 -3
- package/src/commands/market.js +230 -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/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,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIXX CLI - market 命令(1030 产品版)
|
|
3
|
+
*
|
|
4
|
+
* 算力行情数据订阅($998/月):
|
|
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
|
+
*
|
|
16
|
+
* 令牌来源:环境变量 AIXX_MARKET_TOKEN → ~/.aixx/config.json 的 marketToken(兼容读 aciBetaToken)。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
20
|
+
import { homedir } from 'os';
|
|
21
|
+
import { join } from 'path';
|
|
22
|
+
|
|
23
|
+
const BASE = process.env.AIXX_MARKET_BASE_URL || 'https://aixx.ai';
|
|
24
|
+
const FETCH_TIMEOUT = 15000;
|
|
25
|
+
|
|
26
|
+
function configFile() {
|
|
27
|
+
return join(homedir(), '.aixx', 'config.json');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function loadToken() {
|
|
31
|
+
if (process.env.AIXX_MARKET_TOKEN) return process.env.AIXX_MARKET_TOKEN;
|
|
32
|
+
try {
|
|
33
|
+
const f = configFile();
|
|
34
|
+
if (existsSync(f)) {
|
|
35
|
+
const conf = JSON.parse(readFileSync(f, 'utf-8'));
|
|
36
|
+
return conf.marketToken || null;
|
|
37
|
+
}
|
|
38
|
+
} catch (e) { /* 走未配置路径 */ }
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function mFetch(path) {
|
|
43
|
+
const token = loadToken();
|
|
44
|
+
if (!token) {
|
|
45
|
+
console.error('尚未配置访问令牌。');
|
|
46
|
+
console.error('开通: https://www.aixx.vip | 或设置环境变量 AIXX_MARKET_TOKEN');
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
const ctrl = new AbortController();
|
|
50
|
+
const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT);
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetch(`${BASE}${path}`, {
|
|
53
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
54
|
+
signal: ctrl.signal,
|
|
55
|
+
});
|
|
56
|
+
if (res.status === 403) {
|
|
57
|
+
console.error('当前订阅档位不包含该数据 —— 如需升级请访问 aixx.ai 或联系客服');
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
if (res.status === 404) {
|
|
61
|
+
console.error('未查询到该数据(请核对标的代码,或联系客服确认订阅状态)');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
if (res.status === 401 || res.status === 403) {
|
|
65
|
+
console.error('令牌无效或已过期,请重新登录: aixx market login --token <T>');
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
console.error(`服务暂不可用 (${res.status}),请稍后重试`);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
return await res.json();
|
|
73
|
+
} catch (err) {
|
|
74
|
+
console.error(err?.name === 'AbortError' || err?.name === 'TimeoutError'
|
|
75
|
+
? '连接超时,请检查网络后重试' : '网络异常,请稍后重试');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
} finally {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function fmtWan(v, usd) {
|
|
83
|
+
if (typeof v !== 'number') return '-';
|
|
84
|
+
const cur = usd ? '$' : '¥';
|
|
85
|
+
return `${cur}${v >= 1 ? v.toFixed(2) + '万' : (v * 10000).toFixed(0)}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function money(v, usd) {
|
|
89
|
+
if (typeof v !== 'number') return '-';
|
|
90
|
+
return (usd ? '$' : '¥') + v;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function printTicker(c, usd) {
|
|
94
|
+
const lo = usd ? c.listing?.lo_usd : c.listing?.lo;
|
|
95
|
+
const hi = usd ? c.listing?.hi_usd : c.listing?.hi;
|
|
96
|
+
const cur = usd ? '$' : '¥';
|
|
97
|
+
console.log(` ${c.symbol} [${c.category || '-'}]`);
|
|
98
|
+
console.log(` 评分: ${c.score?.raw ?? '-'} (${c.score?.grade ?? '-'})`);
|
|
99
|
+
console.log(` 价格带: ${money(lo, usd) === '-' ? cur + '-' : money(lo, usd)} ~ ${money(hi, usd)} (在售 ${c.listing?.count ?? 0})`);
|
|
100
|
+
if (usd && c.msrp_usd_wan != null) console.log(` 发售价: $${c.msrp_usd_wan}万`);
|
|
101
|
+
console.log(` 租金参考: ${usd ? '$' + (c.rental?.usd_hr ?? '-') : '¥' + (c.rental?.cn_hr ?? '-')}/时`);
|
|
102
|
+
console.log('');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function printScore(d) {
|
|
106
|
+
const s = d.scorecard || {};
|
|
107
|
+
console.log(` ${d.symbol} 记分卡`);
|
|
108
|
+
console.log(` 总分: ${s.raw ?? '-'} 等级: ${s.grade ?? '-'}`);
|
|
109
|
+
const dims = s.dims || {};
|
|
110
|
+
const w = d.weights || {};
|
|
111
|
+
console.log(` 回本维度: ${dims.payback ?? '-'} (权重 ${w.payback ?? 40})`);
|
|
112
|
+
console.log(` 涨价维度: ${dims.appreciation ?? '-'} (权重 ${w.appreciation ?? 30})`);
|
|
113
|
+
console.log(` 流通维度: ${dims.liquidity ?? '-'} (权重 ${w.liquidity ?? 30})`);
|
|
114
|
+
console.log(` 版本: ${d.formula || '-'}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function market(subArgs) {
|
|
118
|
+
const sub = subArgs[0] || 'help';
|
|
119
|
+
const rest = subArgs.slice(1);
|
|
120
|
+
const asJson = rest.includes('--json');
|
|
121
|
+
const usd = rest.includes('--usd');
|
|
122
|
+
const args = rest.filter((a) => !a.startsWith('--'));
|
|
123
|
+
const q = (p) => (usd ? '?currency=USD&' : '?') + 'pretty=1';
|
|
124
|
+
|
|
125
|
+
if (sub === 'login') {
|
|
126
|
+
const i = rest.indexOf('--token');
|
|
127
|
+
const tok = i >= 0 ? rest[i + 1] : null;
|
|
128
|
+
if (!tok) {
|
|
129
|
+
console.error('用法: aixx market login --token <令牌>');
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
const f = configFile();
|
|
133
|
+
let conf = {};
|
|
134
|
+
try { if (existsSync(f)) conf = JSON.parse(readFileSync(f, 'utf-8')); } catch (e) { conf = {}; }
|
|
135
|
+
conf.marketToken = tok;
|
|
136
|
+
mkdirSync(join(homedir(), '.aixx'), { recursive: true });
|
|
137
|
+
writeFileSync(f, JSON.stringify(conf, null, 2));
|
|
138
|
+
console.log('✓ 令牌已保存');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (sub === 'tickers') {
|
|
143
|
+
const d = await mFetch(`/v1/aci/tickers${usd ? '?currency=USD' : ''}`);
|
|
144
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
145
|
+
console.log(`AIXX 算力行情 更新: ${d.generated} 标的: ${d.count} 币种: ${d.currency}\n`);
|
|
146
|
+
for (const c of d.cards || []) printTicker(c, usd);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (sub === 'ticker') {
|
|
151
|
+
const sym = (args[0] || '').toUpperCase();
|
|
152
|
+
if (!sym) { console.error('用法: aixx market ticker <SYMBOL>'); process.exit(1); }
|
|
153
|
+
const d = await mFetch(`/v1/aci/ticker/${encodeURIComponent(sym)}${usd ? '?currency=USD' : ''}`);
|
|
154
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
155
|
+
console.log(`AIXX 算力行情 更新: ${d.generated}`);
|
|
156
|
+
printTicker(d.ticker, d.currency === 'USD');
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (sub === 'score') {
|
|
161
|
+
const sym = (args[0] || '').toUpperCase();
|
|
162
|
+
if (!sym) { console.error('用法: aixx market score <SYMBOL>'); process.exit(1); }
|
|
163
|
+
const d = await mFetch(`/v1/aci/scorecard/${encodeURIComponent(sym)}`);
|
|
164
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
165
|
+
printScore(d);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (sub === 'history') {
|
|
170
|
+
const sym = (args[0] || '').toUpperCase();
|
|
171
|
+
const days = parseInt(args[1] || '30', 10) || 30;
|
|
172
|
+
if (!sym) { console.error('用法: aixx market history <SYMBOL> [天数]'); process.exit(1); }
|
|
173
|
+
const d = await mFetch(`/v1/aci/history/${encodeURIComponent(sym)}?days=${days}`);
|
|
174
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
175
|
+
console.log(`AIXX 行情历史 ${d.symbol} 近 ${d.days} 天\n`);
|
|
176
|
+
for (const p of d.points || []) {
|
|
177
|
+
console.log(` ${p.generated} ${money(p.listing?.lo, false)} ~ ${money(p.listing?.hi, false)} 评分 ${p.score_raw ?? '-'}`);
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (sub === 'detail') {
|
|
183
|
+
const sym = (args[0] || '').toUpperCase();
|
|
184
|
+
if (!sym) { console.error('用法: aixx market detail <SYMBOL> [--usd]'); process.exit(1); }
|
|
185
|
+
const d = await mFetch(`/v1/market/detail/${encodeURIComponent(sym)}${usd ? '?currency=USD' : ''}`);
|
|
186
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
187
|
+
console.log(`AIXX 行情详情 ${d.symbol} 更新: ${d.generated} 币种: ${d.currency}\n`);
|
|
188
|
+
printTicker(d.ticker, d.currency === 'USD');
|
|
189
|
+
const pts = d.history?.points || [];
|
|
190
|
+
console.log(` 近 ${d.history?.days ?? 0} 天走势${d.history?.truncated ? '(截断)' : ''}:`);
|
|
191
|
+
for (const p of pts.slice(-10)) {
|
|
192
|
+
console.log(` ${p.generated} 评分 ${p.score_raw ?? '-'}`);
|
|
193
|
+
}
|
|
194
|
+
const rr = d.rent_regions || [];
|
|
195
|
+
if (rr.length) {
|
|
196
|
+
console.log(`\n 地区租金参考 (USD/时):`);
|
|
197
|
+
console.log(' ' + rr.map((r) => `${r.region} $${r.usd_hr}`).join(' · '));
|
|
198
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (sub === 'consumer') {
|
|
203
|
+
const sym = (args[0] || '').toLowerCase();
|
|
204
|
+
if (!sym) { console.error('用法: aixx market consumer <型号,如 rtx5090>'); process.exit(1); }
|
|
205
|
+
const d = await mFetch(`/v1/market/consumer/${encodeURIComponent(sym)}`);
|
|
206
|
+
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
207
|
+
console.log(`AIXX 消费级行情 ${d.symbol} 更新: ${d.updated_at || '-'}\n`);
|
|
208
|
+
const retail = d.retail || {};
|
|
209
|
+
for (const [ch, v] of Object.entries(retail)) {
|
|
210
|
+
if (!v || typeof v !== 'object') continue;
|
|
211
|
+
console.log(` ${ch}: 中位 ${money(v.median, false)} 区间 ${money(v.min, false)} ~ ${money(v.max, false)} (${v.n || 0} 条)`);
|
|
212
|
+
}
|
|
213
|
+
const rr = d.rent_regions || [];
|
|
214
|
+
if (rr.length) {
|
|
215
|
+
console.log(`\n 地区租金: ${rr.map((r) => `${r.region || r[0]} ${r.usd_hr || r[1]}`).join(' · ')}`);
|
|
216
|
+
}
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
console.log('用法: aixx market <子命令>');
|
|
221
|
+
console.log(' login --token <T> 保存访问令牌');
|
|
222
|
+
console.log(' tickers [--usd] [--json] 全标的快照');
|
|
223
|
+
console.log(' ticker <SYMBOL> 单标的快照');
|
|
224
|
+
console.log(' score <SYMBOL> 标的记分卡');
|
|
225
|
+
console.log(' history <SYMBOL> [天数] 历史点位');
|
|
226
|
+
console.log(' detail <SYMBOL> [--usd] 大宗详情数据包');
|
|
227
|
+
console.log(' consumer <型号> 消费级详情数据包');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
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
|
+
}
|
package/src/commands/test.js
CHANGED