2026-06-14 06:15:34 +02:00
|
|
|
/**
|
|
|
|
|
* @fileoverview Process-wide last-known plan-usage telemetry (account-global).
|
|
|
|
|
*
|
2026-10-22 19:32:17 +02:00
|
|
|
* The Claude status-telemetry route and the host Codex and Copilot polls merge their latest
|
2026-08-26 18:43:52 +08:00
|
|
|
* values here. The SSE init snapshot (`getLightState`) replays the combined
|
|
|
|
|
* value so the header "Plan Usage Limits" chip shows immediately on a fresh
|
|
|
|
|
* page load / SSE reconnect — before either source emits another sample, and
|
|
|
|
|
* without relying on per-browser localStorage.
|
2026-06-14 06:15:34 +02:00
|
|
|
*
|
|
|
|
|
* Null until the first telemetry of the process; cleared naturally on restart.
|
|
|
|
|
*
|
|
|
|
|
* @module plan-usage-latest
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
let latest: Record<string, unknown> | null = null;
|
|
|
|
|
|
2026-08-26 18:43:52 +08:00
|
|
|
export function setLatestPlanUsage(value: Record<string, unknown>): Record<string, unknown> {
|
2026-10-22 19:32:17 +02:00
|
|
|
// The Claude status route replaces the Claude part; the host-polled providers ride along.
|
2026-08-26 18:43:52 +08:00
|
|
|
const codex = latest?.codex;
|
2026-10-22 19:32:17 +02:00
|
|
|
const copilot = latest?.copilot;
|
|
|
|
|
latest = {
|
|
|
|
|
...value,
|
|
|
|
|
...(codex !== undefined ? { codex } : {}),
|
|
|
|
|
...(copilot !== undefined ? { copilot } : {}),
|
|
|
|
|
};
|
2026-08-26 18:43:52 +08:00
|
|
|
return latest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setLatestCodexPlanUsage(value: object | null): Record<string, unknown> {
|
|
|
|
|
latest = { ...(latest ?? {}), codex: value };
|
|
|
|
|
return latest;
|
2026-06-14 06:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-22 19:32:17 +02:00
|
|
|
export function setLatestCopilotPlanUsage(value: object | null): Record<string, unknown> {
|
|
|
|
|
latest = { ...(latest ?? {}), copilot: value };
|
|
|
|
|
return latest;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 06:15:34 +02:00
|
|
|
export function getLatestPlanUsage(): Record<string, unknown> | null {
|
|
|
|
|
return latest;
|
|
|
|
|
}
|