@tokenaut/opentoken 1.3.1 → 1.3.3
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 +10 -17
- package/package.json +2 -2
- package/src/cli.js +21 -27
- package/src/config.js +9 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm install -g @tokenaut/opentoken
|
|
|
11
11
|
## 用法
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
opentoken <tool> [--key <api_key>] [--model <model>] [--
|
|
14
|
+
opentoken <tool> [--key <api_key>] [--model <model>] [--url <base_url>]
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
各参数均可独立使用,只修改指定的配置项,未指定的保持不变。
|
|
@@ -51,8 +51,8 @@ opentoken cc --key sk-xxxxx
|
|
|
51
51
|
# 只改模型
|
|
52
52
|
opentoken cc --model sonnet
|
|
53
53
|
|
|
54
|
-
#
|
|
55
|
-
opentoken cc --key sk-xxxxx --model opus --
|
|
54
|
+
# 完整指定
|
|
55
|
+
opentoken cc --key sk-xxxxx --model opus --url https://gw.opentoken.io
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
### Codex
|
|
@@ -74,29 +74,20 @@ opentoken cx --key sk-xxxxx --model gpt-5.5 --url https://gw.opentoken.io/v1
|
|
|
74
74
|
|
|
75
75
|
```bash
|
|
76
76
|
# Claude Code(注意 cc 的 url 没有 /v1)
|
|
77
|
-
opentoken cc --key <your-api-key> --model
|
|
77
|
+
opentoken cc --key <your-api-key> --model opus --url https://gw.opentoken.io
|
|
78
78
|
|
|
79
79
|
# Codex
|
|
80
|
-
opentoken cx --key <your-api-key> --model
|
|
80
|
+
opentoken cx --key <your-api-key> --model 5.5 --url https://gw.opentoken.io/v1
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
### Omni 网关
|
|
84
84
|
|
|
85
85
|
```bash
|
|
86
86
|
# Claude Code
|
|
87
|
-
opentoken cc --key <your-api-key> --model
|
|
87
|
+
opentoken cc --key <your-api-key> --model opus --url https://omniroute.goio.uk/v1
|
|
88
88
|
|
|
89
89
|
# Codex
|
|
90
|
-
opentoken cx --key <your-api-key> --model
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## --header
|
|
94
|
-
|
|
95
|
-
为模型 ID 添加前缀,例如:
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
opentoken cc --key sk-xxxxx --header vor
|
|
99
|
-
# 模型变为 vor/claude-opus-4-8
|
|
90
|
+
opentoken cx --key <your-api-key> --model 5.5 --url https://omniroute.goio.uk/v1
|
|
100
91
|
```
|
|
101
92
|
|
|
102
93
|
## 写入字段
|
|
@@ -105,7 +96,9 @@ opentoken cc --key sk-xxxxx --header vor
|
|
|
105
96
|
|
|
106
97
|
- `ANTHROPIC_AUTH_TOKEN`
|
|
107
98
|
- `ANTHROPIC_BASE_URL`
|
|
108
|
-
- `ANTHROPIC_MODEL
|
|
99
|
+
- `ANTHROPIC_MODEL`(主模型)
|
|
100
|
+
- `ANTHROPIC_DEFAULT_SONNET_MODEL`(Sonnet 辅助模型)
|
|
101
|
+
- `ANTHROPIC_SMALL_FAST_MODEL`(Haiku 快速小模型)
|
|
109
102
|
- `API_TIMEOUT_MS`
|
|
110
103
|
- `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`
|
|
111
104
|
- `ENABLE_TOOL_SEARCH`
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -18,6 +18,9 @@ const CC_MODEL_MAP = {
|
|
|
18
18
|
'claude-haiku-4-5': 'claude-haiku-4-5',
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
const CC_SONNET_MODEL = 'claude-sonnet-4-6';
|
|
22
|
+
const CC_HAIKU_MODEL = 'claude-haiku-4-5';
|
|
23
|
+
|
|
21
24
|
const CX_MODEL_MAP = {
|
|
22
25
|
'5.5': 'gpt-5.5',
|
|
23
26
|
'5.4': 'gpt-5.4',
|
|
@@ -27,25 +30,17 @@ const CX_MODEL_MAP = {
|
|
|
27
30
|
'gpt-5.4': 'gpt-5.4',
|
|
28
31
|
};
|
|
29
32
|
|
|
30
|
-
function resolveModel(input,
|
|
31
|
-
let modelId;
|
|
32
|
-
|
|
33
|
+
function resolveModel(input, modelMap, defaultAlias) {
|
|
33
34
|
if (!input) {
|
|
34
|
-
|
|
35
|
-
} else {
|
|
36
|
-
const trimmed = String(input).trim().toLowerCase();
|
|
37
|
-
if (modelMap[trimmed]) {
|
|
38
|
-
modelId = modelMap[trimmed];
|
|
39
|
-
} else {
|
|
40
|
-
modelId = String(input).trim();
|
|
41
|
-
}
|
|
35
|
+
return modelMap[defaultAlias];
|
|
42
36
|
}
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
const trimmed = String(input).trim().toLowerCase();
|
|
39
|
+
if (modelMap[trimmed]) {
|
|
40
|
+
return modelMap[trimmed];
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
return
|
|
43
|
+
return String(input).trim();
|
|
49
44
|
}
|
|
50
45
|
|
|
51
46
|
function maskApiKey(key) {
|
|
@@ -61,7 +56,7 @@ function printHelp() {
|
|
|
61
56
|
console.log('OpenToken 一键配置 CLI');
|
|
62
57
|
console.log('');
|
|
63
58
|
console.log('用法:');
|
|
64
|
-
console.log(' opentoken <tool> [--key <api_key>] [--model <model>] [--
|
|
59
|
+
console.log(' opentoken <tool> [--key <api_key>] [--model <model>] [--url <base_url>]');
|
|
65
60
|
console.log('');
|
|
66
61
|
console.log('工具:');
|
|
67
62
|
console.log(' cc Claude Code 配置(~/.claude/settings.json)');
|
|
@@ -79,7 +74,7 @@ function printHelp() {
|
|
|
79
74
|
console.log('');
|
|
80
75
|
console.log('示例:');
|
|
81
76
|
console.log(' opentoken cc --key sk-xxxxx');
|
|
82
|
-
console.log(' opentoken cc --model sonnet
|
|
77
|
+
console.log(' opentoken cc --model sonnet');
|
|
83
78
|
console.log(' opentoken codex --key sk-xxxxx');
|
|
84
79
|
console.log(' opentoken cx --model 5.5');
|
|
85
80
|
console.log(' opentoken cx --url https://gw.opentoken.io/v1');
|
|
@@ -88,7 +83,6 @@ function printHelp() {
|
|
|
88
83
|
console.log(' 各参数均可独立使用,只修改指定的配置项,未指定的保持不变');
|
|
89
84
|
console.log(` Claude Code 默认 Base URL: ${DEFAULT_BASE_URL}`);
|
|
90
85
|
console.log(` Codex 默认 Base URL: ${CODEX_DEFAULT_BASE_URL}`);
|
|
91
|
-
console.log(' --header 为模型 ID 添加前缀,如 --header vor → vor/claude-opus-4-8');
|
|
92
86
|
console.log('');
|
|
93
87
|
}
|
|
94
88
|
|
|
@@ -98,7 +92,6 @@ function parseArgs(argv) {
|
|
|
98
92
|
tool: null,
|
|
99
93
|
key: null,
|
|
100
94
|
model: null,
|
|
101
|
-
header: null,
|
|
102
95
|
url: null,
|
|
103
96
|
help: false,
|
|
104
97
|
};
|
|
@@ -121,9 +114,6 @@ function parseArgs(argv) {
|
|
|
121
114
|
} else if ((current === '--model' || current === '-m') && next) {
|
|
122
115
|
result.model = next;
|
|
123
116
|
i += 1;
|
|
124
|
-
} else if ((current === '--header' || current === '-H') && next) {
|
|
125
|
-
result.header = next;
|
|
126
|
-
i += 1;
|
|
127
117
|
} else if ((current === '--url' || current === '-u') && next) {
|
|
128
118
|
result.url = next;
|
|
129
119
|
i += 1;
|
|
@@ -154,8 +144,10 @@ async function runCc(args) {
|
|
|
154
144
|
patch.apiKey = String(args.key).trim();
|
|
155
145
|
}
|
|
156
146
|
|
|
157
|
-
if (args.model !== null
|
|
158
|
-
patch.model = resolveModel(args.model,
|
|
147
|
+
if (args.model !== null) {
|
|
148
|
+
patch.model = resolveModel(args.model, CC_MODEL_MAP, CC_DEFAULT_MODEL_ALIAS);
|
|
149
|
+
patch.sonnetModel = resolveModel('sonnet', CC_MODEL_MAP, CC_DEFAULT_MODEL_ALIAS);
|
|
150
|
+
patch.haikuModel = resolveModel('haiku', CC_MODEL_MAP, CC_DEFAULT_MODEL_ALIAS);
|
|
159
151
|
}
|
|
160
152
|
|
|
161
153
|
if (args.url && String(args.url).trim()) {
|
|
@@ -164,7 +156,7 @@ async function runCc(args) {
|
|
|
164
156
|
|
|
165
157
|
if (Object.keys(patch).length === 0) {
|
|
166
158
|
console.log('');
|
|
167
|
-
console.log('未指定任何配置项,请使用 --key / --model / --
|
|
159
|
+
console.log('未指定任何配置项,请使用 --key / --model / --url');
|
|
168
160
|
console.log('');
|
|
169
161
|
return;
|
|
170
162
|
}
|
|
@@ -176,6 +168,8 @@ async function runCc(args) {
|
|
|
176
168
|
if (patch.apiKey) console.log(` API Key: ${maskApiKey(patch.apiKey)}`);
|
|
177
169
|
if (patch.baseUrl) console.log(` Base URL: ${patch.baseUrl}`);
|
|
178
170
|
if (patch.model) console.log(` Model: ${patch.model}`);
|
|
171
|
+
if (patch.sonnetModel) console.log(` Sonnet: ${patch.sonnetModel}`);
|
|
172
|
+
if (patch.haikuModel) console.log(` Haiku: ${patch.haikuModel}`);
|
|
179
173
|
console.log(` File: ${SETTINGS_PATH}`);
|
|
180
174
|
console.log('');
|
|
181
175
|
}
|
|
@@ -187,8 +181,8 @@ async function runCodex(args) {
|
|
|
187
181
|
patch.apiKey = String(args.key).trim();
|
|
188
182
|
}
|
|
189
183
|
|
|
190
|
-
if (args.model !== null
|
|
191
|
-
patch.model = resolveModel(args.model,
|
|
184
|
+
if (args.model !== null) {
|
|
185
|
+
patch.model = resolveModel(args.model, CX_MODEL_MAP, CX_DEFAULT_MODEL_ALIAS);
|
|
192
186
|
}
|
|
193
187
|
|
|
194
188
|
if (args.url && String(args.url).trim()) {
|
|
@@ -197,7 +191,7 @@ async function runCodex(args) {
|
|
|
197
191
|
|
|
198
192
|
if (Object.keys(patch).length === 0) {
|
|
199
193
|
console.log('');
|
|
200
|
-
console.log('未指定任何配置项,请使用 --key / --model / --
|
|
194
|
+
console.log('未指定任何配置项,请使用 --key / --model / --url');
|
|
201
195
|
console.log('');
|
|
202
196
|
return;
|
|
203
197
|
}
|
package/src/config.js
CHANGED
|
@@ -72,6 +72,14 @@ function applyConfig(patch) {
|
|
|
72
72
|
settings.env.ANTHROPIC_MODEL = patch.model;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
if (patch.sonnetModel !== undefined) {
|
|
76
|
+
settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL = patch.sonnetModel;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (patch.haikuModel !== undefined) {
|
|
80
|
+
settings.env.ANTHROPIC_SMALL_FAST_MODEL = patch.haikuModel;
|
|
81
|
+
}
|
|
82
|
+
|
|
75
83
|
mergeDefaultClaudeAuxEnv(settings.env);
|
|
76
84
|
writeClaudeSettings(settings);
|
|
77
85
|
}
|
|
@@ -79,4 +87,4 @@ function applyConfig(patch) {
|
|
|
79
87
|
module.exports = {
|
|
80
88
|
SETTINGS_PATH,
|
|
81
89
|
applyConfig,
|
|
82
|
-
};
|
|
90
|
+
};
|