summaryrefslogtreecommitdiff
path: root/quota.lua
diff options
context:
space:
mode:
Diffstat (limited to 'quota.lua')
-rw-r--r--quota.lua33
1 files changed, 26 insertions, 7 deletions
diff --git a/quota.lua b/quota.lua
index 3b6ecbc..7b32a55 100644
--- a/quota.lua
+++ b/quota.lua
@@ -39,6 +39,10 @@ function M.parse(body, reset_time)
end
if pct or at then
local label = group ~= '' and group ~= bucket and (group .. ' / ' .. bucket) or bucket
+ if group == 'Gemini Models' then
+ if bucket == 'Weekly Limit Remaining' then label = '1w'
+ elseif bucket == 'Five Hour Limit Remaining' then label = '5h' end
+ end
windows[#windows + 1] = {
label = pct and label:gsub(' Limit Remaining$', ' Limit Used') or label,
used_percent = pct and 100 - pct or nil,
@@ -58,6 +62,7 @@ function M.activate(ext, footer, acp)
if not state or state.closed then return function() end end
if state.antigravity_refresh then return state.antigravity_refresh end
local alive, ready, pending, next_run = true, false, nil, 0
+ local clock
local function publish(windows)
if not alive then return end
@@ -66,7 +71,8 @@ function M.activate(ext, footer, acp)
end
local render
if windows and #windows > 0 then
- local expires = os.time() + stale_s
+ local sampled = os.time()
+ local expires = sampled + stale_s
local stale = section({}, 'stale')
local cached, deadline = nil, 0
render = function(now)
@@ -74,13 +80,16 @@ function M.activate(ext, footer, acp)
if not cached or now >= deadline then
local current = {}
deadline = expires
+ local expired = false
for _, w in ipairs(windows) do
if not w.resets_at or w.resets_at > now then
current[#current + 1] = w
if w.resets_at then deadline = math.min(deadline, w.resets_at) end
+ elseif w.resets_at > sampled then
+ expired = true -- crossed a real reset since this reading
end
end
- cached = section(current, #current < #windows and 'stale' or nil)
+ cached = section(current, (#current == 0 or expired) and 'stale' or nil)
end
return cached(now)
end
@@ -91,8 +100,7 @@ function M.activate(ext, footer, acp)
pcall(footer.publish, ext, key, render)
end
- -- The caller supplies direct-turn provenance. Only a visible footer needs
- -- a sample. Drop duplicate calls in flight or inside the cooldown; no polling.
+ -- Only a visible footer needs a sample. Coalesce startup and turn reads.
local function refresh()
if not alive or not ready or not state.handle or pending then return end
local now = uv.hrtime() / 1000000
@@ -151,13 +159,24 @@ function M.activate(ext, footer, acp)
ext.on('session_ready', function(event)
if not alive or ready or event.has_tui == false then return end
ready = true
- -- Show a placeholder without touching the account; only a direct turn
- -- may replace it with an actual reading.
- pcall(footer.publish,ext,key,footer.section(ext,'antigravity',{}, {status='awaiting first turn'}))
+ pcall(footer.publish,ext,key,footer.section(ext,'antigravity',{}, {status='loading'}))
+ refresh()
+ -- A long-running or idle Neon thread may not cross a turn boundary
+ -- before the five-minute sample expires. No polling on other models.
+ clock = uv.new_timer()
+ clock:start(180000, 180000, function()
+ if not alive or not state.handle then return end
+ local info = ext.session_info()
+ local provider = info and info.model and info.model:match('^([^:]+):')
+ local cfg = provider and ext.config.providers[provider]
+ if cfg and cfg.protocol == 'antigravity-acp' and cfg.usage_footer ~= false then refresh() end
+ end)
+ clock:unref()
end)
state.antigravity_refresh = refresh
ext.on('session_end', function()
alive = false
+ close(clock)
if pending then pending.stop() end
state.antigravity_refresh, state.sections[key] = nil, nil
end)