@x-all-in-one/coding-helper 0.0.3 → 0.0.4
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/README.md +0 -2
- package/dist/commands/auth.js +10 -10
- package/dist/commands/config.js +17 -17
- package/dist/commands/doctor.js +14 -14
- package/dist/commands/index.d.ts +2 -2
- package/dist/commands/index.js +2 -2
- package/dist/commands/lang.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/lib/api-validator.js +7 -7
- package/dist/lib/claude-code-manager.d.ts +2 -0
- package/dist/lib/claude-code-manager.js +13 -13
- package/dist/lib/command.js +7 -7
- package/dist/lib/config.d.ts +10 -0
- package/dist/lib/config.js +14 -5
- package/dist/lib/i18n.js +4 -4
- package/dist/lib/opencode-manager.d.ts +93 -0
- package/dist/lib/opencode-manager.js +238 -0
- package/dist/lib/tool-manager.d.ts +2 -2
- package/dist/lib/tool-manager.js +65 -43
- package/dist/lib/wizard.d.ts +5 -1
- package/dist/lib/wizard.js +318 -167
- package/dist/locales/en_US.json +7 -0
- package/dist/locales/zh_CN.json +7 -0
- package/dist/utils/string-width.js +27 -27
- package/package.json +17 -16
package/README.md
CHANGED
package/dist/commands/auth.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
1
2
|
import inquirer from 'inquirer';
|
|
2
3
|
import ora from 'ora';
|
|
4
|
+
import { validateApiKey } from '../lib/api-validator.js';
|
|
5
|
+
import { DEFAULT_CONFIG } from '../lib/claude-code-manager.js';
|
|
3
6
|
import { configManager } from '../lib/config.js';
|
|
4
7
|
import { i18n } from '../lib/i18n.js';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
8
|
import { toolManager } from '../lib/tool-manager.js';
|
|
7
|
-
import { validateApiKey } from '../lib/api-validator.js';
|
|
8
|
-
import { DEFAULT_CONFIG } from '../lib/claude-code-manager.js';
|
|
9
9
|
/**
|
|
10
10
|
* 支持的工具列表
|
|
11
11
|
*/
|
|
@@ -31,7 +31,7 @@ async function reloadToTool(tool) {
|
|
|
31
31
|
apiKey,
|
|
32
32
|
haikuModel: models.haikuModel || DEFAULT_CONFIG.ANTHROPIC_DEFAULT_HAIKU_MODEL,
|
|
33
33
|
sonnetModel: models.sonnetModel || DEFAULT_CONFIG.ANTHROPIC_DEFAULT_SONNET_MODEL,
|
|
34
|
-
opusModel: models.opusModel || DEFAULT_CONFIG.ANTHROPIC_DEFAULT_OPUS_MODEL
|
|
34
|
+
opusModel: models.opusModel || DEFAULT_CONFIG.ANTHROPIC_DEFAULT_OPUS_MODEL,
|
|
35
35
|
});
|
|
36
36
|
await new Promise(resolve => setTimeout(resolve, 800));
|
|
37
37
|
console.log(chalk.green(i18n.t('auth.reloaded', { tool: 'Claude Code' })));
|
|
@@ -52,8 +52,8 @@ async function revokeApiKey() {
|
|
|
52
52
|
type: 'confirm',
|
|
53
53
|
name: 'confirm',
|
|
54
54
|
message: i18n.t('auth.revoke_confirm'),
|
|
55
|
-
default: false
|
|
56
|
-
}
|
|
55
|
+
default: false,
|
|
56
|
+
},
|
|
57
57
|
]);
|
|
58
58
|
if (confirm) {
|
|
59
59
|
configManager.revokeApiKey();
|
|
@@ -77,13 +77,13 @@ async function interactiveAuth() {
|
|
|
77
77
|
return i18n.t('auth.token_required');
|
|
78
78
|
}
|
|
79
79
|
return true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
82
|
]);
|
|
83
83
|
// Validate API Key
|
|
84
84
|
const spinner = ora({
|
|
85
85
|
text: i18n.t('wizard.validating_api_key'),
|
|
86
|
-
spinner: 'dots'
|
|
86
|
+
spinner: 'dots',
|
|
87
87
|
}).start();
|
|
88
88
|
const validationResult = await validateApiKey(token.trim());
|
|
89
89
|
if (!validationResult.valid) {
|
|
@@ -105,7 +105,7 @@ async function interactiveAuth() {
|
|
|
105
105
|
async function directAuth(token) {
|
|
106
106
|
const spinner = ora({
|
|
107
107
|
text: i18n.t('wizard.validating_api_key'),
|
|
108
|
-
spinner: 'star2'
|
|
108
|
+
spinner: 'star2',
|
|
109
109
|
}).start();
|
|
110
110
|
const validationResult = await validateApiKey(token);
|
|
111
111
|
await new Promise(resolve => setTimeout(resolve, 800));
|
package/dist/commands/config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import inquirer from 'inquirer';
|
|
2
1
|
import chalk from 'chalk';
|
|
3
|
-
import
|
|
4
|
-
import { toolManager, SUPPORTED_TOOLS } from '../lib/tool-manager.js';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
5
3
|
import { i18n } from '../lib/i18n.js';
|
|
4
|
+
import { SUPPORTED_TOOLS, toolManager } from '../lib/tool-manager.js';
|
|
5
|
+
import { wizard } from '../lib/wizard.js';
|
|
6
6
|
export async function configCommand(args) {
|
|
7
7
|
const subCommand = args[0];
|
|
8
8
|
const toolName = args[1];
|
|
@@ -15,9 +15,9 @@ export async function configCommand(args) {
|
|
|
15
15
|
message: i18n.t('wizard.select_tool'),
|
|
16
16
|
choices: Object.values(SUPPORTED_TOOLS).map(tool => ({
|
|
17
17
|
name: `${tool.displayName} (${tool.name})`,
|
|
18
|
-
value: tool.name
|
|
19
|
-
}))
|
|
20
|
-
}
|
|
18
|
+
value: tool.name,
|
|
19
|
+
})),
|
|
20
|
+
},
|
|
21
21
|
]);
|
|
22
22
|
// 检查工具是否安装
|
|
23
23
|
if (!toolManager.isToolInstalled(selectedTool)) {
|
|
@@ -27,8 +27,8 @@ export async function configCommand(args) {
|
|
|
27
27
|
type: 'confirm',
|
|
28
28
|
name: 'shouldInstall',
|
|
29
29
|
message: i18n.t('wizard.install_tool_confirm'),
|
|
30
|
-
default: true
|
|
31
|
-
}
|
|
30
|
+
default: true,
|
|
31
|
+
},
|
|
32
32
|
]);
|
|
33
33
|
if (shouldInstall) {
|
|
34
34
|
try {
|
|
@@ -49,9 +49,9 @@ export async function configCommand(args) {
|
|
|
49
49
|
message: i18n.t('install.skip_install_confirm'),
|
|
50
50
|
choices: [
|
|
51
51
|
{ name: i18n.t('install.skip_install_yes'), value: true },
|
|
52
|
-
{ name: i18n.t('install.skip_install_no'), value: false }
|
|
53
|
-
]
|
|
54
|
-
}
|
|
52
|
+
{ name: i18n.t('install.skip_install_no'), value: false },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
55
|
]);
|
|
56
56
|
if (!skipInstall) {
|
|
57
57
|
return;
|
|
@@ -76,8 +76,8 @@ export async function configCommand(args) {
|
|
|
76
76
|
type: 'confirm',
|
|
77
77
|
name: 'shouldInstall',
|
|
78
78
|
message: i18n.t('wizard.install_tool_confirm'),
|
|
79
|
-
default: true
|
|
80
|
-
}
|
|
79
|
+
default: true,
|
|
80
|
+
},
|
|
81
81
|
]);
|
|
82
82
|
if (shouldInstall) {
|
|
83
83
|
try {
|
|
@@ -98,9 +98,9 @@ export async function configCommand(args) {
|
|
|
98
98
|
message: i18n.t('install.skip_install_confirm'),
|
|
99
99
|
choices: [
|
|
100
100
|
{ name: i18n.t('install.skip_install_yes'), value: true },
|
|
101
|
-
{ name: i18n.t('install.skip_install_no'), value: false }
|
|
102
|
-
]
|
|
103
|
-
}
|
|
101
|
+
{ name: i18n.t('install.skip_install_no'), value: false },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
104
|
]);
|
|
105
105
|
if (!skipInstall) {
|
|
106
106
|
return;
|
|
@@ -127,7 +127,7 @@ export async function configCommand(args) {
|
|
|
127
127
|
console.error(chalk.red(`Unknown command: ${subCommand}`));
|
|
128
128
|
console.log(chalk.gray('Usage: chelper config [tool-name]'));
|
|
129
129
|
console.log(chalk.gray('Available tools:'));
|
|
130
|
-
Object.values(SUPPORTED_TOOLS).forEach(tool => {
|
|
130
|
+
Object.values(SUPPORTED_TOOLS).forEach((tool) => {
|
|
131
131
|
console.log(chalk.gray(` - ${tool.name}: ${tool.displayName}`));
|
|
132
132
|
});
|
|
133
133
|
}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import ora from 'ora';
|
|
3
|
-
import {
|
|
4
|
-
import { toolManager } from '../lib/tool-manager.js';
|
|
3
|
+
import { validateApiKey } from '../lib/api-validator.js';
|
|
5
4
|
import { claudeCodeManager } from '../lib/claude-code-manager.js';
|
|
5
|
+
import { configManager } from '../lib/config.js';
|
|
6
6
|
import { i18n } from '../lib/i18n.js';
|
|
7
|
-
import {
|
|
7
|
+
import { toolManager } from '../lib/tool-manager.js';
|
|
8
8
|
export async function doctorCommand() {
|
|
9
9
|
const spinner = ora(i18n.t('doctor.checking')).start();
|
|
10
10
|
const results = [];
|
|
@@ -15,14 +15,14 @@ export async function doctorCommand() {
|
|
|
15
15
|
results.push({
|
|
16
16
|
name: 'PATH',
|
|
17
17
|
passed: path.length > 0,
|
|
18
|
-
message: path.length > 0 ? undefined : 'PATH is empty'
|
|
18
|
+
message: path.length > 0 ? undefined : 'PATH is empty',
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
catch (error) {
|
|
22
22
|
results.push({
|
|
23
23
|
name: 'PATH',
|
|
24
24
|
passed: false,
|
|
25
|
-
message: String(error)
|
|
25
|
+
message: String(error),
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
await new Promise(resolve => setTimeout(resolve, 800));
|
|
@@ -33,7 +33,7 @@ export async function doctorCommand() {
|
|
|
33
33
|
results.push({
|
|
34
34
|
name: 'API Key & Network',
|
|
35
35
|
passed: false,
|
|
36
|
-
message: chalk.yellow(i18n.t('doctor.api_key_missing'))
|
|
36
|
+
message: chalk.yellow(i18n.t('doctor.api_key_missing')),
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
@@ -41,21 +41,21 @@ export async function doctorCommand() {
|
|
|
41
41
|
if (validationResult.valid) {
|
|
42
42
|
results.push({
|
|
43
43
|
name: 'API Key & Network',
|
|
44
|
-
passed: true
|
|
44
|
+
passed: true,
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
else if (validationResult.error === 'invalid_api_key') {
|
|
48
48
|
results.push({
|
|
49
49
|
name: 'API Key & Network',
|
|
50
50
|
passed: false,
|
|
51
|
-
message: chalk.yellow(i18n.t('doctor.api_key_invalid'))
|
|
51
|
+
message: chalk.yellow(i18n.t('doctor.api_key_invalid')),
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
results.push({
|
|
56
56
|
name: 'API Key & Network',
|
|
57
57
|
passed: false,
|
|
58
|
-
message: chalk.yellow(i18n.t('doctor.network_error'))
|
|
58
|
+
message: chalk.yellow(i18n.t('doctor.network_error')),
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -67,13 +67,13 @@ export async function doctorCommand() {
|
|
|
67
67
|
results.push({
|
|
68
68
|
name: 'Git Environment',
|
|
69
69
|
passed: gitInstalled,
|
|
70
|
-
message: gitInstalled ? undefined : chalk.yellow(i18n.t('doctor.git_not_installed'))
|
|
70
|
+
message: gitInstalled ? undefined : chalk.yellow(i18n.t('doctor.git_not_installed')),
|
|
71
71
|
});
|
|
72
72
|
await new Promise(resolve => setTimeout(resolve, 800));
|
|
73
73
|
}
|
|
74
74
|
// Check 4: Configuration status
|
|
75
75
|
spinner.text = i18n.t('doctor.check_config');
|
|
76
|
-
|
|
76
|
+
claudeCodeManager.getModelConfig();
|
|
77
77
|
const models = configManager.getModels();
|
|
78
78
|
const configComplete = !!apiKey && !!(models.haikuModel || models.sonnetModel || models.opusModel);
|
|
79
79
|
let configMessage = '';
|
|
@@ -86,7 +86,7 @@ export async function doctorCommand() {
|
|
|
86
86
|
results.push({
|
|
87
87
|
name: 'Configuration',
|
|
88
88
|
passed: configComplete,
|
|
89
|
-
message: configComplete ? undefined : chalk.yellow(configMessage)
|
|
89
|
+
message: configComplete ? undefined : chalk.yellow(configMessage),
|
|
90
90
|
});
|
|
91
91
|
await new Promise(resolve => setTimeout(resolve, 800));
|
|
92
92
|
// Check 5: Installed tools (检测所有支持的工具)
|
|
@@ -97,7 +97,7 @@ export async function doctorCommand() {
|
|
|
97
97
|
results.push({
|
|
98
98
|
name: `Tool: ${tool.displayName} (${tool.name})`,
|
|
99
99
|
passed: isInstalled,
|
|
100
|
-
message: isInstalled ? undefined : chalk.yellow(i18n.t('doctor.tool_not_found', { tool: tool.displayName }))
|
|
100
|
+
message: isInstalled ? undefined : chalk.yellow(i18n.t('doctor.tool_not_found', { tool: tool.displayName })),
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
await new Promise(resolve => setTimeout(resolve, 800));
|
|
@@ -120,7 +120,7 @@ export async function doctorCommand() {
|
|
|
120
120
|
console.log(chalk.green.bold(i18n.t('doctor.all_good')));
|
|
121
121
|
}
|
|
122
122
|
else {
|
|
123
|
-
console.log(chalk.gray(
|
|
123
|
+
console.log(chalk.gray(`\n${i18n.t('doctor.suggestions')}:`));
|
|
124
124
|
console.log(chalk.gray('- Run "chelper init" to configure missing settings'));
|
|
125
125
|
console.log(chalk.gray('- Check your network connection'));
|
|
126
126
|
console.log(chalk.gray('- Ensure required tools are installed'));
|
package/dist/commands/index.d.ts
CHANGED
package/dist/commands/index.js
CHANGED
package/dist/commands/lang.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
1
2
|
import { configManager } from '../lib/config.js';
|
|
2
3
|
import { i18n } from '../lib/i18n.js';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
4
|
export async function langCommand(args) {
|
|
5
5
|
if (args.length === 0 || args[0] === 'show') {
|
|
6
6
|
// Show current language
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,16 +17,16 @@ export async function validateApiKey(apiKey) {
|
|
|
17
17
|
method: 'GET',
|
|
18
18
|
headers: {
|
|
19
19
|
'Authorization': `Bearer ${apiKey}`,
|
|
20
|
-
'Content-Type': 'application/json'
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
21
|
},
|
|
22
|
-
signal: controller.signal
|
|
22
|
+
signal: controller.signal,
|
|
23
23
|
});
|
|
24
24
|
clearTimeout(timeoutId);
|
|
25
25
|
if (response.status === 401) {
|
|
26
26
|
return {
|
|
27
27
|
valid: false,
|
|
28
28
|
error: 'invalid_api_key',
|
|
29
|
-
message: 'API Key is invalid or expired'
|
|
29
|
+
message: 'API Key is invalid or expired',
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
if (response.ok) {
|
|
@@ -47,7 +47,7 @@ export async function validateApiKey(apiKey) {
|
|
|
47
47
|
return {
|
|
48
48
|
valid: false,
|
|
49
49
|
error: 'unknown_error',
|
|
50
|
-
message: `HTTP ${response.status}: ${response.statusText}
|
|
50
|
+
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
catch (error) {
|
|
@@ -57,19 +57,19 @@ export async function validateApiKey(apiKey) {
|
|
|
57
57
|
return {
|
|
58
58
|
valid: false,
|
|
59
59
|
error: 'network_error',
|
|
60
|
-
message: 'Request timeout'
|
|
60
|
+
message: 'Request timeout',
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
return {
|
|
64
64
|
valid: false,
|
|
65
65
|
error: 'network_error',
|
|
66
|
-
message: error.message
|
|
66
|
+
message: error.message,
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
return {
|
|
70
70
|
valid: false,
|
|
71
71
|
error: 'network_error',
|
|
72
|
-
message: 'Network connection failed'
|
|
72
|
+
message: 'Network connection failed',
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
4
|
// 默认配置
|
|
5
5
|
export const DEFAULT_CONFIG = {
|
|
6
6
|
ANTHROPIC_BASE_URL: 'https://code-api.x-aio.com/anthropic',
|
|
7
7
|
ANTHROPIC_API_KEY: 'sk-xxx',
|
|
8
8
|
ANTHROPIC_DEFAULT_HAIKU_MODEL: 'Qwen3-Coder-30B-A3B-Instruct',
|
|
9
9
|
ANTHROPIC_DEFAULT_SONNET_MODEL: 'MiniMax-M2',
|
|
10
|
-
ANTHROPIC_DEFAULT_OPUS_MODEL: 'Qwen3-Coder-480B-A35B-Instruct'
|
|
10
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: 'Qwen3-Coder-480B-A35B-Instruct',
|
|
11
11
|
};
|
|
12
12
|
export class ClaudeCodeManager {
|
|
13
13
|
static instance;
|
|
@@ -115,9 +115,9 @@ export class ClaudeCodeManager {
|
|
|
115
115
|
method: 'GET',
|
|
116
116
|
headers: {
|
|
117
117
|
'Authorization': `Bearer ${apiKey}`,
|
|
118
|
-
'Content-Type': 'application/json'
|
|
118
|
+
'Content-Type': 'application/json',
|
|
119
119
|
},
|
|
120
|
-
signal: controller.signal
|
|
120
|
+
signal: controller.signal,
|
|
121
121
|
});
|
|
122
122
|
clearTimeout(timeoutId);
|
|
123
123
|
if (!response.ok) {
|
|
@@ -155,8 +155,8 @@ export class ClaudeCodeManager {
|
|
|
155
155
|
ANTHROPIC_DEFAULT_SONNET_MODEL: config.sonnetModel,
|
|
156
156
|
ANTHROPIC_DEFAULT_OPUS_MODEL: config.opusModel,
|
|
157
157
|
API_TIMEOUT_MS: '3000000',
|
|
158
|
-
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:
|
|
159
|
-
}
|
|
158
|
+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
|
|
159
|
+
},
|
|
160
160
|
};
|
|
161
161
|
this.saveSettings(newSettings);
|
|
162
162
|
}
|
|
@@ -174,10 +174,10 @@ export class ClaudeCodeManager {
|
|
|
174
174
|
}
|
|
175
175
|
return {
|
|
176
176
|
apiKey,
|
|
177
|
-
haikuModel: settings.env.ANTHROPIC_DEFAULT_HAIKU_MODEL ||
|
|
178
|
-
sonnetModel: settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL ||
|
|
179
|
-
opusModel: settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL ||
|
|
180
|
-
baseUrl: settings.env.ANTHROPIC_BASE_URL ||
|
|
177
|
+
haikuModel: settings.env.ANTHROPIC_DEFAULT_HAIKU_MODEL || '',
|
|
178
|
+
sonnetModel: settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL || '',
|
|
179
|
+
opusModel: settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL || '',
|
|
180
|
+
baseUrl: settings.env.ANTHROPIC_BASE_URL || '',
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
183
|
/**
|
|
@@ -191,7 +191,7 @@ export class ClaudeCodeManager {
|
|
|
191
191
|
const { ANTHROPIC_BASE_URL: _1, ANTHROPIC_API_KEY: _2, ANTHROPIC_DEFAULT_HAIKU_MODEL: _3, ANTHROPIC_DEFAULT_SONNET_MODEL: _4, ANTHROPIC_DEFAULT_OPUS_MODEL: _5, API_TIMEOUT_MS: _6, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: _7, ANTHROPIC_AUTH_TOKEN: _8, ...otherEnv } = currentSettings.env;
|
|
192
192
|
const newSettings = {
|
|
193
193
|
...currentSettings,
|
|
194
|
-
env: otherEnv
|
|
194
|
+
env: otherEnv,
|
|
195
195
|
};
|
|
196
196
|
if (newSettings.env && Object.keys(newSettings.env).length === 0) {
|
|
197
197
|
delete newSettings.env;
|
package/dist/lib/command.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import chalk from 'chalk';
|
|
1
5
|
import { Command as Commander } from 'commander';
|
|
2
|
-
import {
|
|
6
|
+
import { authCommand, configCommand, doctorCommand, langCommand } from '../commands/index.js';
|
|
3
7
|
import { configManager } from './config.js';
|
|
8
|
+
import { i18n } from './i18n.js';
|
|
4
9
|
import { wizard } from './wizard.js';
|
|
5
|
-
import { langCommand, authCommand, doctorCommand, configCommand } from '../commands/index.js';
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
import { readFileSync } from 'fs';
|
|
8
|
-
import { join, dirname } from 'path';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
10
|
export class Command {
|
|
11
11
|
program;
|
|
12
12
|
constructor() {
|
|
@@ -133,7 +133,7 @@ export class Command {
|
|
|
133
133
|
// Custom help
|
|
134
134
|
this.program.configureHelp({
|
|
135
135
|
sortSubcommands: true,
|
|
136
|
-
subcommandTerm:
|
|
136
|
+
subcommandTerm: cmd => `${cmd.name()} ${cmd.usage()}`,
|
|
137
137
|
});
|
|
138
138
|
// Add examples to help
|
|
139
139
|
this.program.addHelpText('after', `
|
package/dist/lib/config.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export interface ChelperConfig {
|
|
|
4
4
|
haikuModel?: string;
|
|
5
5
|
sonnetModel?: string;
|
|
6
6
|
opusModel?: string;
|
|
7
|
+
openCodeModel?: string;
|
|
8
|
+
openCodeSmallModel?: string;
|
|
7
9
|
}
|
|
8
10
|
export declare class ConfigManager {
|
|
9
11
|
private static instance;
|
|
@@ -33,5 +35,13 @@ export declare class ConfigManager {
|
|
|
33
35
|
sonnetModel?: string;
|
|
34
36
|
opusModel?: string;
|
|
35
37
|
}): void;
|
|
38
|
+
getOpenCodeModels(): {
|
|
39
|
+
openCodeModel?: string;
|
|
40
|
+
openCodeSmallModel?: string;
|
|
41
|
+
};
|
|
42
|
+
setOpenCodeModels(models: {
|
|
43
|
+
openCodeModel?: string;
|
|
44
|
+
openCodeSmallModel?: string;
|
|
45
|
+
}): void;
|
|
36
46
|
}
|
|
37
47
|
export declare const configManager: ConfigManager;
|
package/dist/lib/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
4
|
import * as yaml from 'js-yaml';
|
|
5
5
|
export class ConfigManager {
|
|
6
6
|
static instance;
|
|
@@ -42,7 +42,7 @@ export class ConfigManager {
|
|
|
42
42
|
lang: 'en_US',
|
|
43
43
|
haikuModel: 'Qwen3-Coder-30B-A3B-Instruct',
|
|
44
44
|
sonnetModel: 'MiniMax-M2',
|
|
45
|
-
opusModel: 'Qwen3-Coder-480B-A35B-Instruct'
|
|
45
|
+
opusModel: 'Qwen3-Coder-480B-A35B-Instruct',
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
saveConfig(config) {
|
|
@@ -87,11 +87,20 @@ export class ConfigManager {
|
|
|
87
87
|
return {
|
|
88
88
|
haikuModel: this.config.haikuModel,
|
|
89
89
|
sonnetModel: this.config.sonnetModel,
|
|
90
|
-
opusModel: this.config.opusModel
|
|
90
|
+
opusModel: this.config.opusModel,
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
setModels(models) {
|
|
94
94
|
this.updateConfig(models);
|
|
95
95
|
}
|
|
96
|
+
getOpenCodeModels() {
|
|
97
|
+
return {
|
|
98
|
+
openCodeModel: this.config.openCodeModel,
|
|
99
|
+
openCodeSmallModel: this.config.openCodeSmallModel,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
setOpenCodeModels(models) {
|
|
103
|
+
this.updateConfig(models);
|
|
104
|
+
}
|
|
96
105
|
}
|
|
97
106
|
export const configManager = ConfigManager.getInstance();
|
package/dist/lib/i18n.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
4
|
class I18n {
|
|
5
5
|
static instance;
|
|
6
6
|
currentLocale = 'en_US';
|
|
@@ -61,7 +61,7 @@ class I18n {
|
|
|
61
61
|
else {
|
|
62
62
|
// Try language-only match (e.g., 'en' from 'en-US')
|
|
63
63
|
const langOnly = localeCode.split('-')[0];
|
|
64
|
-
const matchingLocale = Array.from(this.translations.keys()).find(key => key.startsWith(langOnly
|
|
64
|
+
const matchingLocale = Array.from(this.translations.keys()).find(key => key.startsWith(`${langOnly}_`));
|
|
65
65
|
if (matchingLocale) {
|
|
66
66
|
this.currentLocale = matchingLocale;
|
|
67
67
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export declare const OPENCODE_DEFAULT_CONFIG: {
|
|
2
|
+
BASE_URL: string;
|
|
3
|
+
PROVIDER_NAME: string;
|
|
4
|
+
DEFAULT_MODEL: string;
|
|
5
|
+
DEFAULT_SMALL_MODEL: string;
|
|
6
|
+
DEFAULT_CONTEXT: number;
|
|
7
|
+
DEFAULT_OUTPUT: number;
|
|
8
|
+
VISION_CONTEXT: number;
|
|
9
|
+
VISION_OUTPUT: number;
|
|
10
|
+
};
|
|
11
|
+
export interface ModelInfo {
|
|
12
|
+
id: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
context_length?: number;
|
|
15
|
+
max_output_tokens?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface OpenCodeModelEntry {
|
|
18
|
+
name?: string;
|
|
19
|
+
limit?: {
|
|
20
|
+
context?: number;
|
|
21
|
+
output?: number;
|
|
22
|
+
};
|
|
23
|
+
modalities?: {
|
|
24
|
+
input?: string[];
|
|
25
|
+
output?: string[];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface OpenCodeProviderConfig {
|
|
29
|
+
npm: string;
|
|
30
|
+
name?: string;
|
|
31
|
+
options: {
|
|
32
|
+
baseURL: string;
|
|
33
|
+
apiKey?: string;
|
|
34
|
+
};
|
|
35
|
+
models: Record<string, OpenCodeModelEntry>;
|
|
36
|
+
}
|
|
37
|
+
export interface OpenCodeConfig {
|
|
38
|
+
$schema?: string;
|
|
39
|
+
model?: string;
|
|
40
|
+
small_model?: string;
|
|
41
|
+
provider?: Record<string, OpenCodeProviderConfig>;
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
}
|
|
44
|
+
export interface OpenCodeModelConfig {
|
|
45
|
+
apiKey: string;
|
|
46
|
+
model: string;
|
|
47
|
+
smallModel: string;
|
|
48
|
+
baseUrl?: string;
|
|
49
|
+
}
|
|
50
|
+
export declare class OpenCodeManager {
|
|
51
|
+
private static instance;
|
|
52
|
+
private configPath;
|
|
53
|
+
private cachedModels;
|
|
54
|
+
private constructor();
|
|
55
|
+
static getInstance(): OpenCodeManager;
|
|
56
|
+
/**
|
|
57
|
+
* Ensure config directory exists
|
|
58
|
+
*/
|
|
59
|
+
private ensureDir;
|
|
60
|
+
/**
|
|
61
|
+
* Read opencode.json config
|
|
62
|
+
*/
|
|
63
|
+
getConfig(): OpenCodeConfig;
|
|
64
|
+
/**
|
|
65
|
+
* Save opencode.json config
|
|
66
|
+
*/
|
|
67
|
+
saveConfig(config: OpenCodeConfig): void;
|
|
68
|
+
/**
|
|
69
|
+
* Fetch available models from API
|
|
70
|
+
*/
|
|
71
|
+
fetchAvailableModels(apiKey: string): Promise<ModelInfo[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Check if model is a vision model (contains "VL" or ends with "V")
|
|
74
|
+
*/
|
|
75
|
+
private isVisionModel;
|
|
76
|
+
/**
|
|
77
|
+
* Build models object from fetched model list
|
|
78
|
+
*/
|
|
79
|
+
private buildModelsConfig;
|
|
80
|
+
/**
|
|
81
|
+
* Save model config to OpenCode (merge, not overwrite)
|
|
82
|
+
*/
|
|
83
|
+
saveModelConfig(config: OpenCodeModelConfig): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Get current model config
|
|
86
|
+
*/
|
|
87
|
+
getModelConfig(): OpenCodeModelConfig | null;
|
|
88
|
+
/**
|
|
89
|
+
* Clear model config (only remove xaio provider)
|
|
90
|
+
*/
|
|
91
|
+
clearModelConfig(): void;
|
|
92
|
+
}
|
|
93
|
+
export declare const openCodeManager: OpenCodeManager;
|