tokentracker-cli 0.5.2 → 0.5.5
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 +14 -10
- package/dashboard/dist/assets/DashboardPage-CxkNLRKl.js +12 -0
- package/dashboard/dist/assets/LeaderboardPage-Bw3kpiq5.js +1 -0
- package/dashboard/dist/assets/{LeaderboardProfilePage-B5Yw_BZM.js → LeaderboardProfilePage-ChBUNzy0.js} +1 -1
- package/dashboard/dist/assets/{ThemeToggle-CQvh_d2Z.js → ThemeToggle-BHa5Nenr.js} +1 -1
- package/dashboard/dist/assets/{leaderboard-columns-COq9DxPJ.js → leaderboard-columns-DqMAm_KH.js} +1 -1
- package/dashboard/dist/assets/main-BSjyKFRx.css +1 -0
- package/dashboard/dist/assets/main-DkSKSbQz.js +4863 -0
- package/dashboard/dist/index.html +2 -2
- package/dashboard/dist/share.html +2 -2
- package/package.json +2 -2
- package/src/commands/init.js +1 -1
- package/src/lib/runtime-config.js +2 -2
- package/dashboard/dist/assets/DashboardPage-ccDq1oTb.js +0 -12
- package/dashboard/dist/assets/LeaderboardPage-BvhBcafd.js +0 -1
- package/dashboard/dist/assets/main-8JBJiGVQ.js +0 -4759
- package/dashboard/dist/assets/main-Cwn9_aQV.css +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{aw as Ce,ax as Pe,ay as Ae,az as Ee,r as c,aA as Ie,h as Me,j as $e,B as o,aB as Re,aC as M,aD as Be,C as e,aE as b,as as F,a9 as le,aF as Ue,aG as ze,a8 as De,aH as de,aI as ce,aJ as Fe}from"./main-8JBJiGVQ.js";import{L as fe,a as Ke,l as ge,b as me,c as xe,d as Oe,e as He}from"./leaderboard-columns-COq9DxPJ.js";import{u as Ge,T as Ve}from"./ThemeToggle-CQvh_d2Z.js";function L(t,{min:r,max:n,fallback:i}){const s=Number(t);if(!Number.isFinite(s))return i;const d=Math.floor(s);return d<r?r:d>n?n:d}function Ye(t,r){const n=L(r,{min:0,max:1e6,fallback:0}),i=L(t,{min:1,max:Math.max(1,n||1),fallback:1});if(n<=1)return[1];const s=new Set([1,n,i-2,i-1,i,i+1,i+2]),d=Array.from(s).filter(g=>Number.isInteger(g)&&g>=1&&g<=n).sort((g,_)=>g-_),h=[];let w=null;for(const g of d)w!=null&&g-w>1&&h.push(null),h.push(g),w=g;return h}function Je({page:t,totalPages:r}){const n=typeof r=="number"&&Number.isFinite(r)&&r>=0,i=n?L(r,{min:0,max:1e6,fallback:0}):null,s=L(t,{min:1,max:n?Math.max(1,i||1):1e6,fallback:1}),d=s>1,h=n?s<i:!0;return{canPrev:d,canNext:h,safePage:s,safeTotal:i}}function We({entries:t,me:r,meLabel:n,limit:i}){const s=L(i,{min:1,max:1e3,fallback:20}),d=Array.isArray(t)?t.slice(0,s):[],h=r&&typeof r.rank=="number"?r.rank:null,w=d.some(x=>!!x?.is_me);if(!h||w)return d;const g={rank:h,is_me:!0,display_name:n,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"},_=3,v=4,T=d.filter(x=>!x?.is_me).filter((x,y)=>y!==_).slice();return T.splice(Math.min(v,T.length),0,g),T.slice(0,s)}const D=20;function ue(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 n=r?"text-oai-gray-700 dark:text-oai-gray-300":"text-oai-gray-500 dark:text-oai-gray-400",i=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 fe.map(s=>e.jsx("td",{className:b("px-4 py-4 whitespace-nowrap",n,i),children:F(t?.[s.key])},s.key))}function K(t){if(typeof t!="string")return null;const r=t.trim().toLowerCase();return r==="week"||r==="month"||r==="total"?r:null}function qe(t){if(!t)return o("shared.error.prefix",{error:o("leaderboard.error.unknown")});const r=t?.message||String(t),n=String(r||"").trim()||o("leaderboard.error.unknown");return o("shared.error.prefix",{error:n})}function pe(t){return typeof t!="string"?"":t.trim()}function Qe(t){const r=pe(t);return r?r.toLowerCase()==="anonymous":!0}function Xe(t,r=""){if(typeof t!="string")return null;const n=t.trim().toLowerCase();if(!n)return null;const i=new URLSearchParams(typeof r=="string"?r:""),s=K(i.get("period")),d=s?`?period=${s}`:"";return`/share/pv1-${n}${d}`}function he(t,r){const n=typeof t?.user_id=="string"?t.user_id.trim():"";return n||`${t?.rank??""}:${r}`}function ta({auth:t,signedIn:r,sessionSoftExpired:n}){const i=Ce(),s=Pe(),{openLoginModal:d}=Ae(),{signedIn:h}=Ee(),{resolvedTheme:w,toggleTheme:g}=Ge(),_=c.useMemo(()=>Ie(),[]),v=Me(),m=r&&!n,T=c.useMemo(()=>m&&(typeof t=="function"||typeof t=="string"||t&&typeof t=="object")?t:null,[t,m]),x=m?T:null,y=m&&$e(x),O=o("shared.placeholder.short"),[$,C]=c.useState(1),[ye,H]=c.useState(0),[u,E]=c.useState(()=>({loading:!1,error:null,data:null})),[G,ke]=c.useState(()=>Re()),[V,Y]=c.useState(!1),[J,W]=c.useState(!1),k=c.useMemo(()=>{const a=new URLSearchParams(i?.search||"");return K(a.get("period"))||"week"},[i?.search]),we=i?.search||"",ve=a=>{const l=K(a);if(!l||l===k)return;const N=new URLSearchParams(i?.search||"");N.set("period",l),C(1),s(`${i?.pathname||"/leaderboard"}?${N.toString()}`,{replace:!0})};c.useEffect(()=>{C(1)},[k]),c.useEffect(()=>{v||m&&(y||E({loading:!1,error:null,data:null}))},[m,y,v]);const q=c.useMemo(()=>(L($,{min:1,max:1e6,fallback:1})-1)*D,[$]);c.useEffect(()=>{if(!_&&!v||!v&&m&&!y)return;let a=!0;return E(l=>({...l,loading:!0,error:null})),(async()=>{const l=m?await M(x):null,N=await Be({accessToken:l,period:k,limit:D,offset:q});a&&E({loading:!1,error:null,data:N})})().catch(l=>{a&&E({loading:!1,error:qe(l),data:null})}),()=>{a=!1}},[_,x,m,y,q,ye,v,k]);const f=u.data,I=f?.total_pages??null,j=f?.page??$,je=c.useMemo(()=>Ye(j,I),[j,I]),Q=f?.from||null,X=f?.to||null,Z=f?.generated_at||null,ee=f?.me||null,R=o("leaderboard.me_label"),Ne=o("leaderboard.anon_label"),ae=o("leaderboard.period.week"),re=o("leaderboard.period.month"),te=o("leaderboard.period.total"),oe=k==="month"?re:k==="total"?te:ae,B=c.useMemo(()=>{const a=Array.isArray(f?.entries)?f.entries:[];return j!==1?a:We({entries:a,me:ee,meLabel:R,limit:D})},[j,f?.entries,ee,R]),_e=async()=>{Y(!0);try{Fe(!0),ke(!0),await de(()=>M(x));const a=await M(x);a&&await ce({accessToken:a}),H(l=>l+1)}catch(a){console.warn("[tokentracker] sync:",a)}finally{Y(!1)}},Se=async()=>{W(!0);try{const a=await M(x);G&&a&&await de(()=>Promise.resolve(a)),a&&await ce({accessToken:a}),H(l=>l+1)}catch(a){console.warn("[tokentracker] refresh:",a)}finally{W(!1)}},{canPrev:ne,canNext:ie}=Je({page:j,totalPages:I}),Le=Array.isArray(B)&&B.length!==0;let P=null;u.loading?P=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.loading")})}):u.error?P=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:u.error})}):Le?P=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:b(Oe,"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:o("leaderboard.column.rank")}),e.jsx("th",{className:b(He,"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:o("leaderboard.column.user")}),e.jsx("th",{className:"px-4 py-4 font-medium text-oai-gray-500 dark:text-oai-gray-400 whitespace-nowrap",children:o("leaderboard.column.total")}),e.jsx("th",{className:"px-4 py-4 font-medium text-oai-gray-500 dark:text-oai-gray-400 whitespace-nowrap",title:"Based on estimated API pricing, not actual billing",children:"Est. Cost"}),fe.map(a=>e.jsx("th",{className:"px-4 py-4 font-medium text-oai-gray-500 dark:text-oai-gray-400 whitespace-nowrap",children:e.jsx(Ke,{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:B.map(a=>{const l=!!a?.is_me,N=typeof a?.user_id=="string"?a.user_id:null,se=pe(a?.display_name),Te=Qe(se)?Ne:se,p=l?R:Te,A=!!N&&!l&&!!a?.is_public?Xe(N,we):null,S=!!A;return 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:b(ge(!0),"font-semibold text-oai-brand-600 dark:text-oai-brand-400"),children:a?.rank??O}),e.jsx("td",{className:xe(!0),children:e.jsxs("div",{className:"flex min-w-0 max-w-[min(320px,55vw)] items-center gap-4",children:[e.jsx(me,{avatarUrl:a?.avatar_url,displayName:p,seed:he(a,p)}),e.jsx("span",{className:"truncate font-semibold text-oai-black dark:text-oai-white",children:p})]})}),e.jsx("td",{className:"px-4 py-4 font-medium text-oai-black dark:text-oai-white whitespace-nowrap 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 bg-oai-brand-50 dark:bg-oai-brand-900/10",title:"Based on estimated API pricing, not actual billing",children:ue(a?.estimated_cost_usd)}),be(a,!0)]},`row-${a?.rank}-${p}`):e.jsxs("tr",{className:b("group transition-colors",S?"cursor-pointer hover:bg-oai-gray-50 dark:hover:bg-oai-gray-900/60":""),onClick:S?()=>{if(typeof window<"u"){window.location.assign(A);return}s(A)}:void 0,onKeyDown:S?z=>{if(z.key==="Enter"||z.key===" "){if(z.preventDefault(),typeof window<"u"){window.location.assign(A);return}s(A)}}:void 0,role:S?"link":void 0,tabIndex:S?0:void 0,"aria-label":S?`Open public dashboard for ${p}`:void 0,children:[e.jsx("td",{className:b(ge(!1),"font-medium text-oai-gray-500 dark:text-oai-gray-400"),children:a?.rank??O}),e.jsx("td",{className:xe(!1),children:e.jsxs("div",{className:"flex min-w-0 max-w-[min(320px,55vw)] items-center gap-4",children:[e.jsx(me,{avatarUrl:a?.avatar_url,displayName:p,seed:he(a,p)}),e.jsx("span",{className:"truncate font-medium text-oai-gray-800 dark:text-oai-gray-200",children:p})]})}),e.jsx("td",{className:"px-4 py-4 text-oai-gray-700 dark:text-oai-gray-300 whitespace-nowrap 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 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:ue(a?.estimated_cost_usd)}),be(a,!1)]},`row-${a?.rank}-${p}`)})})]})}):P=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 U=null;return typeof I=="number"?U=je.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:b("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:()=>C(a),disabled:u.loading,children:String(a)},`page-${a}`)):U=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-16 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(le,{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(Ue,{})})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx(le,{to:ze(),className:b("no-underline inline-flex items-center justify-center h-9 px-5 text-sm font-medium rounded-full transition-colors",h?"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(Ve,{theme:w,onToggle:g}),e.jsx(De,{})]})]})}),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 md:flex-row md:items-end justify-between gap-6 mb-10",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"):Q&&X?o("leaderboard.range",{period:oe,from:Q,to:X}):o("leaderboard.range_loading",{period:oe}),Z&&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:Z})})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[m&&y&&e.jsx("button",{onClick:Se,disabled:J||u.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:J?"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:()=>ve(a),disabled:u.loading,className:b("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"?ae:a==="month"?re:te},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:d,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"})]}),m&&y&&!G&&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:_e,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:[P,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:b("px-3 py-1.5 text-sm font-medium text-oai-gray-500 dark:text-oai-gray-400 rounded-md transition-colors",ne&&!u.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:()=>C(a=>Math.max(1,a-1)),disabled:!ne||u.loading,children:o("leaderboard.pagination.prev")}),e.jsx("button",{className:b("px-3 py-1.5 text-sm font-medium text-oai-gray-500 dark:text-oai-gray-400 rounded-md transition-colors",ie&&!u.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:()=>C(a=>a+1),disabled:!ie||u.loading,children:o("leaderboard.pagination.next")})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1",children:U})]})]})]})}),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{ta as LeaderboardPage};
|