@tokenaut/opentoken 1.4.6 → 1.4.8
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 +21 -2
- package/package.json +1 -1
- package/src/cli.js +6 -6
- package/src/models.js +6 -0
- package/src/tools/atomcode.js +4 -2
- package/src/tools/claude.js +6 -3
- package/src/tools/claude_desktop.js +3 -1
- package/src/tools/codex.js +7 -5
- package/src/tools/hermes.js +4 -2
- package/src/tools/openclaw.js +4 -4
- package/src/tools/opencode.js +4 -4
package/README.md
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npx @tokenaut/opentoken
|
|
9
8
|
npm install -g @tokenaut/opentoken
|
|
10
9
|
```
|
|
11
10
|
|
|
@@ -25,6 +24,7 @@ npm install -g @tokenaut/opentoken
|
|
|
25
24
|
| 应用 | 子命令(别名) | 配置文件 |
|
|
26
25
|
|------|----------------|----------|
|
|
27
26
|
| **Claude Code** | `cc`、`claude` | `~/.claude/settings.json`(环境变量:`ANTHROPIC_AUTH_TOKEN`、`ANTHROPIC_BASE_URL`、`ANTHROPIC_MODEL`) |
|
|
27
|
+
| **Claude Desktop** | `claude_desktop`、`cdp` | `~/Library/Application Support/Claude-3p/configLibrary/*.json`(`inferenceGatewayApiKey`、`inferenceGatewayBaseUrl`) |
|
|
28
28
|
| **Atomcode** | `atomcode`、`ac` | `~/.atomcode/config.toml` |
|
|
29
29
|
| **OpenClaw** | `openclaw`、`oc` | `~/.openclaw/openclaw.json`(合并写入 Opentoken:`models.providers.opentoken`、`agents.defaults.model.primary` 等) |
|
|
30
30
|
| **Hermes** | `hermes`、`hm` | `~/.hermes/config.yaml`(`model.provider`、`model.base_url`、`model.default`)与 `~/.hermes/.env`(`OPENTOKEN_API_KEY`) |
|
|
@@ -39,11 +39,13 @@ OpenCode 会为 **`opentoken`** 提供方写入 **`npm`**(`@ai-sdk/anthropic`
|
|
|
39
39
|
|
|
40
40
|
Codex 会为 **`opentoken`** 提供方写入 **`base_url`**(默认 `https://gw.opentoken.io/v1`)与 **`wire_api = "responses"`**(不写 `env_key`),并只从模型列表中选择 `supported_endpoint_types` 包含 `responses` 的模型。API Key 写入 **`~/.codex/auth.json`** 的 **`OPENAI_API_KEY`**,Codex 命令行与 IDE 插件共用,无需再 export 环境变量。
|
|
41
41
|
|
|
42
|
+
Claude Desktop 会写入 **`inferenceGatewayApiKey`**(API Key)与 **`inferenceGatewayBaseUrl`**(Base URL,默认 `https://gw.opentoken.io`),同时设置 **`inferenceProvider: "gateway"`** 与 **`inferenceGatewayAuthScheme: "bearer"`**。配置文件位于 `configLibrary/` 目录下,通过 UUID 标识的 JSON 文件管理;本工具会自动复用现有配置或创建新条目。Windows 下路径为 `%APPDATA%\Claude\configLibrary\*.json`。
|
|
43
|
+
|
|
42
44
|
---
|
|
43
45
|
|
|
44
46
|
## 快捷一键配置(非交互)
|
|
45
47
|
|
|
46
|
-
以下为各应用在命令行直接写入配置的用法。选项可单独或组合使用:**`--key` / `-k`**,**`--url` / `-u
|
|
48
|
+
以下为各应用在命令行直接写入配置的用法。选项可单独或组合使用:**`--key` / `-k`**,**`--url` / `-u`**(Claude Code、Claude Desktop、Codex),**`--model` / `-m`**。
|
|
47
49
|
|
|
48
50
|
### Claude Code
|
|
49
51
|
|
|
@@ -61,6 +63,23 @@ opentoken cc -k sk-xxx
|
|
|
61
63
|
opentoken cc -k sk-xxx -u https://gw.opentoken.io -m claude-opus-4-5
|
|
62
64
|
```
|
|
63
65
|
|
|
66
|
+
### Claude Desktop
|
|
67
|
+
|
|
68
|
+
写入(或合并)`configLibrary/*.json` 中的第三方推理配置:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
opentoken claude_desktop --key <api_key>
|
|
72
|
+
opentoken cdp --url <base_url>
|
|
73
|
+
opentoken cdp -k <api_key> -u <base_url>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
示例:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
opentoken cdp -k sk-xxx
|
|
80
|
+
opentoken cdp -k sk-xxx -u https://gw.opentoken.io
|
|
81
|
+
```
|
|
82
|
+
|
|
64
83
|
### Atomcode
|
|
65
84
|
|
|
66
85
|
Base URL 固定为 Opentoken 的 OpenAI 兼容地址,仅需 Key 与模型:
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -38,7 +38,7 @@ function isCodexCommand(tool) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function isClaudeDesktopCommand(tool) {
|
|
41
|
-
return tool === 'claude_desktop' || tool === '
|
|
41
|
+
return tool === 'claude_desktop' || tool === 'cdp';
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
function printVersion() {
|
|
@@ -92,17 +92,17 @@ function printHelp() {
|
|
|
92
92
|
console.log(' opentoken cx -k <k> -u <u> -m <m> 一键设置 URL 与模型');
|
|
93
93
|
console.log('');
|
|
94
94
|
console.log(' opentoken claude_desktop 进入 Claude Desktop 配置(configLibrary/*.json)');
|
|
95
|
-
console.log(' opentoken
|
|
96
|
-
console.log(' opentoken
|
|
97
|
-
console.log(' opentoken
|
|
98
|
-
console.log(' opentoken
|
|
95
|
+
console.log(' opentoken cdp 同上(缩写)');
|
|
96
|
+
console.log(' opentoken cdp --key <apikey> 设置 API Key(inferenceGatewayApiKey)');
|
|
97
|
+
console.log(' opentoken cdp --url <baseurl> 设置 Base URL(inferenceGatewayBaseUrl)');
|
|
98
|
+
console.log(' opentoken cdp -k <k> -u <u> 一键设置 Key 与 URL');
|
|
99
99
|
console.log('');
|
|
100
100
|
console.log(chalk.bold('快捷别名(--key / -k,--url / -u,--model / -m)'));
|
|
101
101
|
console.log('');
|
|
102
102
|
console.log(chalk.bold('示例:'));
|
|
103
103
|
console.log(' opentoken cc -k sk-xxx');
|
|
104
104
|
console.log(` opentoken cc -k sk-xxx -u ${DEFAULT_BASE_URL} -m claude-opus-4-5`);
|
|
105
|
-
console.log(` opentoken
|
|
105
|
+
console.log(` opentoken cdp -k sk-xxx -u ${DEFAULT_BASE_URL}`);
|
|
106
106
|
console.log('');
|
|
107
107
|
console.log(chalk.bold('主菜单:'));
|
|
108
108
|
console.log(' 1. 配置 Claude Code');
|
package/src/models.js
CHANGED
|
@@ -30,6 +30,10 @@ const CODEX_AUTH_KEY = 'OPENAI_API_KEY';
|
|
|
30
30
|
|
|
31
31
|
const CODEX_DEFAULT_MODEL = 'gpt-5.4';
|
|
32
32
|
|
|
33
|
+
const CLAUDE_DEFAULT_MODEL = 'claude-sonnet-4-6';
|
|
34
|
+
|
|
35
|
+
const GENERAL_DEFAULT_MODEL = 'gpt-5.4';
|
|
36
|
+
|
|
33
37
|
const API_NODES = [
|
|
34
38
|
{
|
|
35
39
|
name: 'opentoken 默认节点 - https://gw.opentoken.io',
|
|
@@ -58,4 +62,6 @@ module.exports = {
|
|
|
58
62
|
CODEX_PROVIDER_KEY,
|
|
59
63
|
CODEX_AUTH_KEY,
|
|
60
64
|
CODEX_DEFAULT_MODEL,
|
|
65
|
+
CLAUDE_DEFAULT_MODEL,
|
|
66
|
+
GENERAL_DEFAULT_MODEL,
|
|
61
67
|
};
|
package/src/tools/atomcode.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const inquirer = require('inquirer');
|
|
5
|
-
const { DEFAULT_BASE_URL, ATOMCODE_OPENTOKEN_BASE_URL } = require('../models');
|
|
5
|
+
const { DEFAULT_BASE_URL, ATOMCODE_OPENTOKEN_BASE_URL, GENERAL_DEFAULT_MODEL } = require('../models');
|
|
6
6
|
const { fetchModelsForBaseUrl } = require('../fetch-models');
|
|
7
7
|
const {
|
|
8
8
|
CONFIG_PATH,
|
|
@@ -235,6 +235,8 @@ function quickSet({ key, model }) {
|
|
|
235
235
|
if (key) toWrite.apiKey = key;
|
|
236
236
|
if (model) toWrite.model = model;
|
|
237
237
|
|
|
238
|
+
if (key && !model) toWrite.model = GENERAL_DEFAULT_MODEL;
|
|
239
|
+
|
|
238
240
|
if (Object.keys(toWrite).length === 0) return false;
|
|
239
241
|
|
|
240
242
|
applyAtomcodeConfig(toWrite);
|
|
@@ -242,7 +244,7 @@ function quickSet({ key, model }) {
|
|
|
242
244
|
console.log('');
|
|
243
245
|
console.log(chalk.bold(chalk.cyan('Atomcode 配置已更新:')));
|
|
244
246
|
if (key) console.log(chalk.green(' ✓ API Key : ') + maskApiKey(key));
|
|
245
|
-
|
|
247
|
+
console.log(chalk.green(' ✓ 模型 : ') + (toWrite.model || model));
|
|
246
248
|
console.log(chalk.green(' ✓ Base URL : ') + ATOMCODE_OPENTOKEN_BASE_URL + chalk.gray('(固定)'));
|
|
247
249
|
console.log(chalk.gray(' ' + CONFIG_PATH));
|
|
248
250
|
console.log('');
|
package/src/tools/claude.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const inquirer = require('inquirer');
|
|
5
|
-
const { API_NODES, DEFAULT_BASE_URL } = require('../models');
|
|
5
|
+
const { API_NODES, DEFAULT_BASE_URL, CLAUDE_DEFAULT_MODEL } = require('../models');
|
|
6
6
|
const { fetchModelsForBaseUrl } = require('../fetch-models');
|
|
7
7
|
const { getCurrentConfig, applyConfig } = require('../config');
|
|
8
8
|
const { printLogo } = require('../logo');
|
|
@@ -285,6 +285,9 @@ function quickSet({ key, url, model }) {
|
|
|
285
285
|
if (url) toWrite.baseUrl = url;
|
|
286
286
|
if (model) toWrite.model = model;
|
|
287
287
|
|
|
288
|
+
if (key && !url) toWrite.baseUrl = DEFAULT_BASE_URL;
|
|
289
|
+
if (key && !model) toWrite.model = CLAUDE_DEFAULT_MODEL;
|
|
290
|
+
|
|
288
291
|
if (Object.keys(toWrite).length === 0) return false;
|
|
289
292
|
|
|
290
293
|
applyConfig(toWrite);
|
|
@@ -292,8 +295,8 @@ function quickSet({ key, url, model }) {
|
|
|
292
295
|
console.log('');
|
|
293
296
|
console.log(chalk.bold(chalk.cyan('Claude Code 配置已更新:')));
|
|
294
297
|
if (key) console.log(chalk.green(' ✓ API Key : ') + maskApiKey(key));
|
|
295
|
-
|
|
296
|
-
|
|
298
|
+
console.log(chalk.green(' ✓ Base URL : ') + (toWrite.baseUrl || url));
|
|
299
|
+
console.log(chalk.green(' ✓ 模型 : ') + (toWrite.model || model));
|
|
297
300
|
console.log('');
|
|
298
301
|
|
|
299
302
|
return true;
|
|
@@ -169,6 +169,8 @@ function quickSet({ key, url }) {
|
|
|
169
169
|
if (key) toWrite.apiKey = key;
|
|
170
170
|
if (url) toWrite.baseUrl = url;
|
|
171
171
|
|
|
172
|
+
if (key && !url) toWrite.baseUrl = DEFAULT_BASE_URL;
|
|
173
|
+
|
|
172
174
|
if (Object.keys(toWrite).length === 0) return false;
|
|
173
175
|
|
|
174
176
|
applyConfig(toWrite);
|
|
@@ -176,7 +178,7 @@ function quickSet({ key, url }) {
|
|
|
176
178
|
console.log('');
|
|
177
179
|
console.log(chalk.bold(chalk.cyan('Claude Desktop 配置已更新:')));
|
|
178
180
|
if (key) console.log(chalk.green(' ✓ API Key : ') + maskApiKey(key));
|
|
179
|
-
|
|
181
|
+
console.log(chalk.green(' ✓ Base URL : ') + (toWrite.baseUrl || url));
|
|
180
182
|
console.log('');
|
|
181
183
|
|
|
182
184
|
return true;
|
package/src/tools/codex.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const inquirer = require('inquirer');
|
|
5
|
-
const { CODEX_OPENTOKEN_BASE_URL, CODEX_AUTH_KEY } = require('../models');
|
|
5
|
+
const { CODEX_OPENTOKEN_BASE_URL, CODEX_AUTH_KEY, CODEX_DEFAULT_MODEL } = require('../models');
|
|
6
6
|
const { fetchModelsForBaseUrl } = require('../fetch-models');
|
|
7
7
|
const {
|
|
8
8
|
CONFIG_PATH,
|
|
@@ -293,14 +293,16 @@ async function quickSet({ key, url, model }) {
|
|
|
293
293
|
if (model) toWrite.model = model;
|
|
294
294
|
if (key) toWrite.apiKey = key;
|
|
295
295
|
|
|
296
|
+
if (key && !url) toWrite.baseUrl = CODEX_OPENTOKEN_BASE_URL;
|
|
297
|
+
if (key && !model) toWrite.model = CODEX_DEFAULT_MODEL;
|
|
298
|
+
|
|
296
299
|
if (key) {
|
|
297
|
-
const listBase = url || getCurrentCodexConfig().baseUrl || CODEX_OPENTOKEN_BASE_URL;
|
|
300
|
+
const listBase = toWrite.baseUrl || url || getCurrentCodexConfig().baseUrl || CODEX_OPENTOKEN_BASE_URL;
|
|
298
301
|
const fetched = await fetchModelsForBaseUrl(listBase, key, {
|
|
299
302
|
requiredEndpointType: 'responses',
|
|
300
303
|
});
|
|
301
304
|
if (fetched.ok && fetched.models.length > 0) {
|
|
302
305
|
toWrite.models = fetched.models;
|
|
303
|
-
if (!toWrite.model) toWrite.model = fetched.models[0];
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
|
|
@@ -311,8 +313,8 @@ async function quickSet({ key, url, model }) {
|
|
|
311
313
|
console.log('');
|
|
312
314
|
console.log(chalk.bold(chalk.cyan('Codex 配置已更新:')));
|
|
313
315
|
if (key) console.log(chalk.green(' ✓ API Key : ') + maskApiKey(key));
|
|
314
|
-
|
|
315
|
-
|
|
316
|
+
console.log(chalk.green(' ✓ Base URL : ') + (toWrite.baseUrl || url));
|
|
317
|
+
console.log(chalk.green(' ✓ 模型 : ') + toWrite.model);
|
|
316
318
|
if (toWrite.models) {
|
|
317
319
|
console.log(chalk.gray(' (包含 ' + toWrite.models.length + ' 个 responses 模型)'));
|
|
318
320
|
}
|
package/src/tools/hermes.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const inquirer = require('inquirer');
|
|
5
|
-
const { DEFAULT_BASE_URL, HERMES_OPENTOKEN_BASE_URL } = require('../models');
|
|
5
|
+
const { DEFAULT_BASE_URL, HERMES_OPENTOKEN_BASE_URL, GENERAL_DEFAULT_MODEL } = require('../models');
|
|
6
6
|
const { fetchModelsForBaseUrl } = require('../fetch-models');
|
|
7
7
|
const {
|
|
8
8
|
CONFIG_YAML_PATH,
|
|
@@ -255,6 +255,8 @@ function quickSet({ key, model }) {
|
|
|
255
255
|
if (key) toWrite.apiKey = key;
|
|
256
256
|
if (model) toWrite.model = model;
|
|
257
257
|
|
|
258
|
+
if (key && !model) toWrite.model = GENERAL_DEFAULT_MODEL;
|
|
259
|
+
|
|
258
260
|
if (Object.keys(toWrite).length === 0) return false;
|
|
259
261
|
|
|
260
262
|
applyHermesConfig(toWrite);
|
|
@@ -262,7 +264,7 @@ function quickSet({ key, model }) {
|
|
|
262
264
|
console.log('');
|
|
263
265
|
console.log(chalk.bold(chalk.cyan('Hermes 配置已更新:')));
|
|
264
266
|
if (key) console.log(chalk.green(' ✓ Opentoken API KEY(.env): ') + maskApiKey(key));
|
|
265
|
-
|
|
267
|
+
console.log(chalk.green(' ✓ model.default : ') + (toWrite.model || model));
|
|
266
268
|
console.log(chalk.green(' ✓ provider / base_url : ') + 'custom · ' + HERMES_OPENTOKEN_BASE_URL);
|
|
267
269
|
console.log(chalk.gray(' ' + CONFIG_YAML_PATH));
|
|
268
270
|
console.log(chalk.gray(' ' + ENV_PATH));
|
package/src/tools/openclaw.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const inquirer = require('inquirer');
|
|
5
|
-
const { DEFAULT_BASE_URL, OPENCLAW_PROVIDER_KEY } = require('../models');
|
|
5
|
+
const { DEFAULT_BASE_URL, OPENCLAW_PROVIDER_KEY, GENERAL_DEFAULT_MODEL } = require('../models');
|
|
6
6
|
const { fetchModelsForBaseUrl } = require('../fetch-models');
|
|
7
7
|
const {
|
|
8
8
|
OPENCLAW_JSON_PATH,
|
|
@@ -225,6 +225,8 @@ function quickSet({ key, model }) {
|
|
|
225
225
|
if (key) toWrite.apiKey = key;
|
|
226
226
|
if (model) toWrite.model = model;
|
|
227
227
|
|
|
228
|
+
if (key && !model) toWrite.model = GENERAL_DEFAULT_MODEL;
|
|
229
|
+
|
|
228
230
|
if (Object.keys(toWrite).length === 0) return false;
|
|
229
231
|
|
|
230
232
|
applyOpenclawConfig(toWrite);
|
|
@@ -232,9 +234,7 @@ function quickSet({ key, model }) {
|
|
|
232
234
|
console.log('');
|
|
233
235
|
console.log(chalk.bold(chalk.cyan('OpenClaw 配置已更新')));
|
|
234
236
|
if (key) console.log(chalk.green(' ✓ API Key: ') + maskApiKey(key));
|
|
235
|
-
|
|
236
|
-
console.log(chalk.green(' ✓ 模型: ') + OPENCLAW_PROVIDER_KEY + '/' + model);
|
|
237
|
-
}
|
|
237
|
+
console.log(chalk.green(' ✓ 模型: ') + OPENCLAW_PROVIDER_KEY + '/' + (toWrite.model || model));
|
|
238
238
|
console.log(chalk.gray(' ' + OPENCLAW_JSON_PATH));
|
|
239
239
|
console.log('');
|
|
240
240
|
|
package/src/tools/opencode.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const inquirer = require('inquirer');
|
|
5
|
-
const { DEFAULT_BASE_URL, OPENCODE_PROVIDER_KEY } = require('../models');
|
|
5
|
+
const { DEFAULT_BASE_URL, OPENCODE_PROVIDER_KEY, GENERAL_DEFAULT_MODEL } = require('../models');
|
|
6
6
|
const { fetchModelsForBaseUrl } = require('../fetch-models');
|
|
7
7
|
const {
|
|
8
8
|
OPENCODE_JSON_PATH,
|
|
@@ -229,6 +229,8 @@ async function quickSet({ key, model }) {
|
|
|
229
229
|
if (key) toWrite.apiKey = key;
|
|
230
230
|
if (model) toWrite.model = model;
|
|
231
231
|
|
|
232
|
+
if (key && !model) toWrite.model = GENERAL_DEFAULT_MODEL;
|
|
233
|
+
|
|
232
234
|
if (Object.keys(toWrite).length === 0) return false;
|
|
233
235
|
|
|
234
236
|
if (key) {
|
|
@@ -243,9 +245,7 @@ async function quickSet({ key, model }) {
|
|
|
243
245
|
console.log('');
|
|
244
246
|
console.log(chalk.bold(chalk.cyan('OpenCode 配置已更新')));
|
|
245
247
|
if (key) console.log(chalk.green(' ✓ API Key: ') + maskApiKey(key));
|
|
246
|
-
|
|
247
|
-
console.log(chalk.green(' ✓ 模型: ') + model);
|
|
248
|
-
}
|
|
248
|
+
console.log(chalk.green(' ✓ 模型: ') + (toWrite.model || model));
|
|
249
249
|
if (toWrite.models) {
|
|
250
250
|
console.log(chalk.gray(' (包含 ' + toWrite.models.length + ' 个可用模型)'));
|
|
251
251
|
}
|