@openxiaobu/codexl 0.1.7 → 0.1.9
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 +5 -1
- package/dist/cli.js +70 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,11 @@ By default, `status` will:
|
|
|
51
51
|
- Remaining 5-hour / weekly quotas
|
|
52
52
|
- Reset times
|
|
53
53
|
- A status column with local block reasons and countdowns (for example: `5h_limited(2h27m)`)
|
|
54
|
-
- Enter an interactive mode where you can toggle `enabled` for
|
|
54
|
+
- Enter an interactive mode where you can toggle `enabled` for accounts:
|
|
55
|
+
- Up/Down: move selection
|
|
56
|
+
- Space: toggle `[x]` enabled / `[ ]` disabled
|
|
57
|
+
- Enter: confirm and save
|
|
58
|
+
- `q`: quit
|
|
55
59
|
|
|
56
60
|
If you only want a non-interactive snapshot of the current state:
|
|
57
61
|
|
package/dist/cli.js
CHANGED
|
@@ -59,37 +59,79 @@ async function handleInteractiveToggle() {
|
|
|
59
59
|
console.log("当前环境不支持交互式操作,请直接编辑配置文件或使用 --no-interactive 选项。");
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
const stdin = process.stdin;
|
|
63
|
+
node_readline_1.default.emitKeypressEvents(stdin);
|
|
64
|
+
stdin.setRawMode?.(true);
|
|
65
|
+
const config = (0, config_1.loadConfig)();
|
|
66
|
+
if (config.accounts.length === 0) {
|
|
67
|
+
console.log("当前没有已录入账号。");
|
|
68
|
+
stdin.setRawMode?.(false);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// 按名称排序,方便浏览。
|
|
72
|
+
const accounts = [...config.accounts].sort((a, b) => a.name.localeCompare(b.name));
|
|
73
|
+
let cursor = 0;
|
|
74
|
+
let changed = false;
|
|
75
|
+
const render = () => {
|
|
76
|
+
console.log("\n空格切换选中账号启用状态,回车确认,q 退出:\n");
|
|
77
|
+
for (let i = 0; i < accounts.length; i += 1) {
|
|
78
|
+
const account = accounts[i];
|
|
79
|
+
const prefix = i === cursor ? ">" : " ";
|
|
80
|
+
const checkbox = account.enabled ? "[x]" : "[ ]";
|
|
81
|
+
console.log(`${prefix} ${checkbox} ${account.name} (${account.codex_home})`);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const applyChanges = () => {
|
|
85
|
+
if (!changed)
|
|
86
|
+
return;
|
|
87
|
+
const latest = (0, config_1.loadConfig)();
|
|
88
|
+
for (const account of accounts) {
|
|
89
|
+
const index = latest.accounts.findIndex((item) => item.id === account.id);
|
|
90
|
+
if (index >= 0) {
|
|
91
|
+
latest.accounts[index] = account;
|
|
76
92
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
}
|
|
94
|
+
(0, config_1.saveConfig)(latest);
|
|
95
|
+
};
|
|
96
|
+
render();
|
|
97
|
+
const onKeypress = (_str, key) => {
|
|
98
|
+
if (key.name === "up") {
|
|
99
|
+
cursor = (cursor - 1 + accounts.length) % accounts.length;
|
|
100
|
+
render();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (key.name === "down") {
|
|
104
|
+
cursor = (cursor + 1) % accounts.length;
|
|
105
|
+
render();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (key.name === "space") {
|
|
109
|
+
accounts[cursor].enabled = !accounts[cursor].enabled;
|
|
110
|
+
changed = true;
|
|
111
|
+
render();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (key.name === "return" || key.name === "enter") {
|
|
115
|
+
applyChanges();
|
|
116
|
+
stdin.off("keypress", onKeypress);
|
|
117
|
+
stdin.setRawMode?.(false);
|
|
118
|
+
console.log("\n已保存账号启用状态变更。");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (key.name === "q" || (key.ctrl && key.name === "c")) {
|
|
122
|
+
stdin.off("keypress", onKeypress);
|
|
123
|
+
stdin.setRawMode?.(false);
|
|
124
|
+
if (changed) {
|
|
125
|
+
applyChanges();
|
|
126
|
+
console.log("\n已保存账号启用状态变更。");
|
|
82
127
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
console.log(`账号 ${account.name} 已${account.enabled ? "启用" : "禁用"}(id=${account.id},source=${account.codex_home})。`);
|
|
128
|
+
else {
|
|
129
|
+
console.log("\n未做任何变更。");
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
88
132
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
rl.close();
|
|
92
|
-
}
|
|
133
|
+
};
|
|
134
|
+
stdin.on("keypress", onKeypress);
|
|
93
135
|
}
|
|
94
136
|
/**
|
|
95
137
|
* 将已有的 Codex HOME 目录中的登录态复制到 codexl 自己的隔离目录并纳入管理。
|