aixxai 1.7.10 → 1.7.13
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/bin/aixx.js +14 -0
- package/package.json +4 -1
- package/src/commands/market.js +25 -5
- package/src/commands/rotate.js +66 -0
package/bin/aixx.js
CHANGED
|
@@ -34,6 +34,7 @@ import { servers } from '../src/commands/servers.js';
|
|
|
34
34
|
import { status } from '../src/commands/status.js';
|
|
35
35
|
import { subscribe } from '../src/commands/subscribe.js';
|
|
36
36
|
import { envCmd } from '../src/commands/env.js';
|
|
37
|
+
import { rotate } from '../src/commands/rotate.js';
|
|
37
38
|
import { showHelp, showVersion } from '../src/commands/help.js';
|
|
38
39
|
|
|
39
40
|
// 版本号从 package.json 读(单一来源,别再硬编码)
|
|
@@ -44,6 +45,18 @@ const VERSION = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), '
|
|
|
44
45
|
// 改完后请全局搜索 "安全警告" 同步更新 env.js 与 templates/QUICKSTART.md 中的同名地址。
|
|
45
46
|
export const DEFAULT_BASE_URL = 'https://console.aixx.ai/v1';
|
|
46
47
|
|
|
48
|
+
// 1123质检靶单②修: 企业代理环境支持——Node原生fetch不认HTTP(S)_PROXY(公司内网agent用户全挂实锤)。
|
|
49
|
+
// undici ProxyAgent显式接管: 读 HTTPS_PROXY/HTTP_PROXY/ALL_PROXY(小写优先)·无代理零影响。
|
|
50
|
+
try {
|
|
51
|
+
const _px = process.env.HTTPS_PROXY || process.env.https_proxy
|
|
52
|
+
|| process.env.HTTP_PROXY || process.env.http_proxy
|
|
53
|
+
|| process.env.ALL_PROXY || process.env.all_proxy || '';
|
|
54
|
+
if (_px) {
|
|
55
|
+
const { ProxyAgent, setGlobalDispatcher } = await import('undici');
|
|
56
|
+
setGlobalDispatcher(new ProxyAgent(_px));
|
|
57
|
+
}
|
|
58
|
+
} catch { /* 代理设置失败不阻塞CLI·按直连行为走 */ }
|
|
59
|
+
|
|
47
60
|
// 命令表:所有子命令的单一来源(新增命令在这里加一行即可)。
|
|
48
61
|
// 未知命令的"你想用的是不是"近似匹配也从这张表取已知命令名,不另写一份。
|
|
49
62
|
const COMMANDS = [
|
|
@@ -61,6 +74,7 @@ const COMMANDS = [
|
|
|
61
74
|
{ name: 'status', aliases: ['st'], run: status },
|
|
62
75
|
{ name: 'subscribe', aliases: ['sub'], run: subscribe }, /* 1121 K哥令: 一步收银台·对话直达 */
|
|
63
76
|
{ name: 'env', run: envCmd }, /* 1122 K哥令: agent直连闭环·环境变量即用行 */
|
|
77
|
+
{ name: 'rotate', run: rotate }, /* 1123质检靶单③: key泄露一键轮换(额度订阅档继承) */
|
|
64
78
|
];
|
|
65
79
|
|
|
66
80
|
// help/version 不吃子参数(走 flag/无参分支),但命令名仍参与下面的近似匹配
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aixxai",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.13",
|
|
4
4
|
"description": "AIXX CLI - 让你的AI调用万物。One command, every AI model. By AIXX (Wanan Exchange), the verification-first compute exchange. 安装:npx aixxai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -34,5 +34,8 @@
|
|
|
34
34
|
"license": "ISC",
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"undici": "^6.21.0"
|
|
37
40
|
}
|
|
38
41
|
}
|
package/src/commands/market.js
CHANGED
|
@@ -98,8 +98,20 @@ async function mFetch(path) {
|
|
|
98
98
|
process.exit(1);
|
|
99
99
|
}
|
|
100
100
|
if (res.status === 401) {
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
// 1123质检靶单②修: 401先探活再归因——网络层失败(代理/墙/劫持)可能被中间层翻译成401,
|
|
102
|
+
// 误导用户去重新登录绕死圈。无鉴权探活端点200=网络真通=才可能是token问题。
|
|
103
|
+
let netOk = false;
|
|
104
|
+
try {
|
|
105
|
+
const pv = await fetch('https://www.aixx.vip/api/v1/docs.json', { signal: AbortSignal.timeout(8000) });
|
|
106
|
+
netOk = pv.ok;
|
|
107
|
+
} catch {}
|
|
108
|
+
if (!netOk) {
|
|
109
|
+
console.error('网络不可达(无法连接 www.aixx.vip)——若在公司内网/代理环境,请配置 HTTPS_PROXY 环境变量后重试;本次失败与令牌无关。');
|
|
110
|
+
} else {
|
|
111
|
+
console.error('令牌无效或已过期,请重新登录: aixx market login --token <T>');
|
|
112
|
+
}
|
|
113
|
+
process.exitCode = 1; // 1123修: exit()在pending句柄上致UV_HANDLE_CLOSING崩溃——exitCode自然排空
|
|
114
|
+
return null;
|
|
103
115
|
}
|
|
104
116
|
if (!res.ok) {
|
|
105
117
|
console.error(`服务暂不可用 (${res.status}),请稍后重试`);
|
|
@@ -107,9 +119,14 @@ async function mFetch(path) {
|
|
|
107
119
|
}
|
|
108
120
|
return await res.json();
|
|
109
121
|
} catch (err) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
// 1123质检靶单②: 网络失败禁归因令牌——代理环境感知文案(公司内网用户首查项)
|
|
123
|
+
const hasPx = !!(process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy);
|
|
124
|
+
const tip = err?.name === 'AbortError' || err?.name === 'TimeoutError'
|
|
125
|
+
? '连接超时,请检查网络后重试' : '网络异常(无法连接数据服务)';
|
|
126
|
+
console.error(tip + (hasPx ? '——检测到代理环境(HTTP_PROXY/HTTPS_PROXY),请确认代理可用或取消该变量后重试' : '——若在公司内网,请配置 HTTPS_PROXY 环境变量'));
|
|
127
|
+
console.error('本次失败与令牌无关,无需重新登录。');
|
|
128
|
+
process.exitCode = 1;
|
|
129
|
+
return null;
|
|
113
130
|
} finally {
|
|
114
131
|
clearTimeout(timer);
|
|
115
132
|
}
|
|
@@ -168,6 +185,7 @@ async function market(subArgs) {
|
|
|
168
185
|
|
|
169
186
|
if (sub === 'tickers') {
|
|
170
187
|
const d = await mFetch('/api/v1/market/bulk');
|
|
188
|
+
if (!d) return; // mFetch已报错并置exitCode——不再打印空表
|
|
171
189
|
const items = d?.data?.items || [];
|
|
172
190
|
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
173
191
|
console.log(`AIXX 大宗算力行情 更新: ${d?.data?.generated_at || '-'} 标的: ${items.length}\n`);
|
|
@@ -179,6 +197,7 @@ async function market(subArgs) {
|
|
|
179
197
|
const sym = (args[0] || '').trim();
|
|
180
198
|
if (!sym) { console.error(`用法: aixx market ${sub} <标的,如 b300>`); process.exit(1); }
|
|
181
199
|
const d = await mFetch('/api/v1/market/bulk');
|
|
200
|
+
if (!d) return; // mFetch已报错并置exitCode——不再打印空表
|
|
182
201
|
const items = filterItems(d?.data?.items || [], sym);
|
|
183
202
|
if (asJson) { console.log(JSON.stringify(sub === 'detail' ? items : items[0] || {}, null, 2)); return; }
|
|
184
203
|
if (items.length === 0) {
|
|
@@ -205,6 +224,7 @@ async function market(subArgs) {
|
|
|
205
224
|
const sym = (args[0] || '').toLowerCase();
|
|
206
225
|
if (!sym) { console.error('用法: aixx market consumer <型号,如 4090>'); process.exit(1); }
|
|
207
226
|
const d = await mFetch(`/api/v1/market/consumer?symbol=${encodeURIComponent(sym)}`);
|
|
227
|
+
if (!d) return; // mFetch已报错并置exitCode——不再打印空表
|
|
208
228
|
const syms = d?.data?.symbols || [];
|
|
209
229
|
if (asJson) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
210
230
|
if (syms.length === 0) {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIXX CLI - rotate 命令(1123质检靶单③:key泄露自助轮换)
|
|
3
|
+
*
|
|
4
|
+
* aixx rotate —— 本机key泄露应急:一键换新key(旧key立即作废)。
|
|
5
|
+
* 语义分流:
|
|
6
|
+
* - 本机是数据key(wan_dat_) → 直打 /cloudpay/datapi/keys/rotate 自轮换(Bearer旧key)→ 新key回写config
|
|
7
|
+
* - 本机是装机key(sk-) → 提示重跑 install 拿新身份(New-API token体系·旧key可登console吊销)
|
|
8
|
+
* 轮换规则(服务器铁律):剩余额度/订阅档继承——换串不改账。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
12
|
+
import { homedir } from 'os';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import { loadApiKey } from '../utils/env.js';
|
|
15
|
+
|
|
16
|
+
const ROTATE_URL = 'https://console.aixx.ai/cloudpay/datapi/keys/rotate';
|
|
17
|
+
|
|
18
|
+
export async function rotate() {
|
|
19
|
+
const key = loadApiKey();
|
|
20
|
+
if (!key) {
|
|
21
|
+
console.error('❌ 本机未找到key——先运行 npx aixxai install');
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
}
|
|
24
|
+
if (!key.startsWith('wan_dat_')) {
|
|
25
|
+
console.log('ℹ️ 本机是装机身份key(sk-开头·New-API token体系)——轮换方式:');
|
|
26
|
+
console.log(' 1. 重新运行 npx aixxai install(获得全新身份+新key)');
|
|
27
|
+
console.log(' 2. 旧身份登录 console.aixx.ai 个人中心可吊销旧key');
|
|
28
|
+
console.log(' (console创建的数据key wan_dat_ 才支持本命令原地轮换)');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
console.log('🔄 正在轮换数据key(旧key立即作废·额度与订阅档原样继承)...');
|
|
32
|
+
try {
|
|
33
|
+
const r = await fetch(ROTATE_URL, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json' },
|
|
36
|
+
body: JSON.stringify({ token: '', key_id: 0 }),
|
|
37
|
+
signal: AbortSignal.timeout(20000),
|
|
38
|
+
});
|
|
39
|
+
const j = await r.json().catch(() => ({}));
|
|
40
|
+
if (r.ok && j.ok && j.key) {
|
|
41
|
+
// 新key回写config(merge写·保身份字段)
|
|
42
|
+
const cfgPath = join(homedir(), '.aixx', 'config.json');
|
|
43
|
+
let cfg = {};
|
|
44
|
+
try { cfg = JSON.parse(readFileSync(cfgPath, 'utf8')) || {}; } catch {}
|
|
45
|
+
const hadEnv = !!process.env.AIXX_API_KEY;
|
|
46
|
+
cfg.AIXX_API_KEY = j.key;
|
|
47
|
+
try { writeFileSync(cfgPath, JSON.stringify(cfg, null, 2)); } catch {}
|
|
48
|
+
console.log('✅ 轮换完成');
|
|
49
|
+
console.log(`🔑 新key: ${j.key}`);
|
|
50
|
+
console.log(`📊 剩余免费额度: ${j.free_quota} 次 · 档位: ${j.tier}`);
|
|
51
|
+
console.log(' (新key只显示这一次·已写回本机config)');
|
|
52
|
+
if (hadEnv) {
|
|
53
|
+
console.log('⚠️ 检测到环境变量 AIXX_API_KEY 也在供key——请同步更新(或 unset 后用config):');
|
|
54
|
+
console.log(` export AIXX_API_KEY="${j.key}"`);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
console.error(`❌ 轮换失败: ${(j && (j.detail && j.detail[0] && j.detail[0].msg) || j.message) || 'HTTP ' + r.status}`);
|
|
58
|
+
process.exitCode = 1; // 1123: exit()撞pending句柄=UV_HANDLE_CLOSING崩溃·exitCode自然排空
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
const hasPx = !!(process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy);
|
|
62
|
+
console.error('❌ 网络异常: ' + (err?.message || err) + (hasPx ? '(检测到代理环境·请确认代理可用)' : ''));
|
|
63
|
+
console.error(' 本次失败与令牌无关,稍后重试 aixx rotate。');
|
|
64
|
+
process.exitCode = 1;
|
|
65
|
+
}
|
|
66
|
+
}
|