aixxai 1.6.6 → 1.6.7

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.
@@ -1,120 +1,120 @@
1
- /**
2
- * AIXX CLI - models 命令
3
- * 列出AIXX支持的所有模型,按场景分组展示。
4
- * 2026-08-28 更新:按"日常推荐/通用/旗舰/嵌入"分组,用户一眼知道选哪个。
5
- */
6
-
7
- import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
8
- import { loadApiKey, maskKey } from '../utils/env.js';
9
-
10
- const FETCH_TIMEOUT = 15000;
11
-
12
- const MODEL_DESC = {
13
- 'deepseek-chat': '最便宜,日常首选',
14
- 'deepseek-v4-pro': 'DeepSeek 旗舰,推理强',
15
- 'deepseek-ai/DeepSeek-V3': 'DeepSeek V3',
16
- 'glm-4-flash': '智谱免费,速度快',
17
- 'glm-4-plus': '智谱旗舰,中文写作强',
18
- 'glm-4-air': '智谱轻量,便宜',
19
- 'glm-4-long': '智谱超长文本',
20
- 'glm-5-2-260617': 'GLM-5.2',
21
- 'moonshot-v1-8k': 'Kimi 短文本',
22
- 'moonshot-v1-32k': 'Kimi 中文本',
23
- 'moonshot-v1-128k': 'Kimi 超长文本',
24
- 'kimi-latest': 'Kimi 最新',
25
- 'kimi-k2.6': 'Kimi K2.6 代码强',
26
- 'claude-fable-5': 'Claude Fable 5 最强写作',
27
- 'claude-opus-4-8': 'Claude Opus 4.8',
28
- 'claude-opus-5': 'Claude Opus 5 最新旗舰',
29
- 'claude-sonnet-5': 'Claude Sonnet 5 性价比',
30
- 'claude-haiku-4-5': '便宜快速',
31
- 'gpt-5.4': 'GPT-5.4 通用',
32
- 'gpt-5.4-mini': 'GPT-5.4 便宜',
33
- 'gpt-5.5': 'GPT-5.5',
34
- 'gpt-5.6-sol': 'GPT-5.6 Sol 旗舰',
35
- 'gpt-5.6-luna': 'GPT-5.6 Luna 创意',
36
- 'gpt-5.6-terra': 'GPT-5.6 Terra 分析',
37
- 'doubao-pro': '豆包 Pro 中文',
38
- 'doubao-seed-2-0-pro-260215': '豆包 Seed 2.0',
39
- 'abab6.5-chat': 'MiniMax 6.5',
40
- 'bge-m3': '嵌入模型',
41
- 'embedding-3': '智谱嵌入',
42
- };
43
-
44
- function classifyScenario(id) {
45
- const lower = id.toLowerCase();
46
- if (lower.includes('embed') || lower.includes('bge')) return 'embedding';
47
- const budget = ['deepseek-chat', 'glm-4-flash', 'glm-4-air', 'claude-haiku'];
48
- if (budget.some(p => lower.startsWith(p) || lower.includes(p))) return 'budget';
49
- const flagship = ['opus-5', 'gpt-5.6', 'gpt-5.5', 'fable-5', 'deepseek-v4-pro'];
50
- if (flagship.some(p => lower.includes(p))) return 'flagship';
51
- return 'general';
52
- }
53
-
54
- function descOf(id) { return MODEL_DESC[id] || ''; }
55
-
56
- export async function models(subArgs) {
57
- console.log('╔══════════════════════════════════════════╗');
58
- console.log('║ AIXX 可用模型 ║');
59
- console.log('╚══════════════════════════════════════════╝\n');
60
-
61
- const apiKey = loadApiKey();
62
- const baseUrl = process.env.AIXX_BASE_URL || DEFAULT_BASE_URL;
63
-
64
- if (!apiKey) {
65
- console.error('❌ 未找到AIXX API Key');
66
- console.error(' 请先运行 npx aixxai install');
67
- process.exit(1);
68
- }
69
-
70
- let modelIds = [];
71
- try {
72
- const resp = await fetch(`${baseUrl}/models`, {
73
- headers: { Authorization: `Bearer ${apiKey}` },
74
- signal: AbortSignal.timeout(FETCH_TIMEOUT),
75
- });
76
- if (!resp.ok) {
77
- console.error(`❌ 获取模型列表失败: HTTP ${resp.status}`);
78
- process.exit(1);
79
- }
80
- const data = await resp.json();
81
- const arr = data.data || data.models || [];
82
- modelIds = arr.map(m => (typeof m === 'string' ? m : m.id)).filter(Boolean).sort();
83
- } catch (err) {
84
- console.error(`❌ ${err?.message || err}`);
85
- process.exit(1);
86
- }
87
-
88
- if (modelIds.length === 0) {
89
- console.log('⚠️ 后端未返回任何模型');
90
- return;
91
- }
92
-
93
- const groups = { budget: [], general: [], flagship: [], embedding: [] };
94
- modelIds.forEach(id => groups[classifyScenario(id)].push(id));
95
-
96
- const groupMeta = {
97
- budget: { title: '💡 日常推荐(便宜好用)' },
98
- general: { title: '🔧 通用模型(按需选)' },
99
- flagship: { title: '🚀 旗舰模型(最强但贵)' },
100
- embedding:{ title: '📐 嵌入模型(向量化/搜索)' },
101
- };
102
-
103
- for (const [key, meta] of Object.entries(groupMeta)) {
104
- const ids = groups[key];
105
- if (ids.length === 0) continue;
106
- console.log(`\n${meta.title}:`);
107
- ids.forEach(id => {
108
- const desc = descOf(id);
109
- console.log(` • ${id}${desc ? ' —— ' + desc : ''}`);
110
- });
111
- }
112
-
113
- console.log(`\n📊 共 ${modelIds.length} 个模型\n`);
114
- console.log('💡 选模型小抄:');
115
- console.log(' - 日常聊天/写文案 → deepseek-chat(最便宜)');
116
- console.log(' - 中文写作 → glm-4-plus 或 claude-fable-5');
117
- console.log(' - 读超长文档 → moonshot-v1-128k');
118
- console.log(' - 复杂推理/代码 → claude-opus-5 或 gpt-5.6-sol');
119
- console.log(' - 嵌入/搜索 → bge-m3\n');
120
- }
1
+ /**
2
+ * AIXX CLI - models 命令
3
+ * 列出AIXX支持的所有模型,按场景分组展示。
4
+ * 2026-08-28 更新:按"日常推荐/通用/旗舰/嵌入"分组,用户一眼知道选哪个。
5
+ */
6
+
7
+ import { DEFAULT_BASE_URL } from '../../bin/aixx.js';
8
+ import { loadApiKey, maskKey } from '../utils/env.js';
9
+
10
+ const FETCH_TIMEOUT = 15000;
11
+
12
+ const MODEL_DESC = {
13
+ 'deepseek-chat': '最便宜,日常首选',
14
+ 'deepseek-v4-pro': 'DeepSeek 旗舰,推理强',
15
+ 'deepseek-ai/DeepSeek-V3': 'DeepSeek V3',
16
+ 'glm-4-flash': '智谱免费,速度快',
17
+ 'glm-4-plus': '智谱旗舰,中文写作强',
18
+ 'glm-4-air': '智谱轻量,便宜',
19
+ 'glm-4-long': '智谱超长文本',
20
+ 'glm-5-2-260617': 'GLM-5.2',
21
+ 'moonshot-v1-8k': 'Kimi 短文本',
22
+ 'moonshot-v1-32k': 'Kimi 中文本',
23
+ 'moonshot-v1-128k': 'Kimi 超长文本',
24
+ 'kimi-latest': 'Kimi 最新',
25
+ 'kimi-k2.6': 'Kimi K2.6 代码强',
26
+ 'claude-fable-5': 'Claude Fable 5 最强写作',
27
+ 'claude-opus-4-8': 'Claude Opus 4.8',
28
+ 'claude-opus-5': 'Claude Opus 5 最新旗舰',
29
+ 'claude-sonnet-5': 'Claude Sonnet 5 性价比',
30
+ 'claude-haiku-4-5': '便宜快速',
31
+ 'gpt-5.4': 'GPT-5.4 通用',
32
+ 'gpt-5.4-mini': 'GPT-5.4 便宜',
33
+ 'gpt-5.5': 'GPT-5.5',
34
+ 'gpt-5.6-sol': 'GPT-5.6 Sol 旗舰',
35
+ 'gpt-5.6-luna': 'GPT-5.6 Luna 创意',
36
+ 'gpt-5.6-terra': 'GPT-5.6 Terra 分析',
37
+ 'doubao-pro': '豆包 Pro 中文',
38
+ 'doubao-seed-2-0-pro-260215': '豆包 Seed 2.0',
39
+ 'abab6.5-chat': 'MiniMax 6.5',
40
+ 'bge-m3': '嵌入模型',
41
+ 'embedding-3': '智谱嵌入',
42
+ };
43
+
44
+ function classifyScenario(id) {
45
+ const lower = id.toLowerCase();
46
+ if (lower.includes('embed') || lower.includes('bge')) return 'embedding';
47
+ const budget = ['deepseek-chat', 'glm-4-flash', 'glm-4-air', 'claude-haiku'];
48
+ if (budget.some(p => lower.startsWith(p) || lower.includes(p))) return 'budget';
49
+ const flagship = ['opus-5', 'gpt-5.6', 'gpt-5.5', 'fable-5', 'deepseek-v4-pro'];
50
+ if (flagship.some(p => lower.includes(p))) return 'flagship';
51
+ return 'general';
52
+ }
53
+
54
+ function descOf(id) { return MODEL_DESC[id] || ''; }
55
+
56
+ export async function models(subArgs) {
57
+ console.log('╔══════════════════════════════════════════╗');
58
+ console.log('║ AIXX 可用模型 ║');
59
+ console.log('╚══════════════════════════════════════════╝\n');
60
+
61
+ const apiKey = loadApiKey();
62
+ const baseUrl = process.env.AIXX_BASE_URL || DEFAULT_BASE_URL;
63
+
64
+ if (!apiKey) {
65
+ console.error('❌ 未找到AIXX API Key');
66
+ console.error(' 请先运行 npx aixxai install');
67
+ process.exit(1);
68
+ }
69
+
70
+ let modelIds = [];
71
+ try {
72
+ const resp = await fetch(`${baseUrl}/models`, {
73
+ headers: { Authorization: `Bearer ${apiKey}` },
74
+ signal: AbortSignal.timeout(FETCH_TIMEOUT),
75
+ });
76
+ if (!resp.ok) {
77
+ console.error(`❌ 获取模型列表失败: HTTP ${resp.status}`);
78
+ process.exit(1);
79
+ }
80
+ const data = await resp.json();
81
+ const arr = data.data || data.models || [];
82
+ modelIds = arr.map(m => (typeof m === 'string' ? m : m.id)).filter(Boolean).sort();
83
+ } catch (err) {
84
+ console.error(`❌ ${err?.message || err}`);
85
+ process.exit(1);
86
+ }
87
+
88
+ if (modelIds.length === 0) {
89
+ console.log('⚠️ 后端未返回任何模型');
90
+ return;
91
+ }
92
+
93
+ const groups = { budget: [], general: [], flagship: [], embedding: [] };
94
+ modelIds.forEach(id => groups[classifyScenario(id)].push(id));
95
+
96
+ const groupMeta = {
97
+ budget: { title: '💡 日常推荐(便宜好用)' },
98
+ general: { title: '🔧 通用模型(按需选)' },
99
+ flagship: { title: '🚀 旗舰模型(最强但贵)' },
100
+ embedding:{ title: '📐 嵌入模型(向量化/搜索)' },
101
+ };
102
+
103
+ for (const [key, meta] of Object.entries(groupMeta)) {
104
+ const ids = groups[key];
105
+ if (ids.length === 0) continue;
106
+ console.log(`\n${meta.title}:`);
107
+ ids.forEach(id => {
108
+ const desc = descOf(id);
109
+ console.log(` • ${id}${desc ? ' —— ' + desc : ''}`);
110
+ });
111
+ }
112
+
113
+ console.log(`\n📊 共 ${modelIds.length} 个模型\n`);
114
+ console.log('💡 选模型小抄:');
115
+ console.log(' - 日常聊天/写文案 → deepseek-chat(最便宜)');
116
+ console.log(' - 中文写作 → glm-4-plus 或 claude-fable-5');
117
+ console.log(' - 读超长文档 → moonshot-v1-128k');
118
+ console.log(' - 复杂推理/代码 → claude-opus-5 或 gpt-5.6-sol');
119
+ console.log(' - 嵌入/搜索 → bge-m3\n');
120
+ }
@@ -1,131 +1,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
- console.log('╔══════════════════════════════════════════╗');
72
- console.log('║ AIXX 充值 ║');
73
- console.log('╚══════════════════════════════════════════╝\n');
74
-
75
- const apiKey = loadApiKey();
76
- const baseUrl = process.env.AIXX_BASE_URL || DEFAULT_BASE_URL;
77
-
78
- // 从参数取金额,默认 $5(最低)
79
- let amount = 5;
80
- if (subArgs[0]) {
81
- const n = Number(subArgs[0]);
82
- if (!Number.isNaN(n) && n > 0) amount = n;
83
- }
84
-
85
- if (!apiKey) {
86
- console.log('⚠️ 未检测到AIXX API Key,以下为通用充值方式:\n');
87
- console.log('充值方式:');
88
- console.log(' 信用卡 / ApplePay:登录 AIXX 后台 → 充值 → Creem');
89
- console.log(' USDT 加密货币:联系客服或后台提交');
90
- console.log(`\n 最低充值 $5`);
91
- console.log(`\n🌐 后台地址:${baseUrl.replace(/\/v1$/, '')}`);
92
- return;
93
- }
94
-
95
- console.log(`使用Key: ${maskKey(apiKey)}`);
96
- console.log(`充值金额:$${amount}\n`);
97
-
98
- // 尝试生成在线支付链接
99
- console.log('🔄 正在生成在线充值链接...');
100
- const link = await tryGetCreemLink(apiKey, baseUrl, amount);
101
-
102
- console.log('\n────────────────────────────────────');
103
- console.log('💳 充值方式:');
104
- console.log('────────────────────────────────────');
105
-
106
- if (link) {
107
- console.log('\n ① 信用卡 / ApplePay(推荐,即时到账):');
108
- console.log(` ${link}`);
109
- console.log('\n 复制链接到浏览器打开即可支付。');
110
- } else {
111
- console.log('\n ① 信用卡 / ApplePay:');
112
- console.log(' 自动生成链接失败,请直接登录后台充值:');
113
- console.log(` ${baseUrl.replace(/\/v1$/, '')}/console/topup`);
114
- }
115
-
116
- console.log('\n ② USDT 加密货币:');
117
- console.log(' 联系 AIXX 客服,或后台提交 USDT 充值订单');
118
- console.log(' (后续会支持自动生成钱包地址)');
119
-
120
- console.log('\n ③ 微信/支付宝:');
121
- console.log(' 联系 AIXX 客服走人工充值');
122
-
123
- console.log('\n────────────────────────────────────');
124
- console.log(`最低充值 $5(约 ¥${(amount * 7).toFixed(0)})`);
125
- console.log(`充值后额度即时到账,可直接使用。\n`);
126
-
127
- console.log('💡 充值提示:');
128
- console.log(' - 充 $5 用 deepseek-chat 能聊 5 万次以上');
129
- console.log(' - 充 $20 够用 Claude/GPT 跑一个月');
130
- console.log(' - 推荐码注册的用户充值后推荐人有分润\n');
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
+ console.log('╔══════════════════════════════════════════╗');
72
+ console.log('║ AIXX 充值 ║');
73
+ console.log('╚══════════════════════════════════════════╝\n');
74
+
75
+ const apiKey = loadApiKey();
76
+ const baseUrl = process.env.AIXX_BASE_URL || DEFAULT_BASE_URL;
77
+
78
+ // 从参数取金额,默认 $5(最低)
79
+ let amount = 5;
80
+ if (subArgs[0]) {
81
+ const n = Number(subArgs[0]);
82
+ if (!Number.isNaN(n) && n > 0) amount = n;
83
+ }
84
+
85
+ if (!apiKey) {
86
+ console.log('⚠️ 未检测到AIXX API Key,以下为通用充值方式:\n');
87
+ console.log('充值方式:');
88
+ console.log(' 信用卡 / ApplePay:登录 AIXX 后台 → 充值 → Creem');
89
+ console.log(' USDT 加密货币:联系客服或后台提交');
90
+ console.log(`\n 最低充值 $5`);
91
+ console.log(`\n🌐 后台地址:${baseUrl.replace(/\/v1$/, '')}`);
92
+ return;
93
+ }
94
+
95
+ console.log(`使用Key: ${maskKey(apiKey)}`);
96
+ console.log(`充值金额:$${amount}\n`);
97
+
98
+ // 尝试生成在线支付链接
99
+ console.log('🔄 正在生成在线充值链接...');
100
+ const link = await tryGetCreemLink(apiKey, baseUrl, amount);
101
+
102
+ console.log('\n────────────────────────────────────');
103
+ console.log('💳 充值方式:');
104
+ console.log('────────────────────────────────────');
105
+
106
+ if (link) {
107
+ console.log('\n ① 信用卡 / ApplePay(推荐,即时到账):');
108
+ console.log(` ${link}`);
109
+ console.log('\n 复制链接到浏览器打开即可支付。');
110
+ } else {
111
+ console.log('\n ① 信用卡 / ApplePay:');
112
+ console.log(' 自动生成链接失败,请直接登录后台充值:');
113
+ console.log(` ${baseUrl.replace(/\/v1$/, '')}/console/topup`);
114
+ }
115
+
116
+ console.log('\n ② USDT 加密货币:');
117
+ console.log(' 联系 AIXX 客服,或后台提交 USDT 充值订单');
118
+ console.log(' (后续会支持自动生成钱包地址)');
119
+
120
+ console.log('\n ③ 微信/支付宝:');
121
+ console.log(' 联系 AIXX 客服走人工充值');
122
+
123
+ console.log('\n────────────────────────────────────');
124
+ console.log(`最低充值 $5(约 ¥${(amount * 7).toFixed(0)})`);
125
+ console.log(`充值后额度即时到账,可直接使用。\n`);
126
+
127
+ console.log('💡 充值提示:');
128
+ console.log(' - 充 $5 用 deepseek-chat 能聊 5 万次以上');
129
+ console.log(' - 充 $20 够用 Claude/GPT 跑一个月');
130
+ console.log(' - 推荐码注册的用户充值后推荐人有分润\n');
131
+ }
@@ -0,0 +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('❌ 未配置内测令牌:请设置环境变量 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
+ }