@x-all-in-one/coding-helper 0.4.0 → 0.4.2

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.
@@ -7,8 +7,9 @@ export declare class ApiKeyFlow {
7
7
  static getInstance(): ApiKeyFlow;
8
8
  /**
9
9
  * 运行 API Key 配置流程
10
+ * @returns 'success' 验证成功, 'back' 返回上级, undefined 其他情况
10
11
  */
11
- run(): Promise<void>;
12
+ run(): Promise<'success' | 'back' | void>;
12
13
  /**
13
14
  * 输入并验证 API Key
14
15
  */
@@ -24,6 +24,7 @@ export class ApiKeyFlow {
24
24
  }
25
25
  /**
26
26
  * 运行 API Key 配置流程
27
+ * @returns 'success' 验证成功, 'back' 返回上级, undefined 其他情况
27
28
  */
28
29
  async run() {
29
30
  while (true) {
@@ -60,12 +61,12 @@ export class ApiKeyFlow {
60
61
  process.exit(0);
61
62
  }
62
63
  if (action === 'back') {
63
- return;
64
+ return 'back';
64
65
  }
65
66
  if (action === 'input') {
66
67
  const success = await this.inputApiKey();
67
68
  if (success) {
68
- return;
69
+ return 'success';
69
70
  }
70
71
  // 验证失败,继续循环
71
72
  }
@@ -12,12 +12,14 @@ export declare class MainMenu {
12
12
  * @param handlers.onPlan - 套餐配置回调
13
13
  * @param handlers.onApiKey - API Key 配置回调
14
14
  * @param handlers.onTool - 工具配置回调
15
+ * @param handlers.onSelfUpdate - 自更新回调
15
16
  */
16
17
  show(handlers: {
17
18
  onLanguage: () => Promise<void>;
18
19
  onPlan: () => Promise<void>;
19
20
  onApiKey: () => Promise<void>;
20
21
  onTool: () => Promise<void>;
22
+ onSelfUpdate: () => Promise<void>;
21
23
  }): Promise<void>;
22
24
  /**
23
25
  * 打开官网
@@ -29,6 +29,7 @@ export class MainMenu {
29
29
  * @param handlers.onPlan - 套餐配置回调
30
30
  * @param handlers.onApiKey - API Key 配置回调
31
31
  * @param handlers.onTool - 工具配置回调
32
+ * @param handlers.onSelfUpdate - 自更新回调
32
33
  */
33
34
  async show(handlers) {
34
35
  const cfg = configManager.getConfig();
@@ -53,6 +54,7 @@ export class MainMenu {
53
54
  { name: `> ${i18n.t('wizard.menu_config_api_key')}`, value: 'apikey' },
54
55
  { name: `> ${i18n.t('wizard.menu_config_tool')}`, value: 'tool' },
55
56
  new inquirer.Separator(),
57
+ { name: `> ${i18n.t('wizard.menu_self_update')}`, value: 'self_update' },
56
58
  { name: `> ${i18n.t('wizard.menu_open_website')}`, value: 'website' },
57
59
  { name: `x ${i18n.t('wizard.menu_exit')}`, value: 'exit' },
58
60
  ];
@@ -65,6 +67,7 @@ export class MainMenu {
65
67
  message: i18n.t('wizard.select_operation'),
66
68
  choices,
67
69
  default: defaultChoice,
70
+ pageSize: 10,
68
71
  },
69
72
  ]);
70
73
  if (action === 'exit') {
@@ -83,6 +86,9 @@ export class MainMenu {
83
86
  else if (action === 'tool') {
84
87
  await handlers.onTool();
85
88
  }
89
+ else if (action === 'self_update') {
90
+ await handlers.onSelfUpdate();
91
+ }
86
92
  else if (action === 'website') {
87
93
  await this.openOfficialWebsite();
88
94
  }
@@ -47,6 +47,10 @@ export declare class Wizard {
47
47
  * 加载模型配置到工具
48
48
  */
49
49
  private loadModelConfig;
50
+ /**
51
+ * 自更新 Coding Helper
52
+ */
53
+ selfUpdate(): Promise<void>;
50
54
  /**
51
55
  * 显示主菜单
52
56
  */
@@ -1,4 +1,6 @@
1
+ import { execSync } from 'node:child_process';
1
2
  import chalk from 'chalk';
3
+ import ora from 'ora';
2
4
  import { configManager } from '../config.js';
3
5
  import { i18n } from '../i18n.js';
4
6
  import { toolRegistry } from '../tool-manager.js';
@@ -58,7 +60,10 @@ export class Wizard {
58
60
  * 配置 API Key
59
61
  */
60
62
  async configApiKey() {
61
- await apiKeyFlow.run();
63
+ const result = await apiKeyFlow.run();
64
+ if (result === 'success') {
65
+ await this.showMainMenu();
66
+ }
62
67
  }
63
68
  /**
64
69
  * 配置模型(Claude Code 默认3模型配置)
@@ -179,6 +184,26 @@ export class Wizard {
179
184
  async loadModelConfig(toolName) {
180
185
  await toolMenu.loadModelConfig(toolName);
181
186
  }
187
+ /**
188
+ * 自更新 Coding Helper
189
+ */
190
+ async selfUpdate() {
191
+ const spinner = ora({
192
+ text: i18n.t('wizard.self_updating'),
193
+ spinner: 'star2',
194
+ }).start();
195
+ try {
196
+ execSync('npm install -g @x-all-in-one/coding-helper', { stdio: 'pipe' });
197
+ spinner.succeed(chalk.green(i18n.t('wizard.self_updated')));
198
+ console.log(chalk.cyan(`\n${i18n.t('wizard.self_update_restart_hint')}\n`));
199
+ await new Promise(resolve => setTimeout(resolve, 2000));
200
+ process.exit(0);
201
+ }
202
+ catch {
203
+ spinner.fail(chalk.red(i18n.t('wizard.self_update_failed')));
204
+ await new Promise(resolve => setTimeout(resolve, 1500));
205
+ }
206
+ }
182
207
  /**
183
208
  * 显示主菜单
184
209
  */
@@ -188,6 +213,7 @@ export class Wizard {
188
213
  onPlan: () => this.configPlan(),
189
214
  onApiKey: () => this.configApiKey(),
190
215
  onTool: () => this.selectAndConfigureTool(),
216
+ onSelfUpdate: () => this.selfUpdate(),
191
217
  });
192
218
  }
193
219
  /**
@@ -186,6 +186,11 @@
186
186
  "updating_tool": "Updating {{tool}}...",
187
187
  "tool_updated": "{{tool}} updated successfully",
188
188
  "update_failed": "Update failed",
189
+ "menu_self_update": "Update Coding Helper",
190
+ "self_updating": "Updating Coding Helper...",
191
+ "self_updated": "Coding Helper updated successfully",
192
+ "self_update_failed": "Update failed",
193
+ "self_update_restart_hint": "Please run 'chelper' to use the new version",
189
194
  "plugin_submenu": "Plugin",
190
195
  "plugin_menu_title": "Plugin Menu",
191
196
  "plugin_not_installed": "{{plugin}} is not installed",
@@ -186,6 +186,11 @@
186
186
  "updating_tool": "正在更新 {{tool}}...",
187
187
  "tool_updated": "{{tool}} 更新成功",
188
188
  "update_failed": "更新失败",
189
+ "menu_self_update": "更新 Coding Helper",
190
+ "self_updating": "正在更新 Coding Helper...",
191
+ "self_updated": "Coding Helper 更新成功",
192
+ "self_update_failed": "更新失败",
193
+ "self_update_restart_hint": "请运行 'chelper' 以使用新版本",
189
194
  "plugin_submenu": "插件",
190
195
  "plugin_menu_title": "插件菜单",
191
196
  "plugin_not_installed": "{{plugin}} 尚未安装",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@x-all-in-one/coding-helper",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.2",
5
5
  "description": "X All In One Coding Helper",
6
6
  "author": "X.AIO",
7
7
  "homepage": "https://docs.x-aio.com/zh/docs",