























@@ -71,14 +71,19 @@ export function summarizeCodexRateLimits(
7171value: JsonValue | undefined,
7272nowMs = Date.now(),
7373): string | undefined {
74-const snapshots = collectCodexRateLimitSnapshots(value);
74+const snapshots = collectCodexRateLimitSnapshots(value).filter(snapshotHasDisplayableData);
7575if (snapshots.length === 0) {
7676return undefined;
7777}
78-return snapshots
78+const summaries = snapshots
7979.slice(0, 4)
8080.map((snapshot) => summarizeRateLimitSnapshot(snapshot, nowMs))
81-.join("; ");
81+.filter((summary): summary is string => summary !== undefined);
82+return summaries.length > 0 ? summaries.join("; ") : undefined;
83+}
84+85+export function hasCodexRateLimitSnapshots(value: JsonValue | undefined): boolean {
86+return collectCodexRateLimitSnapshots(value).length > 0;
8287}
83888489export function summarizeCodexAccountRateLimits(
@@ -113,7 +118,7 @@ export function summarizeCodexAccountUsage(
113118value: JsonValue | undefined,
114119nowMs = Date.now(),
115120): CodexAccountUsageSummary | undefined {
116-const snapshots = collectCodexRateLimitSnapshots(value);
121+const snapshots = collectCodexRateLimitSnapshots(value).filter(snapshotHasDisplayableData);
117122if (snapshots.length === 0) {
118123return undefined;
119124}
@@ -192,7 +197,7 @@ function selectBlockingRateLimitReset(
192197return blockingSnapshot ? selectSnapshotBlockingReset(blockingSnapshot, nowMs) : undefined;
193198}
194199195-function summarizeRateLimitSnapshot(snapshot: JsonObject, nowMs: number): string {
200+function summarizeRateLimitSnapshot(snapshot: JsonObject, nowMs: number): string | undefined {
196201const label = formatLimitLabel(snapshot);
197202const windows = LIMIT_WINDOW_KEYS.flatMap((key) => {
198203const window = readRateLimitWindow(snapshot, key);
@@ -201,7 +206,13 @@ function summarizeRateLimitSnapshot(snapshot: JsonObject, nowMs: number): string
201206const reachedType =
202207readString(snapshot, "rateLimitReachedType") ?? readString(snapshot, "rate_limit_reached_type");
203208const suffix = reachedType ? ` (${formatReachedType(reachedType)})` : "";
204-return `${label}: ${windows.join(" · ") || "available"}${suffix}`;
209+if (windows.length > 0) {
210+return `${label}: ${windows.join(" · ")}${suffix}`;
211+}
212+if (reachedType) {
213+return `${label}: ${formatReachedType(reachedType)}`;
214+}
215+return undefined;
205216}
206217207218function collectCodexRateLimitSnapshots(value: JsonValue | undefined): JsonObject[] {
@@ -314,6 +325,18 @@ function readRateLimitWindow(
314325};
315326}
316327328+function snapshotHasDisplayableData(snapshot: JsonObject): boolean {
329+if (
330+readString(snapshot, "rateLimitReachedType") ??
331+readString(snapshot, "rate_limit_reached_type")
332+) {
333+return true;
334+}
335+return readWindowEntries(snapshot).some(
336+(entry) => entry.window.usedPercent !== undefined || entry.window.resetsAtMs > 0,
337+);
338+}
339+317340function readOptionalNumberField(
318341record: JsonObject,
319342 ...keys: string[]
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。