codex-slot 0.1.0 → 0.1.1
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 +2 -2
- package/dist/cli.js +46 -17
- package/dist/server.js +1 -1
- package/dist/usage-sync.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -136,8 +136,8 @@ If you previously used `~/.codexsw`, it is migrated automatically.
|
|
|
136
136
|
|
|
137
137
|
## Repository
|
|
138
138
|
|
|
139
|
-
- GitHub: https://github.com/openxiaobu/
|
|
140
|
-
- Issues: https://github.com/openxiaobu/
|
|
139
|
+
- GitHub: https://github.com/openxiaobu/codex-slot
|
|
140
|
+
- Issues: https://github.com/openxiaobu/codex-slot/issues
|
|
141
141
|
|
|
142
142
|
## Development
|
|
143
143
|
|
package/dist/cli.js
CHANGED
|
@@ -267,15 +267,15 @@ async function handleInteractiveToggle(initialStatuses) {
|
|
|
267
267
|
/**
|
|
268
268
|
* 将已有的 Codex HOME 目录中的登录态复制到 cslot 自己的隔离目录并纳入管理。
|
|
269
269
|
*
|
|
270
|
-
* @param
|
|
270
|
+
* @param name 本地账号标识(等同于配置中的 name 字段)。
|
|
271
271
|
* @param codexHome 现有 HOME 目录;若未传则默认使用当前用户 HOME。
|
|
272
272
|
* @returns 无返回值。
|
|
273
273
|
*/
|
|
274
|
-
function handleAccountImport(
|
|
274
|
+
function handleAccountImport(name, codexHome) {
|
|
275
275
|
const sourceHome = codexHome ? (0, config_1.expandHome)(codexHome) : process.env.HOME ?? "";
|
|
276
|
-
const managedHome = (0, config_1.getManagedHome)(
|
|
276
|
+
const managedHome = (0, config_1.getManagedHome)(name);
|
|
277
277
|
(0, account_store_1.cloneCodexAuthState)(sourceHome, managedHome);
|
|
278
|
-
const account = (0, account_store_1.registerManagedAccount)(
|
|
278
|
+
const account = (0, account_store_1.registerManagedAccount)(name, managedHome);
|
|
279
279
|
console.log(`账号已导入: ${account.id}`);
|
|
280
280
|
console.log(`来源 HOME: ${sourceHome}`);
|
|
281
281
|
console.log(`已复制到: ${account.codex_home}`);
|
|
@@ -283,27 +283,56 @@ function handleAccountImport(accountId, codexHome) {
|
|
|
283
283
|
/**
|
|
284
284
|
* 执行隔离登录流程,将账号录入到 cslot 管理目录。
|
|
285
285
|
*
|
|
286
|
-
* @param
|
|
286
|
+
* @param name 本地账号标识(等同于配置中的 name 字段)。
|
|
287
287
|
* @returns Promise,无返回值。
|
|
288
288
|
*/
|
|
289
|
-
async function handleAccountLogin(
|
|
290
|
-
const home = await (0, login_1.loginManagedAccount)(
|
|
289
|
+
async function handleAccountLogin(name) {
|
|
290
|
+
const home = await (0, login_1.loginManagedAccount)(name);
|
|
291
291
|
console.log(`登录完成,账号目录: ${home}`);
|
|
292
292
|
}
|
|
293
293
|
/**
|
|
294
294
|
* 删除配置中的账号项。
|
|
295
295
|
*
|
|
296
|
-
* @param
|
|
296
|
+
* @param name 本地账号标识(等同于配置中的 name 字段)。
|
|
297
297
|
* @returns 无返回值。
|
|
298
298
|
* @throws 当账号不存在时抛出错误。
|
|
299
299
|
*/
|
|
300
|
-
function handleAccountRemove(
|
|
301
|
-
const removed = (0, account_store_1.removeManagedAccount)(
|
|
300
|
+
function handleAccountRemove(name) {
|
|
301
|
+
const removed = (0, account_store_1.removeManagedAccount)(name);
|
|
302
302
|
if (!removed) {
|
|
303
|
-
throw new Error(`未找到账号 ${
|
|
303
|
+
throw new Error(`未找到账号 ${name}`);
|
|
304
304
|
}
|
|
305
305
|
console.log(`已删除账号配置: ${removed.id}`);
|
|
306
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* del 子命令入口:在未提供 name 时先展示当前已录入账号列表,便于选择。
|
|
309
|
+
*
|
|
310
|
+
* @param name 可选的账号标识(等同于配置中的 name 字段)。
|
|
311
|
+
* @returns 无返回值。
|
|
312
|
+
*/
|
|
313
|
+
function handleAccountRemoveCommand(name) {
|
|
314
|
+
if (!name) {
|
|
315
|
+
const config = (0, config_1.loadConfig)();
|
|
316
|
+
if (config.accounts.length === 0) {
|
|
317
|
+
console.log("当前没有已录入账号。");
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
console.log("当前已录入账号(name):");
|
|
321
|
+
for (const account of config.accounts) {
|
|
322
|
+
if (account.email) {
|
|
323
|
+
console.log(`- ${account.id} (${account.email})`);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
console.log(`- ${account.id}`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
console.log("");
|
|
330
|
+
console.log("请使用以下命令删除指定账号,例如:");
|
|
331
|
+
console.log(" codex-slot del <name>");
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
handleAccountRemove(name);
|
|
335
|
+
}
|
|
307
336
|
/**
|
|
308
337
|
* 判断后台服务当前是否在运行。
|
|
309
338
|
*
|
|
@@ -541,19 +570,19 @@ async function main() {
|
|
|
541
570
|
program
|
|
542
571
|
.command("add")
|
|
543
572
|
.description("登录并新增一个账号或工作空间")
|
|
544
|
-
.argument("<
|
|
545
|
-
.action(async (
|
|
546
|
-
await handleAccountLogin(
|
|
573
|
+
.argument("<name>", "账号标识(用于本地区分)")
|
|
574
|
+
.action(async (name) => {
|
|
575
|
+
await handleAccountLogin(name);
|
|
547
576
|
});
|
|
548
577
|
program
|
|
549
578
|
.command("del")
|
|
550
579
|
.description("删除一个已录入账号")
|
|
551
|
-
.argument("
|
|
552
|
-
.action(
|
|
580
|
+
.argument("[name]", "账号标识(用于本地区分),留空时会列出当前所有账号")
|
|
581
|
+
.action(handleAccountRemoveCommand);
|
|
553
582
|
program
|
|
554
583
|
.command("import")
|
|
555
584
|
.description("导入当前或指定 HOME 下的官方 codex 登录态")
|
|
556
|
-
.argument("<
|
|
585
|
+
.argument("<name>", "账号标识(用于本地区分)")
|
|
557
586
|
.argument("[codexHome]", "已有 HOME 目录,默认当前用户 HOME")
|
|
558
587
|
.action(handleAccountImport);
|
|
559
588
|
program
|
package/dist/server.js
CHANGED
|
@@ -153,7 +153,7 @@ function buildUpstreamHeaders(requestHeaders, accessToken, bodyLength, accountId
|
|
|
153
153
|
}
|
|
154
154
|
// body 会在本地先读取成 Buffer 以支持失败后切换账号重试,因此这里重算长度。
|
|
155
155
|
headers["content-length"] = String(bodyLength);
|
|
156
|
-
headers["user-agent"] = "codex-slot/0.1.
|
|
156
|
+
headers["user-agent"] = "codex-slot/0.1.1";
|
|
157
157
|
if (accountIdHeader) {
|
|
158
158
|
headers["chatgpt-account-id"] = accountIdHeader;
|
|
159
159
|
}
|
package/dist/usage-sync.js
CHANGED
|
@@ -94,7 +94,7 @@ async function refreshAccountUsage(accountId) {
|
|
|
94
94
|
headers: {
|
|
95
95
|
authorization: `Bearer ${accessToken}`,
|
|
96
96
|
accept: "application/json",
|
|
97
|
-
"user-agent": "codex-slot/0.1.
|
|
97
|
+
"user-agent": "codex-slot/0.1.1",
|
|
98
98
|
...(accountIdHeader ? { "chatgpt-account-id": accountIdHeader } : {})
|
|
99
99
|
}
|
|
100
100
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-slot",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "本地 Codex 多账号切换与状态管理工具",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/cli.js",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
31
|
-
"url": "git+https://github.com/openxiaobu/
|
|
31
|
+
"url": "git+https://github.com/openxiaobu/codex-slot.git"
|
|
32
32
|
},
|
|
33
|
-
"homepage": "https://github.com/openxiaobu/
|
|
33
|
+
"homepage": "https://github.com/openxiaobu/codex-slot#readme",
|
|
34
34
|
"bugs": {
|
|
35
|
-
"url": "https://github.com/openxiaobu/
|
|
35
|
+
"url": "https://github.com/openxiaobu/codex-slot/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"commander": "^14.0.3",
|