tokentracker-cli 0.5.24 → 0.5.25
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/dashboard/dist/assets/{DashboardPage-vIxKP44Z.js → DashboardPage-Bv4UcOEZ.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardPage-VXJBiwkB.js → LeaderboardPage-CbvvPyY_.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfilePage-DPeOBsNk.js → LeaderboardProfilePage-Co4mAr4h.js} +1 -1
- package/dashboard/dist/assets/{ThemeToggle-8m6pW0Kd.js → ThemeToggle-Qn_pvy0M.js} +1 -1
- package/dashboard/dist/assets/{leaderboard-columns-BtZZjmrK.js → leaderboard-columns-QXmWCpyM.js} +1 -1
- package/dashboard/dist/assets/{main-uLnyEwnj.js → main-C7szutiJ.js} +4 -4
- package/dashboard/dist/index.html +1 -1
- package/dashboard/dist/share.html +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,az as d,aA as Pe,aB as Re,ai as Me,aj as Ie,r as g,aC as $e,h as Be,j as Ue,C as o,aD as ze,aE as P,aF as De,av as F,aa as xe,aG as Ke,aH as Fe,a9 as He,aI as ge,aJ as me,aK as Oe}from"./main-uLnyEwnj.js";import{L as ye,a as ke,b as M,l as H,c as O,d as We,e as ue}from"./leaderboard-columns-BtZZjmrK.js";import{u as Ge,T as Ye}from"./ThemeToggle-8m6pW0Kd.js";function S(t,{min:r,max:s,fallback:n}){const i=Number(t);if(!Number.isFinite(i))return n;const c=Math.floor(i);return c<r?r:c>s?s:c}function Je(t,r){const s=S(r,{min:0,max:1e6,fallback:0}),n=S(t,{min:1,max:Math.max(1,s||1),fallback:1});if(s<=1)return[1];const i=new Set([1,s,n-2,n-1,n,n+1,n+2]),c=Array.from(i).filter(m=>Number.isInteger(m)&&m>=1&&m<=s).sort((m,L)=>m-L),u=[];let y=null;for(const m of c)y!=null&&m-y>1&&u.push(null),u.push(m),y=m;return u}function Ve({page:t,totalPages:r}){const s=typeof r=="number"&&Number.isFinite(r)&&r>=0,n=s?S(r,{min:0,max:1e6,fallback:0}):null,i=S(t,{min:1,max:s?Math.max(1,n||1):1e6,fallback:1}),c=i>1,u=s?i<n:!0;return{canPrev:c,canNext:u,safePage:i,safeTotal:n}}function qe({entries:t,me:r,meLabel:s,limit:n}){const i=S(n,{min:1,max:1e3,fallback:20}),c=Array.isArray(t)?t.slice(0,i):[],u=r&&typeof r.rank=="number"?r.rank:null,y=c.some(x=>!!x?.is_me);if(!u||y)return c;const m={rank:u,is_me:!0,display_name:s,avatar_url:null,gpt_tokens:r?.gpt_tokens??"0",claude_tokens:r?.claude_tokens??"0",gemini_tokens:r?.gemini_tokens??"0",cursor_tokens:r?.cursor_tokens??"0",opencode_tokens:r?.opencode_tokens??"0",openclaw_tokens:r?.openclaw_tokens??"0",other_tokens:r?.other_tokens??"0",total_tokens:r?.total_tokens??"0"},L=3,I=4,h=c.filter(x=>!x?.is_me).filter((x,B)=>B!==L).slice();return h.splice(Math.min(I,h.length),0,m),h.slice(0,i)}function p({className:t}){return e.jsx("div",{className:d("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function Qe({index:t}){const r=t<3?"w-24":t<8?"w-20":"w-16",s=t<3?"w-16":"w-12",n=t<5?"w-14":"w-10";return e.jsxs("tr",{className:"group",children:[e.jsx("td",{className:d(H(!1),"!group-hover:bg-transparent"),children:e.jsx(p,{className:"h-4 w-6"})}),e.jsx("td",{className:d(O(!1),"!group-hover:bg-transparent"),children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(p,{className:"h-8 w-8 min-w-8 rounded-full"}),e.jsx(p,{className:d("h-4",r)})]})}),e.jsx("td",{className:"px-4 py-4 bg-white dark:bg-oai-gray-950",children:e.jsx(p,{className:d("h-4",s)})}),e.jsx("td",{className:"px-4 py-4 bg-white dark:bg-oai-gray-950",children:e.jsx(p,{className:"h-4 w-12"})}),M.map(i=>e.jsx("td",{className:"px-4 py-4 bg-white dark:bg-oai-gray-950",children:e.jsx(p,{className:d("h-4",n)})},i.key))]})}function Xe({rows:t=10}){return e.jsx("div",{className:"w-full overflow-x-auto",children:e.jsxs("table",{className:"min-w-max w-full text-left text-sm",children:[e.jsx("thead",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800",children:e.jsxs("tr",{children:[e.jsx("th",{className:d(ye,"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:e.jsx(p,{className:"h-3.5 w-6"})}),e.jsx("th",{className:d(ke,"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:e.jsx(p,{className:"h-3.5 w-12"})}),e.jsx("th",{className:"px-4 py-4",children:e.jsx(p,{className:"h-3.5 w-10"})}),e.jsx("th",{className:"px-4 py-4",children:e.jsx(p,{className:"h-3.5 w-14"})}),M.map(r=>e.jsx("th",{className:"px-4 py-4",children:e.jsx(p,{className:"h-3.5 w-12"})},r.key))]})}),e.jsx("tbody",{className:"divide-y divide-oai-gray-100 dark:divide-oai-gray-800/50",children:Array.from({length:t},(r,s)=>e.jsx(Qe,{index:s},s))})]})})}const R=20;function he(t){const r=Number(t);return!Number.isFinite(r)||r<=0?"-":r>=1e3?`$${Math.round(r).toLocaleString()}`:r>=10?`$${Math.round(r)}`:`$${r.toFixed(2)}`}function be(t,r){const s=r?"text-oai-gray-700 dark:text-oai-gray-300":"text-oai-gray-500 dark:text-oai-gray-400",n=r?"bg-oai-brand-50 dark:bg-oai-brand-900/10":"bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60";return M.map(i=>e.jsx("td",{className:d("px-4 py-4 whitespace-nowrap text-right tabular-nums",s,n),children:F(t?.[i.key])},i.key))}const Ze={1:{text:"text-amber-600 dark:text-amber-400",badge:"bg-amber-50 dark:bg-amber-900/20"},2:{text:"text-gray-500 dark:text-gray-300",badge:"bg-gray-50 dark:bg-gray-800/40"},3:{text:"text-orange-700 dark:text-orange-400",badge:"bg-orange-50 dark:bg-orange-900/20"}};function pe({rank:t,placeholder:r}){const s=Ze[t];return s?e.jsx("span",{className:d("inline-flex items-center justify-center h-7 w-7 rounded-full text-xs font-bold",s.text,s.badge),children:t}):e.jsx("span",{className:"inline-flex items-center justify-center h-7 w-7 text-sm",children:t??r})}function W(t){if(typeof t!="string")return null;const r=t.trim().toLowerCase();return r==="week"||r==="month"||r==="total"?r:null}function ea(t){if(!t)return o("shared.error.prefix",{error:o("leaderboard.error.unknown")});const r=t?.message||String(t),s=String(r||"").trim()||o("leaderboard.error.unknown");return o("shared.error.prefix",{error:s})}function we(t){return typeof t!="string"?"":t.trim()}function aa(t){const r=we(t);return r?r.toLowerCase()==="anonymous":!0}function ra(t,r=""){if(typeof t!="string")return null;const s=t.trim().toLowerCase();if(!s)return null;const n=new URLSearchParams(typeof r=="string"?r:""),i=W(n.get("period")),c=i?`?period=${i}`:"";return`/share/pv1-${s}${c}`}function fe(t,r){const s=typeof t?.user_id=="string"?t.user_id.trim():"";return s||`${t?.rank??""}:${r}`}function ia({auth:t,signedIn:r,sessionSoftExpired:s}){const n=Pe(),i=Re(),{openLoginModal:c}=Me(),{signedIn:u,loading:y}=Ie(),{theme:m,resolvedTheme:L,setTheme:I}=Ge(),$=g.useMemo(()=>$e(),[]),h=Be(),x=r&&!s,B=g.useMemo(()=>x&&(typeof t=="function"||typeof t=="string"||t&&typeof t=="object")?t:null,[t,x]),v=x?B:null,_=x&&Ue(v),G=o("shared.placeholder.short"),[U,T]=g.useState(1),[je,Y]=g.useState(0),[b,C]=g.useState(()=>({loading:!1,error:null,data:null})),[J,Ne]=g.useState(()=>ze()),[V,q]=g.useState(!1),[Q,X]=g.useState(!1),k=g.useMemo(()=>{const a=new URLSearchParams(n?.search||"");return W(a.get("period"))||"total"},[n?.search]),ve=n?.search||"",_e=a=>{const l=W(a);if(!l||l===k)return;const N=new URLSearchParams(n?.search||"");N.set("period",l),T(1),i(`${n?.pathname||"/leaderboard"}?${N.toString()}`,{replace:!0})};g.useEffect(()=>{y||h||u||c()},[u,y,h,c]),g.useEffect(()=>{T(1)},[k]),g.useEffect(()=>{h||x&&(_||C({loading:!1,error:null,data:null}))},[x,_,h]);const Z=g.useMemo(()=>(S(U,{min:1,max:1e6,fallback:1})-1)*R,[U]);g.useEffect(()=>{if(!$&&!h||!h&&x&&!_)return;let a=!0;return C(l=>({...l,loading:!0,error:null})),(async()=>{const l=x?await P(v):null,N=await De({accessToken:l,period:k,limit:R,offset:Z});a&&C({loading:!1,error:null,data:N})})().catch(l=>{a&&C({loading:!1,error:ea(l),data:null})}),()=>{a=!1}},[$,v,x,_,Z,je,h,k]);const f=b.data,E=f?.total_pages??null,j=f?.page??U,Se=g.useMemo(()=>Je(j,E),[j,E]),ee=f?.from||null,ae=f?.to||null,re=f?.generated_at||null,te=f?.me||null,z=o("leaderboard.me_label"),Le=o("leaderboard.anon_label"),se=o("leaderboard.period.week"),oe=o("leaderboard.period.month"),ne=o("leaderboard.period.total"),ie=k==="month"?oe:k==="total"?ne:se,D=g.useMemo(()=>{const a=Array.isArray(f?.entries)?f.entries:[];return j!==1?a:qe({entries:a,me:te,meLabel:z,limit:R})},[j,f?.entries,te,z]),Te=async()=>{q(!0);try{Oe(!0),Ne(!0),await ge(()=>P(v));const a=await P(v);a&&await me({accessToken:a}),Y(l=>l+1)}catch(a){console.warn("[tokentracker] sync:",a)}finally{q(!1)}},Ae=async()=>{X(!0);try{const a=await P(v);J&&a&&await ge(()=>Promise.resolve(a)),a&&await me({accessToken:a}),Y(l=>l+1)}catch(a){console.warn("[tokentracker] refresh:",a)}finally{X(!1)}},{canPrev:le,canNext:de}=Ve({page:j,totalPages:E}),Ce=Array.isArray(D)&&D.length!==0;let A=null;b.loading?A=e.jsx(Xe,{rows:R}):b.error?A=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:b.error})}):Ce?A=e.jsx("div",{className:"w-full overflow-x-auto",children:e.jsxs("table",{className:"min-w-max w-full text-left text-sm",children:[e.jsx("thead",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800",children:e.jsxs("tr",{children:[e.jsx("th",{className:d(ye,"text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500"),children:o("leaderboard.column.rank")}),e.jsx("th",{className:d(ke,"text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500"),children:o("leaderboard.column.user")}),e.jsx("th",{className:"px-4 py-4 text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500 whitespace-nowrap text-right align-middle",children:o("leaderboard.column.total")}),e.jsx("th",{className:"px-4 py-4 text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500 whitespace-nowrap text-right align-middle",title:"Based on estimated API pricing, not actual billing",children:"Est. Cost"}),M.map(a=>e.jsx("th",{className:"px-4 py-4 text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500 whitespace-nowrap align-middle",children:e.jsx("div",{className:"flex items-center justify-end gap-2",children:e.jsx(We,{iconSrc:a.icon,label:o(a.copyKey)})})},a.key))]})}),e.jsx("tbody",{className:"divide-y divide-oai-gray-100 dark:divide-oai-gray-800/50",children:D.map(a=>{const l=!!a?.is_me,N=typeof a?.user_id=="string"?a.user_id:null,ce=we(a?.display_name),Ee=aa(ce)?Le:ce,w=l?z:Ee;return!!N&&!l&&!!a?.is_public&&ra(N,ve),l?e.jsxs("tr",{className:"border-y border-oai-brand-300/40 dark:border-oai-brand-500/30 bg-oai-brand-50 dark:bg-oai-brand-900/10 transition-colors",children:[e.jsx("td",{className:d(H(!0),"font-semibold text-oai-brand-600 dark:text-oai-brand-400"),children:e.jsx(pe,{rank:a?.rank,placeholder:G})}),e.jsx("td",{className:O(!0),children:e.jsxs("div",{className:"flex min-w-0 max-w-[min(160px,40vw)] items-center gap-4",children:[e.jsx(ue,{avatarUrl:a?.avatar_url,displayName:w,seed:fe(a,w)}),e.jsx("span",{className:"truncate font-semibold text-oai-black dark:text-oai-white",children:w})]})}),e.jsx("td",{className:"px-4 py-4 font-medium text-oai-black dark:text-oai-white whitespace-nowrap text-right tabular-nums bg-oai-brand-50 dark:bg-oai-brand-900/10",children:F(a?.total_tokens)}),e.jsx("td",{className:"px-4 py-4 font-medium text-oai-brand-600 dark:text-oai-brand-400 whitespace-nowrap text-right tabular-nums bg-oai-brand-50 dark:bg-oai-brand-900/10",title:"Based on estimated API pricing, not actual billing",children:he(a?.estimated_cost_usd)}),be(a,!0)]},`row-${a?.rank}-${w}`):e.jsxs("tr",{className:"group transition-colors",children:[e.jsx("td",{className:d(H(!1),"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:e.jsx(pe,{rank:a?.rank,placeholder:G})}),e.jsx("td",{className:O(!1),children:e.jsxs("div",{className:"flex min-w-0 max-w-[min(160px,40vw)] items-center gap-4",children:[e.jsx(ue,{avatarUrl:a?.avatar_url,displayName:w,seed:fe(a,w)}),e.jsx("span",{className:"truncate font-medium text-oai-gray-800 dark:text-oai-gray-200",children:w})]})}),e.jsx("td",{className:"px-4 py-4 font-semibold text-oai-gray-800 dark:text-oai-gray-200 whitespace-nowrap text-right tabular-nums bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60",children:F(a?.total_tokens)}),e.jsx("td",{className:"px-4 py-4 text-oai-gray-500 dark:text-oai-gray-400 whitespace-nowrap text-right tabular-nums bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60",title:"Based on estimated API pricing, not actual billing",children:he(a?.estimated_cost_usd)}),be(a,!1)]},`row-${a?.rank}-${w}`)})})]})}):A=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:o("leaderboard.empty")})});let K=null;return typeof E=="number"?K=Se.map((a,l)=>a==null?e.jsx("span",{className:"px-2 text-oai-gray-400 dark:text-oai-gray-500",children:o("leaderboard.pagination.ellipsis")},`ellipsis-${l}`):e.jsx("button",{className:d("flex h-8 w-8 items-center justify-center rounded-md text-sm font-medium transition-colors",a===j?"bg-oai-gray-200 dark:bg-oai-gray-800 text-oai-black dark:text-white":"text-oai-gray-500 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white"),onClick:()=>T(a),disabled:b.loading,children:String(a)},`page-${a}`)):K=e.jsx("span",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:o("leaderboard.pagination.page_unknown",{page:String(j)})}),e.jsxs("div",{className:"flex flex-col min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-oai antialiased transition-colors duration-200",children:[e.jsx("header",{className:"sticky top-0 z-50 bg-white/80 dark:bg-oai-gray-950/80 backdrop-blur-md border-b border-oai-gray-200 dark:border-oai-gray-900 transition-colors duration-200",children:e.jsxs("div",{className:"mx-auto flex h-14 max-w-6xl items-center justify-between px-4 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsxs(xe,{to:"/",className:"flex items-center gap-3 no-underline outline-none rounded focus-visible:ring-2 focus-visible:ring-oai-brand-500 focus-visible:ring-offset-2 dark:ring-offset-oai-gray-950 transition-opacity hover:opacity-80",children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:24,height:24,className:"rounded-md"}),e.jsx("span",{className:"text-sm font-semibold tracking-wide text-oai-black dark:text-white uppercase",children:"Token Tracker"})]}),e.jsx("div",{className:"hidden sm:block",children:e.jsx(Ke,{})})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx(Ye,{theme:m,resolvedTheme:L,onSetTheme:I}),e.jsx(xe,{to:Fe(),className:d("no-underline inline-flex items-center justify-center h-9 px-5 text-sm font-medium rounded-full transition-colors",u?"shadow-sm ring-1 ring-oai-gray-200 dark:ring-white/10 bg-oai-gray-900 dark:bg-white text-white dark:text-oai-gray-900 hover:bg-oai-gray-800 dark:hover:bg-oai-gray-100":"ring-1 ring-oai-gray-200 dark:ring-oai-gray-700 text-oai-gray-600 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800"),children:o("landing.v2.cta.primary")}),e.jsx(He,{})]})]})}),e.jsx("main",{className:"flex-1 pt-8 sm:pt-10 pb-12 sm:pb-16",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-end justify-between gap-6 mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl sm:text-4xl font-semibold tracking-tight text-oai-black dark:text-white mb-3",children:o("leaderboard.title")}),e.jsxs("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm sm:text-base",children:[k==="total"?o("leaderboard.range.total"):ee&&ae?o("leaderboard.range",{period:ie,from:ee,to:ae}):o("leaderboard.range_loading",{period:ie}),re&&e.jsx("span",{className:"ml-2 pl-2 border-l border-oai-gray-200 dark:border-oai-gray-800 inline-block text-oai-gray-400 dark:text-oai-gray-500 text-xs",children:o("leaderboard.generated_at",{ts:re})})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[x&&_&&e.jsx("button",{onClick:Ae,disabled:Q||b.loading,className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-black dark:hover:text-white transition-colors disabled:opacity-50",children:Q?"Refreshing...":"↻"}),e.jsx("div",{className:"inline-flex p-1 border border-oai-gray-200 dark:border-oai-gray-800 rounded-lg",children:["week","month","total"].map(a=>e.jsx("button",{onClick:()=>_e(a),disabled:b.loading,className:d("px-4 py-1.5 text-sm font-medium rounded-md transition-colors",k===a?"bg-oai-gray-200 dark:bg-oai-gray-800 text-oai-black dark:text-white":"text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-800 dark:hover:text-oai-gray-200"),children:a==="week"?se:a==="month"?oe:ne},a))})]})]}),!r&&e.jsxs("div",{className:"mb-6 flex items-center justify-between text-sm",children:[e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:"Sign in to join the leaderboard"}),e.jsx("button",{onClick:c,className:"px-3 py-1.5 text-sm font-medium text-oai-gray-600 dark:text-oai-gray-300 border border-oai-gray-300 dark:border-oai-gray-700 rounded-md hover:text-oai-black dark:hover:text-white hover:border-oai-gray-400 dark:hover:border-oai-gray-600 transition-colors",children:"Sign In"})]}),x&&_&&!J&&e.jsxs("div",{className:"mb-6 flex items-center justify-between text-sm",children:[e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:"Enable Cloud Sync to appear in rankings"}),e.jsx("button",{onClick:Te,disabled:V,className:"px-3 py-1.5 text-sm font-medium text-oai-gray-600 dark:text-oai-gray-300 border border-oai-gray-300 dark:border-oai-gray-700 rounded-md hover:text-oai-black dark:hover:text-white hover:border-oai-gray-400 dark:hover:border-oai-gray-600 disabled:opacity-50 transition-colors",children:V?"Syncing...":"Enable & Sync"})]}),e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 overflow-hidden",children:[A,e.jsxs("div",{className:"px-6 py-3 border-t border-oai-gray-200 dark:border-oai-gray-800 flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{className:d("px-3 py-1.5 text-sm font-medium text-oai-gray-500 dark:text-oai-gray-400 rounded-md transition-colors",le&&!b.loading?"hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white":"opacity-50 cursor-not-allowed"),onClick:()=>T(a=>Math.max(1,a-1)),disabled:!le||b.loading,children:o("leaderboard.pagination.prev")}),e.jsx("button",{className:d("px-3 py-1.5 text-sm font-medium text-oai-gray-500 dark:text-oai-gray-400 rounded-md transition-colors",de&&!b.loading?"hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white":"opacity-50 cursor-not-allowed"),onClick:()=>T(a=>a+1),disabled:!de||b.loading,children:o("leaderboard.pagination.next")})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1",children:K})]})]})]})}),e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-900 py-8 transition-colors duration-200",children:e.jsxs("div",{className:"mx-auto flex max-w-6xl items-center justify-between px-4 sm:px-6 text-sm text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("p",{children:o("landing.v2.footer.line")}),e.jsx("a",{href:"https://github.com/mm7894215/TokenTracker",className:"text-oai-gray-400 dark:text-oai-gray-500 hover:text-oai-black dark:hover:text-white transition-colors",target:"_blank",rel:"noopener noreferrer",children:o("landing.v2.nav.github")})]})})]})}export{ia as LeaderboardPage};
|
|
1
|
+
import{D as e,az as d,aA as Pe,aB as Re,ai as Me,aj as Ie,r as g,aC as $e,h as Be,j as Ue,C as o,aD as ze,aE as P,aF as De,av as F,aa as xe,aG as Ke,aH as Fe,a9 as He,aI as ge,aJ as me,aK as Oe}from"./main-C7szutiJ.js";import{L as ye,a as ke,b as M,l as H,c as O,d as We,e as ue}from"./leaderboard-columns-QXmWCpyM.js";import{u as Ge,T as Ye}from"./ThemeToggle-Qn_pvy0M.js";function S(t,{min:r,max:s,fallback:n}){const i=Number(t);if(!Number.isFinite(i))return n;const c=Math.floor(i);return c<r?r:c>s?s:c}function Je(t,r){const s=S(r,{min:0,max:1e6,fallback:0}),n=S(t,{min:1,max:Math.max(1,s||1),fallback:1});if(s<=1)return[1];const i=new Set([1,s,n-2,n-1,n,n+1,n+2]),c=Array.from(i).filter(m=>Number.isInteger(m)&&m>=1&&m<=s).sort((m,L)=>m-L),u=[];let y=null;for(const m of c)y!=null&&m-y>1&&u.push(null),u.push(m),y=m;return u}function Ve({page:t,totalPages:r}){const s=typeof r=="number"&&Number.isFinite(r)&&r>=0,n=s?S(r,{min:0,max:1e6,fallback:0}):null,i=S(t,{min:1,max:s?Math.max(1,n||1):1e6,fallback:1}),c=i>1,u=s?i<n:!0;return{canPrev:c,canNext:u,safePage:i,safeTotal:n}}function qe({entries:t,me:r,meLabel:s,limit:n}){const i=S(n,{min:1,max:1e3,fallback:20}),c=Array.isArray(t)?t.slice(0,i):[],u=r&&typeof r.rank=="number"?r.rank:null,y=c.some(x=>!!x?.is_me);if(!u||y)return c;const m={rank:u,is_me:!0,display_name:s,avatar_url:null,gpt_tokens:r?.gpt_tokens??"0",claude_tokens:r?.claude_tokens??"0",gemini_tokens:r?.gemini_tokens??"0",cursor_tokens:r?.cursor_tokens??"0",opencode_tokens:r?.opencode_tokens??"0",openclaw_tokens:r?.openclaw_tokens??"0",other_tokens:r?.other_tokens??"0",total_tokens:r?.total_tokens??"0"},L=3,I=4,h=c.filter(x=>!x?.is_me).filter((x,B)=>B!==L).slice();return h.splice(Math.min(I,h.length),0,m),h.slice(0,i)}function p({className:t}){return e.jsx("div",{className:d("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function Qe({index:t}){const r=t<3?"w-24":t<8?"w-20":"w-16",s=t<3?"w-16":"w-12",n=t<5?"w-14":"w-10";return e.jsxs("tr",{className:"group",children:[e.jsx("td",{className:d(H(!1),"!group-hover:bg-transparent"),children:e.jsx(p,{className:"h-4 w-6"})}),e.jsx("td",{className:d(O(!1),"!group-hover:bg-transparent"),children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(p,{className:"h-8 w-8 min-w-8 rounded-full"}),e.jsx(p,{className:d("h-4",r)})]})}),e.jsx("td",{className:"px-4 py-4 bg-white dark:bg-oai-gray-950",children:e.jsx(p,{className:d("h-4",s)})}),e.jsx("td",{className:"px-4 py-4 bg-white dark:bg-oai-gray-950",children:e.jsx(p,{className:"h-4 w-12"})}),M.map(i=>e.jsx("td",{className:"px-4 py-4 bg-white dark:bg-oai-gray-950",children:e.jsx(p,{className:d("h-4",n)})},i.key))]})}function Xe({rows:t=10}){return e.jsx("div",{className:"w-full overflow-x-auto",children:e.jsxs("table",{className:"min-w-max w-full text-left text-sm",children:[e.jsx("thead",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800",children:e.jsxs("tr",{children:[e.jsx("th",{className:d(ye,"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:e.jsx(p,{className:"h-3.5 w-6"})}),e.jsx("th",{className:d(ke,"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:e.jsx(p,{className:"h-3.5 w-12"})}),e.jsx("th",{className:"px-4 py-4",children:e.jsx(p,{className:"h-3.5 w-10"})}),e.jsx("th",{className:"px-4 py-4",children:e.jsx(p,{className:"h-3.5 w-14"})}),M.map(r=>e.jsx("th",{className:"px-4 py-4",children:e.jsx(p,{className:"h-3.5 w-12"})},r.key))]})}),e.jsx("tbody",{className:"divide-y divide-oai-gray-100 dark:divide-oai-gray-800/50",children:Array.from({length:t},(r,s)=>e.jsx(Qe,{index:s},s))})]})})}const R=20;function he(t){const r=Number(t);return!Number.isFinite(r)||r<=0?"-":r>=1e3?`$${Math.round(r).toLocaleString()}`:r>=10?`$${Math.round(r)}`:`$${r.toFixed(2)}`}function be(t,r){const s=r?"text-oai-gray-700 dark:text-oai-gray-300":"text-oai-gray-500 dark:text-oai-gray-400",n=r?"bg-oai-brand-50 dark:bg-oai-brand-900/10":"bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60";return M.map(i=>e.jsx("td",{className:d("px-4 py-4 whitespace-nowrap text-right tabular-nums",s,n),children:F(t?.[i.key])},i.key))}const Ze={1:{text:"text-amber-600 dark:text-amber-400",badge:"bg-amber-50 dark:bg-amber-900/20"},2:{text:"text-gray-500 dark:text-gray-300",badge:"bg-gray-50 dark:bg-gray-800/40"},3:{text:"text-orange-700 dark:text-orange-400",badge:"bg-orange-50 dark:bg-orange-900/20"}};function pe({rank:t,placeholder:r}){const s=Ze[t];return s?e.jsx("span",{className:d("inline-flex items-center justify-center h-7 w-7 rounded-full text-xs font-bold",s.text,s.badge),children:t}):e.jsx("span",{className:"inline-flex items-center justify-center h-7 w-7 text-sm",children:t??r})}function W(t){if(typeof t!="string")return null;const r=t.trim().toLowerCase();return r==="week"||r==="month"||r==="total"?r:null}function ea(t){if(!t)return o("shared.error.prefix",{error:o("leaderboard.error.unknown")});const r=t?.message||String(t),s=String(r||"").trim()||o("leaderboard.error.unknown");return o("shared.error.prefix",{error:s})}function we(t){return typeof t!="string"?"":t.trim()}function aa(t){const r=we(t);return r?r.toLowerCase()==="anonymous":!0}function ra(t,r=""){if(typeof t!="string")return null;const s=t.trim().toLowerCase();if(!s)return null;const n=new URLSearchParams(typeof r=="string"?r:""),i=W(n.get("period")),c=i?`?period=${i}`:"";return`/share/pv1-${s}${c}`}function fe(t,r){const s=typeof t?.user_id=="string"?t.user_id.trim():"";return s||`${t?.rank??""}:${r}`}function ia({auth:t,signedIn:r,sessionSoftExpired:s}){const n=Pe(),i=Re(),{openLoginModal:c}=Me(),{signedIn:u,loading:y}=Ie(),{theme:m,resolvedTheme:L,setTheme:I}=Ge(),$=g.useMemo(()=>$e(),[]),h=Be(),x=r&&!s,B=g.useMemo(()=>x&&(typeof t=="function"||typeof t=="string"||t&&typeof t=="object")?t:null,[t,x]),v=x?B:null,_=x&&Ue(v),G=o("shared.placeholder.short"),[U,T]=g.useState(1),[je,Y]=g.useState(0),[b,C]=g.useState(()=>({loading:!1,error:null,data:null})),[J,Ne]=g.useState(()=>ze()),[V,q]=g.useState(!1),[Q,X]=g.useState(!1),k=g.useMemo(()=>{const a=new URLSearchParams(n?.search||"");return W(a.get("period"))||"total"},[n?.search]),ve=n?.search||"",_e=a=>{const l=W(a);if(!l||l===k)return;const N=new URLSearchParams(n?.search||"");N.set("period",l),T(1),i(`${n?.pathname||"/leaderboard"}?${N.toString()}`,{replace:!0})};g.useEffect(()=>{y||h||u||c()},[u,y,h,c]),g.useEffect(()=>{T(1)},[k]),g.useEffect(()=>{h||x&&(_||C({loading:!1,error:null,data:null}))},[x,_,h]);const Z=g.useMemo(()=>(S(U,{min:1,max:1e6,fallback:1})-1)*R,[U]);g.useEffect(()=>{if(!$&&!h||!h&&x&&!_)return;let a=!0;return C(l=>({...l,loading:!0,error:null})),(async()=>{const l=x?await P(v):null,N=await De({accessToken:l,period:k,limit:R,offset:Z});a&&C({loading:!1,error:null,data:N})})().catch(l=>{a&&C({loading:!1,error:ea(l),data:null})}),()=>{a=!1}},[$,v,x,_,Z,je,h,k]);const f=b.data,E=f?.total_pages??null,j=f?.page??U,Se=g.useMemo(()=>Je(j,E),[j,E]),ee=f?.from||null,ae=f?.to||null,re=f?.generated_at||null,te=f?.me||null,z=o("leaderboard.me_label"),Le=o("leaderboard.anon_label"),se=o("leaderboard.period.week"),oe=o("leaderboard.period.month"),ne=o("leaderboard.period.total"),ie=k==="month"?oe:k==="total"?ne:se,D=g.useMemo(()=>{const a=Array.isArray(f?.entries)?f.entries:[];return j!==1?a:qe({entries:a,me:te,meLabel:z,limit:R})},[j,f?.entries,te,z]),Te=async()=>{q(!0);try{Oe(!0),Ne(!0),await ge(()=>P(v));const a=await P(v);a&&await me({accessToken:a}),Y(l=>l+1)}catch(a){console.warn("[tokentracker] sync:",a)}finally{q(!1)}},Ae=async()=>{X(!0);try{const a=await P(v);J&&a&&await ge(()=>Promise.resolve(a)),a&&await me({accessToken:a}),Y(l=>l+1)}catch(a){console.warn("[tokentracker] refresh:",a)}finally{X(!1)}},{canPrev:le,canNext:de}=Ve({page:j,totalPages:E}),Ce=Array.isArray(D)&&D.length!==0;let A=null;b.loading?A=e.jsx(Xe,{rows:R}):b.error?A=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:b.error})}):Ce?A=e.jsx("div",{className:"w-full overflow-x-auto",children:e.jsxs("table",{className:"min-w-max w-full text-left text-sm",children:[e.jsx("thead",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800",children:e.jsxs("tr",{children:[e.jsx("th",{className:d(ye,"text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500"),children:o("leaderboard.column.rank")}),e.jsx("th",{className:d(ke,"text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500"),children:o("leaderboard.column.user")}),e.jsx("th",{className:"px-4 py-4 text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500 whitespace-nowrap text-right align-middle",children:o("leaderboard.column.total")}),e.jsx("th",{className:"px-4 py-4 text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500 whitespace-nowrap text-right align-middle",title:"Based on estimated API pricing, not actual billing",children:"Est. Cost"}),M.map(a=>e.jsx("th",{className:"px-4 py-4 text-[11px] font-semibold uppercase tracking-wider text-oai-gray-400 dark:text-oai-gray-500 whitespace-nowrap align-middle",children:e.jsx("div",{className:"flex items-center justify-end gap-2",children:e.jsx(We,{iconSrc:a.icon,label:o(a.copyKey)})})},a.key))]})}),e.jsx("tbody",{className:"divide-y divide-oai-gray-100 dark:divide-oai-gray-800/50",children:D.map(a=>{const l=!!a?.is_me,N=typeof a?.user_id=="string"?a.user_id:null,ce=we(a?.display_name),Ee=aa(ce)?Le:ce,w=l?z:Ee;return!!N&&!l&&!!a?.is_public&&ra(N,ve),l?e.jsxs("tr",{className:"border-y border-oai-brand-300/40 dark:border-oai-brand-500/30 bg-oai-brand-50 dark:bg-oai-brand-900/10 transition-colors",children:[e.jsx("td",{className:d(H(!0),"font-semibold text-oai-brand-600 dark:text-oai-brand-400"),children:e.jsx(pe,{rank:a?.rank,placeholder:G})}),e.jsx("td",{className:O(!0),children:e.jsxs("div",{className:"flex min-w-0 max-w-[min(160px,40vw)] items-center gap-4",children:[e.jsx(ue,{avatarUrl:a?.avatar_url,displayName:w,seed:fe(a,w)}),e.jsx("span",{className:"truncate font-semibold text-oai-black dark:text-oai-white",children:w})]})}),e.jsx("td",{className:"px-4 py-4 font-medium text-oai-black dark:text-oai-white whitespace-nowrap text-right tabular-nums bg-oai-brand-50 dark:bg-oai-brand-900/10",children:F(a?.total_tokens)}),e.jsx("td",{className:"px-4 py-4 font-medium text-oai-brand-600 dark:text-oai-brand-400 whitespace-nowrap text-right tabular-nums bg-oai-brand-50 dark:bg-oai-brand-900/10",title:"Based on estimated API pricing, not actual billing",children:he(a?.estimated_cost_usd)}),be(a,!0)]},`row-${a?.rank}-${w}`):e.jsxs("tr",{className:"group transition-colors",children:[e.jsx("td",{className:d(H(!1),"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:e.jsx(pe,{rank:a?.rank,placeholder:G})}),e.jsx("td",{className:O(!1),children:e.jsxs("div",{className:"flex min-w-0 max-w-[min(160px,40vw)] items-center gap-4",children:[e.jsx(ue,{avatarUrl:a?.avatar_url,displayName:w,seed:fe(a,w)}),e.jsx("span",{className:"truncate font-medium text-oai-gray-800 dark:text-oai-gray-200",children:w})]})}),e.jsx("td",{className:"px-4 py-4 font-semibold text-oai-gray-800 dark:text-oai-gray-200 whitespace-nowrap text-right tabular-nums bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60",children:F(a?.total_tokens)}),e.jsx("td",{className:"px-4 py-4 text-oai-gray-500 dark:text-oai-gray-400 whitespace-nowrap text-right tabular-nums bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60",title:"Based on estimated API pricing, not actual billing",children:he(a?.estimated_cost_usd)}),be(a,!1)]},`row-${a?.rank}-${w}`)})})]})}):A=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:o("leaderboard.empty")})});let K=null;return typeof E=="number"?K=Se.map((a,l)=>a==null?e.jsx("span",{className:"px-2 text-oai-gray-400 dark:text-oai-gray-500",children:o("leaderboard.pagination.ellipsis")},`ellipsis-${l}`):e.jsx("button",{className:d("flex h-8 w-8 items-center justify-center rounded-md text-sm font-medium transition-colors",a===j?"bg-oai-gray-200 dark:bg-oai-gray-800 text-oai-black dark:text-white":"text-oai-gray-500 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white"),onClick:()=>T(a),disabled:b.loading,children:String(a)},`page-${a}`)):K=e.jsx("span",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:o("leaderboard.pagination.page_unknown",{page:String(j)})}),e.jsxs("div",{className:"flex flex-col min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-oai antialiased transition-colors duration-200",children:[e.jsx("header",{className:"sticky top-0 z-50 bg-white/80 dark:bg-oai-gray-950/80 backdrop-blur-md border-b border-oai-gray-200 dark:border-oai-gray-900 transition-colors duration-200",children:e.jsxs("div",{className:"mx-auto flex h-14 max-w-6xl items-center justify-between px-4 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsxs(xe,{to:"/",className:"flex items-center gap-3 no-underline outline-none rounded focus-visible:ring-2 focus-visible:ring-oai-brand-500 focus-visible:ring-offset-2 dark:ring-offset-oai-gray-950 transition-opacity hover:opacity-80",children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:24,height:24,className:"rounded-md"}),e.jsx("span",{className:"text-sm font-semibold tracking-wide text-oai-black dark:text-white uppercase",children:"Token Tracker"})]}),e.jsx("div",{className:"hidden sm:block",children:e.jsx(Ke,{})})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx(Ye,{theme:m,resolvedTheme:L,onSetTheme:I}),e.jsx(xe,{to:Fe(),className:d("no-underline inline-flex items-center justify-center h-9 px-5 text-sm font-medium rounded-full transition-colors",u?"shadow-sm ring-1 ring-oai-gray-200 dark:ring-white/10 bg-oai-gray-900 dark:bg-white text-white dark:text-oai-gray-900 hover:bg-oai-gray-800 dark:hover:bg-oai-gray-100":"ring-1 ring-oai-gray-200 dark:ring-oai-gray-700 text-oai-gray-600 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800"),children:o("landing.v2.cta.primary")}),e.jsx(He,{})]})]})}),e.jsx("main",{className:"flex-1 pt-8 sm:pt-10 pb-12 sm:pb-16",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-end justify-between gap-6 mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl sm:text-4xl font-semibold tracking-tight text-oai-black dark:text-white mb-3",children:o("leaderboard.title")}),e.jsxs("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm sm:text-base",children:[k==="total"?o("leaderboard.range.total"):ee&&ae?o("leaderboard.range",{period:ie,from:ee,to:ae}):o("leaderboard.range_loading",{period:ie}),re&&e.jsx("span",{className:"ml-2 pl-2 border-l border-oai-gray-200 dark:border-oai-gray-800 inline-block text-oai-gray-400 dark:text-oai-gray-500 text-xs",children:o("leaderboard.generated_at",{ts:re})})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[x&&_&&e.jsx("button",{onClick:Ae,disabled:Q||b.loading,className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-black dark:hover:text-white transition-colors disabled:opacity-50",children:Q?"Refreshing...":"↻"}),e.jsx("div",{className:"inline-flex p-1 border border-oai-gray-200 dark:border-oai-gray-800 rounded-lg",children:["week","month","total"].map(a=>e.jsx("button",{onClick:()=>_e(a),disabled:b.loading,className:d("px-4 py-1.5 text-sm font-medium rounded-md transition-colors",k===a?"bg-oai-gray-200 dark:bg-oai-gray-800 text-oai-black dark:text-white":"text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-800 dark:hover:text-oai-gray-200"),children:a==="week"?se:a==="month"?oe:ne},a))})]})]}),!r&&e.jsxs("div",{className:"mb-6 flex items-center justify-between text-sm",children:[e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:"Sign in to join the leaderboard"}),e.jsx("button",{onClick:c,className:"px-3 py-1.5 text-sm font-medium text-oai-gray-600 dark:text-oai-gray-300 border border-oai-gray-300 dark:border-oai-gray-700 rounded-md hover:text-oai-black dark:hover:text-white hover:border-oai-gray-400 dark:hover:border-oai-gray-600 transition-colors",children:"Sign In"})]}),x&&_&&!J&&e.jsxs("div",{className:"mb-6 flex items-center justify-between text-sm",children:[e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400",children:"Enable Cloud Sync to appear in rankings"}),e.jsx("button",{onClick:Te,disabled:V,className:"px-3 py-1.5 text-sm font-medium text-oai-gray-600 dark:text-oai-gray-300 border border-oai-gray-300 dark:border-oai-gray-700 rounded-md hover:text-oai-black dark:hover:text-white hover:border-oai-gray-400 dark:hover:border-oai-gray-600 disabled:opacity-50 transition-colors",children:V?"Syncing...":"Enable & Sync"})]}),e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 overflow-hidden",children:[A,e.jsxs("div",{className:"px-6 py-3 border-t border-oai-gray-200 dark:border-oai-gray-800 flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{className:d("px-3 py-1.5 text-sm font-medium text-oai-gray-500 dark:text-oai-gray-400 rounded-md transition-colors",le&&!b.loading?"hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white":"opacity-50 cursor-not-allowed"),onClick:()=>T(a=>Math.max(1,a-1)),disabled:!le||b.loading,children:o("leaderboard.pagination.prev")}),e.jsx("button",{className:d("px-3 py-1.5 text-sm font-medium text-oai-gray-500 dark:text-oai-gray-400 rounded-md transition-colors",de&&!b.loading?"hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white":"opacity-50 cursor-not-allowed"),onClick:()=>T(a=>a+1),disabled:!de||b.loading,children:o("leaderboard.pagination.next")})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1",children:K})]})]})]})}),e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-900 py-8 transition-colors duration-200",children:e.jsxs("div",{className:"mx-auto flex max-w-6xl items-center justify-between px-4 sm:px-6 text-sm text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("p",{children:o("landing.v2.footer.line")}),e.jsx("a",{href:"https://github.com/mm7894215/TokenTracker",className:"text-oai-gray-400 dark:text-oai-gray-500 hover:text-oai-black dark:hover:text-white transition-colors",target:"_blank",rel:"noopener noreferrer",children:o("landing.v2.nav.github")})]})})]})}export{ia as LeaderboardPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{aA as M,r as x,aC as O,h as D,j as G,aE as Y,aL as $,C as a,D as e,az as f,av as A,aa as j,aG as W,a9 as q}from"./main-
|
|
1
|
+
import{aA as M,r as x,aC as O,h as D,j as G,aE as Y,aL as $,C as a,D as e,az as f,av as A,aa as j,aG as W,a9 as q}from"./main-C7szutiJ.js";import{b as E,d as F,l as J,f as Q,e as V,L as X,g as Z}from"./leaderboard-columns-QXmWCpyM.js";import{u as I,T as ee}from"./ThemeToggle-Qn_pvy0M.js";function ae(r){if(!r)return a("shared.error.prefix",{error:a("leaderboard.error.unknown")});const o=r?.message||String(r),y=String(o||"").trim()||a("leaderboard.error.unknown");return a("shared.error.prefix",{error:y})}function re(r){return typeof r!="string"?"":r.trim()}function te(r){if(typeof r!="string")return null;const o=r.trim().toLowerCase();return o==="week"||o==="month"||o==="total"?o:null}function ne({auth:r,signedIn:o,sessionSoftExpired:y,userId:s}){const b=M(),{theme:R,resolvedTheme:C,setTheme:P}=I(),N=x.useMemo(()=>O(),[]),p=D(),i=o&&!y,z=x.useMemo(()=>i&&(typeof r=="function"||typeof r=="string"||r&&typeof r=="object")?r:null,[r,i]),u=i?z:null,v=i&&G(u),c=x.useMemo(()=>{const t=new URLSearchParams(b?.search||"");return te(t.get("period"))||"week"},[b?.search]),w=b?.search||"",[m,g]=x.useState(()=>({loading:!1,error:null,data:null}));x.useEffect(()=>{if(!N&&!p||!s||!p&&(!i||!v))return;let t=!0;return g(d=>({...d,loading:!0,error:null})),(async()=>{const d=await Y(u);if(!t)return;if(!d){g({loading:!1,error:null,data:null});return}const K=await $({accessToken:d,userId:s,period:c});t&&g({loading:!1,error:null,data:K})})().catch(d=>{t&&g({loading:!1,error:ae(d),data:null})}),()=>{t=!1}},[i,v,N,u,p,c,s]);const h=m.data,T=h?.from||null,L=h?.to||null,S=h?.generated_at||null,n=h?.entry||null,k=re(n?.display_name)||a("leaderboard.anon_label"),U=a("leaderboard.period.week"),B=a("leaderboard.period.month"),H=a("leaderboard.period.total"),_=c==="month"?B:c==="total"?H:U;let l=null;return s?m.loading?l=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("leaderboard.loading")})}):m.error?l=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:m.error})}):n?l=e.jsx("div",{className:"w-full overflow-x-auto",children:e.jsxs("table",{className:"min-w-max w-full text-left text-sm",children:[e.jsx("thead",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800",children:e.jsxs("tr",{children:[e.jsx("th",{className:f(X,"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:a("leaderboard.column.rank")}),e.jsx("th",{className:f(Z,"font-medium text-oai-gray-500 dark:text-oai-gray-400 whitespace-nowrap"),children:a("leaderboard.column.total")}),E.map(t=>e.jsx("th",{className:"px-4 py-4 font-medium text-oai-gray-500 dark:text-oai-gray-400 whitespace-nowrap",children:e.jsx(F,{iconSrc:t.icon,label:a(t.copyKey)})},t.key))]})}),e.jsx("tbody",{className:"divide-y divide-oai-gray-100 dark:divide-oai-gray-800/50",children:e.jsxs("tr",{className:"transition-colors hover:bg-oai-gray-50 dark:hover:bg-oai-gray-900/60",children:[e.jsx("td",{className:f(J(!1),"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:n?.rank??a("shared.placeholder.short")}),e.jsx("td",{className:f(Q(),"text-oai-gray-700 dark:text-oai-gray-300"),children:A(n?.total_tokens)}),E.map(t=>e.jsx("td",{className:"px-4 py-4 text-oai-gray-500 dark:text-oai-gray-400 whitespace-nowrap",children:A(n?.[t.key])},t.key))]})})]})}):l=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("leaderboard.empty")})}):l=e.jsx("div",{className:"px-6 py-12 text-center",children:e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("leaderboard.empty")})}),e.jsxs("div",{className:"flex flex-col min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-oai antialiased transition-colors duration-200",children:[e.jsx("header",{className:"sticky top-0 z-50 bg-white/80 dark:bg-oai-gray-950/80 backdrop-blur-md border-b border-oai-gray-200 dark:border-oai-gray-900 transition-colors duration-200",children:e.jsxs("div",{className:"mx-auto flex h-14 max-w-6xl items-center justify-between px-4 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsxs(j,{to:"/",className:"flex items-center gap-3 no-underline outline-none rounded focus-visible:ring-2 focus-visible:ring-oai-brand-500 focus-visible:ring-offset-2 dark:ring-offset-oai-gray-950 transition-opacity hover:opacity-80",children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:24,height:24,className:"rounded-md"}),e.jsx("span",{className:"text-sm font-semibold tracking-wide text-oai-black dark:text-white uppercase",children:"Token Tracker"})]}),e.jsx("div",{className:"hidden sm:block",children:e.jsx(W,{})})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx(j,{to:`/leaderboard${w}`,className:"no-underline inline-flex items-center justify-center h-9 px-5 text-sm font-medium rounded-full shadow-sm ring-1 ring-oai-gray-200 dark:ring-white/10 bg-oai-gray-900 dark:bg-white text-white dark:text-oai-gray-900 hover:bg-oai-gray-800 dark:hover:bg-oai-gray-100 transition-colors",children:a("leaderboard.profile.nav.back")}),e.jsx(ee,{theme:R,resolvedTheme:C,onSetTheme:P}),e.jsx(q,{})]})]})}),e.jsx("main",{className:"flex-1 py-12 sm:py-16",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-6 mb-10",children:[e.jsx(V,{avatarUrl:n?.avatar_url,displayName:k,seed:typeof s=="string"?s:k,size:"lg",className:"shrink-0 ring-2 ring-oai-gray-200 dark:ring-oai-gray-800"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-3xl sm:text-4xl font-semibold tracking-tight text-oai-black dark:text-white mb-3",children:k}),e.jsxs("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm sm:text-base",children:[c==="total"?a("leaderboard.range.total"):T&&L?a("leaderboard.range",{period:_,from:T,to:L}):a("leaderboard.range_loading",{period:_}),S&&e.jsx("span",{className:"ml-2 pl-2 border-l border-oai-gray-200 dark:border-oai-gray-800 inline-block text-oai-gray-400 dark:text-oai-gray-500 text-xs",children:a("leaderboard.generated_at",{ts:S})})]})]})]}),e.jsx("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 overflow-hidden",children:l})]})}),e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-900 py-8 transition-colors duration-200",children:e.jsxs("div",{className:"mx-auto flex max-w-6xl items-center justify-between px-4 sm:px-6 text-sm text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("p",{children:a("landing.v2.footer.line")}),e.jsx(j,{to:`/leaderboard${w}`,className:"text-oai-gray-400 dark:text-oai-gray-500 hover:text-oai-black dark:hover:text-white transition-colors",children:a("leaderboard.profile.nav.back")})]})})]})}export{ne as LeaderboardProfilePage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as n,aM as v,D as e}from"./main-
|
|
1
|
+
import{r as n,aM as v,D as e}from"./main-C7szutiJ.js";function w(){const r=n.useContext(v);if(r===null)throw new Error("useTheme must be used within a ThemeProvider");return r}const a=18;function h(){return e.jsxs("svg",{"aria-hidden":!0,width:a,height:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"4"}),e.jsx("path",{d:"M12 2v2"}),e.jsx("path",{d:"M12 20v2"}),e.jsx("path",{d:"m4.93 4.93 1.41 1.41"}),e.jsx("path",{d:"m17.66 17.66 1.41 1.41"}),e.jsx("path",{d:"M2 12h2"}),e.jsx("path",{d:"M20 12h2"}),e.jsx("path",{d:"m6.34 17.66-1.41 1.41"}),e.jsx("path",{d:"m19.07 4.93-1.41 1.41"})]})}function u(){return e.jsx("svg",{"aria-hidden":!0,width:a,height:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})}function f(){return e.jsxs("svg",{"aria-hidden":!0,width:a,height:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("path",{d:"M8 21h8"}),e.jsx("path",{d:"M12 17v4"})]})}const j=[{value:"light",label:"Light",Icon:h},{value:"dark",label:"Dark",Icon:u},{value:"system",label:"System",Icon:f}];function b(r){return r==="dark"?u:h}function E({theme:r,resolvedTheme:l,onSetTheme:x,className:g=""}){const[o,c]=n.useState(!1),d=n.useRef(null),s=n.useCallback(()=>c(!1),[]);n.useEffect(()=>{if(!o)return;const t=i=>{d.current&&!d.current.contains(i.target)&&s()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[o,s]),n.useEffect(()=>{if(!o)return;const t=i=>{i.key==="Escape"&&s()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[o,s]);const k=b(l);return e.jsxs("div",{ref:d,className:`relative ${g}`,children:[e.jsx("button",{type:"button","aria-label":"Theme","aria-expanded":o,onClick:()=>c(t=>!t),className:"flex items-center justify-center w-9 h-9 rounded-lg 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",children:e.jsx(k,{})}),o&&e.jsx("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[140px] py-1 rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 shadow-lg",children:j.map(({value:t,label:i,Icon:m})=>{const p=r===t;return e.jsxs("button",{type:"button",onClick:()=>{x(t),s()},className:`flex w-full items-center gap-2.5 px-3 py-2 text-sm transition-colors ${p?"text-oai-black dark:text-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-600 dark:text-oai-gray-400 hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/60 hover:text-oai-black dark:hover:text-white"}`,children:[e.jsx(m,{}),e.jsx("span",{children:i})]},t)})})]})}export{E as T,w as u};
|
package/dashboard/dist/assets/{leaderboard-columns-BtZZjmrK.js → leaderboard-columns-QXmWCpyM.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as n,az as i}from"./main-
|
|
1
|
+
import{D as n,az as i}from"./main-C7szutiJ.js";function l(r){let e=0;const o=String(r??"");for(let a=0;a<o.length;a+=1)e=Math.imul(31,e)+o.charCodeAt(a)|0;return Math.abs(e)%360}function b(r){const e=String(r??"").trim();if(!e)return"?";const o=e.split(/\s+/).filter(Boolean);if(o.length>=2){const a=o[0][0]||"",t=o[1][0]||"";return`${a}${t}`.toUpperCase()}return e.slice(0,2).toUpperCase()}const c={sm:"h-7 w-7 min-h-7 min-w-7 text-[10px]",md:"h-8 w-8 min-h-8 min-w-8 text-[11px]",lg:"h-14 w-14 min-h-14 min-w-14 text-base"};function y({avatarUrl:r,displayName:e,seed:o,size:a="md",className:t}){const s=c[a]||c.md,g=l(o??e??""),d=typeof r=="string"?r.trim():"";return d?n.jsx("img",{src:d,alt:"",className:i("rounded-full object-cover ring-1 ring-white/10",s,t)}):n.jsx("div",{className:i("flex shrink-0 items-center justify-center rounded-full font-semibold text-white ring-1 ring-white/10",s,t),style:{backgroundColor:`hsl(${g} 42% 34%)`},"aria-hidden":!0,children:b(e)})}function m({iconSrc:r,label:e}){return n.jsxs("span",{className:"inline-flex items-center gap-3",children:[n.jsx("img",{src:r,alt:"",width:16,height:16,className:`h-4 w-4 shrink-0 object-contain opacity-90 ${r==="/brand-logos/cursor.svg"?"dark:invert":""}`}),n.jsx("span",{className:"whitespace-nowrap",children:e})]})}const u=[{key:"gpt_tokens",copyKey:"leaderboard.column.codex",icon:"/brand-logos/codex.svg"},{key:"claude_tokens",copyKey:"leaderboard.column.claude",icon:"/brand-logos/claude-code.svg"},{key:"gemini_tokens",copyKey:"leaderboard.column.gemini",icon:"/brand-logos/gemini.svg"},{key:"cursor_tokens",copyKey:"leaderboard.column.cursor",icon:"/brand-logos/cursor.svg"},{key:"opencode_tokens",copyKey:"leaderboard.column.opencode",icon:"/brand-logos/opencode.svg"},{key:"openclaw_tokens",copyKey:"leaderboard.column.openclaw",icon:"/brand-logos/openclaw.svg"},{key:"other_tokens",copyKey:"leaderboard.column.supplemental",icon:"/brand-logos/gemini.svg"}],k="sticky left-0 z-40 w-[72px] min-w-[72px] max-w-[72px] border-r border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-950 px-4 py-4 align-middle",h="sticky left-[72px] z-40 min-w-[140px] max-w-[min(180px,35vw)] border-r border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-950 px-4 py-4 align-middle",x="sticky left-[72px] z-40 min-w-[6rem] border-r border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-950 px-4 py-4";function w(r){return i("sticky left-0 z-30 w-[72px] min-w-[72px] max-w-[72px] border-r border-oai-gray-200 dark:border-oai-gray-800 px-4 py-4 whitespace-nowrap",r?"bg-oai-brand-50 dark:bg-oai-brand-900/10":"bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60")}function f(r){return i("sticky left-[72px] z-30 min-w-[140px] max-w-[min(180px,35vw)] border-r border-oai-gray-200 dark:border-oai-gray-800 px-4 py-4 min-w-0",r?"bg-oai-brand-50 dark:bg-oai-brand-900/10":"bg-white dark:bg-oai-gray-950 group-hover:bg-oai-gray-50 dark:group-hover:bg-oai-gray-900/60")}function _(r){return i("sticky left-[72px] z-30 min-w-[6rem] border-r border-oai-gray-200 dark:border-oai-gray-800 px-4 py-4 whitespace-nowrap","bg-white dark:bg-oai-gray-950")}export{k as L,h as a,u as b,f as c,m as d,y as e,_ as f,x as g,w as l};
|