aihezu 2.0.1 → 2.2.0

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/aihezu.js CHANGED
@@ -38,77 +38,95 @@ async function askQuestion(rl, question) {
38
38
  }
39
39
 
40
40
  async function main() {
41
- // Removed global rl creation
42
-
43
41
  try {
44
- if (args.length === 0 || args[0] === 'help') { // Handle 'aihezu' or 'aihezu help'
42
+ if (args.length === 0 || args[0] === 'help') {
45
43
  showHelp();
46
44
  return;
47
45
  }
48
46
 
49
47
  const commandName = args[0];
50
- let serviceName = args[1];
51
-
52
48
  if (!commands[commandName]) {
53
- console.error(`❌ 未知命��: ${commandName}`);
49
+ console.error(`❌ 未知命令: ${commandName}`);
54
50
  showHelp();
55
51
  process.exit(1);
56
52
  }
57
53
 
54
+ let serviceName = '';
55
+ let commandArgs = [];
56
+
57
+ // Check if the second argument is a service name or an option/flag
58
+ if (args.length > 1 && !args[1].startsWith('-')) {
59
+ serviceName = args[1].toLowerCase();
60
+ commandArgs = args.slice(2);
61
+ } else {
62
+ // No service name provided, or an option was provided instead.
63
+ // The command arguments will be all arguments after the command itself.
64
+ commandArgs = args.slice(1);
65
+ }
66
+
67
+ // If service name is not provided, and command is 'install', enter interactive mode.
58
68
  if (!serviceName) {
59
69
  if (commandName === 'install') {
60
- // Init rl ONLY here for selection
61
70
  const rl = readline.createInterface({
62
71
  input: process.stdin,
63
72
  output: process.stdout
64
73
  });
65
74
 
66
75
  try {
67
- // Interactive service selection for 'install' command
68
76
  console.log('\n请选择要安装的服务:');
69
77
  const serviceKeys = Object.keys(services);
78
+ const claudeIndex = serviceKeys.indexOf('claude');
79
+
70
80
  serviceKeys.forEach((key, index) => {
71
- console.log(` [${index + 1}] ${services[key].displayName}`);
81
+ const isDefault = (key === 'claude');
82
+ console.log(` [${index + 1}] ${services[key].displayName}${isDefault ? ' (默认)' : ''}`);
72
83
  });
73
84
 
74
- let chosenIndex;
85
+ let chosenIndex = claudeIndex !== -1 ? claudeIndex : 0; // Default to Claude
75
86
  let validChoice = false;
87
+
76
88
  while (!validChoice) {
77
- const answer = await askQuestion(rl, '请输入选项编号: ');
78
- chosenIndex = parseInt(answer, 10) - 1;
79
- if (chosenIndex >= 0 && chosenIndex < serviceKeys.length) {
80
- serviceName = serviceKeys[chosenIndex];
81
- validChoice = true;
89
+ const answer = await askQuestion(rl, '请输入选项编号 (直接回车使用默认值): ');
90
+ if (answer === '') {
91
+ validChoice = true; // Use the default index
82
92
  } else {
83
- console.log('无效的选择,请输入列表中的数字。');
93
+ const selectedIdx = parseInt(answer, 10) - 1;
94
+ if (selectedIdx >= 0 && selectedIdx < serviceKeys.length) {
95
+ chosenIndex = selectedIdx;
96
+ validChoice = true;
97
+ } else {
98
+ console.log('无效的选择,请输入列表中的数字。');
99
+ }
84
100
  }
85
101
  }
102
+ serviceName = serviceKeys[chosenIndex];
86
103
  console.log(`✅ 已选择: ${services[serviceName].displayName}`);
104
+
87
105
  } finally {
88
- // Close rl immediately after selection and BEFORE calling the command
89
106
  rl.close();
90
107
  }
91
108
  } else {
92
- // For 'clear' or other commands, service name is mandatory
109
+ // For other commands like 'clear', service name is mandatory.
93
110
  console.error(`❌ 请为 '${commandName}' 命令指定一个服务名称。`);
94
111
  showHelp();
95
112
  process.exit(1);
96
113
  }
97
114
  }
98
115
 
99
- const service = services[serviceName.toLowerCase()];
116
+ const service = services[serviceName];
100
117
  if (!service) {
101
118
  console.error(`❌ 未知服务: ${serviceName}`);
102
119
  console.log('可用服务: ' + Object.keys(services).map(key => services[key].displayName).join(', '));
103
120
  process.exit(1);
104
121
  }
105
122
 
106
- // Execute
107
- await commands[commandName](service, args.slice(2));
123
+ // Execute the command with the correct service and arguments
124
+ await commands[commandName](service, commandArgs);
125
+
108
126
  } catch (error) {
109
127
  console.error('❌ 发生错误:', error);
110
128
  process.exit(1);
111
129
  }
112
130
  }
113
131
 
114
- main();
132
+ main();
@@ -56,7 +56,23 @@ async function installCommand(service, args = []) {
56
56
  const apiUrlInput = await askQuestion(rl, '请输入 API 地址 (直接回车使用默认地址): ');
57
57
  let apiUrl = apiUrlInput || defaultUrl;
58
58
 
59
+ // Determine service-specific suffix
60
+ let suffix = '';
61
+ if (service.name === 'claude') {
62
+ suffix = '/api';
63
+ } else if (service.name === 'codex') {
64
+ suffix = '/openai';
65
+ } else if (service.name === 'gemini') {
66
+ suffix = '/gemini';
67
+ }
68
+
69
+ // Append suffix if apiUrl does not already end with it
70
+ if (suffix && !apiUrl.endsWith(suffix)) {
71
+ apiUrl = apiUrl.replace(/\/+$/, '') + suffix; // Remove any trailing slash and add suffix
72
+ }
73
+
59
74
  // Basic URL validation/normalization
75
+ // This part should handle http/https prefixing.
60
76
  if (!/^https?:\/\//i.test(apiUrl)) {
61
77
  apiUrl = 'https://' + apiUrl;
62
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aihezu",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "description": "AI 开发环境配置工具 - 支持 Claude Code, Codex, Google Gemini 的本地化配置、代理设置与缓存清理",
5
5
  "main": "bin/aihezu.js",
6
6
  "bin": {