aixxai 1.7.5 → 1.7.6
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/package.json +1 -1
- package/src/commands/balance.js +84 -110
- package/src/commands/market.js +11 -5
package/package.json
CHANGED
package/src/commands/balance.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AIXX CLI - balance 命令
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 查询当前账户余额、已用额度(模型API)+ 数据API额度一屏。
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* 1. GET /
|
|
8
|
-
* 2. GET /
|
|
6
|
+
* 数据来源:
|
|
7
|
+
* 1. GET {model}/dashboard/billing/subscription → hard_limit_usd(总额度,美元)
|
|
8
|
+
* 2. GET {model}/dashboard/billing/usage → 已用量(多格式兜底)
|
|
9
|
+
* 3. GET www.aixx.vip/api/v1/account/usage → 数据API免费额度(1121千问终检③接入)
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
* "
|
|
11
|
+
* 1121终验四修:三路并发(5.7s→~2s)·指引走stdout(PowerShell不再包NativeCommandError)·
|
|
12
|
+
* 耗尽态隐藏"省着用"通用提示·lifetime与daily文案分流。
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
|
|
@@ -20,18 +21,13 @@ const USD_TO_CNY = 7;
|
|
|
20
21
|
const COST_PER_CHAT_CNY = 0.01;
|
|
21
22
|
// 所有对外请求统一 15 秒超时
|
|
22
23
|
const FETCH_TIMEOUT = 15000;
|
|
23
|
-
|
|
24
|
+
|
|
24
25
|
function friendlyNetErr(err) {
|
|
25
26
|
return err?.name === 'TimeoutError' || err?.name === 'AbortError'
|
|
26
27
|
? '连接超时,请检查网络'
|
|
27
28
|
: err?.message || String(err);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
/**
|
|
31
|
-
* apiKey 读取统一走 src/utils/env.js 的 loadApiKey:
|
|
32
|
-
* 环境变量 AIXX_API_KEY → ~/.aixx/config.json → ~/.aixx/account.json
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
31
|
export async function balance(subArgs) {
|
|
36
32
|
console.log('╔══════════════════════════════════════════╗');
|
|
37
33
|
console.log('║ AIXX 账户余额 ║');
|
|
@@ -46,24 +42,56 @@ export async function balance(subArgs) {
|
|
|
46
42
|
process.exit(1);
|
|
47
43
|
}
|
|
48
44
|
|
|
49
|
-
// 0.5 数据API额度预取(1121千问终检⑥顺序优化:先打快的,展示也排前面)
|
|
50
|
-
let dataApi = null;
|
|
51
|
-
try {
|
|
52
|
-
const c = new AbortController();
|
|
53
|
-
const t0 = setTimeout(() => c.abort(), 8000);
|
|
54
|
-
const u = await fetch('https://www.aixx.vip/api/v1/account/usage', {
|
|
55
|
-
headers: { Authorization: `Bearer ${apiKey}` },
|
|
56
|
-
signal: c.signal,
|
|
57
|
-
});
|
|
58
|
-
clearTimeout(t0);
|
|
59
|
-
const j = await u.json();
|
|
60
|
-
if (j && j.ok) dataApi = j;
|
|
61
|
-
} catch { /* 数据API额度查询失败不影响主流程 */ }
|
|
62
|
-
|
|
63
45
|
console.log(`使用Key: ${maskKey(apiKey)}`);
|
|
64
|
-
console.log(
|
|
46
|
+
console.log(`模型接口: ${baseUrl} · 数据接口: www.aixx.vip/api/v1\n`);
|
|
47
|
+
|
|
48
|
+
// 1121终验: 三路并发(数据API额度 / 订阅总额度 / 已用量)——串行5.7s→并发~2s
|
|
49
|
+
const pData = (async () => {
|
|
50
|
+
try {
|
|
51
|
+
const u = await fetch('https://www.aixx.vip/api/v1/account/usage', {
|
|
52
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
53
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT),
|
|
54
|
+
});
|
|
55
|
+
const j = await u.json();
|
|
56
|
+
if (j && j.ok) return j;
|
|
57
|
+
} catch { /* 数据API额度查询失败不影响主流程 */ }
|
|
58
|
+
return null;
|
|
59
|
+
})();
|
|
60
|
+
|
|
61
|
+
const pSub = (async () => {
|
|
62
|
+
try {
|
|
63
|
+
const r = await fetch(`${baseUrl}/dashboard/billing/subscription`, {
|
|
64
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
65
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT),
|
|
66
|
+
});
|
|
67
|
+
if (r.status === 401) return { _unauthorized: true };
|
|
68
|
+
if (!r.ok) return null;
|
|
69
|
+
const d = await r.json();
|
|
70
|
+
return { hard: d.hard_limit_usd ?? d.hard_limit ?? d.data?.hard_limit_usd ?? 0 };
|
|
71
|
+
} catch { return null; }
|
|
72
|
+
})();
|
|
73
|
+
|
|
74
|
+
const pUse = (async () => {
|
|
75
|
+
try {
|
|
76
|
+
const today = new Date();
|
|
77
|
+
const r = await fetch(
|
|
78
|
+
`${baseUrl}/dashboard/billing/usage?start_date=${today.getFullYear()}-01-01&end_date=${today.getFullYear()}-12-31`,
|
|
79
|
+
{ headers: { Authorization: `Bearer ${apiKey}` }, signal: AbortSignal.timeout(FETCH_TIMEOUT) }
|
|
80
|
+
);
|
|
81
|
+
if (!r.ok) return null;
|
|
82
|
+
const d = await r.json();
|
|
83
|
+
return { used: d.total_usage ?? d.total_cost ?? d.data?.total_usage ?? d.cumulative_usage ?? 0 };
|
|
84
|
+
} catch { return null; }
|
|
85
|
+
})();
|
|
86
|
+
|
|
87
|
+
const [dataApi, subR, useR] = await Promise.all([pData, pSub, pUse]);
|
|
65
88
|
|
|
66
|
-
|
|
89
|
+
if (subR && subR._unauthorized) {
|
|
90
|
+
console.error('❌ API Key 无效(401),请重新 install 或检查 key');
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ── GPU 行情数据 API ──(先显示:最快最准的额度账)
|
|
67
95
|
if (dataApi) {
|
|
68
96
|
const left = dataApi.free_quota - dataApi.free_used;
|
|
69
97
|
const dRem = typeof dataApi.daily_remaining === 'number' ? dataApi.daily_remaining
|
|
@@ -71,9 +99,13 @@ export async function balance(subArgs) {
|
|
|
71
99
|
console.log('── GPU 行情数据 API ──');
|
|
72
100
|
console.log(`📊 档位:${dataApi.tier === 'sub' ? '订阅中' : '免费档'}${dataApi.sub_expires_at ? `(至 ${String(dataApi.sub_expires_at).slice(0, 10)})` : ''}`);
|
|
73
101
|
console.log(`📊 免费额度:剩 ${left} / ${dataApi.free_quota} 次(今日已用 ${dataApi.today_counted})`);
|
|
74
|
-
if (
|
|
75
|
-
// 1121
|
|
76
|
-
console.log('
|
|
102
|
+
if (left <= 0) {
|
|
103
|
+
// 1121终验新增: lifetime耗尽分支——"明日重置"对lifetime耗尽者=空头承诺(0点后撞403)
|
|
104
|
+
console.log('🚫 免费档总量已用完——日重置不恢复总量,升级订阅档继续使用');
|
|
105
|
+
console.log(' 订阅档: https://aixx.ai/data-api.html#price');
|
|
106
|
+
} else if (dRem <= 0) {
|
|
107
|
+
// 1121千问P0-3: 日额度用尽置顶引导
|
|
108
|
+
console.log(`⚠️ 今日免费额度已用尽——北京时间次日00:00恢复(免费总量剩 ${left} 次)`);
|
|
77
109
|
console.log(' 需要现在继续? 订阅档: https://aixx.ai/data-api.html#price');
|
|
78
110
|
} else if (dataApi.tier !== 'sub' && dRem <= 10) {
|
|
79
111
|
console.log(`💡 今日剩余 ${dRem} 次,快到日上限(40/日)——省着点用`);
|
|
@@ -81,91 +113,24 @@ export async function balance(subArgs) {
|
|
|
81
113
|
console.log('────────────────────────────────────\n');
|
|
82
114
|
}
|
|
83
115
|
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const resp = await fetch(`${baseUrl}/dashboard/billing/subscription`, {
|
|
91
|
-
headers: { Authorization: `Bearer ${apiKey}` },
|
|
92
|
-
signal: AbortSignal.timeout(FETCH_TIMEOUT),
|
|
93
|
-
});
|
|
94
|
-
if (!resp.ok) {
|
|
95
|
-
if (resp.status === 401) {
|
|
96
|
-
console.error('❌ API Key 无效(401),请重新 install 或检查 key');
|
|
97
|
-
process.exit(1);
|
|
98
|
-
}
|
|
99
|
-
console.error(`❌ 查询余额失败: HTTP ${resp.status}`);
|
|
100
|
-
process.exit(1);
|
|
101
|
-
}
|
|
102
|
-
const data = await resp.json();
|
|
103
|
-
// New-API/OpenAI兼容:hard_limit_usd 是总额度
|
|
104
|
-
hardLimitUsd =
|
|
105
|
-
data.hard_limit_usd ??
|
|
106
|
-
data.hard_limit ??
|
|
107
|
-
data.data?.hard_limit_usd ??
|
|
108
|
-
0;
|
|
109
|
-
} catch (err) {
|
|
110
|
-
console.error(`❌ ${friendlyNetErr(err)}`);
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// 2. 查已用量(usage)
|
|
115
|
-
// 不同后端字段不一样,尽量兜底
|
|
116
|
-
let usedUsd = 0;
|
|
117
|
-
try {
|
|
118
|
-
// 用一个宽日期范围,确保能查到所有用量
|
|
119
|
-
const today = new Date();
|
|
120
|
-
const start = `${today.getFullYear()}-01-01`;
|
|
121
|
-
const end = `${today.getFullYear()}-12-31`;
|
|
122
|
-
const resp = await fetch(
|
|
123
|
-
`${baseUrl}/dashboard/billing/usage?start_date=${start}&end_date=${end}`,
|
|
124
|
-
{
|
|
125
|
-
headers: { Authorization: `Bearer ${apiKey}` },
|
|
126
|
-
signal: AbortSignal.timeout(FETCH_TIMEOUT),
|
|
127
|
-
}
|
|
128
|
-
);
|
|
129
|
-
if (resp.ok) {
|
|
130
|
-
const data = await resp.json();
|
|
131
|
-
// 常见字段优先级
|
|
132
|
-
usedUsd =
|
|
133
|
-
data.total_usage ??
|
|
134
|
-
data.total_cost ??
|
|
135
|
-
data.data?.total_usage ??
|
|
136
|
-
data.cumulative_usage ??
|
|
137
|
-
0;
|
|
138
|
-
// New-API 的 total_usage 单位有时是"分(美元)",要除以100
|
|
139
|
-
// 这里做个粗判断:如果usedUsd比hardLimit还大100倍,多半是没除100
|
|
140
|
-
if (usedUsd > 0 && hardLimitUsd > 0 && usedUsd > hardLimitUsd * 50) {
|
|
141
|
-
usedUsd = usedUsd / 100;
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
// usage 接口挂了不影响主流程,总额度照常显示
|
|
145
|
-
console.log(' (用量接口未返回数据,仅显示总额度)\n');
|
|
146
|
-
}
|
|
147
|
-
} catch (err) {
|
|
148
|
-
console.log(' (用量查询失败,仅显示总额度)\n');
|
|
116
|
+
// ── 模型 API 余额 ──
|
|
117
|
+
let hardLimitUsd = (subR && subR.hard) || 0;
|
|
118
|
+
let usedUsd = (useR && useR.used) || 0;
|
|
119
|
+
if (usedUsd > 0 && hardLimitUsd > 0 && usedUsd > hardLimitUsd * 50) {
|
|
120
|
+
usedUsd = usedUsd / 100; // New-API total_usage 偶尔是"分"单位
|
|
149
121
|
}
|
|
150
122
|
|
|
151
|
-
// 3. 计算并展示
|
|
152
|
-
// New-API 的"无限额度"哨兵:hard_limit_usd >= 100000000(1亿)表示这个token不限额。
|
|
153
|
-
// 直接显示真实数字(¥7亿)会吓到用户,所以单独走"无限额度"分支。
|
|
154
123
|
const UNLIMITED_SENTINEL = 100000000;
|
|
155
124
|
const isUnlimited = hardLimitUsd >= UNLIMITED_SENTINEL;
|
|
156
125
|
const usedCny = usedUsd * USD_TO_CNY;
|
|
157
126
|
|
|
158
127
|
console.log('────────────────────────────────────');
|
|
159
|
-
if (
|
|
128
|
+
if (!subR) {
|
|
129
|
+
console.log('💰 模型余额查询暂不可用(稍后再试或看 aixx status)');
|
|
130
|
+
} else if (isUnlimited) {
|
|
160
131
|
// unlimited token(New-API对unlimited_quota=true的token返回1亿作为标记)
|
|
161
|
-
// 实际是"按账户余额扣费",不是真的无限。账户余额是注册送的¥5起,用完就停。
|
|
162
|
-
// billing接口拿不到真实账户余额(它对unlimited token只返回1亿标记),
|
|
163
|
-
// 所以这里如实告知用户,引导去后台查精确余额。
|
|
164
132
|
console.log(`💰 计费方式:按账户余额扣费(注册送$0.5试用额度,用完需充值)`);
|
|
165
|
-
// 1120 WorkBuddy实测: unlimited档下dashboard/billing/usage返回的单位不可信(曾显示¥58969虚惊)
|
|
166
|
-
// 按账户余额扣费时"已用"以账户维度为准——不展示误算值;1121千问终检:死文案删除
|
|
167
133
|
} else {
|
|
168
|
-
// 正常有限额度
|
|
169
134
|
const remainingUsd = Math.max(0, hardLimitUsd - usedUsd);
|
|
170
135
|
const totalCny = hardLimitUsd * USD_TO_CNY;
|
|
171
136
|
const remainingCny = remainingUsd * USD_TO_CNY;
|
|
@@ -176,9 +141,18 @@ export async function balance(subArgs) {
|
|
|
176
141
|
}
|
|
177
142
|
console.log('────────────────────────────────────');
|
|
178
143
|
|
|
144
|
+
// 1121终验(a): 耗尽态隐藏"省着用"通用提示——都烧干了还劝省着用=噪音
|
|
145
|
+
const dataDry = dataApi && ((dataApi.free_quota - dataApi.free_used) <= 0
|
|
146
|
+
|| (typeof dataApi.daily_remaining === 'number' ? dataApi.daily_remaining : 40 - (dataApi.today_counted || 0)) <= 0);
|
|
179
147
|
console.log('\n💡 提示:');
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
148
|
+
if (dataDry) {
|
|
149
|
+
console.log(' - 数据API额度已用尽——升级或等重置: https://aixx.ai/data-api.html#price');
|
|
150
|
+
console.log(' - 余额不足时运行 aixx recharge 查看充值方式');
|
|
151
|
+
console.log(' - 一条命令看全貌:aixx status\n');
|
|
152
|
+
} else {
|
|
153
|
+
console.log(' - 新用户注册送 $0.5 试用额度');
|
|
154
|
+
console.log(' - glm-4-air 便宜,省着用能聊很久');
|
|
155
|
+
console.log(' - 余额不足时运行 aixx recharge 查看充值方式');
|
|
156
|
+
console.log(' - 一条命令看全貌:aixx status\n');
|
|
157
|
+
}
|
|
184
158
|
}
|
package/src/commands/market.js
CHANGED
|
@@ -69,15 +69,21 @@ async function mFetch(path) {
|
|
|
69
69
|
process.exit(1);
|
|
70
70
|
}
|
|
71
71
|
if (res.status === 429) {
|
|
72
|
-
// 1121千问P0-2
|
|
72
|
+
// 1121千问P0-2+终验: 解析429体分流——指引走stdout(终验b: stderr在PowerShell包成NativeCommandError乱屏)
|
|
73
73
|
let eb = {};
|
|
74
74
|
try { eb = await res.json(); } catch { /* 无体走默认 */ }
|
|
75
75
|
if (eb && eb.error === 'quota_exhausted') {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
if (eb.reason === 'lifetime_free_quota') {
|
|
77
|
+
console.log('🚫 免费档总量已用完(lifetime)——日重置不恢复总量,升级订阅档继续使用');
|
|
78
|
+
console.log(' 订阅档: https://aixx.ai/data-api.html#price');
|
|
79
|
+
console.log(' 额度账目: aixx balance');
|
|
80
|
+
} else {
|
|
81
|
+
console.log('🔥 今日免费数据额度已用完(北京时间次日00:00恢复,免费总量剩 ' + (eb.lifetime_remaining ?? '?') + ' 次)');
|
|
82
|
+
console.log(' 现在重试无意义。额度账目: aixx balance');
|
|
83
|
+
console.log(' 需要现在继续? 订阅档: https://aixx.ai/data-api.html#price');
|
|
84
|
+
}
|
|
79
85
|
} else {
|
|
80
|
-
console.
|
|
86
|
+
console.log('⏳ 请求太快,' + ((eb && eb.retry_after) || 60) + '秒后可继续');
|
|
81
87
|
}
|
|
82
88
|
process.exit(1);
|
|
83
89
|
}
|