aixxai 1.7.6 → 1.7.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/bin/aixx.js +5 -1
- package/package.json +1 -1
- package/src/commands/balance.js +24 -3
- package/src/commands/env.js +31 -0
- package/src/commands/install.js +96 -35
- package/src/commands/market.js +6 -0
- package/src/commands/models.js +120 -120
- package/src/commands/recharge.js +158 -131
- package/src/commands/subscribe.js +73 -0
- package/src/commands/test.js +91 -91
- package/src/utils/env.js +138 -136
package/src/commands/recharge.js
CHANGED
|
@@ -1,131 +1,158 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AIXX CLI - recharge 命令
|
|
3
|
-
*
|
|
4
|
-
* 显示充值方式。优先尝试调后端 creem/pay 接口生成在线充值链接;
|
|
5
|
-
* 如果后端不支持或失败,则给出通用引导(联系客服/后台充值)。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
|
|
9
|
-
import { loadApiKey, maskKey } from '../utils/env.js';
|
|
10
|
-
|
|
11
|
-
// 所有对外请求统一 15 秒超时
|
|
12
|
-
const FETCH_TIMEOUT = 15000;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* apiKey 读取统一走 src/utils/env.js 的 loadApiKey:
|
|
16
|
-
* 环境变量 AIXX_API_KEY → ~/.aixx/config.json → ~/.aixx/account.json
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 尝试调后端的 creem 支付接口生成充值链接。
|
|
21
|
-
* New-API 的在线充值常见接口:
|
|
22
|
-
* POST /api/user/creem/pay { amount, ... }
|
|
23
|
-
* 不同版本字段不一,失败就回退到手动引导。
|
|
24
|
-
*/
|
|
25
|
-
async function tryGetCreemLink(apiKey, baseUrl, amount) {
|
|
26
|
-
const apiBase = baseUrl.replace(/\/v1$/, '');
|
|
27
|
-
const candidates = [
|
|
28
|
-
{
|
|
29
|
-
url: `${apiBase}/api/user/creem/pay`,
|
|
30
|
-
body: { amount, currency: 'USD', gateway: 'creem' },
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
url: `${apiBase}/api/user/topup`,
|
|
34
|
-
body: { amount, top_up_code: '', payment_method: 'creem' },
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
for (const c of candidates) {
|
|
39
|
-
try {
|
|
40
|
-
const resp = await fetch(c.url, {
|
|
41
|
-
method: 'POST',
|
|
42
|
-
headers: {
|
|
43
|
-
Authorization: `Bearer ${apiKey}`,
|
|
44
|
-
'Content-Type': 'application/json',
|
|
45
|
-
},
|
|
46
|
-
body: JSON.stringify(c.body),
|
|
47
|
-
signal: AbortSignal.timeout(FETCH_TIMEOUT),
|
|
48
|
-
});
|
|
49
|
-
if (!resp.ok) continue;
|
|
50
|
-
const data = await resp.json().catch(() => null);
|
|
51
|
-
if (!data) continue;
|
|
52
|
-
// 多种可能的字段名兜底
|
|
53
|
-
const link =
|
|
54
|
-
data.data?.url ||
|
|
55
|
-
data.data?.payment_url ||
|
|
56
|
-
data.data?.checkout_url ||
|
|
57
|
-
data.url ||
|
|
58
|
-
data.payment_url;
|
|
59
|
-
if (link) return link;
|
|
60
|
-
} catch (e) {
|
|
61
|
-
// 超时单独提示一次(其余错误静默试下一个候选接口)
|
|
62
|
-
if (e?.name === 'TimeoutError' || e?.name === 'AbortError') {
|
|
63
|
-
console.log(' ⚠️ 连接超时,请检查网络');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function recharge(subArgs) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
console.log('
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
console.log(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
console.log(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
console.log('
|
|
130
|
-
console.log('
|
|
131
|
-
|
|
1
|
+
/**
|
|
2
|
+
* AIXX CLI - recharge 命令
|
|
3
|
+
*
|
|
4
|
+
* 显示充值方式。优先尝试调后端 creem/pay 接口生成在线充值链接;
|
|
5
|
+
* 如果后端不支持或失败,则给出通用引导(联系客服/后台充值)。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
|
|
9
|
+
import { loadApiKey, maskKey } from '../utils/env.js';
|
|
10
|
+
|
|
11
|
+
// 所有对外请求统一 15 秒超时
|
|
12
|
+
const FETCH_TIMEOUT = 15000;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* apiKey 读取统一走 src/utils/env.js 的 loadApiKey:
|
|
16
|
+
* 环境变量 AIXX_API_KEY → ~/.aixx/config.json → ~/.aixx/account.json
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 尝试调后端的 creem 支付接口生成充值链接。
|
|
21
|
+
* New-API 的在线充值常见接口:
|
|
22
|
+
* POST /api/user/creem/pay { amount, ... }
|
|
23
|
+
* 不同版本字段不一,失败就回退到手动引导。
|
|
24
|
+
*/
|
|
25
|
+
async function tryGetCreemLink(apiKey, baseUrl, amount) {
|
|
26
|
+
const apiBase = baseUrl.replace(/\/v1$/, '');
|
|
27
|
+
const candidates = [
|
|
28
|
+
{
|
|
29
|
+
url: `${apiBase}/api/user/creem/pay`,
|
|
30
|
+
body: { amount, currency: 'USD', gateway: 'creem' },
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
url: `${apiBase}/api/user/topup`,
|
|
34
|
+
body: { amount, top_up_code: '', payment_method: 'creem' },
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
for (const c of candidates) {
|
|
39
|
+
try {
|
|
40
|
+
const resp = await fetch(c.url, {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `Bearer ${apiKey}`,
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify(c.body),
|
|
47
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT),
|
|
48
|
+
});
|
|
49
|
+
if (!resp.ok) continue;
|
|
50
|
+
const data = await resp.json().catch(() => null);
|
|
51
|
+
if (!data) continue;
|
|
52
|
+
// 多种可能的字段名兜底
|
|
53
|
+
const link =
|
|
54
|
+
data.data?.url ||
|
|
55
|
+
data.data?.payment_url ||
|
|
56
|
+
data.data?.checkout_url ||
|
|
57
|
+
data.url ||
|
|
58
|
+
data.payment_url;
|
|
59
|
+
if (link) return link;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// 超时单独提示一次(其余错误静默试下一个候选接口)
|
|
62
|
+
if (e?.name === 'TimeoutError' || e?.name === 'AbortError') {
|
|
63
|
+
console.log(' ⚠️ 连接超时,请检查网络');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function recharge(subArgs) {
|
|
71
|
+
// 1121 K哥令一步收银台: aixx recharge 10 --channel alipay → checkout-intent直接开单(零登录)
|
|
72
|
+
const _num = (subArgs || []).find(a => /^\d+(\.\d+)?$/.test(a));
|
|
73
|
+
const _ch = (subArgs || []).find(a => a.startsWith('--channel'));
|
|
74
|
+
if (_num) {
|
|
75
|
+
const apiKey = loadApiKey ? loadApiKey() : '';
|
|
76
|
+
try {
|
|
77
|
+
const r = await fetch('https://console.aixx.ai/cloudpay/checkout/intent', {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
|
|
80
|
+
body: JSON.stringify({ item: 'balance', amount_usd: parseFloat(_num), channel: (_ch ? _ch.split('=')[1] || 'alipay' : 'alipay') }),
|
|
81
|
+
signal: AbortSignal.timeout(20000),
|
|
82
|
+
});
|
|
83
|
+
const j = await r.json().catch(() => ({}));
|
|
84
|
+
if (r.ok && j.ok) {
|
|
85
|
+
console.log(`✅ 收银台已开(订单 ${j.order_no})`);
|
|
86
|
+
console.log(` 金额:$${Number(j.amount_usd).toFixed(2)} ≈ ¥${Number(j.amount_cny).toFixed(2)} · 通道 ${j.channel}`);
|
|
87
|
+
// 1122质检窗P1-2: go短链优先(50字符·终端不折断/IM不转义)·旧版服务器无go_url字段则回退pay_url
|
|
88
|
+
console.log(`
|
|
89
|
+
💳 收银台链接(点开或发到手机打开):
|
|
90
|
+
${j.go_url || j.pay_url}`);
|
|
91
|
+
console.log(`
|
|
92
|
+
付款到账自动入余额——aixx balance 随时看。`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
console.log(`(一步收银台开单失败: ${(j && (j.detail || j.message)) || 'HTTP ' + r.status}——回退传统方式)`);
|
|
96
|
+
} catch { console.log('(一步收银台网络异常——回退传统方式)'); }
|
|
97
|
+
}
|
|
98
|
+
console.log('╔══════════════════════════════════════════╗');
|
|
99
|
+
console.log('║ AIXX 充值 ║');
|
|
100
|
+
console.log('╚══════════════════════════════════════════╝\n');
|
|
101
|
+
|
|
102
|
+
const apiKey = loadApiKey();
|
|
103
|
+
const baseUrl = process.env.AIXX_BASE_URL || DEFAULT_BASE_URL;
|
|
104
|
+
|
|
105
|
+
// 从参数取金额,默认 $5(最低)
|
|
106
|
+
let amount = 5;
|
|
107
|
+
if (subArgs[0]) {
|
|
108
|
+
const n = Number(subArgs[0]);
|
|
109
|
+
if (!Number.isNaN(n) && n > 0) amount = n;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!apiKey) {
|
|
113
|
+
console.log('⚠️ 未检测到AIXX API Key,以下为通用充值方式:\n');
|
|
114
|
+
console.log('充值方式:');
|
|
115
|
+
console.log(' 信用卡 / ApplePay:登录 AIXX 后台 → 充值 → Creem');
|
|
116
|
+
console.log(' USDT 加密货币:联系客服或后台提交');
|
|
117
|
+
console.log(`\n 最低充值 $5`);
|
|
118
|
+
console.log(`\n🌐 后台地址:${baseUrl.replace(/\/v1$/, '')}`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(`使用Key: ${maskKey(apiKey)}`);
|
|
123
|
+
console.log(`充值金额:$${amount}\n`);
|
|
124
|
+
|
|
125
|
+
// 尝试生成在线支付链接
|
|
126
|
+
console.log('🔄 正在生成在线充值链接...');
|
|
127
|
+
const link = await tryGetCreemLink(apiKey, baseUrl, amount);
|
|
128
|
+
|
|
129
|
+
console.log('\n────────────────────────────────────');
|
|
130
|
+
console.log('💳 充值方式:');
|
|
131
|
+
console.log('────────────────────────────────────');
|
|
132
|
+
|
|
133
|
+
if (link) {
|
|
134
|
+
console.log('\n ① 信用卡 / ApplePay(推荐,即时到账):');
|
|
135
|
+
console.log(` ${link}`);
|
|
136
|
+
console.log('\n 复制链接到浏览器打开即可支付。');
|
|
137
|
+
} else {
|
|
138
|
+
console.log('\n ① 信用卡 / ApplePay:');
|
|
139
|
+
console.log(' 自动生成链接失败,请直接登录后台充值:');
|
|
140
|
+
console.log(` ${baseUrl.replace(/\/v1$/, '')}/console/topup`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
console.log('\n ② USDT 加密货币:');
|
|
144
|
+
console.log(' 联系 AIXX 客服,或后台提交 USDT 充值订单');
|
|
145
|
+
console.log(' (后续会支持自动生成钱包地址)');
|
|
146
|
+
|
|
147
|
+
console.log('\n ③ 微信/支付宝:');
|
|
148
|
+
console.log(' 联系 AIXX 客服走人工充值');
|
|
149
|
+
|
|
150
|
+
console.log('\n────────────────────────────────────');
|
|
151
|
+
console.log(`最低充值 $5(约 ¥${(amount * 7).toFixed(0)})`);
|
|
152
|
+
console.log(`充值后额度即时到账,可直接使用。\n`);
|
|
153
|
+
|
|
154
|
+
console.log('💡 充值提示:');
|
|
155
|
+
console.log(' - 充 $5 用 deepseek-chat 能聊很久');
|
|
156
|
+
console.log(' - 充 $20 够用 Claude/GPT 跑一个月');
|
|
157
|
+
console.log(' - 推荐码注册的用户充值后推荐人有分润\n');
|
|
158
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIXX CLI - subscribe 命令(1121 K哥令:一步收银台·零登录·对话直达)
|
|
3
|
+
*
|
|
4
|
+
* aixx subscribe 1m → 数据API月档收银链接+二维码(支付宝默认)
|
|
5
|
+
* aixx subscribe 3m --channel wxpay
|
|
6
|
+
* aixx subscribe 12m --channel usdt(USDT需整数美元·测试期档价为1/2/3/4分)
|
|
7
|
+
*
|
|
8
|
+
* 凭证 = 本机 sk- 数据key(装机自带)——POST /cloudpay/checkout/intent
|
|
9
|
+
* 返回 pay_url + qr_url,打印给用户/agent:链接打开即真实收银台,付款自动升档。
|
|
10
|
+
* 金额/档位/收款地址全部服务端生成——agent拿不到也改不了。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { loadApiKey } from '../utils/env.js';
|
|
14
|
+
|
|
15
|
+
const CHECKOUT = 'https://console.aixx.ai/cloudpay/checkout/intent';
|
|
16
|
+
const FETCH_TIMEOUT = 20000;
|
|
17
|
+
|
|
18
|
+
const PLANS = {
|
|
19
|
+
'1m': '1个月档', '3m': '3个月档', '6m': '6个月档', '12m': '12个月档',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export async function subscribe(subArgs) {
|
|
23
|
+
const rest = (subArgs || []).filter((a) => a && !a.startsWith('--'));
|
|
24
|
+
const plan = (rest[0] || '').toLowerCase();
|
|
25
|
+
const chArg = (subArgs || []).find((a) => a.startsWith('--channel'));
|
|
26
|
+
const channel = chArg ? chArg.split('=')[1] || subArgs[(subArgs.indexOf(chArg) + 1)] || '' : 'alipay';
|
|
27
|
+
|
|
28
|
+
if (!plan || !PLANS[plan]) {
|
|
29
|
+
console.log('用法: aixx subscribe <1m|3m|6m|12m> [--channel alipay|wxpay|usdt]\n');
|
|
30
|
+
console.log('示例:');
|
|
31
|
+
console.log(' aixx subscribe 1m 一个月档(支付宝扫码/打开)');
|
|
32
|
+
console.log(' aixx subscribe 12m --channel usdt 年档USDT付款');
|
|
33
|
+
console.log('\n订阅=行情数据API六域全开(80次免费额度之外的不限量档)。');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const apiKey = loadApiKey();
|
|
38
|
+
if (!apiKey) {
|
|
39
|
+
console.error('❌ 未找到AIXX API Key——请先 npx aixxai install');
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.log(`🧾 正在开单:${PLANS[plan]} · 通道 ${channel}…\n`);
|
|
44
|
+
try {
|
|
45
|
+
const r = await fetch(CHECKOUT, {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
|
|
48
|
+
body: JSON.stringify({ item: `sub:${plan}`, channel }),
|
|
49
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT),
|
|
50
|
+
});
|
|
51
|
+
const j = await r.json().catch(() => ({}));
|
|
52
|
+
if (!r.ok || !j.ok) {
|
|
53
|
+
console.error(`❌ 开单失败: ${(j && (j.detail || j.message)) || 'HTTP ' + r.status}`);
|
|
54
|
+
if (j && j.detail && String(j.detail).includes('测试价')) {
|
|
55
|
+
console.error(' (订阅测试价当前仅限内部验证账号)');
|
|
56
|
+
}
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
console.log(`✅ 收银台已开(订单 ${j.order_no})`);
|
|
60
|
+
console.log(` 档位:${PLANS[plan]} 金额:$${Number(j.amount_usd).toFixed(2)} ≈ ¥${Number(j.amount_cny).toFixed(2)}`);
|
|
61
|
+
console.log(` 通道:${j.channel}`);
|
|
62
|
+
// 1122质检窗P1-2: go短链优先(50字符·终端不折断/IM不转义)·旧版服务器无go_url字段则回退pay_url
|
|
63
|
+
console.log(`\n💳 收银台链接(点开或发到手机打开):\n${j.go_url || j.pay_url}`);
|
|
64
|
+
if (j.qr_url && j.qr_url !== j.pay_url) {
|
|
65
|
+
console.log(`\n📱 二维码图片(可贴进对话):\n${j.qr_url}`);
|
|
66
|
+
}
|
|
67
|
+
console.log('\n付款到账后自动升级订阅档——aixx status 可随时看档位与到期日。');
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error('❌ ' + (err?.name === 'TimeoutError' || err?.name === 'AbortError'
|
|
70
|
+
? '连接超时,请检查网络' : err?.message || String(err)));
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/commands/test.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AIXX CLI - test 命令
|
|
3
|
-
* 测试AIXX是否可用
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
|
|
7
|
-
import { loadApiKey, maskKey } from '../utils/env.js';
|
|
8
|
-
|
|
9
|
-
export async function test(subArgs) {
|
|
10
|
-
console.log('╔══════════════════════════════════════════╗');
|
|
11
|
-
console.log('║ AIXX 连通性测试 ║');
|
|
12
|
-
console.log('╚══════════════════════════════════════════╝\n');
|
|
13
|
-
|
|
14
|
-
// 统一配置链:环境变量 → ~/.aixx/config.json → ~/.aixx/account.json
|
|
15
|
-
const apiKey = loadApiKey();
|
|
16
|
-
const baseUrl = process.env.AIXX_BASE_URL || DEFAULT_BASE_URL;
|
|
17
|
-
|
|
18
|
-
if (!apiKey) {
|
|
19
|
-
console.error('❌ 未找到AIXX API Key');
|
|
20
|
-
console.error(' 运行 npx aixxai install 配置,或设置环境变量 AIXX_API_KEY');
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
console.log(`测试地址: ${baseUrl}`);
|
|
25
|
-
console.log(`使用Key: ${maskKey(apiKey)}\n`);
|
|
26
|
-
|
|
27
|
-
// 1. 测试模型列表(带key调 /v1/models,这才是真实的可用性验证)
|
|
28
|
-
let modelCount = 0;
|
|
29
|
-
console.log('1️⃣ 获取可用模型列表...');
|
|
30
|
-
try {
|
|
31
|
-
const resp = await fetch(`${baseUrl}/models`, {
|
|
32
|
-
headers: { 'Authorization': `Bearer ${apiKey}` }
|
|
33
|
-
});
|
|
34
|
-
if (resp.ok) {
|
|
35
|
-
const data = await resp.json();
|
|
36
|
-
const models = data.data || data.models || [];
|
|
37
|
-
modelCount = models.length;
|
|
38
|
-
console.log(` ✅ 可用模型 (${models.length}个):`);
|
|
39
|
-
models.slice(0, 10).forEach(m => {
|
|
40
|
-
const id = typeof m === 'string' ? m : m.id;
|
|
41
|
-
console.log(` • ${id}`);
|
|
42
|
-
});
|
|
43
|
-
if (models.length > 10) console.log(` ... 还有 ${models.length - 10} 个`);
|
|
44
|
-
} else if (resp.status === 401) {
|
|
45
|
-
console.error(' ❌ API Key 无效(401)');
|
|
46
|
-
process.exit(1);
|
|
47
|
-
} else if (resp.status === 404) {
|
|
48
|
-
console.error(` ❌ 接口404,检查 AIXX_BASE_URL 是否正确(当前: ${baseUrl})`);
|
|
49
|
-
process.exit(1);
|
|
50
|
-
} else {
|
|
51
|
-
console.error(` ❌ 返回 ${resp.status}`);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
} catch (err) {
|
|
55
|
-
console.error(` ❌ 失败: ${err.message}`);
|
|
56
|
-
process.exit(1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 2. 测试实际调用
|
|
60
|
-
console.log('\n2️⃣ 测试调用
|
|
61
|
-
try {
|
|
62
|
-
const resp = await fetch(`${baseUrl}/chat/completions`, {
|
|
63
|
-
method: 'POST',
|
|
64
|
-
headers: {
|
|
65
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
66
|
-
'Content-Type': 'application/json'
|
|
67
|
-
},
|
|
68
|
-
body: JSON.stringify({
|
|
69
|
-
model: 'deepseek-chat',
|
|
70
|
-
messages: [{ role: 'user', content: '说"测试成功"三个字' }],
|
|
71
|
-
max_tokens: 20
|
|
72
|
-
})
|
|
73
|
-
});
|
|
74
|
-
if (resp.ok) {
|
|
75
|
-
const data = await resp.json();
|
|
76
|
-
const reply = data.choices?.[0]?.message?.content || '(空回复)';
|
|
77
|
-
const usage = data.usage || {};
|
|
78
|
-
console.log(` ✅ 调用成功!`);
|
|
79
|
-
console.log(` 模型回复: ${reply}`);
|
|
80
|
-
console.log(` Token用量: ${usage.total_tokens || '?'}`);
|
|
81
|
-
} else {
|
|
82
|
-
const errData = await resp.json().catch(() => ({}));
|
|
83
|
-
console.error(` ❌ 调用失败 (${resp.status}): ${errData.error?.message || resp.statusText}`);
|
|
84
|
-
if (resp.status === 402) console.error(' 提示: 额度不足,请充值');
|
|
85
|
-
}
|
|
86
|
-
} catch (err) {
|
|
87
|
-
console.error(` ❌ 网络错误: ${err.message}`);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
console.log('\n测试完成。\n');
|
|
91
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* AIXX CLI - test 命令
|
|
3
|
+
* 测试AIXX是否可用
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
|
|
7
|
+
import { loadApiKey, maskKey } from '../utils/env.js';
|
|
8
|
+
|
|
9
|
+
export async function test(subArgs) {
|
|
10
|
+
console.log('╔══════════════════════════════════════════╗');
|
|
11
|
+
console.log('║ AIXX 连通性测试 ║');
|
|
12
|
+
console.log('╚══════════════════════════════════════════╝\n');
|
|
13
|
+
|
|
14
|
+
// 统一配置链:环境变量 → ~/.aixx/config.json → ~/.aixx/account.json
|
|
15
|
+
const apiKey = loadApiKey();
|
|
16
|
+
const baseUrl = process.env.AIXX_BASE_URL || DEFAULT_BASE_URL;
|
|
17
|
+
|
|
18
|
+
if (!apiKey) {
|
|
19
|
+
console.error('❌ 未找到AIXX API Key');
|
|
20
|
+
console.error(' 运行 npx aixxai install 配置,或设置环境变量 AIXX_API_KEY');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
console.log(`测试地址: ${baseUrl}`);
|
|
25
|
+
console.log(`使用Key: ${maskKey(apiKey)}\n`);
|
|
26
|
+
|
|
27
|
+
// 1. 测试模型列表(带key调 /v1/models,这才是真实的可用性验证)
|
|
28
|
+
let modelCount = 0;
|
|
29
|
+
console.log('1️⃣ 获取可用模型列表...');
|
|
30
|
+
try {
|
|
31
|
+
const resp = await fetch(`${baseUrl}/models`, {
|
|
32
|
+
headers: { 'Authorization': `Bearer ${apiKey}` }
|
|
33
|
+
});
|
|
34
|
+
if (resp.ok) {
|
|
35
|
+
const data = await resp.json();
|
|
36
|
+
const models = data.data || data.models || [];
|
|
37
|
+
modelCount = models.length;
|
|
38
|
+
console.log(` ✅ 可用模型 (${models.length}个):`);
|
|
39
|
+
models.slice(0, 10).forEach(m => {
|
|
40
|
+
const id = typeof m === 'string' ? m : m.id;
|
|
41
|
+
console.log(` • ${id}`);
|
|
42
|
+
});
|
|
43
|
+
if (models.length > 10) console.log(` ... 还有 ${models.length - 10} 个`);
|
|
44
|
+
} else if (resp.status === 401) {
|
|
45
|
+
console.error(' ❌ API Key 无效(401)');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
} else if (resp.status === 404) {
|
|
48
|
+
console.error(` ❌ 接口404,检查 AIXX_BASE_URL 是否正确(当前: ${baseUrl})`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
} else {
|
|
51
|
+
console.error(` ❌ 返回 ${resp.status}`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error(` ❌ 失败: ${err.message}`);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 2. 测试实际调用
|
|
60
|
+
console.log('\n2️⃣ 测试调用 deepseek-chat...');
|
|
61
|
+
try {
|
|
62
|
+
const resp = await fetch(`${baseUrl}/chat/completions`, {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: {
|
|
65
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
66
|
+
'Content-Type': 'application/json'
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify({
|
|
69
|
+
model: 'deepseek-chat',
|
|
70
|
+
messages: [{ role: 'user', content: '说"测试成功"三个字' }],
|
|
71
|
+
max_tokens: 20
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
if (resp.ok) {
|
|
75
|
+
const data = await resp.json();
|
|
76
|
+
const reply = data.choices?.[0]?.message?.content || '(空回复)';
|
|
77
|
+
const usage = data.usage || {};
|
|
78
|
+
console.log(` ✅ 调用成功!`);
|
|
79
|
+
console.log(` 模型回复: ${reply}`);
|
|
80
|
+
console.log(` Token用量: ${usage.total_tokens || '?'}`);
|
|
81
|
+
} else {
|
|
82
|
+
const errData = await resp.json().catch(() => ({}));
|
|
83
|
+
console.error(` ❌ 调用失败 (${resp.status}): ${errData.error?.message || resp.statusText}`);
|
|
84
|
+
if (resp.status === 402) console.error(' 提示: 额度不足,请充值');
|
|
85
|
+
}
|
|
86
|
+
} catch (err) {
|
|
87
|
+
console.error(` ❌ 网络错误: ${err.message}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.log('\n测试完成。\n');
|
|
91
|
+
}
|