tokentracker-cli 1.4.2 → 1.4.3
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/{AchievementBadge-WGbdoboF.js → AchievementBadge-3IYidbrI.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-BvybbsXv.js → AchievementsPage-DmZ_ojyM.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-ChNzTFSR.js → AchievementsSection-DIYrrzhw.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-DhI9Ejz3.js → BadgeDetailModal-DMMExCe4.js} +1 -1
- package/dashboard/dist/assets/{BotAnimated-Bch0Yxej.js → BotAnimated-y6vZNRvC.js} +1 -1
- package/dashboard/dist/assets/{Card-DWdL7d1T.js → Card-LJX3G3zo.js} +1 -1
- package/dashboard/dist/assets/{CloudCheckoutPage-BjGoOz6P.js → CloudCheckoutPage-BGBgSXNE.js} +1 -1
- package/dashboard/dist/assets/{CloudPage-Btb6a97x.js → CloudPage-Dij2GTXi.js} +2 -2
- package/dashboard/dist/assets/{CommandPalette-DwP3k7LE.js → CommandPalette-BIky6Fk0.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-mzqLxpwE.js → CommunityStatsModal-DbM99i0s.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-Dm76q4EX.js → ConfirmModal-C_NH8vgO.js} +1 -1
- package/dashboard/dist/assets/{Controls-ClZjOBoD.js → Controls-BEAj_kvr.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-Doc8f4NL.js → DashboardPage-DO7h2dfu.js} +1 -1
- package/dashboard/dist/assets/{DateRangePopover-vfTUePPg.js → DateRangePopover-PQXB8v0k.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-Jjg5q0C2.js → DevicePage-0JZ3OIWZ.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-Ci5mPZ6X.js → DialogClose-BpWoD5h9.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-ne_rYSD7.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-DI21oZxH.js → DialogTitle-DoQgdh5w.js} +1 -1
- package/dashboard/dist/assets/{ElectricLogo-DfeZBwPZ.js → ElectricLogo-0O87VjKv.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-C7SIILTc.js → FadeIn-9ph1h_AG.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-RStLbadn.js → HeaderGithubStar-DCZ92xbH.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-DI7uAp1_.js → HoverTooltip-CCKdmuOP.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-DTZNTJVh.js → IpCheckPage-CpyhpmdS.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-Df5scNlw.js → LandingPage-spvsPkYy.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardPage-Ck3SqtnI.js → LeaderboardPage-2nJ08ohw.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProBadge-CGx6m7R6.js → LeaderboardProBadge-D6FSL3Qy.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfileModal-DuP7rgfv.js → LeaderboardProfileModal-DD1jX-rD.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-B5qUJkZX.js → LeaderboardProfilePage-DYqRrntL.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-Bv_Lcvcz.js → LimitsPage-DXHikunk.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-Cg4y02JM.js → LocalOnlyNotice-BURiQAtP.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-Wz0uJKXx.js → LoginCard-Cv2ijoJx.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-C13v_Gs0.js → LoginModal-DyOideDA.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-COH9xXtd.js → LoginPage-BKNvqvYi.js} +1 -1
- package/dashboard/dist/assets/{PetPage-BWCnURub.js → PetPage-BBmozE0L.js} +2 -2
- package/dashboard/dist/assets/{PopoverPopup-Dw811N-_.js → PopoverPopup-DDnISLKM.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-CHxhYzK-.js → ProviderIcon-Da90GDcM.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-Ll6jshqg.js → ResetPasswordPage-DsETr50j.js} +1 -1
- package/dashboard/dist/assets/{Select-BbooQ3sa.js → Select-pZDawyxt.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-DBiW70wi.js → SelectItemText-D5wuuN7G.js} +1 -1
- package/dashboard/dist/assets/{SelfHostPage-BMHJxz5q.js → SelfHostPage-sm-PARYj.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-D6LH0ac-.js → ServiceStatusPage-D4f8h0sL.js} +1 -1
- package/dashboard/dist/assets/{SessionsPage-Mrer6v17.js → SessionsPage-xVLsTN4m.js} +1 -1
- package/dashboard/dist/assets/{SettingsPage-D_7P_y_l.js → SettingsPage-Dt9iFheY.js} +3 -3
- package/dashboard/dist/assets/{SkillsPage-Ka7xm-1v.js → SkillsPage-BdWalPpd.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-BEURDPFq.js → TokenGalaxy-d2_ml0tE.js} +1 -1
- package/dashboard/dist/assets/{TooltipPopup-ZiuFFARC.js → TooltipPopup-B4masxDW.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-H73lyGEf.js → TrendMonitor-CceYpa2O.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-_7iCvyTk.js → WidgetsPage-CSN0829H.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-DEXNb6-k.js → WrappedPage-gP4WfO_m.js} +1 -1
- package/dashboard/dist/assets/{__vite-browser-external-BkNP5Ecj.js → __vite-browser-external-BtJVmciH.js} +2 -2
- package/dashboard/dist/assets/{agent-logos-OVBc_0cF.js → agent-logos-wxccxfWz.js} +1 -1
- package/dashboard/dist/assets/{arrow-left-DDphsclm.js → arrow-left-Bd5C77R2.js} +1 -1
- package/dashboard/dist/assets/{arrow-right-B1aNq0Ki.js → arrow-right-C1RqrK4A.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-yTM9azz_.js → arrow-up-right-B_b2i8hn.js} +1 -1
- package/dashboard/dist/assets/{calendar-days-D22ithNF.js → calendar-days-C8eYygme.js} +1 -1
- package/dashboard/dist/assets/{check-Dk7tknvE.js → check-BlBHefQ7.js} +1 -1
- package/dashboard/dist/assets/{chevron-down-DdyEzQ4f.js → chevron-down-mjUspqZv.js} +1 -1
- package/dashboard/dist/assets/{cloud-checkout-BJjbipnH.js → cloud-checkout-CEkMnWXf.js} +1 -1
- package/dashboard/dist/assets/{composite-DEqP00XV.js → composite-CzXFY9IC.js} +1 -1
- package/dashboard/dist/assets/{download-C9ixNyzn.js → download-CQvg59w1.js} +1 -1
- package/dashboard/dist/assets/{external-link-DL4HSsLw.js → external-link-CDYfIZ3Z.js} +1 -1
- package/dashboard/dist/assets/{flame-DqNH65nB.js → flame-C9NXQRil.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-CyVjKz4I.js → format-tokens-fKy_3qpW.js} +1 -1
- package/dashboard/dist/assets/{gift-ChJQQe_G.js → gift-WmV4SBGR.js} +1 -1
- package/dashboard/dist/assets/{host-mode-DpUDpoOz.js → host-mode-C5MvZ7SV.js} +1 -1
- package/dashboard/dist/assets/{icons-CJiHeOaU.js → icons-B1EtsaZs.js} +1 -1
- package/dashboard/dist/assets/{index-72LQsAaf.js → index-9EZ3o2RV.js} +1 -1
- package/dashboard/dist/assets/{index-CrFlTSra.js → index-BEecBW06.js} +1 -1
- package/dashboard/dist/assets/{index-BucEg3fu.js → index-DXNwBFNi.js} +1 -1
- package/dashboard/dist/assets/{info-DReYqxC7.js → info-CWDhggIW.js} +1 -1
- package/dashboard/dist/assets/{link-2-kIZbhK2S.js → link-2-DEWNkK7s.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-1An-X85y.js → loader-circle-DotT5gVp.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-FoVheEKT.js → modifiers.esm-qZnGgJAz.js} +1 -1
- package/dashboard/dist/assets/{monitor-smartphone-Ch6lr_P2.js → monitor-smartphone-DOP5eqBD.js} +1 -1
- package/dashboard/dist/assets/{play-CbJ6ZF1K.js → play-BUsybi9m.js} +1 -1
- package/dashboard/dist/assets/{plus-C-5ID3a9.js → plus-DAjojh_m.js} +1 -1
- package/dashboard/dist/assets/{provider-display-BFzRtoL2.js → provider-display-BCQQYPWD.js} +1 -1
- package/dashboard/dist/assets/{react-D4CR_fLQ.js → react-BgpqhoCj.js} +1 -1
- package/dashboard/dist/assets/{safePolygon-DP21Ibqj.js → safePolygon-C-PFpZSA.js} +1 -1
- package/dashboard/dist/assets/{search-CaznkY7U.js → search-W1A-6ugo.js} +1 -1
- package/dashboard/dist/assets/{server-CUOmC6xZ.js → server-CE7pFjDr.js} +1 -1
- package/dashboard/dist/assets/{shield-check-Dr2KBMmA.js → shield-check-KL5xc2FR.js} +1 -1
- package/dashboard/dist/assets/{skills-api-BAz_fblS.js → skills-api-DL_zLjKA.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-knEfm5hE.js → sortable.esm-CehJQvFH.js} +1 -1
- package/dashboard/dist/assets/{store-CL97jcij.js → store-BHAXkHPR.js} +1 -1
- package/dashboard/dist/assets/{terminal-EjFyreWj.js → terminal-Br5vyD6Q.js} +1 -1
- package/dashboard/dist/assets/{trash-ByqaZXkQ.js → trash-CzaCJP6G.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-Bs4RDJZE.js → use-community-stats-DbJrecQw.js} +1 -1
- package/dashboard/dist/assets/{use-latest-request-guard-CG3Ir1cP.js → use-latest-request-guard-DGhwmlX8.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-tACgCxeR.js → use-limits-display-prefs-T7KWAWZ6.js} +1 -1
- package/dashboard/dist/assets/{use-native-settings-CWjXyJXi.js → use-native-settings-MZJhS328.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-DsuC9JQa.js → use-ordered-list-BDN24weA.js} +1 -1
- package/dashboard/dist/assets/use-reduced-motion-CfCY-K-a.js +1 -0
- package/dashboard/dist/assets/{use-session-efficiency-pref-NeoJE8BL.js → use-session-efficiency-pref-DUu16y8Z.js} +1 -1
- package/dashboard/dist/assets/{use-transform-BWGKOsya.js → use-transform-BczE46xm.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-CFWFNwHS.js → use-usage-limits-CjyDfH-M.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-B_C4_P5x.js → useCurrency-BgZmWbkx.js} +1 -1
- package/dashboard/dist/assets/{usePositioner-B0L5_o38.js → usePositioner-dWENyY8z.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-DH1GWHSU.js → useTokenFormat-D7s1-Zuk.js} +1 -1
- package/dashboard/dist/assets/{zap-Chv1p7pS.js → zap-Dr__bKlq.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dashboard/dist/ip-check.html +1 -1
- package/dashboard/dist/leaderboard.html +1 -1
- package/dashboard/dist/share.html +1 -1
- package/package.json +1 -1
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/dashboard/dist/assets/DialogDescription-Di5ev5K6.js +0 -1
- package/dashboard/dist/assets/use-reduced-motion-CwFguzkm.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{o as Oe,r as i,j as e,y as Q,c as s,Z as Re,X as Ee,i as N,az as ke,W as we,R as ls,V as ye,aM as cs,bk as Y}from"./__vite-browser-external-BkNP5Ecj.js";import{L as ds,I as us}from"./LocalOnlyNotice-Cg4y02JM.js";import{S as ie}from"./Select-BbooQ3sa.js";import{C as ms}from"./chevron-down-DdyEzQ4f.js";import{S as $e}from"./search-CaznkY7U.js";import{C as xs}from"./check-Dk7tknvE.js";import{P as gs,a as hs,b as ps,c as fs,d as bs}from"./PopoverPopup-Dw811N-_.js";import{P as Pe}from"./ProviderIcon-CHxhYzK-.js";import{H as ys}from"./HoverTooltip-DI7uAp1_.js";import{u as je}from"./useCurrency-B_C4_P5x.js";import{i as _s,C as ks}from"./host-mode-DpUDpoOz.js";import{L as js}from"./loader-circle-1An-X85y.js";import{I as vs}from"./info-DReYqxC7.js";import{a as ws,b as Ns,c as Ss,d as Cs,e as Ms}from"./TooltipPopup-ZiuFFARC.js";import"./arrow-up-right-yTM9azz_.js";import"./download-C9ixNyzn.js";import"./SelectItemText-DBiW70wi.js";import"./composite-DEqP00XV.js";import"./usePositioner-B0L5_o38.js";import"./store-CL97jcij.js";import"./safePolygon-DP21Ibqj.js";const Ae={name:"calendar",size:24,node:[["path",{d:"M8 2v3",key:"1ioesn"}],["path",{d:"M16 2v3",key:"otl347"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}],["path",{d:"M3 9h18",key:"1pudct"}]]};Ae.node;const Ts=Oe(Ae);const qe={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};qe.node;const Ds=Oe(qe),Ls="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm text-oai-black outline-none hover:bg-oai-gray-100 dark:text-white dark:hover:bg-oai-gray-800";function Ne({options:a,value:t,onChange:r,allValue:o="all",allLabel:u,searchPlaceholder:p,emptyLabel:n,ariaLabel:f,disabled:k=!1,className:j=""}){const[v,w]=i.useState(!1),[x,g]=i.useState(""),[b,y]=i.useState(-1),L=i.useRef(null),S=`${i.useId()}-listbox`,P=t===o?u:a.find(h=>h.value===t)?.label??t,M=x.trim().toLowerCase(),D=i.useMemo(()=>M?a.filter(h=>h.label.toLowerCase().includes(M)):a,[a,M]),C=i.useMemo(()=>[{value:o,label:u},...D],[o,u,D]),O=b>=0&&b<C.length?C[b]:null,A=h=>{r(h),w(!1),g(""),y(-1)};i.useEffect(()=>{v&&L.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[v,b]);const J=h=>{if(h.key==="ArrowDown"||h.key==="ArrowUp"){h.preventDefault();const T=h.key==="ArrowDown";y(I=>{const c=C.length;return c?T?I>=c-1?0:I+1:I<=0?c-1:I-1:-1});return}if(h.key==="Enter"){const T=O||(M&&D.length?D[0]:null);if(!T)return;h.preventDefault(),A(T.value)}};return e.jsxs(gs,{open:v,onOpenChange:h=>{w(h),y(-1),h||g("")},children:[e.jsxs(hs,{disabled:k,"aria-label":f,className:Q("inline-flex h-8 max-w-[12rem] shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 bg-oai-white px-2.5 text-xs font-medium transition hover:border-oai-gray-300 focus:outline-none focus:ring-2 focus:ring-oai-gray-400/30 disabled:opacity-60 data-[popup-open]:border-oai-gray-300 dark:border-oai-gray-800 dark:bg-oai-gray-900 dark:hover:border-oai-gray-700",t!==o?"text-oai-black dark:text-white":"text-oai-gray-700 dark:text-oai-gray-200",j),children:[e.jsx(Ds,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),e.jsx("span",{className:"truncate",children:P}),e.jsx(ms,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(ps,{children:e.jsx(fs,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(bs,{className:"w-56 overflow-hidden rounded-md border border-oai-gray-200 bg-white p-1 shadow-[0_12px_32px_-12px_rgba(0,0,0,0.18)] outline-none dark:border-oai-gray-800 dark:bg-oai-gray-950 dark:shadow-[0_12px_32px_-12px_rgba(0,0,0,0.6)]",children:[e.jsxs("div",{className:"relative mb-1",children:[e.jsx($e,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-oai-gray-400","aria-hidden":!0}),e.jsx("input",{type:"text",role:"combobox","aria-expanded":!0,"aria-controls":S,"aria-activedescendant":O?`${S}-${b}`:void 0,value:x,onChange:h=>{g(h.target.value),y(-1)},onKeyDown:J,placeholder:p,className:"h-8 w-full rounded border border-oai-gray-200 bg-transparent pl-8 pr-2 text-xs text-oai-black outline-none placeholder:text-oai-gray-400 focus:border-oai-gray-400 dark:border-oai-gray-800 dark:text-white dark:focus:border-oai-gray-500"})]}),e.jsxs("div",{ref:L,id:S,role:"listbox","aria-label":f,className:"max-h-64 overflow-y-auto",children:[C.map((h,T)=>e.jsxs("button",{id:`${S}-${T}`,type:"button",role:"option","aria-selected":t===h.value,"data-active":T===b?"true":void 0,onMouseEnter:()=>y(T),onClick:()=>A(h.value),className:Q(Ls,t===h.value&&"bg-oai-gray-100 dark:bg-oai-gray-800",T===b&&"ring-1 ring-inset ring-oai-gray-300 dark:ring-oai-gray-600"),children:[e.jsx("span",{className:"flex-1 truncate",children:h.label}),t===h.value?e.jsx(xs,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},h.value)),D.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:n}):null]})]})})})]})}const Fs="tokentracker-sessions";async function Is(a={}){const t=new URL(`/functions/${Fs}`,window.location.origin);a.from&&t.searchParams.set("from",a.from),a.to&&t.searchParams.set("to",a.to),a.limit&&t.searchParams.set("limit",String(a.limit)),a.refresh&&t.searchParams.set("refresh","1");const r=await fetch(t.toString(),{headers:{Accept:"application/json"},cache:"no-store"}),o=await r.json().catch(()=>null);if(!r.ok){const u=r.status===404?s("sessions.error.outdated_app"):`Request failed with HTTP ${r.status}`,p=new Error(o?.error||u);throw p.status=r.status,p}return o}function ze(a,t,{timeOnly:r=!1}={}){if(!a)return"—";const o=Date.parse(a);if(!Number.isFinite(o))return"—";const u=r?{hour:"2-digit",minute:"2-digit"}:{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"};try{return new Date(o).toLocaleString(t||void 0,u)}catch{const p=new Date(o).toISOString();return r?p.slice(11,16):p.slice(0,16).replace("T"," ")}}function Ge(a){const t=Number(a);if(!Number.isFinite(t)||t<=0)return null;const r=Math.round(t/6e4);if(r<60)return s("sessions.duration.minutes",{minutes:r});const o=Math.floor(r/60),u=r%60;return s("sessions.duration.hours",{hours:o,minutes:u})}function W(a){return E(a?.own_total_tokens??a?.total_tokens)}function Os(a,t=0,r=1/0){if(!t&&r===1/0)return a;const o=a.map(n=>{if(!Array.isArray(n.usage_buckets))return{...n};const f=n.usage_buckets.filter(x=>{const g=Date.parse(x.timestamp);return g>=t&&g<=r}),k=new Map,j=Object.fromEntries([...ce,...fe].map(x=>[x,0]));let v=0,w=0;for(const x of f){v+=E(x.total_tokens),w+=E(x.cost_usd);const g=k.get(x.model)||{...(n.model_usage||[]).find(b=>b.model===x.model),model:x.model,...Object.fromEntries([...ce,...fe].map(b=>[b,0])),cost_usd:0,selected_models:[],reroute_reasons:[],model_attribution:"selected"};for(const b of[...ce,...fe]){const y=E(x[b]);j[b]+=y,g[b]+=y}g.cost_usd+=E(x.cost_usd);for(const b of["selected_models","reroute_reasons"])Array.isArray(x[b])&&(g[b]=[...new Set([...g[b],...x[b]])]);x.model_attribution==="effective"&&(g.model_attribution="effective"),k.set(x.model,g)}return{...n,...j,total_tokens:v,own_total_tokens:v,cost_usd:w,own_cost_usd:w,model_usage:[...k.values()]}}).filter(n=>!Array.isArray(n.usage_buckets)||W(n)>0),u=new Map;for(const n of o){if(!n.parent_session_hash)continue;const f=u.get(n.parent_session_hash)||[];f.push(n),u.set(n.parent_session_hash,f)}const p=(n,f=new Set)=>{if(f.has(n.session_hash))return{tokens:0,cost:0};const k=new Set(f).add(n.session_hash);let j=W(n),v=Z(n);for(const w of u.get(n.session_hash)||[]){const x=p(w,k);j+=x.tokens,v+=x.cost}return{tokens:j,cost:v}};for(const n of o){const f=p(n);n.combined_total_tokens=f.tokens,n.combined_cost_usd=f.cost,n.subagent_total_tokens=f.tokens-W(n),n.subagent_cost_usd=f.cost-Z(n)}return o}function Z(a){return E(a?.own_cost_usd??a?.cost_usd)}function E(a){const t=Number(a);return Number.isFinite(t)&&t>=0?t:0}const ce=["input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","total_tokens"],fe=["long_context_","priority_","priority_long_context_"].flatMap(a=>ce.filter(t=>t!=="total_tokens").map(t=>a+t));function B(a){const t=Array.isArray(a?.model_usage)?a.model_usage.filter(r=>r&&typeof r.model=="string"&&r.model):[];return t.length?t:[{model:a?.model||"",total_tokens:W(a),cost_usd:Z(a),performance:a?.performance}]}function Rs(a){const t={estimated_output_tokens:0,estimated_duration_ms:0,estimated_request_count:0,estimated_tokens_per_second:null,first_response_total_ms:0,first_response_sample_count:0,first_response_ms:null};for(const r of a){const o=r?.performance;if(!o)continue;const u=E(o.estimated_duration_ms),p=E(o.estimated_output_tokens),n=E(o.estimated_request_count);u>0&&p>0&&n>0&&(t.estimated_output_tokens+=p,t.estimated_duration_ms+=u,t.estimated_request_count+=n);const f=E(o.first_response_sample_count),k=E(o.first_response_total_ms);f>0&&k>0&&(t.first_response_total_ms+=k,t.first_response_sample_count+=f)}return t.estimated_duration_ms>0&&(t.estimated_tokens_per_second=t.estimated_output_tokens*1e3/t.estimated_duration_ms),t.first_response_sample_count>0&&(t.first_response_ms=t.first_response_total_ms/t.first_response_sample_count),t}function Ke(a){const t=new Set,r=a.filter(o=>t.has(o.session_hash)?!1:(t.add(o.session_hash),!0));return{count:r.length,tokens:r.reduce((o,u)=>o+W(u),0),cost:r.reduce((o,u)=>o+Z(u),0),costIsPartial:r.some(o=>o.cost_is_partial),performance:Rs(r)}}function _e(a){const t=Date.parse(a?.ended_at||a?.started_at||"");return Number.isFinite(t)?t:0}function Es(a,t){return[...a].sort((r,o)=>(t==="cost"?Z(o)-Z(r):t==="tokens"?W(o)-W(r):0)||_e(o)-_e(r))}function de(a){const t=_e(a);if(!t)return"";const r=new Date(t);return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`}function $s(a,t){const r=new Map;for(const o of a){const u=t==="project"?o.project_key||"":de(o),p=r.get(u)||{key:u,sessions:[]};p.sessions.push(o),r.set(u,p)}return[...r.values()]}function Ps(a){const t=new URLSearchParams(a),r=t.get("source"),o=n=>{const f=t.get(n)||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(f))return"";const k=new Date(`${f}T00:00:00`);return Number.isFinite(k.getTime())&&de({ended_at:k.toISOString()})===f?f:""},u=o("from"),p=o("to");return{source:["claude","codex","grok","zcode","opencode","kimi"].includes(r)?r:"all",model:t.get("model")||"all",from:u,to:p}}function As(a,t,r){let o=t?new Date(`${t}T00:00:00`).getTime():0,u=r?new Date(`${r}T23:59:59.999`).getTime():1/0;o>u&&(o=new Date(`${r}T00:00:00`).getTime(),u=new Date(`${t}T23:59:59.999`).getTime());const p=Date.parse(a.ended_at||a.started_at||""),n=Date.parse(a.started_at||a.ended_at||"");return(!Number.isFinite(p)||p>=o)&&(!Number.isFinite(n)||n<=u)}function ae({performance:a,className:t=""}){const r=Number(a?.estimated_tokens_per_second),o=Number(a?.estimated_request_count||0);return!Number.isFinite(r)||r<=0||o<=0?null:e.jsx("span",{className:t,title:`${s("sessions.performance.samples",{count:o})}
|
|
1
|
+
import{o as Oe,r as i,j as e,y as Q,c as s,Z as Re,X as Ee,i as N,az as ke,W as we,R as ls,V as ye,aM as cs,bk as Y}from"./__vite-browser-external-BtJVmciH.js";import{L as ds,I as us}from"./LocalOnlyNotice-BURiQAtP.js";import{S as ie}from"./Select-pZDawyxt.js";import{C as ms}from"./chevron-down-mjUspqZv.js";import{S as $e}from"./search-W1A-6ugo.js";import{C as xs}from"./check-BlBHefQ7.js";import{P as gs,a as hs,b as ps,c as fs,d as bs}from"./PopoverPopup-DDnISLKM.js";import{P as Pe}from"./ProviderIcon-Da90GDcM.js";import{H as ys}from"./HoverTooltip-CCKdmuOP.js";import{u as je}from"./useCurrency-BgZmWbkx.js";import{i as _s,C as ks}from"./host-mode-C5MvZ7SV.js";import{L as js}from"./loader-circle-DotT5gVp.js";import{I as vs}from"./info-CWDhggIW.js";import{a as ws,b as Ns,c as Ss,d as Cs,e as Ms}from"./TooltipPopup-B4masxDW.js";import"./arrow-up-right-B_b2i8hn.js";import"./download-CQvg59w1.js";import"./SelectItemText-D5wuuN7G.js";import"./composite-CzXFY9IC.js";import"./usePositioner-dWENyY8z.js";import"./store-BHAXkHPR.js";import"./safePolygon-C-PFpZSA.js";const Ae={name:"calendar",size:24,node:[["path",{d:"M8 2v3",key:"1ioesn"}],["path",{d:"M16 2v3",key:"otl347"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}],["path",{d:"M3 9h18",key:"1pudct"}]]};Ae.node;const Ts=Oe(Ae);const qe={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};qe.node;const Ds=Oe(qe),Ls="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm text-oai-black outline-none hover:bg-oai-gray-100 dark:text-white dark:hover:bg-oai-gray-800";function Ne({options:a,value:t,onChange:r,allValue:o="all",allLabel:u,searchPlaceholder:p,emptyLabel:n,ariaLabel:f,disabled:k=!1,className:j=""}){const[v,w]=i.useState(!1),[x,g]=i.useState(""),[b,y]=i.useState(-1),L=i.useRef(null),S=`${i.useId()}-listbox`,P=t===o?u:a.find(h=>h.value===t)?.label??t,M=x.trim().toLowerCase(),D=i.useMemo(()=>M?a.filter(h=>h.label.toLowerCase().includes(M)):a,[a,M]),C=i.useMemo(()=>[{value:o,label:u},...D],[o,u,D]),O=b>=0&&b<C.length?C[b]:null,A=h=>{r(h),w(!1),g(""),y(-1)};i.useEffect(()=>{v&&L.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[v,b]);const J=h=>{if(h.key==="ArrowDown"||h.key==="ArrowUp"){h.preventDefault();const T=h.key==="ArrowDown";y(I=>{const c=C.length;return c?T?I>=c-1?0:I+1:I<=0?c-1:I-1:-1});return}if(h.key==="Enter"){const T=O||(M&&D.length?D[0]:null);if(!T)return;h.preventDefault(),A(T.value)}};return e.jsxs(gs,{open:v,onOpenChange:h=>{w(h),y(-1),h||g("")},children:[e.jsxs(hs,{disabled:k,"aria-label":f,className:Q("inline-flex h-8 max-w-[12rem] shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 bg-oai-white px-2.5 text-xs font-medium transition hover:border-oai-gray-300 focus:outline-none focus:ring-2 focus:ring-oai-gray-400/30 disabled:opacity-60 data-[popup-open]:border-oai-gray-300 dark:border-oai-gray-800 dark:bg-oai-gray-900 dark:hover:border-oai-gray-700",t!==o?"text-oai-black dark:text-white":"text-oai-gray-700 dark:text-oai-gray-200",j),children:[e.jsx(Ds,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),e.jsx("span",{className:"truncate",children:P}),e.jsx(ms,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(ps,{children:e.jsx(fs,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(bs,{className:"w-56 overflow-hidden rounded-md border border-oai-gray-200 bg-white p-1 shadow-[0_12px_32px_-12px_rgba(0,0,0,0.18)] outline-none dark:border-oai-gray-800 dark:bg-oai-gray-950 dark:shadow-[0_12px_32px_-12px_rgba(0,0,0,0.6)]",children:[e.jsxs("div",{className:"relative mb-1",children:[e.jsx($e,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-oai-gray-400","aria-hidden":!0}),e.jsx("input",{type:"text",role:"combobox","aria-expanded":!0,"aria-controls":S,"aria-activedescendant":O?`${S}-${b}`:void 0,value:x,onChange:h=>{g(h.target.value),y(-1)},onKeyDown:J,placeholder:p,className:"h-8 w-full rounded border border-oai-gray-200 bg-transparent pl-8 pr-2 text-xs text-oai-black outline-none placeholder:text-oai-gray-400 focus:border-oai-gray-400 dark:border-oai-gray-800 dark:text-white dark:focus:border-oai-gray-500"})]}),e.jsxs("div",{ref:L,id:S,role:"listbox","aria-label":f,className:"max-h-64 overflow-y-auto",children:[C.map((h,T)=>e.jsxs("button",{id:`${S}-${T}`,type:"button",role:"option","aria-selected":t===h.value,"data-active":T===b?"true":void 0,onMouseEnter:()=>y(T),onClick:()=>A(h.value),className:Q(Ls,t===h.value&&"bg-oai-gray-100 dark:bg-oai-gray-800",T===b&&"ring-1 ring-inset ring-oai-gray-300 dark:ring-oai-gray-600"),children:[e.jsx("span",{className:"flex-1 truncate",children:h.label}),t===h.value?e.jsx(xs,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},h.value)),D.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:n}):null]})]})})})]})}const Fs="tokentracker-sessions";async function Is(a={}){const t=new URL(`/functions/${Fs}`,window.location.origin);a.from&&t.searchParams.set("from",a.from),a.to&&t.searchParams.set("to",a.to),a.limit&&t.searchParams.set("limit",String(a.limit)),a.refresh&&t.searchParams.set("refresh","1");const r=await fetch(t.toString(),{headers:{Accept:"application/json"},cache:"no-store"}),o=await r.json().catch(()=>null);if(!r.ok){const u=r.status===404?s("sessions.error.outdated_app"):`Request failed with HTTP ${r.status}`,p=new Error(o?.error||u);throw p.status=r.status,p}return o}function ze(a,t,{timeOnly:r=!1}={}){if(!a)return"—";const o=Date.parse(a);if(!Number.isFinite(o))return"—";const u=r?{hour:"2-digit",minute:"2-digit"}:{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"};try{return new Date(o).toLocaleString(t||void 0,u)}catch{const p=new Date(o).toISOString();return r?p.slice(11,16):p.slice(0,16).replace("T"," ")}}function Ge(a){const t=Number(a);if(!Number.isFinite(t)||t<=0)return null;const r=Math.round(t/6e4);if(r<60)return s("sessions.duration.minutes",{minutes:r});const o=Math.floor(r/60),u=r%60;return s("sessions.duration.hours",{hours:o,minutes:u})}function W(a){return E(a?.own_total_tokens??a?.total_tokens)}function Os(a,t=0,r=1/0){if(!t&&r===1/0)return a;const o=a.map(n=>{if(!Array.isArray(n.usage_buckets))return{...n};const f=n.usage_buckets.filter(x=>{const g=Date.parse(x.timestamp);return g>=t&&g<=r}),k=new Map,j=Object.fromEntries([...ce,...fe].map(x=>[x,0]));let v=0,w=0;for(const x of f){v+=E(x.total_tokens),w+=E(x.cost_usd);const g=k.get(x.model)||{...(n.model_usage||[]).find(b=>b.model===x.model),model:x.model,...Object.fromEntries([...ce,...fe].map(b=>[b,0])),cost_usd:0,selected_models:[],reroute_reasons:[],model_attribution:"selected"};for(const b of[...ce,...fe]){const y=E(x[b]);j[b]+=y,g[b]+=y}g.cost_usd+=E(x.cost_usd);for(const b of["selected_models","reroute_reasons"])Array.isArray(x[b])&&(g[b]=[...new Set([...g[b],...x[b]])]);x.model_attribution==="effective"&&(g.model_attribution="effective"),k.set(x.model,g)}return{...n,...j,total_tokens:v,own_total_tokens:v,cost_usd:w,own_cost_usd:w,model_usage:[...k.values()]}}).filter(n=>!Array.isArray(n.usage_buckets)||W(n)>0),u=new Map;for(const n of o){if(!n.parent_session_hash)continue;const f=u.get(n.parent_session_hash)||[];f.push(n),u.set(n.parent_session_hash,f)}const p=(n,f=new Set)=>{if(f.has(n.session_hash))return{tokens:0,cost:0};const k=new Set(f).add(n.session_hash);let j=W(n),v=Z(n);for(const w of u.get(n.session_hash)||[]){const x=p(w,k);j+=x.tokens,v+=x.cost}return{tokens:j,cost:v}};for(const n of o){const f=p(n);n.combined_total_tokens=f.tokens,n.combined_cost_usd=f.cost,n.subagent_total_tokens=f.tokens-W(n),n.subagent_cost_usd=f.cost-Z(n)}return o}function Z(a){return E(a?.own_cost_usd??a?.cost_usd)}function E(a){const t=Number(a);return Number.isFinite(t)&&t>=0?t:0}const ce=["input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","total_tokens"],fe=["long_context_","priority_","priority_long_context_"].flatMap(a=>ce.filter(t=>t!=="total_tokens").map(t=>a+t));function B(a){const t=Array.isArray(a?.model_usage)?a.model_usage.filter(r=>r&&typeof r.model=="string"&&r.model):[];return t.length?t:[{model:a?.model||"",total_tokens:W(a),cost_usd:Z(a),performance:a?.performance}]}function Rs(a){const t={estimated_output_tokens:0,estimated_duration_ms:0,estimated_request_count:0,estimated_tokens_per_second:null,first_response_total_ms:0,first_response_sample_count:0,first_response_ms:null};for(const r of a){const o=r?.performance;if(!o)continue;const u=E(o.estimated_duration_ms),p=E(o.estimated_output_tokens),n=E(o.estimated_request_count);u>0&&p>0&&n>0&&(t.estimated_output_tokens+=p,t.estimated_duration_ms+=u,t.estimated_request_count+=n);const f=E(o.first_response_sample_count),k=E(o.first_response_total_ms);f>0&&k>0&&(t.first_response_total_ms+=k,t.first_response_sample_count+=f)}return t.estimated_duration_ms>0&&(t.estimated_tokens_per_second=t.estimated_output_tokens*1e3/t.estimated_duration_ms),t.first_response_sample_count>0&&(t.first_response_ms=t.first_response_total_ms/t.first_response_sample_count),t}function Ke(a){const t=new Set,r=a.filter(o=>t.has(o.session_hash)?!1:(t.add(o.session_hash),!0));return{count:r.length,tokens:r.reduce((o,u)=>o+W(u),0),cost:r.reduce((o,u)=>o+Z(u),0),costIsPartial:r.some(o=>o.cost_is_partial),performance:Rs(r)}}function _e(a){const t=Date.parse(a?.ended_at||a?.started_at||"");return Number.isFinite(t)?t:0}function Es(a,t){return[...a].sort((r,o)=>(t==="cost"?Z(o)-Z(r):t==="tokens"?W(o)-W(r):0)||_e(o)-_e(r))}function de(a){const t=_e(a);if(!t)return"";const r=new Date(t);return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`}function $s(a,t){const r=new Map;for(const o of a){const u=t==="project"?o.project_key||"":de(o),p=r.get(u)||{key:u,sessions:[]};p.sessions.push(o),r.set(u,p)}return[...r.values()]}function Ps(a){const t=new URLSearchParams(a),r=t.get("source"),o=n=>{const f=t.get(n)||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(f))return"";const k=new Date(`${f}T00:00:00`);return Number.isFinite(k.getTime())&&de({ended_at:k.toISOString()})===f?f:""},u=o("from"),p=o("to");return{source:["claude","codex","grok","zcode","opencode","kimi"].includes(r)?r:"all",model:t.get("model")||"all",from:u,to:p}}function As(a,t,r){let o=t?new Date(`${t}T00:00:00`).getTime():0,u=r?new Date(`${r}T23:59:59.999`).getTime():1/0;o>u&&(o=new Date(`${r}T00:00:00`).getTime(),u=new Date(`${t}T23:59:59.999`).getTime());const p=Date.parse(a.ended_at||a.started_at||""),n=Date.parse(a.started_at||a.ended_at||"");return(!Number.isFinite(p)||p>=o)&&(!Number.isFinite(n)||n<=u)}function ae({performance:a,className:t=""}){const r=Number(a?.estimated_tokens_per_second),o=Number(a?.estimated_request_count||0);return!Number.isFinite(r)||r<=0||o<=0?null:e.jsx("span",{className:t,title:`${s("sessions.performance.samples",{count:o})}
|
|
2
2
|
${s("sessions.performance.method")}`,children:s("sessions.performance.speed",{speed:Number(r.toFixed(1))})})}const qs=[{key:"input_tokens",label:()=>s("dashboard.projects.detail.comp_input")},{key:"cached_input_tokens",label:()=>s("dashboard.projects.detail.comp_cached")},{key:"cache_creation_input_tokens",label:()=>s("dashboard.projects.detail.comp_cache_write")},{key:"output_tokens",label:()=>s("dashboard.projects.detail.comp_output")},{key:"reasoning_output_tokens",label:()=>s("dashboard.projects.detail.comp_reasoning")}],zs=[{key:"turns",label:()=>s("sessions.col.turns")},{key:"edit_turns",label:()=>s("sessions.col.edits")},{key:"retry_turns",label:()=>s("sessions.detail.retries")},{key:"subagent_calls",label:()=>s("sessions.card.subagents")},{key:"tool_calls",grokOnly:!0,label:()=>s("sessions.detail.tools")},{key:"tool_failures",grokOnly:!0,label:()=>s("sessions.detail.tool_failures")},{key:"error_count",grokOnly:!0,label:()=>s("sessions.detail.errors")},{key:"model_calls",grokOnly:!0,label:()=>s("sessions.detail.model_calls")},{key:"compaction_count",grokOnly:!0,label:()=>s("sessions.detail.compactions")}];function Gs(a){return a==="provider_reported"?s("sessions.detail.cost_reported"):a==="model_pricing"?s("sessions.detail.cost_estimated"):a==="mixed"?s("sessions.detail.cost_mixed"):s("sessions.detail.cost_unknown")}function Se(a){return String(a||"").startsWith("litellm")?s("sessions.detail.pricing_litellm"):String(a||"").startsWith("curated")?s("sessions.detail.pricing_curated"):null}function Ks(a,t){return t||Number(a)>0}function Ce({label:a,children:t}){return e.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-4",children:[e.jsx("dt",{className:"text-sm text-oai-gray-600 dark:text-oai-gray-300",children:a}),e.jsx("dd",{className:"min-w-0 break-words text-right text-sm tabular-nums text-oai-black dark:text-white",children:t})]})}function le({label:a,title:t,className:r="",children:o}){return e.jsxs("div",{className:`min-w-0 border-oai-gray-200 px-3 py-2.5 dark:border-oai-gray-800 ${r}`,title:t,children:[e.jsx("dt",{className:"truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a}),e.jsx("dd",{className:"mt-0.5 truncate text-base font-medium tabular-nums text-oai-black dark:text-white",children:o})]})}function Us({session:a,subagents:t=[],onClose:r}){const o=i.useRef(null),u=i.useRef(null),{currency:p,rate:n}=je(),{resolvedLocale:f}=Re(),k=c=>ke(c,{currency:p,rate:n}),j=B(a),v=i.useMemo(()=>Ke(t),[t]),w=W(a),x=Z(a),g=Number(a.subagent_total_tokens??v.tokens),b=Number(a.subagent_cost_usd??v.cost),y=a.performance,L=Number(y?.estimated_tokens_per_second)>0&&Number(y?.estimated_request_count)>0,S=Number(y?.first_response_sample_count)>0&&y?.first_response_ms!=null&&Number.isFinite(Number(y.first_response_ms)),P=S?{seconds:(Number(y.first_response_ms)/1e3).toFixed(2),count:y.first_response_sample_count}:null,M=Number(a.reasoning_output_tokens)>0,D=a.source==="grok",C=D&&Number(a.context_window_tokens)>0;i.useEffect(()=>{const c=document.activeElement,R=document.body.style.overflow;document.body.style.overflow="hidden",o.current?.focus();const $=F=>{if(F.key==="Escape"&&(F.preventDefault(),r()),F.key!=="Tab")return;const z=Array.from(u.current?.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), summary, [tabindex="0"]')||[]),ee=z[0],se=z[z.length-1];ee?F.shiftKey&&(document.activeElement===ee||!u.current?.contains(document.activeElement))?(F.preventDefault(),se.focus()):!F.shiftKey&&(document.activeElement===se||!u.current?.contains(document.activeElement))&&(F.preventDefault(),ee.focus()):(F.preventDefault(),u.current?.focus())};return window.addEventListener("keydown",$),()=>{window.removeEventListener("keydown",$),document.body.style.overflow=R,c instanceof HTMLElement&&c.isConnected&&c.focus()}},[r]);const O=g>0||b>0,A=a.cost_is_partial||O&&v.costIsPartial,J=[{label:s("sessions.detail.own"),tokens:w,cost:x,partial:a.cost_is_partial},{label:s("sessions.detail.subagents"),tokens:g,cost:b,partial:v.costIsPartial}],h=a.agent_nickname||a.title||a.project_key||s("sessions.project.unknown"),T=Ge(a.duration_ms),I=[a.project_key&&a.project_key!==h?a.project_key:null,ze(a.started_at,f),T].filter(Boolean);return e.jsx("div",{className:"fixed inset-0 z-50 flex justify-end bg-black/20 dark:bg-black/40",onClick:c=>{c.target===c.currentTarget&&r()},children:e.jsxs("div",{ref:u,role:"dialog","aria-modal":"true","aria-label":s("sessions.detail.title"),tabIndex:-1,className:"flex h-full w-full max-w-[36rem] flex-col border-l border-oai-gray-200 bg-white dark:border-oai-gray-800 dark:bg-oai-gray-950",children:[e.jsxs("div",{className:"flex shrink-0 items-start gap-3 border-b border-oai-gray-200 px-5 py-4 dark:border-oai-gray-800",children:[e.jsx("span",{className:"shrink-0 pt-0.5 text-oai-gray-600 dark:text-oai-gray-300",children:e.jsx(Pe,{provider:String(a.source||"").toUpperCase(),size:20})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h2",{className:"break-words text-base font-semibold leading-6 text-oai-black dark:text-white",children:h}),e.jsx("p",{className:"mt-0.5 break-words text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:I.join(" · ")})]}),e.jsx("button",{ref:o,type:"button",onClick:r,"aria-label":s("sessions.detail.close"),className:"-mr-2 -mt-1 flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-oai-gray-500 hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white sm:h-9 sm:w-9",children:e.jsx(Ee,{size:18,"aria-hidden":!0})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-5",children:[e.jsxs("section",{"aria-label":s("sessions.detail.consumption"),children:[e.jsxs("dl",{className:"grid grid-cols-2 overflow-hidden rounded-lg border border-oai-gray-200 dark:border-oai-gray-800",children:[e.jsx(le,{label:s("sessions.col.tokens"),children:N(w+g)}),e.jsxs(le,{label:s("sessions.col.cost"),className:"border-l",children:[A?"≥":"",k(x+b)]}),e.jsx(le,{label:s("sessions.summary.speed"),className:"border-t",title:L?s("sessions.performance.samples",{count:y.estimated_request_count}):s("sessions.detail.no_speed"),children:L?e.jsx(ae,{performance:y}):"—"}),e.jsx(le,{label:s("sessions.performance.first_response"),className:"border-l border-t",title:s("sessions.performance.first_response_method"),children:S?Number(y.first_response_sample_count)===1?s("sessions.performance.first_response_value_single",P):s("sessions.performance.first_response_value",P):"—"})]}),O?e.jsx("dl",{className:"mt-3 space-y-1.5",children:J.map(c=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_80px_88px] items-baseline gap-3 text-sm",children:[e.jsx("dt",{className:"text-oai-gray-600 dark:text-oai-gray-300",children:c.label}),e.jsx("dd",{className:"text-right tabular-nums",children:N(c.tokens)}),e.jsxs("dd",{className:"text-right tabular-nums",children:[c.partial?"≥":"",k(c.cost)]})]},c.label))}):null,e.jsxs("p",{className:"mt-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:[s("sessions.detail.cost_source")," · ",Gs(a.cost_source),a.cost_is_partial?e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[" · ",s("sessions.cost.partial_title")]}):null,a.usage_is_incomplete?e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[" · ",s("sessions.badge.partial_usage")]}):null]})]}),e.jsxs("section",{className:"mt-6",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-white",children:s("sessions.detail.tokens")}),e.jsx("dl",{className:"mt-2 grid grid-cols-1 gap-x-8 gap-y-1.5 sm:grid-cols-2",children:qs.map(({key:c,label:R})=>e.jsx(Ce,{label:R(),children:a[c]==null?"—":N(a[c])},c))})]}),e.jsxs("section",{className:"mt-6",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_80px_88px] items-baseline gap-3",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-white",children:s("sessions.detail.models")}),e.jsx("span",{className:"text-right text-xs text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0,children:s("sessions.col.tokens")}),e.jsx("span",{className:"text-right text-xs text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0,children:s("sessions.col.cost")})]}),e.jsx("ul",{className:"mt-1 divide-y divide-oai-gray-100 dark:divide-oai-gray-800/70",children:j.map(c=>{const R=c.pricing?.status==="unpriced",$=a.cost_source==="provider_reported"&&j.length===1,F=$?x:c.cost_usd,z=Ks(F,$);return e.jsxs("li",{className:"py-2.5",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_80px_88px] items-baseline gap-3 text-sm",children:[e.jsx("span",{className:"min-w-0 break-words text-oai-black dark:text-white",children:c.model||s("sessions.model.unknown")}),e.jsx("span",{className:"text-right tabular-nums",children:N(c.total_tokens)}),e.jsx("span",{className:"text-right tabular-nums",children:R&&!z?"—":k(F)})]}),c.pricing?e.jsxs("details",{className:"group text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsxs("summary",{className:"flex min-h-10 cursor-pointer list-none items-center gap-2 rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 sm:min-h-0 sm:pt-1 [&::-webkit-details-marker]:hidden",children:[e.jsx(ae,{performance:c.performance,className:"tabular-nums"}),e.jsx("span",{className:"underline decoration-dotted underline-offset-4 group-open:no-underline",children:s("sessions.detail.pricing_details")})]}),e.jsxs("div",{className:"space-y-1 pt-1.5 leading-5",children:[R?e.jsx("p",{children:s("sessions.detail.pricing_unpriced")}):null,c.pricing.status==="free"?e.jsx("p",{children:s("sessions.detail.pricing_free")}):null,c.pricing.status==="priced"?e.jsx("p",{children:s("sessions.detail.pricing_rates",{input:c.pricing.input,output:c.pricing.output,cacheRead:c.pricing.cache_read,cacheWrite:c.pricing.cache_write})}):null,Se(c.pricing.source)?e.jsx("p",{children:Se(c.pricing.source)}):null]})]}):e.jsx(ae,{performance:c.performance,className:"block pt-1 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400"})]},c.model)})})]}),e.jsxs("details",{className:"mt-5 border-t border-oai-gray-200 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"flex min-h-11 cursor-pointer items-center rounded text-sm font-medium text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-white",children:s("sessions.detail.signals")}),e.jsx("dl",{className:"grid grid-cols-1 gap-x-8 gap-y-1.5 pb-4 sm:grid-cols-2",children:zs.map(({key:c,label:R,grokOnly:$})=>e.jsx(Ce,{label:R(),children:typeof a[c]=="number"&&(!$||D)?N(a[c]):s("sessions.detail.not_recorded")},c))}),D&&a.usage_precision?e.jsx("p",{className:"pb-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.grok.runtime_breakdown",{calls:N(a.model_calls),seconds:(Number(a.api_duration_ms||0)/1e3).toFixed(1),tools:N(a.tool_calls),errors:N(a.error_count)})}):null,C?e.jsx("p",{className:"pb-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.grok.context_breakdown",{used:N(a.context_tokens_used),window:N(a.context_window_tokens),percent:Number(a.context_usage_percent||0).toFixed(0)})}):null]}),e.jsxs("details",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800",children:[e.jsx("summary",{className:"flex min-h-11 cursor-pointer items-center rounded text-sm font-medium text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-white",children:s("sessions.detail.identifiers")}),e.jsxs("dl",{className:"space-y-3 pb-4",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.detail.session_id")}),e.jsx("dd",{className:"mt-1 break-all font-mono text-xs leading-5",children:a.session_id||a.session_hash})]}),a.project_ref?e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.detail.local_path")}),e.jsx("dd",{className:"mt-1 break-all font-mono text-xs leading-5",children:a.project_ref})]}):null,a.resume_command?e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.detail.resume_command")}),e.jsx("dd",{className:"mt-1 break-all font-mono text-xs leading-5",children:a.resume_command})]}):null]})]}),e.jsxs("div",{className:"mt-2 space-y-1.5 border-t border-oai-gray-200 pt-4 text-xs leading-5 text-oai-gray-500 dark:border-oai-gray-800 dark:text-oai-gray-400",children:[L?e.jsx("p",{children:s("sessions.performance.method")}):null,M?e.jsx("p",{children:s("sessions.detail.reasoning_note")}):null,e.jsx("p",{children:s("sessions.privacy")})]})]})]})})}const Me=_s(),Te=[],be=100,Ws=[{id:"all",label:()=>s("usage.filter.source_all")},{id:"claude",label:()=>"Claude Code"},{id:"codex",label:()=>"Codex"},{id:"opencode",label:()=>"OpenCode"},{id:"grok",label:()=>"Grok"},{id:"zcode",label:()=>"ZCode"},{id:"kimi",label:()=>s("leaderboard.column.kimi")}],Ue=[{id:"all",days:0,label:()=>s("sessions.filter.range_label_all")},{id:"7d",days:7,label:()=>s("sessions.filter.range_7d")},{id:"30d",days:30,label:()=>s("sessions.filter.range_30d")},{id:"90d",days:90,label:()=>s("sessions.filter.range_90d")}];function De(a){const t=Ue.find(o=>o.id===a)?.days||0;if(!t)return 0;const r=new Date;return r.setDate(r.getDate()-(t-1)),r.setHours(0,0,0,0),r.getTime()}function Hs(a,t){if(!t)return!0;const r=Date.parse(a.ended_at||a.started_at||"");return Number.isFinite(r)?r>=t:!0}function Vs(a){const t=Date.parse(a.started_at||"");return!Number.isFinite(t)||de({started_at:a.started_at})===de(a)}function Le(a){const t=B(a);return t.length===1?t[0].model||s("sessions.model.unknown"):t.map(r=>`${r.model} ${N(Number(r.total_tokens||0))}`).join(" · ")}async function Fe(a){if(navigator?.clipboard?.writeText)return await navigator.clipboard.writeText(a),!0;const t=document.createElement("textarea");t.value=a,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();const r=document.execCommand("copy");return document.body.removeChild(t),r}function Bs(){const[a,t]=i.useState(!1),r=i.useId();return e.jsxs(ws,{open:a,onOpenChange:t,children:[e.jsx(Ns,{delay:150,closeDelay:100,closeOnClick:!1,onClick:()=>t(!0),"aria-label":s("sessions.summary.scope_help"),"aria-describedby":a?r:void 0,className:"sessions-summary-help relative inline-flex h-4 w-4 shrink-0 items-center justify-center rounded text-oai-gray-500 hover:text-oai-black dark:text-oai-gray-400 dark:hover:text-white before:absolute before:-inset-2 before:content-['']",children:e.jsx(vs,{className:"h-3.5 w-3.5","aria-hidden":!0})}),e.jsx(Ss,{children:e.jsx(Cs,{side:"bottom",align:"end",sideOffset:12,className:"z-[60]",children:e.jsx(Ms,{id:r,role:"tooltip",className:"max-w-xs rounded-lg border border-oai-gray-200 bg-white p-4 text-sm leading-6 text-oai-gray-700 outline-none dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-gray-200",children:s("sessions.summary.scope")})})})]})}const Ie=ye.memo(function({session:t,locale:r,nested:o=!1,timeOnly:u=!1,childCount:p=0,expanded:n=!1,onToggle:f,onDetail:k}){const{currency:j,rate:v}=je(),w=String(t.source||"").toUpperCase(),x=Ge(t.duration_ms),g=t.resume_command,b=t.project_key||s("sessions.project.unknown"),y=o||t.thread_kind==="subagent",L=y?t.agent_nickname||t.agent_role||t.title||b:t.title||b,S=t.usage_is_incomplete?s("sessions.badge.partial_usage"):t.cost_is_partial?s("sessions.badge.partial_cost"):null,P=t.project_ref?`${t.project_ref}
|
|
3
3
|
${s("sessions.project.copy_hint")}`:void 0,M=async()=>{if(t.project_ref)try{await Fe(t.project_ref)?Y({title:s("sessions.project.copied")}):Y({title:s("sessions.project.copy_failed")})}catch{Y({title:s("sessions.project.copy_failed")})}},D=O=>e.jsxs("span",{className:"group relative inline-flex min-w-0 max-w-full",children:[e.jsx(ys,{text:P,placement:"bottom"}),e.jsx("button",{type:"button",onClick:M,"aria-label":s("sessions.project.copy_aria",{project:b}),className:Q("max-w-full truncate rounded text-left underline decoration-dotted decoration-oai-gray-300 underline-offset-4 hover:decoration-oai-gray-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:decoration-oai-gray-600 dark:hover:decoration-oai-gray-400",O),children:b})]}),C=async()=>{if(g)try{await Fe(g)?Y({title:s("sessions.resume.copied")}):Y({title:s("sessions.resume.copy_failed")})}catch{Y({title:s("sessions.resume.copy_failed")})}};return e.jsxs("li",{className:Q("sessions-row sessions-row-grid py-3",o&&"sessions-row-nested"),children:[e.jsxs("div",{className:"sessions-row-identity min-w-0",children:[e.jsx("span",{className:"sessions-row-provider inline-flex items-center justify-center text-oai-gray-600 dark:text-oai-gray-300","aria-hidden":"true",children:e.jsx(Pe,{provider:w,size:o?16:18})}),e.jsxs("div",{className:"contents",children:[e.jsx("button",{type:"button",onClick:()=>k(t),"aria-label":s("sessions.detail.open_aria",{title:L}),title:L,className:"sessions-row-title block min-h-9 min-w-0 max-w-full truncate rounded text-left text-sm font-medium text-oai-black underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-white md:min-h-5",children:L}),e.jsxs("div",{className:"sessions-row-meta flex min-w-0 flex-wrap items-center gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{className:"sessions-meta-item min-w-0 max-w-full",children:t.project_ref?D("min-h-6 inline-flex items-center md:min-h-0"):e.jsx("span",{className:"truncate",children:b})}),e.jsx("span",{className:"sessions-meta-item min-w-0 max-w-full truncate",title:Le(t),children:Le(t)}),e.jsx("span",{className:"sessions-meta-item tabular-nums",children:ze(t.started_at,r,{timeOnly:u&&Vs(t)})}),x?e.jsx("span",{className:"sessions-meta-item tabular-nums",children:x}):null,Number.isFinite(t.session_store_bytes)?e.jsx("span",{className:"sessions-meta-item tabular-nums",title:s("sessions.storage.tooltip",{metric:s(t.session_store_metric==="allocated"?"sessions.storage.allocated":"sessions.storage.logical"),ratio:Math.round(t.bytes_per_1k_tokens||0).toLocaleString(r)}),children:s("sessions.storage.label",{size:s("sessions.storage.size",{value:(t.session_store_bytes/1024/1024).toLocaleString(r,{maximumFractionDigits:2})})})}):null,y?e.jsxs("span",{className:"sessions-meta-item",children:[s("sessions.badge.subagent"),t.agent_role?` · ${t.agent_role}`:""]}):null,t.first_pass?e.jsx("span",{className:"sessions-meta-item text-emerald-700 dark:text-emerald-300",children:s("sessions.badge.first_pass")}):null,S?e.jsx("span",{className:"sessions-meta-item text-amber-700 dark:text-amber-300",children:S}):null,t.cost_source==="provider_reported"?e.jsx("span",{className:"sessions-meta-item",children:s("sessions.badge.reported_cost")}):null,p?e.jsxs("button",{type:"button",onClick:()=>f(t.session_hash),"aria-expanded":n,className:"-mx-1.5 inline-flex min-h-8 items-center md:-my-1 md:ml-2 md:mr-0 gap-0.5 rounded px-1.5 font-medium text-oai-gray-700 hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-200 dark:hover:bg-oai-gray-800 dark:hover:text-white md:min-h-6",children:[e.jsx(cs,{className:Q("h-3.5 w-3.5 transition-transform",n&&"rotate-90"),"aria-hidden":!0}),n?s("sessions.thread.collapse",{count:p}):s("sessions.thread.expand",{count:p})]}):null]})]})]}),e.jsxs("dl",{className:"sessions-row-metrics",children:[e.jsxs("div",{className:"sessions-row-value",children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300 md:sr-only",children:s("sessions.col.tokens")}),e.jsxs("dd",{title:Number(t.subagent_total_tokens)?s("sessions.thread.tokens_summary",{own:N(t.own_total_tokens),subagents:N(t.subagent_total_tokens),combined:N(t.combined_total_tokens)}):void 0,className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",children:[N(t.total_tokens),Number(t.subagent_total_tokens)?e.jsxs("span",{className:"mt-0.5 block text-xs text-oai-gray-500 dark:text-oai-gray-400",children:["Σ ",N(t.combined_total_tokens)]}):null]})]}),e.jsxs("div",{className:"sessions-row-value",children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300 md:sr-only",children:s("sessions.col.cost")}),e.jsxs("dd",{className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",title:t.cost_is_partial?s("sessions.cost.partial_title"):void 0,children:[t.cost_is_partial?"≥":"",ke(t.cost_usd,{currency:j,rate:v})]})]}),e.jsxs("div",{className:"sessions-row-value",children:[e.jsx("dt",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300 md:sr-only",children:s("sessions.col.speed")}),e.jsx("dd",{className:"mt-1 min-h-5 text-sm tabular-nums text-oai-gray-600 dark:text-oai-gray-300 md:mt-0",children:e.jsx(ae,{performance:t.performance})})]})]}),e.jsx("button",{type:"button",onClick:C,disabled:!g,title:g||s("sessions.resume.unavailable"),"aria-label":g?s("sessions.resume.copy_aria",{command:g}):s("sessions.resume.unavailable"),className:"sessions-row-action inline-flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-oai-gray-500 transition hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:cursor-not-allowed dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white md:h-8 md:w-8",children:e.jsx(ks,{className:"h-4 w-4","aria-hidden":!0})})]})});function Qs({sessions:a,selectedModel:t,onSelect:r}){const{groups:o,totalTokens:u}=i.useMemo(()=>{const n=new Map;let f=0;for(const k of a)for(const j of B(k)){const v=j.model||s("sessions.model.unknown"),w=Number(j.total_tokens||0),x=n.get(v)||{model:v,count:0,tokens:0};x.count+=1,x.tokens+=w,f+=w,n.set(v,x)}return{groups:[...n.values()].sort((k,j)=>j.tokens-k.tokens),totalTokens:f}},[a]);function p(n){return Q("min-h-10 rounded-md border px-2.5 text-xs tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 md:min-h-7",n?"border-oai-brand-500 bg-oai-brand-50 text-oai-brand-700 dark:bg-oai-brand-500/10 dark:text-oai-brand-300":"border-oai-gray-200 text-oai-gray-600 hover:bg-oai-gray-100 dark:border-oai-gray-700 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800")}return e.jsx("li",{className:"sessions-thread-models py-2.5",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"mr-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.thread.model_usage")}),e.jsx("button",{type:"button","aria-pressed":t==="all",onClick:()=>r("all"),className:p(t==="all"),children:s("sessions.thread.model_all",{count:a.length,tokens:N(u)})}),o.map(n=>e.jsx("button",{type:"button","aria-pressed":t===n.model,onClick:()=>r(n.model),className:p(t===n.model),children:s("sessions.thread.model_item",{model:n.model,count:n.count,tokens:N(n.tokens)})},n.model))]})})}function ft(){const[a]=i.useState(()=>Ps(window.location.search)),[t,r]=i.useState(null),[o,u]=i.useState(null),[p,n]=i.useState(!0),[f,k]=i.useState(!1),[j,v]=i.useState(a.source),[w,x]=i.useState(a.model),[g,b]=i.useState(a.from||a.to?"custom":"all"),[y,L]=i.useState(a.from),[S,P]=i.useState(a.to),[M,D]=i.useState("all"),[C,O]=i.useState("time"),[A,J]=i.useState("recent"),[h,T]=i.useState(null),[I,c]=i.useState(""),[R,$]=i.useState(be),[F,z]=i.useState(()=>new Set),[ee,se]=i.useState(()=>new Map),re=i.useRef(0),{resolvedLocale:H}=Re(),{currency:We,rate:He}=je(),oe=i.useCallback(async(l=!1)=>{const m=++re.current;l?k(!0):n(!0),u(null);try{const d=await Is({refresh:l});m===re.current&&r(d)}catch(d){m===re.current&&u(d?.message||String(d))}finally{m===re.current&&(n(!1),k(!1))}},[]);i.useEffect(()=>{Me||we()?oe(!1):n(!1)},[oe]);const G=t?.sessions||Te,Ve=i.useMemo(()=>{const l=new Set,m=[];for(const d of G){const _=d.project_key;!_||l.has(_)||(l.add(_),m.push({value:_,label:_}))}return m.sort((d,_)=>d.label.localeCompare(_.label))},[G]),Be=i.useMemo(()=>{const l=new Set;for(const m of G)for(const d of B(m))d.model&&l.add(d.model);return[...l].sort().map(m=>({value:m,label:m}))},[G]),ue=i.useDeferredValue(I),ne=i.useMemo(()=>{let m=De(g),d=1/0;return g==="custom"&&(m=y?new Date(`${y}T00:00:00`).getTime():0,d=S?new Date(`${S}T23:59:59.999`).getTime():1/0,m>d&&(m=new Date(`${S}T00:00:00`).getTime(),d=new Date(`${y}T23:59:59.999`).getTime())),Os(G,m,d)},[G,g,y,S]),K=i.useMemo(()=>{const l=ue.trim().toLowerCase(),m=De(g);return ne.filter(d=>{if(j!=="all"&&d.source!==j||M!=="all"&&d.project_key!==M||w!=="all"&&!B(d).some(U=>U.model===w))return!1;if(g==="custom"){if(!As(d,y,S))return!1}else if(!Hs(d,m))return!1;if(!l)return!0;const _=B(d).map(U=>U.model).join(" ");return`${d.title||""} ${d.project_key||""} ${_} ${d.agent_nickname||""} ${d.agent_role||""} ${d.project_ref||""} ${d.session_id||""}`.toLowerCase().includes(l)})},[ne,j,M,w,g,y,S,ue]),X=i.useMemo(()=>Ke(K),[K]),V=i.useMemo(()=>{const l=new Set(K.map(_=>_.session_hash)),m=new Map,d=[];for(const _ of Es(K,A)){const q=_.root_session_hash||_.parent_session_hash;if(_.parent_session_hash&&q&&l.has(q)){const U=m.get(q)||[];U.push(_),m.set(q,U)}else d.push(_)}return{roots:d,childrenByRoot:m,foldedCount:K.length-d.length}},[K,A]),me=j!=="all"||w!=="all"||g!=="all"||M!=="all"||I.trim()!=="";i.useEffect(()=>{$(be),z(new Set),se(new Map)},[j,M,w,g,y,S,ue,A,C,G]);const xe=i.useMemo(()=>V.roots.slice(0,R),[V.roots,R]),Qe=i.useMemo(()=>$s(xe,C),[xe,C]),Ze=i.useMemo(()=>h?ne.filter(l=>l.session_hash!==h.session_hash&&(l.root_session_hash===h.session_hash||l.parent_session_hash===h.session_hash)):Te,[ne,h]),Xe=i.useCallback(()=>T(null),[]),ge=i.useCallback(l=>{b(l),l!=="custom"&&(L(""),P(""))},[]),Ye=i.useCallback(()=>{v("all"),x("all"),D("all"),c(""),ge("all")},[ge]),he=V.roots.length>xe.length,pe=i.useCallback(()=>$(l=>l+be),[]),Je=i.useCallback(l=>{z(m=>{const d=new Set(m);return d.has(l)?d.delete(l):d.add(l),d})},[]),es=i.useCallback((l,m)=>{se(d=>{const _=new Map(d);return m==="all"?_.delete(l):_.set(l,m),_})},[]),ve=i.useRef(null);i.useEffect(()=>{if(!he||typeof IntersectionObserver>"u")return;const l=ve.current;if(!l)return;const m=new IntersectionObserver(d=>{d.some(_=>_.isIntersecting)&&pe()},{rootMargin:"400px"});return m.observe(l),()=>m.disconnect()},[he,pe]);const ss=i.useMemo(()=>Ws.map(l=>({value:l.id,label:l.label()})),[H]),ts=i.useMemo(()=>[...Ue.map(l=>({value:l.id,label:l.label()})),{value:"custom",label:s("sessions.filter.range_custom")}],[H]),as=i.useMemo(()=>[{value:"time",label:s("sessions.group.time")},{value:"project",label:s("sessions.group.project")}],[H]),rs=i.useMemo(()=>[{value:"recent",label:s("sessions.sort.recent")},{value:"cost",label:s("sessions.sort.cost")},{value:"tokens",label:s("sessions.sort.tokens")}],[H]),os=Number(t?.session_count)>Number(t?.returned_count);return!Me&&!we()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(ds,{})}):e.jsxs("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:[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:"mb-8 flex flex-row items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"mb-3 text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:s("nav.sessions")}),e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:s("sessions.page.summary")})]}),e.jsx("button",{type:"button",onClick:()=>{oe(!0)},disabled:f||p,"aria-label":s("sessions.page.refresh"),title:s("sessions.page.refresh"),className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-oai-gray-200 text-oai-gray-600 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-400 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:e.jsx(ls,{className:Q("h-4 w-4",f&&"animate-spin"),"aria-hidden":!0})})]}),e.jsxs("div",{className:"mb-6 space-y-3",children:[e.jsxs("div",{className:"sessions-toolbar",children:[e.jsxs("div",{className:"sessions-toolbar-search relative",children:[e.jsx($e,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),e.jsx(us,{type:"search",value:I,onChange:l=>c(l.target.value),onKeyDown:l=>{l.key==="Escape"&&I&&(l.preventDefault(),c(""))},"aria-label":s("sessions.action.search_aria"),placeholder:s("sessions.search.placeholder"),className:"h-11 pl-10 pr-12 text-sm !bg-white dark:!bg-oai-gray-900 !border-oai-gray-200 placeholder:!text-oai-gray-500 dark:!border-oai-gray-800 dark:placeholder:!text-oai-gray-400 sm:h-9 [&::-webkit-search-cancel-button]:appearance-none"}),I?e.jsx("button",{type:"button",onMouseDown:l=>l.preventDefault(),onClick:()=>c(""),"aria-label":s("sessions.action.search_clear"),className:"absolute right-0 top-0 flex h-11 w-11 items-center justify-center rounded-md text-oai-gray-600 hover:bg-oai-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800 sm:h-9 sm:w-9",children:e.jsx(Ee,{className:"h-4 w-4","aria-hidden":!0})}):null]}),e.jsx(ie,{ariaLabel:s("sessions.filter.source_aria"),options:ss,value:j,onValueChange:v,className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(ie,{ariaLabel:s("sessions.filter.range_aria"),options:ts,value:g,onValueChange:ge,leadingIcon:e.jsx(Ts,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(Ne,{options:Ve,value:M,onChange:D,allLabel:s("sessions.filter.project_all"),searchPlaceholder:s("sessions.filter.project_search"),emptyLabel:s("sessions.filter.project_empty"),ariaLabel:s("sessions.filter.project_aria"),className:"sessions-filter-trigger !h-11 !w-full !max-w-none !px-3 !text-sm !font-normal sm:!h-9 !bg-white !text-oai-black dark:!bg-oai-gray-900 dark:!text-white [&>svg]:!text-oai-gray-500 dark:[&>svg]:!text-oai-gray-400"}),e.jsx(Ne,{options:Be,value:w,onChange:x,allLabel:s("sessions.filter.model_all"),searchPlaceholder:s("sessions.filter.model_search"),emptyLabel:s("sessions.filter.model_empty"),ariaLabel:s("sessions.filter.model_aria"),className:"sessions-filter-trigger sessions-model-filter !h-11 !w-full !max-w-none !px-3 !text-sm !font-normal sm:!h-9 !bg-white !text-oai-black dark:!bg-oai-gray-900 dark:!text-white [&>svg]:!text-oai-gray-500 dark:[&>svg]:!text-oai-gray-400"})]}),g==="custom"?e.jsxs("div",{className:"grid max-w-lg grid-cols-2 gap-3",children:[e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("span",{className:"mb-1 block",children:s("sessions.filter.from")}),e.jsx("input",{type:"date","aria-label":s("sessions.filter.from"),value:y,onChange:l=>L(l.target.value),className:"h-11 w-full min-w-0 rounded-md border border-oai-gray-200 bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-oai-brand-500 dark:border-oai-gray-800 dark:bg-oai-gray-900 sm:h-10"})]}),e.jsxs("label",{className:"min-w-0 text-xs text-oai-gray-600 dark:text-oai-gray-300",children:[e.jsx("span",{className:"mb-1 block",children:s("sessions.filter.to")}),e.jsx("input",{type:"date","aria-label":s("sessions.filter.to"),value:S,onChange:l=>P(l.target.value),className:"h-11 w-full min-w-0 rounded-md border border-oai-gray-200 bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-oai-brand-500 dark:border-oai-gray-800 dark:bg-oai-gray-900 sm:h-10"})]})]}):null]}),!p&&t?e.jsx("section",{className:"mb-6 flex items-start gap-3 rounded-lg border border-oai-gray-200 px-4 py-3 dark:border-oai-gray-800",children:e.jsxs("dl",{className:"sessions-kpis grid min-w-0 flex-1 grid-cols-2 gap-y-3 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.summary.count")}),e.jsx("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:N(X.count)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.col.tokens")}),e.jsx("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:N(X.tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.col.cost")}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[X.costIsPartial?"≥":"",ke(X.cost,{currency:We,rate:He})]})]}),e.jsxs("div",{children:[e.jsxs("dt",{className:"flex items-center gap-1.5 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:s("sessions.summary.speed")}),e.jsx(Bs,{})]}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[e.jsx(ae,{performance:X.performance}),X.performance.estimated_tokens_per_second==null?"—":null]})]})]})}):null,e.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-x-3 gap-y-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:V.foldedCount>0?s("sessions.thread.result_count",{roots:V.roots.length,subagents:V.foldedCount}):s("sessions.filter.result_count",{filtered:K.length,total:G.length})}),me?e.jsx("button",{type:"button",onClick:Ye,className:"inline-flex min-h-10 items-center rounded text-oai-gray-700 underline decoration-oai-gray-300 underline-offset-4 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:text-oai-gray-200 dark:decoration-oai-gray-600 dark:hover:text-white sm:min-h-0",children:s("sessions.filter.clear")}):null]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(ie,{ariaLabel:s("sessions.group.aria"),options:as,value:C,onValueChange:O,className:"sessions-filter-trigger h-11 min-w-0 max-w-40 px-2.5 text-xs sm:h-8"}),e.jsx(ie,{ariaLabel:s("sessions.sort.aria"),options:rs,value:A,onValueChange:J,className:"sessions-filter-trigger h-11 min-w-0 max-w-44 px-2.5 text-xs sm:h-8",align:"end"})]})]}),os?e.jsx("p",{className:"mb-4 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.truncated",{shown:t.returned_count,total:t.session_count})}):null,o&&!t?e.jsxs("div",{className:"rounded-xl border border-dashed border-red-300 py-16 text-center dark:border-red-500/40",children:[e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:s("sessions.error.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:o}),e.jsx("button",{type:"button",onClick:()=>{oe(!1)},className:"mt-4 inline-flex h-11 items-center rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:border-oai-gray-800 dark:text-oai-gray-200 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:s("sessions.error.retry")})]}):p?e.jsxs("div",{className:"flex items-center gap-2 py-16 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(js,{className:"h-4 w-4 animate-spin","aria-hidden":!0}),s("sessions.loading")]}):K.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-oai-gray-200 py-16 text-center dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm font-medium text-oai-black dark:text-white",children:me?s("sessions.empty.filtered_title"):s("sessions.empty.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:me?s("sessions.empty.filtered_body"):s("sessions.empty.body")})]}):e.jsxs(e.Fragment,{children:[o?e.jsx("p",{className:"mb-4 text-sm text-red-500 dark:text-red-400",children:s("shared.error.prefix",{error:o})}):null,e.jsxs("div",{className:"sessions-row-grid sessions-list-header border-b border-oai-gray-200 py-2 text-xs text-oai-gray-500 dark:border-oai-gray-800 dark:text-oai-gray-400","aria-hidden":!0,children:[e.jsx("span",{children:s("sessions.col.session")}),e.jsx("span",{className:"text-right",children:s("sessions.col.tokens")}),e.jsx("span",{className:"text-right",children:s("sessions.col.cost")}),e.jsx("span",{className:"text-right",children:s("sessions.col.speed")}),e.jsx("span",{className:"sr-only",children:s("sessions.col.actions")})]}),e.jsx("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:Qe.map(l=>e.jsxs(ye.Fragment,{children:[e.jsx("li",{className:"pb-2 pt-5",children:e.jsx("h2",{className:"break-words text-xs font-medium text-oai-gray-900 dark:text-oai-gray-100",children:C==="project"?l.key||s("sessions.project.unknown"):l.key?new Date(`${l.key}T12:00:00`).toLocaleDateString(H||void 0,{year:"numeric",month:"short",day:"numeric"}):s("sessions.group.unknown_date")})}),l.sessions.map(m=>{const d=V.childrenByRoot.get(m.session_hash)||[],_=F.has(m.session_hash),q=ee.get(m.session_hash)||"all",U=q==="all"?d:d.filter(function(ns){return B(ns).some(is=>is.model===q)});return e.jsxs(ye.Fragment,{children:[e.jsx(Ie,{session:m,locale:H,timeOnly:C==="time",childCount:d.length,expanded:_,onToggle:Je,onDetail:T}),_&&d.length?e.jsx(Qs,{sessions:d,selectedModel:q,onSelect:te=>es(m.session_hash,te)}):null,_?U.map(te=>e.jsx(Ie,{session:te,locale:H,nested:!0,timeOnly:C==="time",onDetail:T},te.session_hash)):null]},m.session_hash)})]},l.key))}),he?e.jsx("div",{ref:ve,className:"flex justify-center pt-6",children:e.jsx("button",{type:"button",onClick:pe,className:"inline-flex h-11 items-center rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-600 transition-colors hover:bg-oai-gray-100 hover:text-oai-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800 dark:hover:text-white",children:s("sessions.action.load_more")})}):null]}),e.jsx("p",{className:"mt-8 max-w-3xl text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:s("sessions.privacy")})]})}),h?e.jsx(Us,{session:h,subagents:Ze,onClose:Xe}):null]})}export{ft as SessionsPage};
|