@ipv9/tokentracker-cli 0.39.41 → 0.39.43
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 +84 -38
- package/dashboard/dist/assets/{Card-BwY_Qv6N.js → Card-LPizs_gs.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-C7b_GjA-.js → DashboardPage-CkhqD3x3.js} +3 -3
- package/dashboard/dist/assets/{FadeIn-DiAafUDN.js → FadeIn-B8aDegoD.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-CYgWVZJr.js → IpCheckPage-Vo2ZZXov.js} +1 -1
- package/dashboard/dist/assets/LimitsPage-C5-Q9Q30.js +2 -0
- package/dashboard/dist/assets/{LocalOnlyNotice-B5_-ydeu.js → LocalOnlyNotice-DXVmRcyV.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-DDjjQ5CG.js → PopoverPopup-CJf61ahu.js} +1 -1
- package/dashboard/dist/assets/{Select-BPspkl9p.js → Select-BLGoaqgw.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-CX0dWYB1.js → SelectItemText-Bt02Fgwf.js} +1 -1
- package/dashboard/dist/assets/{SettingsPage-9K5ST4D_.js → SettingsPage-BnUJew-8.js} +1 -1
- package/dashboard/dist/assets/{SkillsPage-BpCSS7ls.js → SkillsPage-ImHg3Puy.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-aBisLWrM.js → WidgetsPage-qscVE2nO.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-BgkuBG_j.js → WrappedPage-qM_7aClE.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-DPb2FRSP.js → arrow-up-right-CByq3BPT.js} +1 -1
- package/dashboard/dist/assets/{download-CbZ8YL8m.js → download-CTwO-YeA.js} +1 -1
- package/dashboard/dist/assets/{format-aRaCvnht.js → format-4chvNBjF.js} +1 -1
- package/dashboard/dist/assets/limitDisplay-CXlkWhjp.js +1 -0
- package/dashboard/dist/assets/{main-DRcFJLLD.js → main-CCPcJ7ti.js} +6 -3
- package/dashboard/dist/assets/{mock-data-sZ3-GZV0.js → mock-data-DSiJ-9lr.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-2-qYvffB.js → use-limits-display-prefs-Dgd-bQBC.js} +1 -1
- package/dashboard/dist/assets/{use-native-settings-C1uhDKdL.js → use-native-settings-CjZRLdFT.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-BPCF4zUv.js → useCurrency-BJRU0syn.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/package.json +5 -3
- package/src/lib/pricing/index.js +23 -1
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/usage-limits.js +49 -9
- package/dashboard/dist/assets/LimitsPage-C1y75ftN.js +0 -2
- package/dashboard/dist/assets/limitDisplay-1O9-AdgI.js +0 -1
package/src/lib/usage-limits.js
CHANGED
|
@@ -41,13 +41,28 @@ function clampPercent(value) {
|
|
|
41
41
|
return n;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
// `used`/`limit` are optional and only emitted when a provider actually reports
|
|
45
|
+
// countable units — Copilot's premium requests are the first. Most providers
|
|
46
|
+
// publish a percentage and nothing to count, so the keys are omitted rather than
|
|
47
|
+
// set to null: their payload shape stays byte-identical and no consumer has to
|
|
48
|
+
// learn a new field it will never see.
|
|
49
|
+
function buildWindow({ usedPercent, resetAt, used, limit }) {
|
|
45
50
|
const pct = clampPercent(usedPercent);
|
|
46
51
|
if (pct === null) return null;
|
|
47
|
-
|
|
52
|
+
const window = {
|
|
48
53
|
used_percent: pct,
|
|
49
54
|
reset_at: typeof resetAt === "string" && resetAt ? resetAt : null,
|
|
50
55
|
};
|
|
56
|
+
const usedCount = Number(used);
|
|
57
|
+
const limitCount = Number(limit);
|
|
58
|
+
if (Number.isFinite(usedCount) && Number.isFinite(limitCount) && limitCount > 0) {
|
|
59
|
+
// Clamp to the allowance: a plan can report more consumed than granted
|
|
60
|
+
// (over-quota keeps billing), and "312/300 used" reads as a bug even when
|
|
61
|
+
// it is the truth. The percentage is already clamped for the same reason.
|
|
62
|
+
window.used = Math.max(0, Math.min(limitCount, usedCount));
|
|
63
|
+
window.limit = limitCount;
|
|
64
|
+
}
|
|
65
|
+
return window;
|
|
51
66
|
}
|
|
52
67
|
|
|
53
68
|
function decodeJwtPayload(token) {
|
|
@@ -1155,22 +1170,47 @@ function copilotResetIso(value) {
|
|
|
1155
1170
|
return new Date(ts).toISOString();
|
|
1156
1171
|
}
|
|
1157
1172
|
|
|
1173
|
+
// `Number(null)` is 0 and `Number("")` is 0, so coercing a missing field reads
|
|
1174
|
+
// as "none left" — a snapshot with `remaining: null` reported the entire
|
|
1175
|
+
// allowance consumed. Require an actual finite number.
|
|
1176
|
+
function copilotCount(value) {
|
|
1177
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1158
1180
|
function buildCopilotWindow(snapshot, resetIso) {
|
|
1159
1181
|
if (!snapshot || typeof snapshot !== "object") return null;
|
|
1160
|
-
const entitlement =
|
|
1161
|
-
const remaining =
|
|
1162
|
-
const percentRemaining =
|
|
1182
|
+
const entitlement = copilotCount(snapshot.entitlement);
|
|
1183
|
+
const remaining = copilotCount(snapshot.remaining);
|
|
1184
|
+
const percentRemaining = copilotCount(snapshot.percent_remaining);
|
|
1163
1185
|
const allZero = (!entitlement || entitlement <= 0) && (!remaining || remaining <= 0) && (!percentRemaining || percentRemaining <= 0);
|
|
1164
1186
|
if (allZero) return null;
|
|
1187
|
+
// The counts are what the user actually asked about ("how many premium
|
|
1188
|
+
// requests do I have left"), and they were being read, divided once, and
|
|
1189
|
+
// thrown away.
|
|
1190
|
+
const hasCounts = entitlement !== null && entitlement > 0 && remaining !== null;
|
|
1191
|
+
|
|
1192
|
+
// When GitHub sends BOTH a percentage and counts, derive the percentage from
|
|
1193
|
+
// the counts rather than trusting `percent_remaining`. The two can disagree —
|
|
1194
|
+
// `percent_remaining: 30` alongside `entitlement: 300, remaining: 72` means a
|
|
1195
|
+
// 70%-wide bar captioned "228/300", which is 76%. The caption is the number
|
|
1196
|
+
// the user reads, so the bar has to be a drawing of it, not of a separately
|
|
1197
|
+
// rounded field. `percent_remaining` stays the fallback for the case it was
|
|
1198
|
+
// added for: a percentage with no denominator to count against.
|
|
1165
1199
|
let usedPercent;
|
|
1166
|
-
if (
|
|
1167
|
-
usedPercent = 100 - percentRemaining;
|
|
1168
|
-
} else if (Number.isFinite(entitlement) && entitlement > 0 && Number.isFinite(remaining)) {
|
|
1200
|
+
if (hasCounts) {
|
|
1169
1201
|
usedPercent = ((entitlement - remaining) / entitlement) * 100;
|
|
1202
|
+
} else if (percentRemaining !== null) {
|
|
1203
|
+
usedPercent = 100 - percentRemaining;
|
|
1170
1204
|
} else {
|
|
1171
1205
|
return null;
|
|
1172
1206
|
}
|
|
1173
|
-
|
|
1207
|
+
|
|
1208
|
+
return buildWindow({
|
|
1209
|
+
usedPercent,
|
|
1210
|
+
resetAt: resetIso,
|
|
1211
|
+
used: hasCounts ? entitlement - remaining : undefined,
|
|
1212
|
+
limit: hasCounts ? entitlement : undefined,
|
|
1213
|
+
});
|
|
1174
1214
|
}
|
|
1175
1215
|
|
|
1176
1216
|
function describeCopilotOtelStatus({ home, env = process.env } = {}) {
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as i,x as f,p as s,r as I,G as O,L as P,S as R}from"./main-DRcFJLLD.js";import{j as o,u as C}from"./limitDisplay-1O9-AdgI.js";import{L as x,u as T}from"./use-limits-display-prefs-2-qYvffB.js";import{C as v}from"./Card-BwY_Qv6N.js";import{F as S}from"./FadeIn-DiAafUDN.js";import{L as A}from"./LocalOnlyNotice-B5_-ydeu.js";import{i as M}from"./mock-data-sZ3-GZV0.js";import"./arrow-up-right-DPb2FRSP.js";import"./download-CbZ8YL8m.js";import"./format-aRaCvnht.js";const z=[3,2,3,3,2,2,3];function u({className:n}){return i.jsx("div",{className:f("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",n)})}function D(){return i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(u,{className:"h-3 w-12 shrink-0"}),i.jsx(u,{className:"flex-1 h-1.5 rounded-full min-w-0"}),i.jsx(u,{className:"h-3 w-[30px] shrink-0"}),i.jsx(u,{className:"h-3 w-6 shrink-0"})]})}function G({bars:n,index:e}){const r=e%3===0?"w-24":e%3===1?"w-20":"w-[4.5rem]";return i.jsxs("div",{className:"flex flex-col gap-1.5",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(u,{className:"h-[14px] w-[14px] rounded shrink-0"}),i.jsx(u,{className:f("h-4",r)})]}),Array.from({length:n},(t,l)=>i.jsx(D,{},l))]})}function H(){return i.jsx(v,{children:i.jsxs("div",{className:"flex flex-col gap-3",children:[i.jsx(u,{className:"h-3.5 w-28"}),z.map((n,e)=>i.jsx(G,{bars:n,index:e},e))]})})}function U(n,e){const r=e===x.REMAINING?100-n:n;return r>=90?"bg-red-500":r>=70?"bg-amber-500":"bg-emerald-500"}function a({label:n,pct:e,reset:r,mode:t=x.USED}){const l=Math.max(0,Math.min(100,Number(e)||0)),d=t===x.REMAINING?100-l:l,w=Math.round(d),_=d>0&&w===0?Math.max(d,.35):d,y=d>0&&w===0?"<1":String(w);return i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 w-12 shrink-0",children:n}),i.jsx("div",{className:"flex-1 bg-oai-gray-100 dark:bg-oai-gray-700/50 rounded-full h-1.5 overflow-hidden",children:i.jsx("div",{className:`${U(d,t)} rounded-full h-full transition-[width] duration-500 ease-out`,style:{width:`${_}%`,minWidth:d>0?"3px":0}})}),i.jsxs("span",{className:"text-[11px] tabular-nums text-oai-gray-500 dark:text-oai-gray-400 w-9 text-right shrink-0 whitespace-nowrap",children:[y,"%"]}),r?i.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-500 w-6 text-right shrink-0",children:r}):null]})}function m({name:n,icon:e,children:r}){const l=e==="/brand-logos/cursor.svg"||e==="/brand-logos/kiro.svg"||e==="/brand-logos/copilot.svg"||e==="/brand-logos/kimi.svg"?"w-[14px] h-[14px] dark:invert":"w-[14px] h-[14px]";return i.jsxs("div",{className:"flex flex-col gap-1.5",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[e?i.jsx("img",{src:e,alt:"",className:l}):null,i.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:n})]}),r]})}const $=["claude","codex","cursor","gemini","kimi","zai","kiro","copilot","antigravity"],B={claude:{name:"Claude",icon:"/brand-logos/claude-code.svg"},codex:{name:"Codex",icon:"/brand-logos/codex.svg"},cursor:{name:"Cursor",icon:"/brand-logos/cursor.svg"},gemini:{name:"Gemini",icon:"/brand-logos/gemini.svg"},kimi:{name:"Kimi",icon:"/brand-logos/kimi.svg"},zai:{name:"Z.AI",icon:null},kiro:{name:"Kiro",icon:"/brand-logos/kiro.svg"},copilot:{name:"GitHub Copilot",icon:"/brand-logos/copilot.svg"},antigravity:{name:"Antigravity",icon:"/brand-logos/antigravity.svg"}};function c({children:n,tone:e="neutral"}){const r=e==="error"?"text-red-600 dark:text-red-400":"text-oai-gray-500 dark:text-oai-gray-400";return i.jsx("div",{className:`text-[11px] leading-snug ${r}`,children:n})}function F(n,e,r){const t=B[n];if(!t)return null;if(!e?.configured)return i.jsx(m,{name:t.name,icon:t.icon,children:i.jsx(c,{children:s("limits.status.not_connected")})},n);if(e.error)return i.jsx(m,{name:t.name,icon:t.icon,children:i.jsx(c,{tone:"error",children:s("shared.error.prefix",{error:e.error})})},n);const l=e.plan_label?`${t.name} ${e.plan_label}`:t.name;switch(n){case"claude":return i.jsxs(m,{name:l,icon:t.icon,children:[e.five_hour?i.jsx(a,{label:"5h",pct:e.five_hour.utilization,reset:o(e.five_hour.resets_at),mode:r}):null,e.seven_day?i.jsx(a,{label:"7d",pct:e.seven_day.utilization,reset:o(e.seven_day.resets_at),mode:r}):null,e.seven_day_opus?i.jsx(a,{label:"Opus",pct:e.seven_day_opus.utilization,reset:o(e.seven_day_opus.resets_at),mode:r}):null,e.cached?i.jsx(c,{children:s("limits.status.cached")}):null,!e.five_hour&&!e.seven_day&&!e.seven_day_opus?i.jsx(c,{children:s("limits.status.no_data")}):null]},"claude");case"codex":return i.jsxs(m,{name:l,icon:t.icon,children:[e.primary_window?i.jsx(a,{label:"5h",pct:e.primary_window.used_percent,reset:o(e.primary_window.reset_at),mode:r}):null,e.secondary_window?i.jsx(a,{label:"7d",pct:e.secondary_window.used_percent,reset:o(e.secondary_window.reset_at),mode:r}):null,!e.primary_window&&!e.secondary_window?i.jsx(c,{children:s("limits.status.no_data")}):null]},"codex");case"cursor":return i.jsxs(m,{name:l,icon:t.icon,children:[e.primary_window?i.jsx(a,{label:s("limits.label.cursor_plan"),pct:e.primary_window.used_percent,reset:o(e.primary_window.reset_at),mode:r}):null,e.secondary_window?i.jsx(a,{label:s("limits.label.cursor_auto"),pct:e.secondary_window.used_percent,reset:o(e.secondary_window.reset_at),mode:r}):null,e.tertiary_window?i.jsx(a,{label:s("limits.label.cursor_api"),pct:e.tertiary_window.used_percent,reset:o(e.tertiary_window.reset_at),mode:r}):null,!e.primary_window&&!e.secondary_window&&!e.tertiary_window?i.jsx(c,{children:s("limits.status.no_data")}):null]},"cursor");case"gemini":return i.jsxs(m,{name:l,icon:t.icon,children:[e.primary_window?i.jsx(a,{label:"Pro",pct:e.primary_window.used_percent,reset:o(e.primary_window.reset_at),mode:r}):null,e.secondary_window?i.jsx(a,{label:"Flash",pct:e.secondary_window.used_percent,reset:o(e.secondary_window.reset_at),mode:r}):null,e.tertiary_window?i.jsx(a,{label:"Lite",pct:e.tertiary_window.used_percent,reset:o(e.tertiary_window.reset_at),mode:r}):null,!e.primary_window&&!e.secondary_window&&!e.tertiary_window?i.jsx(c,{children:s("limits.status.no_data")}):null]},"gemini");case"kimi":return i.jsxs(m,{name:l,icon:t.icon,children:[e.primary_window?i.jsx(a,{label:s("limits.label.kimi_weekly"),pct:e.primary_window.used_percent,reset:o(e.primary_window.reset_at),mode:r}):null,e.secondary_window?i.jsx(a,{label:s("limits.label.kimi_5h"),pct:e.secondary_window.used_percent,reset:o(e.secondary_window.reset_at),mode:r}):null,e.tertiary_window?i.jsx(a,{label:s("limits.label.kimi_total"),pct:e.tertiary_window.used_percent,reset:o(e.tertiary_window.reset_at),mode:r}):null,e.parallel_limit?i.jsx(c,{children:s("limits.label.kimi_parallel",{count:e.parallel_limit})}):null,!e.primary_window&&!e.secondary_window&&!e.tertiary_window?i.jsx(c,{children:s("limits.status.no_data")}):null]},"kimi");case"zai":return i.jsxs(m,{name:l,icon:t.icon,children:[e.primary_window?i.jsx(a,{label:s("limits.label.zai_5h"),pct:e.primary_window.used_percent,reset:o(e.primary_window.reset_at),mode:r}):null,e.secondary_window?i.jsx(a,{label:s("limits.label.zai_weekly"),pct:e.secondary_window.used_percent,reset:o(e.secondary_window.reset_at),mode:r}):null,e.tertiary_window?i.jsx(a,{label:s("limits.label.zai_mcp"),pct:e.tertiary_window.used_percent,reset:o(e.tertiary_window.reset_at),mode:r}):null,!e.primary_window&&!e.secondary_window&&!e.tertiary_window?i.jsx(c,{children:s("limits.status.no_data")}):null]},"zai");case"kiro":return i.jsxs(m,{name:l,icon:t.icon,children:[e.primary_window?i.jsx(a,{label:s("limits.label.kiro_month"),pct:e.primary_window.used_percent,reset:o(e.primary_window.reset_at),mode:r}):null,e.secondary_window?i.jsx(a,{label:s("limits.label.kiro_bonus"),pct:e.secondary_window.used_percent,reset:o(e.secondary_window.reset_at),mode:r}):null,!e.primary_window&&!e.secondary_window?i.jsx(c,{children:s("limits.status.no_data")}):null]},"kiro");case"antigravity":return i.jsxs(m,{name:l,icon:t.icon,children:[e.primary_window?i.jsx(a,{label:"Claude",pct:e.primary_window.used_percent,reset:o(e.primary_window.reset_at),mode:r}):null,e.secondary_window?i.jsx(a,{label:"G Pro",pct:e.secondary_window.used_percent,reset:o(e.secondary_window.reset_at),mode:r}):null,e.tertiary_window?i.jsx(a,{label:"Flash",pct:e.tertiary_window.used_percent,reset:o(e.tertiary_window.reset_at),mode:r}):null,!e.primary_window&&!e.secondary_window&&!e.tertiary_window?i.jsx(c,{children:s("limits.status.no_data")}):null]},"antigravity");case"copilot":return i.jsxs(m,{name:l,icon:t.icon,children:[e.primary_window?i.jsx(a,{label:s("limits.label.copilot_premium"),pct:e.primary_window.used_percent,reset:o(e.primary_window.reset_at),mode:r}):null,e.secondary_window?i.jsx(a,{label:s("limits.label.copilot_chat"),pct:e.secondary_window.used_percent,reset:o(e.secondary_window.reset_at),mode:r}):null,!e.primary_window&&!e.secondary_window?i.jsx(c,{children:s("limits.status.no_data")}):null,e.otel_has_files||e.otel_enabled?null:i.jsx(Y,{defaultDir:e.otel_default_dir})]},"copilot");default:return null}}function Y({defaultDir:n}){const[e,r]=I.useState(!1),l=["export COPILOT_OTEL_ENABLED=true","export COPILOT_OTEL_EXPORTER_TYPE=file",`export COPILOT_OTEL_FILE_EXPORTER_PATH="${n||"$HOME/.copilot/otel"}/copilot-otel-$(date +%Y%m%d).jsonl"`].join(`
|
|
2
|
-
`),d=async()=>{try{await navigator.clipboard.writeText(l),r(!0),setTimeout(()=>r(!1),1600)}catch{}};return i.jsxs("div",{className:"mt-1 rounded-md border border-amber-300/60 dark:border-amber-700/40 bg-amber-50/50 dark:bg-amber-900/10 px-2.5 py-2 text-[11px] text-oai-gray-600 dark:text-oai-gray-300",children:[i.jsx("div",{className:"font-medium text-oai-gray-700 dark:text-oai-gray-200",children:s("limits.copilot.otelHint.title")}),i.jsx("div",{className:"mt-0.5 leading-snug",children:s("limits.copilot.otelHint.body")}),i.jsx("pre",{className:"mt-1.5 overflow-x-auto rounded bg-oai-gray-100 dark:bg-oai-gray-900/60 px-2 py-1.5 font-mono text-[10.5px] leading-tight whitespace-pre",children:l}),i.jsx("button",{type:"button",onClick:d,className:"mt-1 inline-flex items-center gap-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 px-1.5 py-0.5 text-[10.5px] text-oai-gray-700 dark:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:e?s("limits.copilot.otelHint.copied"):s("limits.copilot.otelHint.copy")})]})}function K({claude:n,codex:e,cursor:r,gemini:t,kimi:l,zai:d,kiro:w,antigravity:_,copilot:y,order:h,visibility:g,displayMode:k}){const N={claude:n,codex:e,cursor:r,gemini:t,kimi:l,zai:d,kiro:w,antigravity:_,copilot:y},L=Array.isArray(h)&&h.length>0?h:$,b=k===x.REMAINING?x.REMAINING:x.USED,E=b===x.REMAINING?s("limits.settings.display_mode_remaining"):s("limits.settings.display_mode_used"),j=L.filter(p=>!g||g[p]!==!1).map(p=>F(p,N[p],b)).filter(Boolean);return i.jsx(S,{delay:.15,children:i.jsx(v,{children:i.jsxs("div",{className:"flex flex-col gap-3",children:[i.jsxs("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:[s("limits.panel.title"),s("limits.panel.mode_separator"),E]}),j.length>0?j:i.jsx(c,{children:s("limits.status.all_hidden")})]})})})}const V=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");function ne(){const n=O(),{data:e,error:r,isLoading:t}=C(n?{initialRefresh:!0,initialState:n,publishToPreloadCache:!0}:{initialRefresh:!0,publishToPreloadCache:!0}),l=T();return!V&&!M()?i.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:i.jsx(A,{})}):i.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:i.jsx("main",{className:"flex-1 pt-8 sm:pt-10 pb-12 sm:pb-16",children:i.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[i.jsxs("div",{className:"flex flex-row items-start justify-between gap-4 mb-8",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("h1",{className:"text-3xl sm:text-4xl font-semibold tracking-tight text-oai-black dark:text-white mb-3",children:s("nav.limits")}),i.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm sm:text-base",children:s("limits.page.subtitle")})]}),i.jsx(P,{to:"/settings","aria-label":s("limits.page.openSettings"),title:s("limits.page.openSettings"),className:"shrink-0 inline-flex h-9 w-9 items-center justify-center rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors no-underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:i.jsx(R,{className:"h-4 w-4","aria-hidden":!0})})]}),t?i.jsx(H,{}):i.jsxs(i.Fragment,{children:[r?i.jsx("p",{className:"mb-4 text-sm text-red-500 dark:text-red-400",children:s("shared.error.prefix",{error:r})}):null,i.jsx(K,{claude:e?.claude,codex:e?.codex,cursor:e?.cursor,gemini:e?.gemini,kimi:e?.kimi,zai:e?.zai,kiro:e?.kiro,antigravity:e?.antigravity,copilot:e?.copilot,order:l.order,visibility:l.visibility,displayMode:l.displayMode})]})]})})})}export{ne as LimitsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{H as L,r as w,F as j,j as p,p as _}from"./main-DRcFJLLD.js";import{i as g,n as U,o as z,p as I,q as N,r as v,s as C,t as D,u as E,v as H}from"./mock-data-sZ3-GZV0.js";import{L as k}from"./use-limits-display-prefs-2-qYvffB.js";const f={usageSummary:"tokentracker-usage-summary",usageDaily:"tokentracker-usage-daily",usageHourly:"tokentracker-usage-hourly",usageMonthly:"tokentracker-usage-monthly",usageHeatmap:"tokentracker-usage-heatmap",usageModelBreakdown:"tokentracker-usage-model-breakdown",usageCategoryBreakdown:"tokentracker-usage-category-breakdown",projectUsageSummary:"tokentracker-project-usage-summary",userStatus:"tokentracker-user-status",localSync:"tokentracker-local-sync",usageLimits:"tokentracker-usage-limits"};async function m(t,e,a){const r=new URL(`/functions/${t}`,window.location.origin);if(e)for(const[i,l]of Object.entries(e))l!=null&&l!==""&&r.searchParams.set(i,String(l));const{accessToken:n,...s}=a||{},o=await fetch(r.toString(),{headers:{Accept:"application/json"},cache:"no-store",...s});if(!o.ok){const i=new Error(`Request failed with HTTP ${o.status}`);throw i.status=o.status,i}return o.json()}function y({timeZone:t,tzOffsetMinutes:e}={}){const a={},r=typeof t=="string"?t.trim():"";return r&&(a.tz=r),Number.isFinite(e)&&(a.tz_offset_minutes=String(Math.trunc(e))),a}function b({source:t,model:e}={}){const a={},r=typeof t=="string"?t.trim().toLowerCase():"";r&&(a.source=r);const n=typeof e=="string"?e.trim():"";return n&&(a.model=n),a}async function J({from:t,to:e,source:a,model:r,timeZone:n,tzOffsetMinutes:s,rolling:o=!1,accessToken:i}={}){if(g())return z({from:t,to:e,seed:i,rolling:o});const l=y({timeZone:n,tzOffsetMinutes:s}),u=b({source:a,model:r}),h=o?{rolling:"1"}:{};return m(f.usageSummary,{from:t,to:e,...u,...l,...h},{accessToken:i})}async function O({from:t,to:e,source:a,limit:r,timeZone:n,tzOffsetMinutes:s,accessToken:o}={}){if(g())return v({seed:o,limit:r});const i=y({timeZone:n,tzOffsetMinutes:s}),u={...b({source:a}),...i};return t&&(u.from=t),e&&(u.to=e),r!=null&&(u.limit=String(r)),m(f.projectUsageSummary,u)}async function Y(t={}){if(g()){const e=new Date().toISOString();return{user_id:"local-user",created_at:e,pro:{active:!1,sources:[],expires_at:null,partial:!1,as_of:e},subscriptions:{partial:!1,as_of:e,items:[]}}}return m(f.userStatus)}async function Q({signal:t}={}){const e=await L(),a=await fetch(`/functions/${f.localSync}`,{method:"POST",headers:{Accept:"application/json",...e},cache:"no-store",signal:t}),r=await a.json().catch(()=>({ok:!1,error:`Local sync request failed with HTTP ${a.status}`}));if(!a.ok||r?.ok===!1){const n=r?.error||r?.message||`Local sync request failed with HTTP ${a.status}`,s=new Error(n);throw s.status=a.status,s}return r}async function V({from:t,to:e,source:a,timeZone:r,tzOffsetMinutes:n,accessToken:s}={}){if(g())return I({from:t,to:e,seed:s});const o=y({timeZone:r,tzOffsetMinutes:n}),i=b({source:a});return m(f.usageModelBreakdown,{from:t,to:e,...i,...o},{accessToken:s})}async function X({from:t,to:e,source:a="claude",timeZone:r,tzOffsetMinutes:n}={}){if(g())return H({from:t,to:e,source:a});const s=y({timeZone:r,tzOffsetMinutes:n});return m(f.usageCategoryBreakdown,{from:t,to:e,source:a,...s})}async function Z({from:t,to:e,source:a,model:r,timeZone:n,tzOffsetMinutes:s,accessToken:o}={}){if(g())return U({from:t,to:e,seed:o});const i=y({timeZone:n,tzOffsetMinutes:s}),l=b({source:a,model:r});return m(f.usageDaily,{from:t,to:e,...l,...i},{accessToken:o})}async function ee({day:t,source:e,model:a,timeZone:r,tzOffsetMinutes:n,accessToken:s}={}){if(g())return N({day:t,seed:s});const o=y({timeZone:r,tzOffsetMinutes:n}),i=b({source:e,model:a}),l=t?{day:t,...i,...o}:{...i,...o};return m(f.usageHourly,l,{accessToken:s})}async function te({months:t,to:e,source:a,model:r,timeZone:n,tzOffsetMinutes:s,accessToken:o}={}){if(g())return C({months:t,to:e,seed:o});const i=y({timeZone:n,tzOffsetMinutes:s}),l=b({source:a,model:r});return m(f.usageMonthly,{...t?{months:String(t)}:{},...e?{to:e}:{},...l,...i},{accessToken:o})}async function P(t={}){if(g())return E();const e=t?.refresh?{refresh:"1"}:void 0;return m(f.usageLimits,e)}async function ae({weeks:t,to:e,weekStartsOn:a,source:r,model:n,timeZone:s,tzOffsetMinutes:o,accessToken:i}={}){if(g())return D({weeks:t,to:e,weekStartsOn:a,seed:i});const l=y({timeZone:s,tzOffsetMinutes:o}),u=b({source:r,model:n});return m(f.usageHeatmap,{weeks:String(t),to:e,week_starts_on:a,...u,...l},{accessToken:i})}function re(t){const e=!!t?.initialState,[a,r]=w.useState(()=>e?t?.initialState?.data??null:null),[n,s]=w.useState(()=>e?t?.initialState?.error??null:null),[o,i]=w.useState(!e),l=!!t?.initialRefresh,u=!!t?.publishToPreloadCache,h=w.useCallback((c,d)=>{!u||!c||typeof c!="object"||j(c,{source:d})},[u]),x=w.useCallback(async()=>{try{const c=await P({refresh:!0}),d=c&&typeof c=="object"?c:null;r(d),s(null),h(d,"manual-refresh")}catch(c){s(c?.message||String(c))}},[h]);return w.useEffect(()=>{if(e&&!l)return;let c=!1;return(async()=>{try{const d=await P(l?{refresh:!0}:{});if(c)return;const S=d&&typeof d=="object"?d:null;r(S),s(null),h(S,"page-load")}catch(d){if(c)return;s(d?.message||String(d))}finally{c||i(!1)}})(),()=>{c=!0}},[e,l,h]),{data:a,error:n,isLoading:o,refresh:x}}function A(t){if(!t)return null;const e=typeof t=="number"?t*1e3:Date.parse(t);if(!Number.isFinite(e))return null;const a=e-Date.now();if(a<=0)return _("shared.time.now");const r=Math.floor(a/6e4);if(r<60)return`${r}m`;const n=Math.floor(r/60);return n<24?`${n}h`:`${Math.floor(n/24)}d`}const F=["claude","codex","cursor","gemini","kimi","zai","kiro","copilot","antigravity"],M={githubcopilot:"copilot",zhipu:"zai",glm:"zai"};function B(t){const e=String(t||"").toLowerCase().replace(/[^a-z0-9]/g,"");return F.includes(e)?e:M[e]?M[e]:null}const K={claude:[{field:"five_hour",label:"5h",pctField:"utilization",resetField:"resets_at"},{field:"seven_day",label:"7d",pctField:"utilization",resetField:"resets_at"}],codex:[{field:"primary_window",label:"5h"},{field:"secondary_window",label:"7d"}],cursor:[{field:"primary_window",labelKey:"limits.label.cursor_plan"},{field:"secondary_window",labelKey:"limits.label.cursor_auto"}],gemini:[{field:"primary_window",label:"Pro"},{field:"secondary_window",label:"Flash"}],kimi:[{field:"primary_window",labelKey:"limits.label.kimi_weekly"},{field:"secondary_window",labelKey:"limits.label.kimi_5h"}],zai:[{field:"primary_window",labelKey:"limits.label.zai_5h"},{field:"secondary_window",labelKey:"limits.label.zai_weekly"}],kiro:[{field:"primary_window",labelKey:"limits.label.kiro_month"},{field:"secondary_window",labelKey:"limits.label.kiro_bonus"}],antigravity:[{field:"primary_window",label:"Claude"},{field:"secondary_window",label:"G Pro"}],copilot:[{field:"primary_window",labelKey:"limits.label.copilot_premium"},{field:"secondary_window",labelKey:"limits.label.copilot_chat"}]};function R(t,e,a){const r=K[t];if(!r||!e)return[];const n=[];for(const s of r){const o=e[s.field];if(!o)continue;const i=Number(o[s.pctField||"used_percent"]);if(!Number.isFinite(i))continue;const l=Math.max(0,Math.min(100,i)),u=a===k.REMAINING?100-l:l;n.push({label:s.labelKey?_(s.labelKey):s.label,displayPct:u,reset:A(o[s.resetField||"reset_at"])})}return n}function $(t,e){const a=e===k.REMAINING?100-t:t;return a>=90?{dot:"bg-red-500",chip:"border-red-500/30 bg-red-500/10"}:a>=75?{dot:"bg-orange-500",chip:"border-orange-500/30 bg-orange-500/10"}:a>=50?{dot:"bg-amber-500",chip:"border-amber-500/30 bg-amber-500/10"}:{dot:"bg-oai-gray-400 dark:bg-oai-gray-500",chip:"border-oai-gray-200 dark:border-oai-gray-700 bg-oai-gray-100/70 dark:bg-oai-gray-800/40"}}function T({label:t,displayPct:e,reset:a,mode:r}){const n=$(e,r),s=Math.round(e),o=_("usage.overview.model_percent",{percent:s}),i=a?_("usage.overview.provider_limit_reset",{label:t,percent:s,reset:a}):_("usage.overview.provider_limit",{label:t,percent:s});return p.jsxs("span",{className:`inline-flex items-center gap-1.5 rounded-full border px-2 py-1 text-[11px] leading-none ${n.chip}`,title:i,"aria-label":i,children:[p.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${n.dot}`,"aria-hidden":"true"}),p.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:t}),p.jsx("span",{className:"font-semibold tabular-nums text-oai-black dark:text-oai-white",children:o})]})}function se({label:t,usageLimits:e,mode:a=k.USED}){if(!e||typeof e!="object")return null;const r=B(t);if(!r)return null;const n=e[r];if(!n||!n.configured)return null;const s=a===k.REMAINING?k.REMAINING:k.USED;if(n.error)return p.jsx("div",{className:"mt-2.5 pt-2.5 border-t border-dashed border-oai-gray-200 dark:border-oai-gray-700 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:_("shared.error.prefix",{error:n.error})});const o=R(r,n,s);return o.length===0?null:p.jsx("div",{className:"mt-2.5 pt-2.5 border-t border-dashed border-oai-gray-200 dark:border-oai-gray-700 flex flex-wrap items-center gap-1.5",children:o.map(i=>p.jsx(T,{label:i.label,displayPct:i.displayPct,reset:i.reset,mode:s},i.label))})}export{se as L,Z as a,O as b,te as c,ee as d,J as e,V as f,ae as g,X as h,Y as i,A as j,Q as t,re as u};
|