codex-slot 0.1.2 → 0.1.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/package.json +2 -2
- package/dist/app/config-service.js +0 -61
- package/dist/config-command.js +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-slot",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "本地 Codex 多账号切换与状态管理工具",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/cli.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"clean": "rm -rf dist",
|
|
16
|
-
"build": "tsc -p tsconfig.json && chmod +x dist/cli.js dist/serve.js",
|
|
16
|
+
"build": "npm run clean && tsc -p tsconfig.json && chmod +x dist/cli.js dist/serve.js",
|
|
17
17
|
"prepublishOnly": "npm run build",
|
|
18
18
|
"dev": "tsx src/cli.ts",
|
|
19
19
|
"check": "tsc --noEmit -p tsconfig.json"
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.describeConfig = describeConfig;
|
|
4
|
-
exports.mutateConfig = mutateConfig;
|
|
5
|
-
exports.applyCodexProviderConfig = applyCodexProviderConfig;
|
|
6
|
-
const config_1 = require("../config");
|
|
7
|
-
const codex_config_1 = require("../codex-config");
|
|
8
|
-
const cli_helpers_1 = require("../cli-helpers");
|
|
9
|
-
/**
|
|
10
|
-
* 返回当前本地配置的只读快照,供 CLI 或其他调用方展示。
|
|
11
|
-
*
|
|
12
|
-
* @returns 当前配置快照与默认 Codex 配置路径。
|
|
13
|
-
* @throws 当配置读取失败时抛出异常。
|
|
14
|
-
*/
|
|
15
|
-
function describeConfig() {
|
|
16
|
-
return {
|
|
17
|
-
config: (0, config_1.loadConfig)(),
|
|
18
|
-
codexConfigPath: (0, codex_config_1.getDefaultCodexConfigPath)()
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* 按输入选项修改本地配置,并返回本次变更摘要。
|
|
23
|
-
*
|
|
24
|
-
* @param input 配置修改输入;字段缺失表示不修改该项。
|
|
25
|
-
* @returns 最新配置快照与已应用的变更列表。
|
|
26
|
-
* @throws 当端口非法或配置写入失败时抛出异常。
|
|
27
|
-
*/
|
|
28
|
-
function mutateConfig(input) {
|
|
29
|
-
const config = (0, config_1.loadConfig)();
|
|
30
|
-
const updates = [];
|
|
31
|
-
if (input.host) {
|
|
32
|
-
config.server.host = input.host;
|
|
33
|
-
updates.push(`host=${config.server.host}`);
|
|
34
|
-
}
|
|
35
|
-
if (input.port) {
|
|
36
|
-
config.server.port = (0, cli_helpers_1.parsePort)(input.port);
|
|
37
|
-
updates.push(`port=${config.server.port}`);
|
|
38
|
-
}
|
|
39
|
-
if (input.apiKey) {
|
|
40
|
-
config.server.api_key = input.apiKey;
|
|
41
|
-
updates.push("api_key=已手动设置");
|
|
42
|
-
}
|
|
43
|
-
else if (input.regenApiKey) {
|
|
44
|
-
config.server.api_key = (0, codex_config_1.generateServerApiKey)();
|
|
45
|
-
updates.push("api_key=已重新生成");
|
|
46
|
-
}
|
|
47
|
-
if (updates.length > 0) {
|
|
48
|
-
(0, config_1.saveConfig)(config);
|
|
49
|
-
}
|
|
50
|
-
return { config, updates };
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* 将当前受管 provider 配置写入指定的 Codex `config.toml`。
|
|
54
|
-
*
|
|
55
|
-
* @param targetPath 可选目标路径;未传时写入默认全局路径。
|
|
56
|
-
* @returns 实际写入的目标文件路径。
|
|
57
|
-
* @throws 当配置接管写入失败时抛出异常。
|
|
58
|
-
*/
|
|
59
|
-
function applyCodexProviderConfig(targetPath) {
|
|
60
|
-
return (0, codex_config_1.applyManagedCodexConfig)(targetPath);
|
|
61
|
-
}
|
package/dist/config-command.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleConfig = handleConfig;
|
|
4
|
-
const config_service_1 = require("./app/config-service");
|
|
5
|
-
const text_1 = require("./text");
|
|
6
|
-
/**
|
|
7
|
-
* 处理 `config` 子命令,支持查看、修改本地配置并按需写入 `codex config.toml`。
|
|
8
|
-
*
|
|
9
|
-
* 业务含义:
|
|
10
|
-
* 1. 将 `server.port`、`server.host`、`server.api_key` 的维护入口集中到一个命令中。
|
|
11
|
-
* 2. 支持显式轮换本地 API Key,避免继续使用固定默认值。
|
|
12
|
-
* 3. 支持在不启动代理服务的情况下预写入 Codex provider 配置,便于用户单独检查。
|
|
13
|
-
*
|
|
14
|
-
* @param options CLI 解析后的配置项;字段缺失表示用户未修改对应值。
|
|
15
|
-
* @returns 无返回值。
|
|
16
|
-
* @throws 当端口非法或配置持久化失败时抛出异常。
|
|
17
|
-
*/
|
|
18
|
-
function handleConfig(options) {
|
|
19
|
-
const { config, updates } = (0, config_service_1.mutateConfig)(options);
|
|
20
|
-
if (updates.length > 0) {
|
|
21
|
-
console.log((0, text_1.bi)("本地配置已更新:", "Local config updated:"));
|
|
22
|
-
for (const line of updates) {
|
|
23
|
-
console.log(`- ${line}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (options.applyCodex !== undefined) {
|
|
27
|
-
const applyTarget = typeof options.applyCodex === "string" ? options.applyCodex : undefined;
|
|
28
|
-
(0, config_service_1.applyCodexProviderConfig)(applyTarget);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (updates.length === 0) {
|
|
32
|
-
const description = (0, config_service_1.describeConfig)();
|
|
33
|
-
console.log((0, text_1.bi)("当前本地配置:", "Current local config:"));
|
|
34
|
-
console.log(`- host=${description.config.server.host}`);
|
|
35
|
-
console.log(`- port=${description.config.server.port}`);
|
|
36
|
-
console.log(`- api_key=${description.config.server.api_key}`);
|
|
37
|
-
console.log(`- codex_config=${description.codexConfigPath}`);
|
|
38
|
-
console.log("");
|
|
39
|
-
console.log((0, text_1.bi)("提示:", "Notes:"));
|
|
40
|
-
console.log(`- ${(0, text_1.bi)("`import current ~` 里的 current 只是示例槽位名,不是系统内置账号。", "`current` in `import current ~` is only an example slot name, not a built-in account.")}`);
|
|
41
|
-
console.log(`- ${(0, text_1.bi)("用 `cslot config --regen-api-key` 可轮换本地 API Key。", "Use `cslot config --regen-api-key` to rotate the local API key.")}`);
|
|
42
|
-
console.log(`- ${(0, text_1.bi)("用 `cslot config --apply-codex` 可单独预写入 codex provider 配置。", "Use `cslot config --apply-codex` to write the managed Codex provider without starting the proxy.")}`);
|
|
43
|
-
}
|
|
44
|
-
}
|