1314mc-helper 0.2.21

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 ADDED
@@ -0,0 +1,160 @@
1
+ # Duojie Helper
2
+
3
+ 🎮 **Duojie API 一键配置助手** - 支持主流 AI 编程工具
4
+
5
+ 一条命令,配置所有 AI 编程工具!
6
+
7
+ ## ✨ 特性
8
+
9
+ - 🚀 **一键配置** - 交互式向导,傻瓜式操作
10
+ - 🔄 **智能合并** - 不覆盖已有配置,只添加/更新 Duojie 相关配置
11
+ - 🛠️ **多工具支持** - Claude Code, OpenClaw, OpenCode, Cursor, Cline, Codex, Continue
12
+ - 📊 **状态检测** - 查看各工具配置状态
13
+ - ↩️ **可撤销** - 随时撤销配置,恢复原状
14
+
15
+ ## 🚀 快速开始
16
+
17
+ ```bash
18
+ # 一键配置(推荐使用 @latest 确保最新版本)
19
+ npx duojie-helper@latest
20
+
21
+ # 或者全局安装
22
+ npm install -g duojie-helper
23
+ duojie
24
+ ```
25
+
26
+ > ⚠️ **提示**: 建议使用 `npx duojie-helper@latest` 以确保使用最新版本。如果遇到版本问题,可以清理 npx 缓存:
27
+ > - Windows: `rd /s /q "%USERPROFILE%\.npm\_npx"`
28
+ > - macOS/Linux: `rm -rf ~/.npm/_npx`
29
+
30
+ 运行后会引导你:
31
+ 1. 输入 Duojie API Key
32
+ 2. 选择要配置的工具
33
+ 3. 自动配置所有可用模型!
34
+
35
+ ## 📋 支持的工具
36
+
37
+ ### 自动配置
38
+
39
+ | 工具 | 命令 | 说明 |
40
+ |------|------|------|
41
+ | Claude Code | `claude` | Anthropic 官方 CLI |
42
+ | OpenClaw | `openclaw` | 多平台 AI 助手网关 |
43
+ | OpenCode | `opencode` | 终端 AI 编码助手 |
44
+ | Continue | `continue` | VS Code/JetBrains 插件 |
45
+ | Codex CLI | `codex` | OpenAI Codex 命令行 |
46
+
47
+ ### 手动配置(输出配置信息)
48
+
49
+ | 工具 | 命令 | 说明 |
50
+ |------|------|------|
51
+ | Cursor | `cursor` | AI 代码编辑器 (需 Pro 订阅) |
52
+ | Cline | `cline` | VS Code AI 插件 |
53
+
54
+ ## 🔧 命令
55
+
56
+ ```bash
57
+ # 交互式配置向导
58
+ npx duojie-helper@latest
59
+ npx duojie-helper@latest init
60
+
61
+ # 配置单个工具
62
+ npx duojie-helper@latest config claude -k sk-xxx
63
+ npx duojie-helper@latest config opencode
64
+
65
+ # 查看配置状态
66
+ npx duojie-helper@latest status
67
+
68
+ # 列出支持的工具
69
+ npx duojie-helper@latest list
70
+
71
+ # 撤销配置
72
+ npx duojie-helper@latest revoke # 撤销全部
73
+ npx duojie-helper@latest revoke claude # 撤销单个
74
+ ```
75
+
76
+ ## 📖 使用示例
77
+
78
+ ### 交互式配置(推荐)
79
+
80
+ ```bash
81
+ $ npx duojie-helper@latest
82
+
83
+ ╔═══════════════════════════════════════════════════════════╗
84
+ ║ 🎮 Duojie API 配置助手 ║
85
+ ╚═══════════════════════════════════════════════════════════╝
86
+
87
+ ? 请输入你的 Duojie API Key: ********
88
+ ? 选择要配置的工具:
89
+ ◉ 🤖 Claude Code - 自动配置
90
+ ◉ 🦞 OpenClaw / Moltbot - 自动配置
91
+ ◉ 🖥️ OpenCode - 自动配置
92
+ ◯ 📝 Cursor - 输出配置信息
93
+
94
+ ✅ 配置结果:
95
+ ──────────────────────────────────────────────────
96
+ ✓ Claude Code: 已配置 → ~/.claude/settings.json
97
+ ✓ OpenClaw: 已配置 3 个模型 → ~/.openclaw/openclaw.json
98
+ ✓ OpenCode: 已配置 3 个模型 → ~/.config/opencode/opencode.json
99
+ ──────────────────────────────────────────────────
100
+
101
+ 🎉 配置完成!
102
+ ```
103
+
104
+ ### 配置单个工具
105
+
106
+ ```bash
107
+ # 配置 Claude Code
108
+ npx duojie-helper@latest config claude -k sk-your-api-key
109
+
110
+ # 配置 OpenCode(会提示输入 key)
111
+ npx duojie-helper@latest config opencode
112
+ ```
113
+
114
+ ### 查看状态
115
+
116
+ ```bash
117
+ $ npx duojie-helper@latest status
118
+
119
+ 📊 配置状态:
120
+
121
+ ✓ Claude Code 已配置 Duojie API
122
+ ✓ OpenClaw 已配置 Duojie API
123
+ ✓ OpenCode 已配置 Duojie API
124
+ ○ Continue 未配置
125
+ ○ Cursor 未检测到
126
+ ```
127
+
128
+ ## 🔑 获取 API Key
129
+
130
+ 访问 [api.duojie.games](https://api.duojie.games) 获取你的 API Key。
131
+
132
+ ## 📝 配置文件位置
133
+
134
+ | 工具 | 配置路径 |
135
+ |------|----------|
136
+ | Claude Code | `~/.claude/settings.json` |
137
+ | OpenClaw | `~/.openclaw/openclaw.json` |
138
+ | OpenCode | `~/.config/opencode/opencode.json` |
139
+ | Continue | `~/.continue/config.json` |
140
+ | Codex | `~/.codex/config.toml` |
141
+ | Cursor | Cursor Settings → Models |
142
+ | Cline | Cline 插件设置 |
143
+
144
+ ## ⚠️ 注意事项
145
+
146
+ 1. **不会覆盖已有配置** - 工具只会添加或更新 Duojie 相关的配置项
147
+ 2. **重启生效** - 配置后需要重启相应的工具
148
+ 3. **可随时撤销** - 使用 `revoke` 命令可以撤销配置
149
+
150
+ ## 🤝 贡献
151
+
152
+ 欢迎提交 Issue 和 PR!
153
+
154
+ ## 📄 License
155
+
156
+ MIT
157
+
158
+ ---
159
+
160
+ Made with ❤️ by [Duojie](https://api.duojie.games)
package/bin/cli.js ADDED
@@ -0,0 +1,328 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import inquirer from 'inquirer';
5
+ import chalk from 'chalk';
6
+ import ora from 'ora';
7
+ import { createRequire } from 'module';
8
+ import { configureAll, configureTool, listTools, showStatus, revokeKey, fetchModels, getModels } from '../src/index.js';
9
+
10
+ const require = createRequire(import.meta.url);
11
+ const pkg = require('../package.json');
12
+
13
+ const program = new Command();
14
+
15
+ program
16
+ .name('mc-helper')
17
+ .description('🎮 1314mc API 一键配置助手 - 支持主流 AI 编程工具')
18
+ .version(pkg.version);
19
+
20
+ // 默认命令 - 交互式配置
21
+ program
22
+ .command('init', { isDefault: true })
23
+ .description('交互式配置向导')
24
+ .action(async () => {
25
+ console.log(chalk.cyan(`
26
+ ╔═══════════════════════════════════════════════════════════╗
27
+ ║ ║
28
+ ║ 🎮 1314mc API 配置助手 ║
29
+ ║ ║
30
+ ║ 一键配置你的 AI 编程工具 ║
31
+ ║ 支持: Claude Code, OpenClaw, Cursor, Cline 等 ║
32
+ ║ ║
33
+ ║ 提示: 按 Ctrl+C 可随时退出 ║
34
+ ║ ║
35
+ ╚═══════════════════════════════════════════════════════════╝
36
+ `));
37
+
38
+ let apiKey = null;
39
+ let tools = null;
40
+ let step = 1;
41
+
42
+ try {
43
+ while (step > 0) {
44
+ if (step === 1) {
45
+ // 步骤 1: 输入 API Key
46
+ const result = await inquirer.prompt([
47
+ {
48
+ type: 'input',
49
+ name: 'apiKey',
50
+ message: '请输入你的 1314mc API Key (Ctrl+C 退出):',
51
+ filter: (input) => input.trim(),
52
+ validate: (input) => {
53
+ if (!input || input.length < 10) {
54
+ return 'API Key 不能为空且长度至少 10 位';
55
+ }
56
+ return true;
57
+ }
58
+ }
59
+ ]);
60
+
61
+ apiKey = result.apiKey.trim();
62
+
63
+ // 验证 API Key 并获取模型列表
64
+ const modelSpinner = ora('正在验证 API Key 并获取模型列表...').start();
65
+ const models = await fetchModels(apiKey);
66
+
67
+ const totalModels = (models.claude?.length || 0) +
68
+ (models.gpt?.length || 0) +
69
+ (models.gemini?.length || 0) +
70
+ (models.other?.length || 0);
71
+
72
+ if (totalModels === 0) {
73
+ modelSpinner.fail('API Key 无效或无法获取模型列表');
74
+ continue; // 重新输入
75
+ }
76
+
77
+ modelSpinner.succeed(`验证成功!可用模型: ${totalModels} 个`);
78
+ step = 2;
79
+ }
80
+
81
+ else if (step === 2) {
82
+ // 步骤 2: 选择要配置的工具
83
+ console.log(chalk.gray('\n 提示: 按 Ctrl+C 返回上一步\n'));
84
+
85
+ try {
86
+ const result = await inquirer.prompt([
87
+ {
88
+ type: 'checkbox',
89
+ name: 'tools',
90
+ message: '选择要配置的工具 (空格选择,回车确认):',
91
+ loop: false,
92
+ choices: [
93
+ { name: '🤖 Claude Code - 自动配置', value: 'claude' },
94
+ { name: '🏭 Droid - 自动配置', value: 'droid' },
95
+ { name: '🦞 OpenClaw / Moltbot - 自动配置', value: 'openclaw' },
96
+ { name: '🖥️ OpenCode - 自动配置', value: 'opencode' },
97
+ { name: '💻 Continue - 自动配置', value: 'continue' },
98
+ { name: '🤖 Codex CLI - 自动配置', value: 'codex' },
99
+ new inquirer.Separator('── 以下需要手动配置 ──'),
100
+ { name: '📝 Cursor - 输出配置信息', value: 'cursor' },
101
+ { name: '🔌 Cline (VS Code) - 输出配置信息', value: 'cline' },
102
+ ],
103
+ validate: (input) => {
104
+ if (input.length === 0) {
105
+ return '请至少选择一个工具 (使用空格键选择)';
106
+ }
107
+ return true;
108
+ }
109
+ }
110
+ ]);
111
+
112
+ tools = result.tools;
113
+ step = 3;
114
+ } catch (err) {
115
+ if (err.message?.includes('User force closed')) {
116
+ step = 1; // 返回上一步
117
+ console.log(chalk.yellow('\n↩ 返回上一步...\n'));
118
+ continue;
119
+ }
120
+ throw err;
121
+ }
122
+ }
123
+
124
+ else if (step === 3) {
125
+ // 步骤 3: 执行配置
126
+ const spinner = ora('正在配置...').start();
127
+
128
+ const results = await configureAll(apiKey, tools);
129
+
130
+ spinner.succeed('配置完成!');
131
+
132
+ // 显示结果
133
+ console.log('\n' + chalk.green('✅ 配置结果:'));
134
+ console.log(chalk.gray('─'.repeat(60)));
135
+
136
+ const autoConfigured = [];
137
+ const manualRequired = [];
138
+
139
+ for (const result of results) {
140
+ if (result.success) {
141
+ if (result.manual) {
142
+ manualRequired.push(result);
143
+ } else {
144
+ autoConfigured.push(result);
145
+ console.log(chalk.green(` ✓ ${result.tool}: ${result.message}`));
146
+ }
147
+ } else {
148
+ console.log(chalk.red(` ✗ ${result.tool}: ${result.message}`));
149
+ }
150
+ }
151
+
152
+ console.log(chalk.gray('─'.repeat(60)));
153
+
154
+ // 显示需要手动配置的工具
155
+ if (manualRequired.length > 0) {
156
+ console.log(chalk.yellow('\n📋 以下工具需要手动配置:\n'));
157
+
158
+ for (const result of manualRequired) {
159
+ console.log(chalk.cyan(`\n━━━ ${result.tool} ━━━`));
160
+ if (result.instructions) {
161
+ console.log(result.instructions);
162
+ }
163
+ }
164
+ }
165
+
166
+ console.log(chalk.cyan('\n🎉 配置完成!\n'));
167
+
168
+ // 显示后续步骤
169
+ if (autoConfigured.length > 0) {
170
+ console.log(chalk.yellow('📋 后续步骤:'));
171
+ if (tools.includes('claude')) {
172
+ console.log(chalk.gray(' • Claude Code: 重新打开终端窗口'));
173
+ }
174
+ if (tools.includes('droid')) {
175
+ console.log(chalk.gray(' • Droid: 重启 Factory'));
176
+ }
177
+ if (tools.includes('openclaw')) {
178
+ console.log(chalk.gray(' • OpenClaw: 运行 openclaw gateway restart'));
179
+ }
180
+ if (tools.includes('opencode')) {
181
+ console.log(chalk.gray(' • OpenCode: 重启 OpenCode'));
182
+ }
183
+ if (tools.includes('continue')) {
184
+ console.log(chalk.gray(' • Continue: 重启 VS Code/JetBrains'));
185
+ }
186
+ if (tools.includes('codex')) {
187
+ console.log(chalk.gray(' • Codex CLI: 已写入 ~/.codex/config.toml(无需设置 DUOJIE_API_KEY)'));
188
+ }
189
+ console.log('');
190
+ }
191
+
192
+ step = 0; // 完成,退出循环
193
+ }
194
+ }
195
+
196
+ } catch (error) {
197
+ if (error.message?.includes('User force closed')) {
198
+ console.log(chalk.yellow('\n\n👋 已退出配置向导\n'));
199
+ process.exit(0);
200
+ }
201
+ console.error(chalk.red('\n❌ 配置失败:'), error.message);
202
+ process.exit(1);
203
+ }
204
+ });
205
+
206
+ // 配置单个工具
207
+ program
208
+ .command('config <tool>')
209
+ .description('配置单个工具 (claude/droid/openclaw/opencode/cursor/cline/codex/continue)')
210
+ .option('-k, --key <apiKey>', 'API Key')
211
+ .action(async (tool, options) => {
212
+ try {
213
+ let apiKey = options.key;
214
+
215
+ if (!apiKey) {
216
+ const answer = await inquirer.prompt([
217
+ {
218
+ type: 'input',
219
+ name: 'apiKey',
220
+ message: '请输入你的 1314mc API Key:',
221
+ filter: (input) => input.trim(),
222
+ }
223
+ ]);
224
+ apiKey = answer.apiKey;
225
+ } else {
226
+ apiKey = apiKey.trim();
227
+ }
228
+
229
+ // 获取模型列表
230
+ const spinner = ora('正在验证 API Key...').start();
231
+ await fetchModels(apiKey);
232
+ spinner.succeed('验证成功');
233
+
234
+ const configSpinner = ora(`正在配置 ${tool}...`).start();
235
+ const result = await configureTool(tool, apiKey);
236
+
237
+ if (result.success) {
238
+ configSpinner.succeed(result.message);
239
+
240
+ // 如果需要手动配置,显示说明
241
+ if (result.manual && result.instructions) {
242
+ console.log(chalk.yellow('\n📋 手动配置说明:\n'));
243
+ console.log(result.instructions);
244
+ }
245
+ } else {
246
+ configSpinner.fail(result.message);
247
+ }
248
+ } catch (error) {
249
+ console.error(chalk.red('配置失败:'), error.message);
250
+ process.exit(1);
251
+ }
252
+ });
253
+
254
+ // 查看状态
255
+ program
256
+ .command('status')
257
+ .description('查看当前配置状态')
258
+ .action(async () => {
259
+ await showStatus();
260
+ });
261
+
262
+ // 列出支持的工具
263
+ program
264
+ .command('list')
265
+ .description('列出支持的工具')
266
+ .action(() => {
267
+ listTools();
268
+ });
269
+
270
+ // 撤销配置
271
+ program
272
+ .command('revoke [tool]')
273
+ .description('撤销配置 (不指定工具则撤销全部)')
274
+ .action(async (tool) => {
275
+ const { confirm } = await inquirer.prompt([
276
+ {
277
+ type: 'confirm',
278
+ name: 'confirm',
279
+ message: tool
280
+ ? `确定要撤销 ${tool} 的配置吗?`
281
+ : '确定要撤销所有工具的配置吗?',
282
+ default: false
283
+ }
284
+ ]);
285
+
286
+ if (confirm) {
287
+ await revokeKey(tool);
288
+ }
289
+ });
290
+
291
+ // 帮助信息
292
+ program
293
+ .command('help')
294
+ .description('显示帮助信息')
295
+ .action(() => {
296
+ console.log(chalk.cyan(`
297
+ 🎮 1314mc API 配置助手
298
+
299
+ 使用方法:
300
+ npx mc-helper # 交互式配置向导
301
+ npx mc-helper init # 同上
302
+ npx mc-helper config <tool> -k <key> # 配置单个工具
303
+ npx mc-helper status # 查看配置状态
304
+ npx mc-helper list # 列出支持的工具
305
+ npx mc-helper revoke # 撤销配置
306
+
307
+ 支持的工具 (自动配置):
308
+ • claude - Claude Code (Anthropic 官方 CLI)
309
+ • droid - Droid (Factory 的 AI 编程工具)
310
+ • openclaw - OpenClaw / Moltbot
311
+ • opencode - OpenCode (终端 AI 编码助手)
312
+ • continue - Continue (VS Code/JetBrains)
313
+ • codex - OpenAI Codex CLI
314
+
315
+ 支持的工具 (输出配置信息):
316
+ • cursor - Cursor 编辑器 (需手动在 UI 配置)
317
+ • cline - Cline VS Code 插件 (需手动在 UI 配置)
318
+
319
+ 示例:
320
+ npx mc-helper # 交互式配置
321
+ npx mc-helper config claude -k sk-xxx # 只配置 Claude Code
322
+ npx mc-helper config opencode # 配置 OpenCode
323
+
324
+ 获取 API Key: http://www.1314mc.net:3333
325
+ `));
326
+ });
327
+
328
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "1314mc-helper",
3
+ "version": "0.2.21",
4
+ "description": "1314mc API 一键配置助手 - 支持 Claude Code, Droid, OpenClaw, Cursor, Cline 等主流 AI 编程工具",
5
+ "type": "module",
6
+ "bin": {
7
+ "mc-helper": "./bin/cli.js",
8
+ "mc": "./bin/cli.js"
9
+ },
10
+ "scripts": {
11
+ "dev": "node bin/cli.js",
12
+ "build": "echo 'No build needed'",
13
+ "test": "node bin/cli.js --help"
14
+ },
15
+ "keywords": [
16
+ "1314mc",
17
+ "ai",
18
+ "api",
19
+ "claude",
20
+ "droid",
21
+ "factory",
22
+ "openclaw",
23
+ "opencode",
24
+ "cursor",
25
+ "cline",
26
+ "config",
27
+ "helper"
28
+ ],
29
+ "author": "Mc1314Server",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/Mc1314Server/mc-helper.git"
34
+ },
35
+ "homepage": "https://github.com/Mc1314Server/mc-helper#readme",
36
+ "bugs": {
37
+ "url": "https://github.com/Mc1314Server/mc-helper/issues"
38
+ },
39
+ "files": [
40
+ "bin",
41
+ "src",
42
+ "templates",
43
+ "README.md"
44
+ ],
45
+ "dependencies": {
46
+ "@iarna/toml": "^2.2.5",
47
+ "chalk": "^5.3.0",
48
+ "commander": "^12.1.0",
49
+ "inquirer": "^9.2.12",
50
+ "ora": "^8.0.1",
51
+ "fs-extra": "^11.2.0"
52
+ },
53
+ "engines": {
54
+ "node": ">=18.0.0"
55
+ }
56
+ }