ccus-cli 0.1.25 → 0.1.26
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/dist/lib/api-mode.js +31 -9
- package/package.json +1 -1
package/dist/lib/api-mode.js
CHANGED
|
@@ -161,9 +161,11 @@ function renderHeader(value, token) {
|
|
|
161
161
|
/**
|
|
162
162
|
* 智谱 GLM Coding Plan 的内置 extractor 脚本(zhipu provider 的预设)。
|
|
163
163
|
*
|
|
164
|
-
* data.limits 里筛 type==="TOKENS_LIMIT"
|
|
165
|
-
*
|
|
166
|
-
*
|
|
164
|
+
* data.limits 里筛 type==="TOKENS_LIMIT",用 number 字段识别桶位:5h 桶 number===5、周桶 number===1。
|
|
165
|
+
* 不能用 nextResetTime 大小排序区分——5h 与周窗口的重置时刻互不相关,实测周桶 nextResetTime 可早于 5h,
|
|
166
|
+
* 升序会把周桶当 5h、5h 当周桶,5h/7d 互换(曾因「缺 nextResetTime 归 5h」启发式反复互换)。
|
|
167
|
+
* 5h 桶 = number===5 的那条,周桶 = 余下第一条;number 缺失(老接口)才退回 nextResetTime 稳定排序
|
|
168
|
+
* (有值优先、缺值按原序,不强制归前/后)。对照 deluo/glm-quota-line 的同类实现。
|
|
167
169
|
* success !== true / code !== 200 / 缺 data.limits 时返回会让归一化判 null 的值。
|
|
168
170
|
* zhipu 不再单独维护提取函数,与 custom 走同一条 `runExtractor` 路径,只是 extractor 用这组内置脚本。
|
|
169
171
|
*/
|
|
@@ -177,13 +179,33 @@ exports.ZHIPU_EXTRACTOR = `function(response) {
|
|
|
177
179
|
if (!Array.isArray(limits)) return null;
|
|
178
180
|
const tokenLimits = limits
|
|
179
181
|
.filter((l) => l && l.type === "TOKENS_LIMIT")
|
|
180
|
-
.map((l) => ({ p: l.percentage, r: l.nextResetTime }))
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
.map((l, i) => ({ p: l.percentage, n: l.number, r: l.nextResetTime, i }));
|
|
183
|
+
if (tokenLimits.length === 0) return null;
|
|
184
|
+
// 5h 桶 number===5、周桶 number===1。nextResetTime 大小不可靠(周桶重置可早于 5h),
|
|
185
|
+
// 必须用 number 显式识别 5h,否则两槽位互换。
|
|
186
|
+
const fiveHour = tokenLimits.find((l) => l.n === 5);
|
|
187
|
+
let first, second;
|
|
188
|
+
if (fiveHour) {
|
|
189
|
+
first = fiveHour;
|
|
190
|
+
second = tokenLimits.find((l) => l !== fiveHour);
|
|
191
|
+
} else if (tokenLimits.length === 1) {
|
|
192
|
+
first = tokenLimits[0];
|
|
193
|
+
} else {
|
|
194
|
+
// 老接口无 number:退回 nextResetTime 稳定排序(有值优先,缺值按原序,不强制归前/后)。
|
|
195
|
+
tokenLimits.sort((a, b) => {
|
|
196
|
+
const ar = typeof a.r === "number";
|
|
197
|
+
const br = typeof b.r === "number";
|
|
198
|
+
if (ar && br && a.r !== b.r) return a.r - b.r;
|
|
199
|
+
if (ar && !br) return -1;
|
|
200
|
+
if (!ar && br) return 1;
|
|
201
|
+
return a.i - b.i;
|
|
202
|
+
});
|
|
203
|
+
first = tokenLimits[0];
|
|
204
|
+
second = tokenLimits[1];
|
|
205
|
+
}
|
|
184
206
|
return {
|
|
185
|
-
fiveHour:
|
|
186
|
-
sevenDay:
|
|
207
|
+
fiveHour: first ? first.p : null,
|
|
208
|
+
sevenDay: second ? second.p : null,
|
|
187
209
|
level: typeof data.level === "string" && data.level !== "" ? data.level : null,
|
|
188
210
|
};
|
|
189
211
|
}`;
|