duojie-helper 0.2.0 → 0.2.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.
- package/README.md +47 -34
- package/bin/cli.js +4 -3
- package/package.json +1 -1
- package/src/tools/claude.js +56 -8
- package/src/tools/cline.js +1 -1
- package/src/tools/codex.js +2 -2
- package/src/tools/continue.js +3 -3
- package/src/tools/cursor.js +1 -1
- package/src/tools/openclaw.js +4 -4
- package/src/tools/opencode.js +1 -1
package/README.md
CHANGED
|
@@ -8,59 +8,69 @@
|
|
|
8
8
|
|
|
9
9
|
- 🚀 **一键配置** - 交互式向导,傻瓜式操作
|
|
10
10
|
- 🔄 **智能合并** - 不覆盖已有配置,只添加/更新 Duojie 相关配置
|
|
11
|
-
- 🛠️ **多工具支持** - Claude Code, OpenClaw, Cursor, Cline,
|
|
11
|
+
- 🛠️ **多工具支持** - Claude Code, OpenClaw, OpenCode, Cursor, Cline, Codex, Continue
|
|
12
12
|
- 📊 **状态检测** - 查看各工具配置状态
|
|
13
13
|
- ↩️ **可撤销** - 随时撤销配置,恢复原状
|
|
14
14
|
|
|
15
15
|
## 🚀 快速开始
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
#
|
|
19
|
-
npx duojie-helper
|
|
18
|
+
# 一键配置(推荐使用 @latest 确保最新版本)
|
|
19
|
+
npx duojie-helper@latest
|
|
20
20
|
|
|
21
21
|
# 或者全局安装
|
|
22
22
|
npm install -g duojie-helper
|
|
23
23
|
duojie
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
> ⚠️ **提示**: 建议使用 `npx duojie-helper@latest` 以确保使用最新版本。如果遇到版本问题,可以清理 npx 缓存:
|
|
27
|
+
> - Windows: `rd /s /q "%USERPROFILE%\.npm\_npx"`
|
|
28
|
+
> - macOS/Linux: `rm -rf ~/.npm/_npx`
|
|
29
|
+
|
|
26
30
|
运行后会引导你:
|
|
27
31
|
1. 输入 Duojie API Key
|
|
28
32
|
2. 选择要配置的工具
|
|
29
|
-
3.
|
|
30
|
-
4. 自动完成配置!
|
|
33
|
+
3. 自动配置所有可用模型!
|
|
31
34
|
|
|
32
35
|
## 📋 支持的工具
|
|
33
36
|
|
|
37
|
+
### 自动配置
|
|
38
|
+
|
|
34
39
|
| 工具 | 命令 | 说明 |
|
|
35
40
|
|------|------|------|
|
|
36
41
|
| Claude Code | `claude` | Anthropic 官方 CLI |
|
|
37
42
|
| OpenClaw | `openclaw` | 多平台 AI 助手网关 |
|
|
38
|
-
|
|
|
39
|
-
| Cline | `cline` | VS Code AI 插件 |
|
|
40
|
-
| Windsurf | `windsurf` | Codeium AI 编辑器 |
|
|
41
|
-
| Codex CLI | `codex` | OpenAI Codex 命令行 |
|
|
43
|
+
| OpenCode | `opencode` | 终端 AI 编码助手 |
|
|
42
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 插件 |
|
|
43
53
|
|
|
44
54
|
## 🔧 命令
|
|
45
55
|
|
|
46
56
|
```bash
|
|
47
57
|
# 交互式配置向导
|
|
48
|
-
npx duojie-helper
|
|
49
|
-
npx duojie-helper init
|
|
58
|
+
npx duojie-helper@latest
|
|
59
|
+
npx duojie-helper@latest init
|
|
50
60
|
|
|
51
61
|
# 配置单个工具
|
|
52
|
-
npx duojie-helper config claude -k sk-xxx
|
|
53
|
-
npx duojie-helper config
|
|
62
|
+
npx duojie-helper@latest config claude -k sk-xxx
|
|
63
|
+
npx duojie-helper@latest config opencode
|
|
54
64
|
|
|
55
65
|
# 查看配置状态
|
|
56
|
-
npx duojie-helper status
|
|
66
|
+
npx duojie-helper@latest status
|
|
57
67
|
|
|
58
68
|
# 列出支持的工具
|
|
59
|
-
npx duojie-helper list
|
|
69
|
+
npx duojie-helper@latest list
|
|
60
70
|
|
|
61
71
|
# 撤销配置
|
|
62
|
-
npx duojie-helper revoke # 撤销全部
|
|
63
|
-
npx duojie-helper revoke claude # 撤销单个
|
|
72
|
+
npx duojie-helper@latest revoke # 撤销全部
|
|
73
|
+
npx duojie-helper@latest revoke claude # 撤销单个
|
|
64
74
|
```
|
|
65
75
|
|
|
66
76
|
## 📖 使用示例
|
|
@@ -68,7 +78,7 @@ npx duojie-helper revoke claude # 撤销单个
|
|
|
68
78
|
### 交互式配置(推荐)
|
|
69
79
|
|
|
70
80
|
```bash
|
|
71
|
-
$ npx duojie-helper
|
|
81
|
+
$ npx duojie-helper@latest
|
|
72
82
|
|
|
73
83
|
╔═══════════════════════════════════════════════════════════╗
|
|
74
84
|
║ 🎮 Duojie API 配置助手 ║
|
|
@@ -76,15 +86,16 @@ $ npx duojie-helper
|
|
|
76
86
|
|
|
77
87
|
? 请输入你的 Duojie API Key: ********
|
|
78
88
|
? 选择要配置的工具:
|
|
79
|
-
◉ 🤖 Claude Code
|
|
80
|
-
◉ 🦞 OpenClaw / Moltbot
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
◉ 🤖 Claude Code - 自动配置
|
|
90
|
+
◉ 🦞 OpenClaw / Moltbot - 自动配置
|
|
91
|
+
◉ 🖥️ OpenCode - 自动配置
|
|
92
|
+
◯ 📝 Cursor - 输出配置信息
|
|
83
93
|
|
|
84
94
|
✅ 配置结果:
|
|
85
95
|
──────────────────────────────────────────────────
|
|
86
|
-
✓ Claude Code: 已配置 → ~/.claude
|
|
87
|
-
✓ OpenClaw: 已配置 → ~/.openclaw/openclaw.json
|
|
96
|
+
✓ Claude Code: 已配置 → ~/.claude/settings.json
|
|
97
|
+
✓ OpenClaw: 已配置 3 个模型 → ~/.openclaw/openclaw.json
|
|
98
|
+
✓ OpenCode: 已配置 3 个模型 → ~/.config/opencode/opencode.json
|
|
88
99
|
──────────────────────────────────────────────────
|
|
89
100
|
|
|
90
101
|
🎉 配置完成!
|
|
@@ -94,23 +105,24 @@ $ npx duojie-helper
|
|
|
94
105
|
|
|
95
106
|
```bash
|
|
96
107
|
# 配置 Claude Code
|
|
97
|
-
npx duojie-helper config claude -k sk-your-api-key
|
|
108
|
+
npx duojie-helper@latest config claude -k sk-your-api-key
|
|
98
109
|
|
|
99
|
-
# 配置
|
|
100
|
-
npx duojie-helper config
|
|
110
|
+
# 配置 OpenCode(会提示输入 key)
|
|
111
|
+
npx duojie-helper@latest config opencode
|
|
101
112
|
```
|
|
102
113
|
|
|
103
114
|
### 查看状态
|
|
104
115
|
|
|
105
116
|
```bash
|
|
106
|
-
$ npx duojie-helper status
|
|
117
|
+
$ npx duojie-helper@latest status
|
|
107
118
|
|
|
108
119
|
📊 配置状态:
|
|
109
120
|
|
|
110
|
-
✓ Claude Code 已配置 Duojie API
|
|
121
|
+
✓ Claude Code 已配置 Duojie API
|
|
111
122
|
✓ OpenClaw 已配置 Duojie API
|
|
123
|
+
✓ OpenCode 已配置 Duojie API
|
|
124
|
+
○ Continue 未配置
|
|
112
125
|
○ Cursor 未检测到
|
|
113
|
-
○ Cline 未检测到
|
|
114
126
|
```
|
|
115
127
|
|
|
116
128
|
## 🔑 获取 API Key
|
|
@@ -121,12 +133,13 @@ $ npx duojie-helper status
|
|
|
121
133
|
|
|
122
134
|
| 工具 | 配置路径 |
|
|
123
135
|
|------|----------|
|
|
124
|
-
| Claude Code | `~/.claude
|
|
136
|
+
| Claude Code | `~/.claude/settings.json` |
|
|
125
137
|
| OpenClaw | `~/.openclaw/openclaw.json` |
|
|
126
|
-
|
|
|
127
|
-
| Cline | VS Code `settings.json` |
|
|
138
|
+
| OpenCode | `~/.config/opencode/opencode.json` |
|
|
128
139
|
| Continue | `~/.continue/config.json` |
|
|
129
|
-
| Codex | `~/.codex/config.
|
|
140
|
+
| Codex | `~/.codex/config.toml` |
|
|
141
|
+
| Cursor | Cursor Settings → Models |
|
|
142
|
+
| Cline | Cline 插件设置 |
|
|
130
143
|
|
|
131
144
|
## ⚠️ 注意事项
|
|
132
145
|
|
package/bin/cli.js
CHANGED
|
@@ -84,9 +84,10 @@ program
|
|
|
84
84
|
type: 'checkbox',
|
|
85
85
|
name: 'tools',
|
|
86
86
|
message: '选择要配置的工具 (空格选择,回车确认):',
|
|
87
|
+
loop: false,
|
|
87
88
|
choices: [
|
|
88
|
-
{ name: '🤖 Claude Code - 自动配置', value: 'claude'
|
|
89
|
-
{ name: '🦞 OpenClaw / Moltbot - 自动配置', value: 'openclaw'
|
|
89
|
+
{ name: '🤖 Claude Code - 自动配置', value: 'claude' },
|
|
90
|
+
{ name: '🦞 OpenClaw / Moltbot - 自动配置', value: 'openclaw' },
|
|
90
91
|
{ name: '🖥️ OpenCode - 自动配置', value: 'opencode' },
|
|
91
92
|
{ name: '💻 Continue - 自动配置', value: 'continue' },
|
|
92
93
|
{ name: '🤖 Codex CLI - 自动配置', value: 'codex' },
|
|
@@ -96,7 +97,7 @@ program
|
|
|
96
97
|
],
|
|
97
98
|
validate: (input) => {
|
|
98
99
|
if (input.length === 0) {
|
|
99
|
-
return '请至少选择一个工具';
|
|
100
|
+
return '请至少选择一个工具 (使用空格键选择)';
|
|
100
101
|
}
|
|
101
102
|
return true;
|
|
102
103
|
}
|
package/package.json
CHANGED
package/src/tools/claude.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import os from 'os';
|
|
4
|
-
import { API_CONFIG } from '../index.js';
|
|
4
|
+
import { API_CONFIG, getModels } from '../index.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 获取 Claude Code 配置路径
|
|
@@ -46,22 +46,63 @@ export async function configureClaudeCode(apiKey) {
|
|
|
46
46
|
settings.env = {};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
// 3.
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
// 3. 获取可用的 Claude 模型
|
|
50
|
+
const models = getModels();
|
|
51
|
+
const claudeModels = models.claude || [];
|
|
52
|
+
|
|
53
|
+
// 查找各类型模型(优先查找 kiro 版本)
|
|
54
|
+
let sonnetModel = null;
|
|
55
|
+
let opusModel = null;
|
|
56
|
+
|
|
57
|
+
for (const m of claudeModels) {
|
|
58
|
+
const id = m.id.toLowerCase();
|
|
59
|
+
// 优先使用 kiro 版本的 opus
|
|
60
|
+
if (id.includes('opus') && id.includes('kiro')) {
|
|
61
|
+
opusModel = m.id;
|
|
62
|
+
} else if (id.includes('opus') && !opusModel) {
|
|
63
|
+
opusModel = m.id;
|
|
64
|
+
}
|
|
65
|
+
// sonnet 模型
|
|
66
|
+
if (id.includes('sonnet') && !sonnetModel) {
|
|
67
|
+
sonnetModel = m.id;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 4. 设置 Duojie API 环境变量
|
|
72
|
+
settings.env.ANTHROPIC_API_KEY = apiKey;
|
|
73
|
+
settings.env.ANTHROPIC_BASE_URL = API_CONFIG.baseUrl;
|
|
52
74
|
settings.env.API_TIMEOUT_MS = "300000";
|
|
53
75
|
settings.env.ANTHROPIC_MAX_TOKENS = "8192";
|
|
54
76
|
|
|
77
|
+
// 配置各类型模型(不配置 haiku/fast 模型)
|
|
78
|
+
if (sonnetModel) {
|
|
79
|
+
settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL = sonnetModel;
|
|
80
|
+
}
|
|
81
|
+
if (opusModel) {
|
|
82
|
+
settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL = opusModel;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 设置默认主模型为 claude-opus-4-5-kiro(或可用的 opus)
|
|
86
|
+
const defaultModel = opusModel || sonnetModel || claudeModels[0]?.id;
|
|
87
|
+
if (defaultModel) {
|
|
88
|
+
settings.model = defaultModel;
|
|
89
|
+
}
|
|
90
|
+
|
|
55
91
|
// 标记为 Duojie 配置
|
|
56
92
|
settings._duojie = {
|
|
57
93
|
configured: true,
|
|
58
94
|
configuredAt: new Date().toISOString(),
|
|
95
|
+
models: {
|
|
96
|
+
default: defaultModel,
|
|
97
|
+
sonnet: sonnetModel,
|
|
98
|
+
opus: opusModel,
|
|
99
|
+
},
|
|
59
100
|
};
|
|
60
101
|
|
|
61
|
-
//
|
|
102
|
+
// 5. 写入 settings.json
|
|
62
103
|
await fs.writeJson(paths.settingsFile, settings, { spaces: 2 });
|
|
63
104
|
|
|
64
|
-
//
|
|
105
|
+
// 6. 创建/更新 .claude.json(跳过登录流程)
|
|
65
106
|
let claudeJson = {};
|
|
66
107
|
if (await fs.pathExists(paths.claudeJson)) {
|
|
67
108
|
try {
|
|
@@ -74,9 +115,12 @@ export async function configureClaudeCode(apiKey) {
|
|
|
74
115
|
claudeJson.hasCompletedOnboarding = true;
|
|
75
116
|
await fs.writeJson(paths.claudeJson, claudeJson, { spaces: 2 });
|
|
76
117
|
|
|
118
|
+
// 统计配置的模型数量
|
|
119
|
+
const configuredModels = [sonnetModel, opusModel].filter(Boolean).length;
|
|
120
|
+
|
|
77
121
|
return {
|
|
78
122
|
success: true,
|
|
79
|
-
message: `已配置 → ${paths.settingsFile}`,
|
|
123
|
+
message: `已配置 ${configuredModels} 个模型 → ${paths.settingsFile}`,
|
|
80
124
|
configPath: paths.settingsFile,
|
|
81
125
|
};
|
|
82
126
|
} catch (error) {
|
|
@@ -104,7 +148,7 @@ configureClaudeCode.checkStatus = async function() {
|
|
|
104
148
|
configured: true,
|
|
105
149
|
message: '已配置 Duojie API',
|
|
106
150
|
};
|
|
107
|
-
} else if (settings.env?.ANTHROPIC_AUTH_TOKEN) {
|
|
151
|
+
} else if (settings.env?.ANTHROPIC_API_KEY || settings.env?.ANTHROPIC_AUTH_TOKEN) {
|
|
108
152
|
return {
|
|
109
153
|
configured: true,
|
|
110
154
|
message: '已配置 (非 Duojie)',
|
|
@@ -130,10 +174,13 @@ configureClaudeCode.revoke = async function() {
|
|
|
130
174
|
|
|
131
175
|
// 只删除 Duojie 相关的环境变量
|
|
132
176
|
if (settings.env) {
|
|
177
|
+
delete settings.env.ANTHROPIC_API_KEY;
|
|
133
178
|
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
134
179
|
delete settings.env.ANTHROPIC_BASE_URL;
|
|
135
180
|
delete settings.env.API_TIMEOUT_MS;
|
|
136
181
|
delete settings.env.ANTHROPIC_MAX_TOKENS;
|
|
182
|
+
delete settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL;
|
|
183
|
+
delete settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL;
|
|
137
184
|
|
|
138
185
|
// 如果 env 为空,删除整个 env
|
|
139
186
|
if (Object.keys(settings.env).length === 0) {
|
|
@@ -141,6 +188,7 @@ configureClaudeCode.revoke = async function() {
|
|
|
141
188
|
}
|
|
142
189
|
}
|
|
143
190
|
|
|
191
|
+
delete settings.model;
|
|
144
192
|
delete settings._duojie;
|
|
145
193
|
|
|
146
194
|
await fs.writeJson(paths.settingsFile, settings, { spaces: 2 });
|
package/src/tools/cline.js
CHANGED
package/src/tools/codex.js
CHANGED
|
@@ -130,7 +130,7 @@ export async function configureCodex(apiKey) {
|
|
|
130
130
|
// 构建新配置
|
|
131
131
|
const duojieProvider = {
|
|
132
132
|
name: 'Duojie',
|
|
133
|
-
base_url:
|
|
133
|
+
base_url: API_CONFIG.baseUrl,
|
|
134
134
|
env_key: 'DUOJIE_API_KEY',
|
|
135
135
|
wire_api: 'chat',
|
|
136
136
|
};
|
|
@@ -178,7 +178,7 @@ export async function configureCodex(apiKey) {
|
|
|
178
178
|
# Duojie API Provider
|
|
179
179
|
[model_providers.duojie]
|
|
180
180
|
name = "Duojie"
|
|
181
|
-
base_url = "${API_CONFIG.baseUrl}
|
|
181
|
+
base_url = "${API_CONFIG.baseUrl}"
|
|
182
182
|
env_key = "DUOJIE_API_KEY"
|
|
183
183
|
wire_api = "chat"
|
|
184
184
|
`;
|
package/src/tools/continue.js
CHANGED
|
@@ -45,7 +45,7 @@ export async function configureContinue(apiKey) {
|
|
|
45
45
|
provider: "anthropic",
|
|
46
46
|
model: m.id,
|
|
47
47
|
apiKey: apiKey,
|
|
48
|
-
apiBase:
|
|
48
|
+
apiBase: API_CONFIG.baseUrl,
|
|
49
49
|
completionOptions: {
|
|
50
50
|
maxTokens: 8192,
|
|
51
51
|
},
|
|
@@ -61,7 +61,7 @@ export async function configureContinue(apiKey) {
|
|
|
61
61
|
provider: "openai",
|
|
62
62
|
model: m.id,
|
|
63
63
|
apiKey: apiKey,
|
|
64
|
-
apiBase:
|
|
64
|
+
apiBase: API_CONFIG.baseUrl,
|
|
65
65
|
completionOptions: {
|
|
66
66
|
maxTokens: 8192,
|
|
67
67
|
},
|
|
@@ -77,7 +77,7 @@ export async function configureContinue(apiKey) {
|
|
|
77
77
|
provider: "openai",
|
|
78
78
|
model: m.id,
|
|
79
79
|
apiKey: apiKey,
|
|
80
|
-
apiBase:
|
|
80
|
+
apiBase: API_CONFIG.baseUrl,
|
|
81
81
|
completionOptions: {
|
|
82
82
|
maxTokens: 8192,
|
|
83
83
|
},
|
package/src/tools/cursor.js
CHANGED
package/src/tools/openclaw.js
CHANGED
|
@@ -94,7 +94,7 @@ export async function configureOpenClaw(apiKey) {
|
|
|
94
94
|
|
|
95
95
|
if (claudeModels.length > 0) {
|
|
96
96
|
providers['duojie-claude'] = {
|
|
97
|
-
baseUrl:
|
|
97
|
+
baseUrl: API_CONFIG.baseUrl,
|
|
98
98
|
apiKey: apiKey,
|
|
99
99
|
api: 'anthropic-messages',
|
|
100
100
|
models: claudeModels,
|
|
@@ -105,7 +105,7 @@ export async function configureOpenClaw(apiKey) {
|
|
|
105
105
|
// GPT 使用 openai-responses (如果支持) 或 openai-completions
|
|
106
106
|
const gptApi = models.gpt[0]?.api || 'openai-responses';
|
|
107
107
|
providers['duojie-gpt'] = {
|
|
108
|
-
baseUrl:
|
|
108
|
+
baseUrl: API_CONFIG.baseUrl,
|
|
109
109
|
apiKey: apiKey,
|
|
110
110
|
api: gptApi,
|
|
111
111
|
models: gptModels,
|
|
@@ -114,7 +114,7 @@ export async function configureOpenClaw(apiKey) {
|
|
|
114
114
|
|
|
115
115
|
if (geminiModels.length > 0) {
|
|
116
116
|
providers['duojie-gemini'] = {
|
|
117
|
-
baseUrl:
|
|
117
|
+
baseUrl: API_CONFIG.baseUrl,
|
|
118
118
|
apiKey: apiKey,
|
|
119
119
|
api: 'anthropic-messages',
|
|
120
120
|
models: geminiModels,
|
|
@@ -123,7 +123,7 @@ export async function configureOpenClaw(apiKey) {
|
|
|
123
123
|
|
|
124
124
|
if (otherModels.length > 0) {
|
|
125
125
|
providers['duojie-other'] = {
|
|
126
|
-
baseUrl:
|
|
126
|
+
baseUrl: API_CONFIG.baseUrl,
|
|
127
127
|
apiKey: apiKey,
|
|
128
128
|
api: 'openai-completions',
|
|
129
129
|
models: otherModels,
|
package/src/tools/opencode.js
CHANGED