tokentracker-cli 1.5.13 → 1.5.15
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-Ct0vfdYb.js → AchievementBadge-CwjI28oT.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-dfoRxqOv.js → AchievementsPage-Dq544fjX.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-DHFyssU0.js → AchievementsSection-DufV6nod.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-ChJYZMSq.js → BadgeDetailModal-vw8xydKu.js} +1 -1
- package/dashboard/dist/assets/{BotAnimated-C_qaJy1-.js → BotAnimated-De0anwsh.js} +1 -1
- package/dashboard/dist/assets/{Card-BhK2nmOu.js → Card-CuSeWBDM.js} +1 -1
- package/dashboard/dist/assets/{CloudCheckoutPage-Ele1kkut.js → CloudCheckoutPage-CxFcOwAj.js} +1 -1
- package/dashboard/dist/assets/{CloudPage-C5DMqcoV.js → CloudPage-Beb7_JLW.js} +2 -2
- package/dashboard/dist/assets/{CommandPalette-C_hxoIwL.js → CommandPalette-PsUq2iRS.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-BSTqBIEU.js → CommunityStatsModal-b54WaPbK.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-DI4QK5EV.js → ConfirmModal-_NdunIh5.js} +1 -1
- package/dashboard/dist/assets/{Controls-zK1rzS_8.js → Controls-5Is6MWln.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-BdDnmc60.js → DashboardPage-C0n0qC7h.js} +1 -1
- package/dashboard/dist/assets/{DateRangePopover-DqwgxpNF.js → DateRangePopover-C3WfGy-0.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-C0fQKKuI.js → DevicePage-Vn6k-mGd.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-C_cbyHpb.js → DialogClose-CXttnna-.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-C3KGos_G.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-BcBpd--_.js → DialogTitle-B0cNIo0E.js} +1 -1
- package/dashboard/dist/assets/{ElectricLogo-Dw9gkExE.js → ElectricLogo-DC3XSfIu.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-Ci69gBGl.js → FadeIn-H7S3TMHi.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-pb03c0kb.js → HeaderGithubStar-xgbIo5OP.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-Cqd0D789.js → HoverTooltip-CpzM5Dju.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-qILbvOJn.js → IpCheckPage-BdV7S4dY.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-CCIwaAeu.js → LandingPage-D9f28ryO.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardPage-BwzABmKU.js → LeaderboardPage--WUFpkBI.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProBadge-7kdzfw8r.js → LeaderboardProBadge-CEvrQ75Y.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfileModal-uMnN-IGe.js → LeaderboardProfileModal-Bn0HFr5h.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-CQNc4MES.js → LeaderboardProfilePage-DJ7fQI68.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-CJ1LImRm.js → LimitsPage-7tPDheuX.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-Dm0l_F0I.js → LocalOnlyNotice-DlGbVQS8.js} +1 -1
- package/dashboard/dist/assets/{LoginCard--tUiBVtr.js → LoginCard-BZZmzUGh.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-B1-5fFMY.js → LoginModal-BT5_bIxU.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-BYl6NnZ8.js → LoginPage-DMjDUPPi.js} +1 -1
- package/dashboard/dist/assets/{PetPage-DJNGJZrR.js → PetPage-Dk3j6ITn.js} +2 -2
- package/dashboard/dist/assets/{PopoverPopup-aRAdIkTs.js → PopoverPopup-pugRu3RC.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-uiA-KBe2.js → ProviderIcon-CtmL1CmY.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-BZT353_T.js → ResetPasswordPage-BB6U7t8P.js} +1 -1
- package/dashboard/dist/assets/{Select-CPC04j0g.js → Select-7w1su8lw.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-D1vJVrFO.js → SelectItemText-CaEUmWkj.js} +1 -1
- package/dashboard/dist/assets/{SelfHostPage-FL3EDqmb.js → SelfHostPage-DctWoF-A.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-BohSSNai.js → ServiceStatusPage-Dg3ljEXC.js} +1 -1
- package/dashboard/dist/assets/{SessionsPage-Cf_HASvt.js → SessionsPage-B1dvW-be.js} +1 -1
- package/dashboard/dist/assets/{SettingsPage-B4ztKHnj.js → SettingsPage-DuXSX1R2.js} +3 -3
- package/dashboard/dist/assets/{SkillsPage-BFiQkY7O.js → SkillsPage-CvXQFgc9.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-BHVdTJAP.js → TokenGalaxy-DKC8Rk_Y.js} +1 -1
- package/dashboard/dist/assets/{TooltipPopup-BMtQyFn6.js → TooltipPopup-Dp9EpHLG.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-DN-g3CNm.js → TrendMonitor-DWnlBn3H.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-Bv32yu8M.js → WidgetsPage-GECNmb1Q.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-HVTOehNb.js → WrappedPage-Dq_1lOnb.js} +1 -1
- package/dashboard/dist/assets/{__vite-browser-external-DnYJww7c.js → __vite-browser-external-CkF0pdTJ.js} +2 -2
- package/dashboard/dist/assets/{agent-logos-BOwAJQqL.js → agent-logos-Dqe3Vrah.js} +1 -1
- package/dashboard/dist/assets/{arrow-left-CeXuUuES.js → arrow-left-Cr_2QnDu.js} +1 -1
- package/dashboard/dist/assets/{arrow-right-DOdBG1FZ.js → arrow-right-BsK2sJgt.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-Dponssa4.js → arrow-up-right-DkWMGqXo.js} +1 -1
- package/dashboard/dist/assets/{calendar-days-CsxE6ot0.js → calendar-days-BB9VV438.js} +1 -1
- package/dashboard/dist/assets/{check-BroNG_vu.js → check-bpSCJZWh.js} +1 -1
- package/dashboard/dist/assets/{chevron-down-C5ZpGeO1.js → chevron-down-CtECtDmx.js} +1 -1
- package/dashboard/dist/assets/{cloud-checkout-BtS-hZTc.js → cloud-checkout-C4PrzKhN.js} +1 -1
- package/dashboard/dist/assets/{composite-fgJbx88k.js → composite-BHisG82k.js} +1 -1
- package/dashboard/dist/assets/{copy-CHBuwNUs.js → copy-Dmxzd-Sw.js} +1 -1
- package/dashboard/dist/assets/{download-EKd2MHkv.js → download-CkdQzw2w.js} +1 -1
- package/dashboard/dist/assets/{external-link-GkSo9C78.js → external-link-C971FjvC.js} +1 -1
- package/dashboard/dist/assets/{flame-Cg96qJrE.js → flame-mKbp7kxw.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-ChG2_n4h.js → format-tokens-C35FrJnH.js} +1 -1
- package/dashboard/dist/assets/{gift-B3QDbWPE.js → gift-BX2lSOmc.js} +1 -1
- package/dashboard/dist/assets/{icons-BEAyMjau.js → icons-ov92u52T.js} +1 -1
- package/dashboard/dist/assets/{index-B0kZThUB.js → index-9OCL-BL8.js} +1 -1
- package/dashboard/dist/assets/{index-DFcQyAnr.js → index-Bgm38oHe.js} +1 -1
- package/dashboard/dist/assets/{index-Cuc8ZXgl.js → index-Ca5xkNrK.js} +1 -1
- package/dashboard/dist/assets/{index-B9a1fK8I.js → index-DF03nIHb.js} +1 -1
- package/dashboard/dist/assets/{info-796bNttV.js → info-B-f9hWcw.js} +1 -1
- package/dashboard/dist/assets/{link-2-LYRIPLwz.js → link-2-l1wuezTo.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-DpKC9Uel.js → loader-circle-Lmjrs8XX.js} +1 -1
- package/dashboard/dist/assets/{local-usage-transfer-Ctbuc6U4.js → local-usage-transfer-Ds6cF41d.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-C5YTeNW1.js → modifiers.esm-tVlltJXO.js} +1 -1
- package/dashboard/dist/assets/{monitor-smartphone-DJUCfEvG.js → monitor-smartphone-XRiYiY8u.js} +1 -1
- package/dashboard/dist/assets/{play-LC-lnw6w.js → play-DaD9EMjk.js} +1 -1
- package/dashboard/dist/assets/{plus-CDF0S5xd.js → plus-D30fbsKQ.js} +1 -1
- package/dashboard/dist/assets/{provider-display-CkITUZgR.js → provider-display-CKdhBOwz.js} +1 -1
- package/dashboard/dist/assets/{react-BIpM-G7K.js → react-BY0y0K4x.js} +1 -1
- package/dashboard/dist/assets/{safePolygon-C3Ea423q.js → safePolygon-CSG_P7rG.js} +1 -1
- package/dashboard/dist/assets/{search-C-tN1mTM.js → search-Kiq8wVHA.js} +1 -1
- package/dashboard/dist/assets/{server-DJ4gq_fT.js → server-CjovGBGz.js} +1 -1
- package/dashboard/dist/assets/{shield-check-f75hry9N.js → shield-check-DF9MmMCq.js} +1 -1
- package/dashboard/dist/assets/{skills-api-CZ_vfnRL.js → skills-api-CEzr6p92.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-mLJSvq3M.js → sortable.esm-D7jd9mE_.js} +1 -1
- package/dashboard/dist/assets/{store-CZV1KXw2.js → store-D9_jo_do.js} +1 -1
- package/dashboard/dist/assets/{terminal-B9vOwCl9.js → terminal-CLOlvzR-.js} +1 -1
- package/dashboard/dist/assets/{trash-BN9GbynA.js → trash-DIe0fsDD.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-Bc2d8tqa.js → use-community-stats-gDkdiRBz.js} +1 -1
- package/dashboard/dist/assets/{use-latest-request-guard-_0H4Rk58.js → use-latest-request-guard-tXGuKvua.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-Dln-Rxps.js → use-limits-display-prefs-CCuLFy00.js} +1 -1
- package/dashboard/dist/assets/{use-native-settings-CpkcGzXp.js → use-native-settings-hgYqaiR7.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-DpGA5U4S.js → use-ordered-list-D6-YzYJI.js} +1 -1
- package/dashboard/dist/assets/use-reduced-motion-DfbDxs5a.js +1 -0
- package/dashboard/dist/assets/{use-transform-JXJt1W74.js → use-transform-BEiXvAuE.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-BK_H1-b7.js → use-usage-limits-BlwtyPtT.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-ilbtKs16.js → useCurrency-CwCGJLHb.js} +1 -1
- package/dashboard/dist/assets/{usePositioner-M35LtCGR.js → usePositioner-BqHtRIrE.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-BtTQjv7z.js → useTokenFormat-BUNBUX-x.js} +1 -1
- package/dashboard/dist/assets/{zap-5xemt9EH.js → zap-C0RFs2qQ.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/commands/sync.js +2 -2
- package/src/lib/limits-cache.js +475 -0
- package/src/lib/pricing/curated-overrides.json +24 -0
- package/src/lib/pricing/matcher.js +4 -1
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/rollout.js +261 -102
- package/src/lib/usage-limits.js +370 -1063
- package/dashboard/dist/assets/DialogDescription--_wg9JdV.js +0 -1
- package/dashboard/dist/assets/use-reduced-motion-Cy21hg3t.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{o as qe,r as i,j as e,y as $,Q as fs,U as bs,c as t,Z as Ue,X as Ge,i as S,aA as Ne,W as De,R as ys,V as we,aN as _s,bl as ee}from"./__vite-browser-external-DnYJww7c.js";import{L as ks,I as js}from"./LocalOnlyNotice-Dm0l_F0I.js";import{S as de}from"./Select-CPC04j0g.js";import{C as ws}from"./chevron-down-C5ZpGeO1.js";import{S as Ke}from"./search-C-tN1mTM.js";import{C as vs}from"./check-BroNG_vu.js";import{P as Ns,a as Ss,b as Cs,c as Ms,d as Ts}from"./PopoverPopup-aRAdIkTs.js";import{P as We}from"./ProviderIcon-uiA-KBe2.js";import{H as Ds}from"./HoverTooltip-Cqd0D789.js";import{u as Se}from"./useCurrency-ilbtKs16.js";import{i as Fs}from"./host-mode-Bc_iTzHk.js";import{I as Rs}from"./info-796bNttV.js";import{C as Is}from"./copy-CHBuwNUs.js";import{a as Ls,b as Os,c as Es,d as Ps,e as $s}from"./TooltipPopup-BMtQyFn6.js";import"./arrow-up-right-Dponssa4.js";import"./download-EKd2MHkv.js";import"./SelectItemText-D1vJVrFO.js";import"./composite-fgJbx88k.js";import"./usePositioner-M35LtCGR.js";import"./store-CZV1KXw2.js";import"./safePolygon-C3Ea423q.js";const Be={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"}]]};Be.node;const As=qe(Be);const He={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"}]]};He.node;const zs=qe(He),qs="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 Fe({options:a,value:s,onChange:r,allValue:o="all",allLabel:u,searchPlaceholder:h,emptyLabel:l,ariaLabel:f,disabled:_=!1,className:k=""}){const[j,w]=i.useState(!1),[g,x]=i.useState(""),[b,y]=i.useState(-1),R=i.useRef(null),v=`${i.useId()}-listbox`,q=s===o?u:a.find(p=>p.value===s)?.label??s,M=g.trim().toLowerCase(),D=i.useMemo(()=>M?a.filter(p=>p.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=p=>{r(p),w(!1),x(""),y(-1)};i.useEffect(()=>{j&&R.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[j,b]);const se=p=>{if(p.key==="ArrowDown"||p.key==="ArrowUp"){p.preventDefault();const T=p.key==="ArrowDown";y(L=>{const m=C.length;return m?T?L>=m-1?0:L+1:L<=0?m-1:L-1:-1});return}if(p.key==="Enter"){const T=O||(M&&D.length?D[0]:null);if(!T)return;p.preventDefault(),A(T.value)}};return e.jsxs(Ns,{open:j,onOpenChange:p=>{w(p),y(-1),p||x("")},children:[e.jsxs(Ss,{disabled:_,"aria-label":f,className:$("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",s!==o?"text-oai-black dark:text-white":"text-oai-gray-700 dark:text-oai-gray-200",k),children:[e.jsx(zs,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),e.jsx("span",{className:"truncate",children:q}),e.jsx(ws,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(Cs,{children:e.jsx(Ms,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(Ts,{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(Ke,{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":v,"aria-activedescendant":O?`${v}-${b}`:void 0,value:g,onChange:p=>{x(p.target.value),y(-1)},onKeyDown:se,placeholder:h,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:R,id:v,role:"listbox","aria-label":f,className:"max-h-64 overflow-y-auto",children:[C.map((p,T)=>e.jsxs("button",{id:`${v}-${T}`,type:"button",role:"option","aria-selected":s===p.value,"data-active":T===b?"true":void 0,onMouseEnter:()=>y(T),onClick:()=>A(p.value),className:$(qs,s===p.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:p.label}),s===p.value?e.jsx(vs,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},p.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:l}):null]})]})})})]})}const Us="tokentracker-sessions";async function Gs(a={}){const s=new URL(`/functions/${Us}`,window.location.origin);if(a.from&&s.searchParams.set("from",a.from),a.to&&s.searchParams.set("to",a.to),a.limit&&s.searchParams.set("limit",String(a.limit)),a.refresh&&s.searchParams.set("refresh","1"),a.includeBuckets===!1&&s.searchParams.set("include_buckets","0"),a.includeModelDetail===!1&&s.searchParams.set("include_model_detail","0"),a.from||a.to){const u=fs();u&&s.searchParams.set("tz",u),s.searchParams.set("tz_offset_minutes",String(bs()))}const r=await fetch(s.toString(),{headers:{Accept:"application/json"},cache:"no-store"}),o=await r.json().catch(()=>null);if(!r.ok){const u=r.status===404?t("sessions.error.outdated_app"):`Request failed with HTTP ${r.status}`,h=new Error(o?.error||u);throw h.status=r.status,h}return o}function Ve(a,s,{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(s||void 0,u)}catch{const h=new Date(o).toISOString();return r?h.slice(11,16):h.slice(0,16).replace("T"," ")}}function Qe(a){const s=Number(a);if(!Number.isFinite(s)||s<=0)return null;const r=Math.round(s/6e4);if(r<60)return t("sessions.duration.minutes",{minutes:r});const o=Math.floor(r/60),u=r%60;return t("sessions.duration.hours",{hours:o,minutes:u})}function V(a){return P(a?.own_total_tokens??a?.total_tokens)}function Ks(a,s=0,r=1/0){if(!s&&r===1/0)return a;const o=a.map(l=>{if(!Array.isArray(l.usage_buckets))return{...l};const f=l.usage_buckets.filter(g=>{const x=Date.parse(g.timestamp);return x>=s&&x<=r}),_=new Map,k=Object.fromEntries([...me,..._e].map(g=>[g,0]));let j=0,w=0;for(const g of f){j+=P(g.total_tokens),w+=P(g.cost_usd);const x=_.get(g.model)||{...(l.model_usage||[]).find(b=>b.model===g.model),model:g.model,...Object.fromEntries([...me,..._e].map(b=>[b,0])),cost_usd:0,selected_models:[],reroute_reasons:[],model_attribution:"selected"};for(const b of[...me,..._e]){const y=P(g[b]);k[b]+=y,x[b]+=y}x.cost_usd+=P(g.cost_usd);for(const b of["selected_models","reroute_reasons"])Array.isArray(g[b])&&(x[b]=[...new Set([...x[b],...g[b]])]);g.model_attribution==="effective"&&(x.model_attribution="effective"),_.set(g.model,x)}return{...l,...k,total_tokens:j,own_total_tokens:j,cost_usd:w,own_cost_usd:w,model_usage:[..._.values()]}}).filter(l=>!Array.isArray(l.usage_buckets)||V(l)>0),u=new Map;for(const l of o){if(!l.parent_session_hash)continue;const f=u.get(l.parent_session_hash)||[];f.push(l),u.set(l.parent_session_hash,f)}const h=(l,f=new Set)=>{if(f.has(l.session_hash))return{tokens:0,cost:0};const _=new Set(f).add(l.session_hash);let k=V(l),j=J(l);for(const w of u.get(l.session_hash)||[]){const g=h(w,_);k+=g.tokens,j+=g.cost}return{tokens:k,cost:j}};for(const l of o){const f=h(l);l.combined_total_tokens=f.tokens,l.combined_cost_usd=f.cost,l.subagent_total_tokens=f.tokens-V(l),l.subagent_cost_usd=f.cost-J(l)}return o}function J(a){return P(a?.own_cost_usd??a?.cost_usd)}function P(a){const s=Number(a);return Number.isFinite(s)&&s>=0?s:0}const me=["input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","total_tokens"],_e=["long_context_","priority_","priority_long_context_","ultrafast_","ultrafast_long_context_"].flatMap(a=>me.filter(s=>s!=="total_tokens").map(s=>a+s));function X(a){const s=Array.isArray(a?.model_usage)?a.model_usage.filter(r=>r&&typeof r.model=="string"&&r.model):[];return s.length?s:[{model:a?.model||"",total_tokens:V(a),cost_usd:J(a),performance:a?.performance}]}function Ws(a){const s={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=P(o.estimated_duration_ms),h=P(o.estimated_output_tokens),l=P(o.estimated_request_count);u>0&&h>0&&l>0&&(s.estimated_output_tokens+=h,s.estimated_duration_ms+=u,s.estimated_request_count+=l);const f=P(o.first_response_sample_count),_=P(o.first_response_total_ms);f>0&&_>0&&(s.first_response_total_ms+=_,s.first_response_sample_count+=f)}return s.estimated_duration_ms>0&&(s.estimated_tokens_per_second=s.estimated_output_tokens*1e3/s.estimated_duration_ms),s.first_response_sample_count>0&&(s.first_response_ms=s.first_response_total_ms/s.first_response_sample_count),s}function Ze(a){const s=new Set,r=a.filter(o=>s.has(o.session_hash)?!1:(s.add(o.session_hash),!0));return{count:r.length,tokens:r.reduce((o,u)=>o+V(u),0),cost:r.reduce((o,u)=>o+J(u),0),costIsPartial:r.some(o=>o.cost_is_partial),performance:Ws(r)}}function ve(a){const s=Date.parse(a?.ended_at||a?.started_at||"");return Number.isFinite(s)?s:0}function Bs(a,s){return[...a].sort((r,o)=>(s==="cost"?J(o)-J(r):s==="tokens"?V(o)-V(r):0)||ve(o)-ve(r))}function xe(a){const s=ve(a);if(!s)return"";const r=new Date(s);return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`}function Hs(a,s){const r=new Map;for(const o of a){const u=s==="project"?o.project_key||"":xe(o),h=r.get(u)||{key:u,sessions:[]};h.sessions.push(o),r.set(u,h)}return[...r.values()]}function Vs(a){const s=new URLSearchParams(a),r=s.get("source"),o=l=>{const f=s.get(l)||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(f))return"";const _=new Date(`${f}T00:00:00`);return Number.isFinite(_.getTime())&&xe({ended_at:_.toISOString()})===f?f:""},u=o("from"),h=o("to");return{source:["claude","codex","grok","zcode","opencode","kimi","omp","dsh"].includes(r)?r:"all",model:s.get("model")||"all",from:u,to:h}}function Qs(a,s,r){let o=s?new Date(`${s}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(`${s}T23:59:59.999`).getTime());const h=Date.parse(a.ended_at||a.started_at||""),l=Date.parse(a.started_at||a.ended_at||"");return(!Number.isFinite(h)||h>=o)&&(!Number.isFinite(l)||l<=u)}function oe({performance:a,className:s=""}){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:s,title:`${t("sessions.performance.samples",{count:o})}
|
|
1
|
+
import{o as qe,r as i,j as e,y as $,Q as fs,U as bs,c as t,Z as Ue,X as Ge,i as S,aA as Ne,W as De,R as ys,V as we,aN as _s,bl as ee}from"./__vite-browser-external-CkF0pdTJ.js";import{L as ks,I as js}from"./LocalOnlyNotice-DlGbVQS8.js";import{S as de}from"./Select-7w1su8lw.js";import{C as ws}from"./chevron-down-CtECtDmx.js";import{S as Ke}from"./search-Kiq8wVHA.js";import{C as vs}from"./check-bpSCJZWh.js";import{P as Ns,a as Ss,b as Cs,c as Ms,d as Ts}from"./PopoverPopup-pugRu3RC.js";import{P as We}from"./ProviderIcon-CtmL1CmY.js";import{H as Ds}from"./HoverTooltip-CpzM5Dju.js";import{u as Se}from"./useCurrency-CwCGJLHb.js";import{i as Fs}from"./host-mode-Bc_iTzHk.js";import{I as Rs}from"./info-B-f9hWcw.js";import{C as Is}from"./copy-Dmxzd-Sw.js";import{a as Ls,b as Os,c as Es,d as Ps,e as $s}from"./TooltipPopup-Dp9EpHLG.js";import"./arrow-up-right-DkWMGqXo.js";import"./download-CkdQzw2w.js";import"./SelectItemText-CaEUmWkj.js";import"./composite-BHisG82k.js";import"./usePositioner-BqHtRIrE.js";import"./store-D9_jo_do.js";import"./safePolygon-CSG_P7rG.js";const Be={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"}]]};Be.node;const As=qe(Be);const He={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"}]]};He.node;const zs=qe(He),qs="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 Fe({options:a,value:s,onChange:r,allValue:o="all",allLabel:u,searchPlaceholder:h,emptyLabel:l,ariaLabel:f,disabled:_=!1,className:k=""}){const[j,w]=i.useState(!1),[g,x]=i.useState(""),[b,y]=i.useState(-1),R=i.useRef(null),v=`${i.useId()}-listbox`,q=s===o?u:a.find(p=>p.value===s)?.label??s,M=g.trim().toLowerCase(),D=i.useMemo(()=>M?a.filter(p=>p.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=p=>{r(p),w(!1),x(""),y(-1)};i.useEffect(()=>{j&&R.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[j,b]);const se=p=>{if(p.key==="ArrowDown"||p.key==="ArrowUp"){p.preventDefault();const T=p.key==="ArrowDown";y(L=>{const m=C.length;return m?T?L>=m-1?0:L+1:L<=0?m-1:L-1:-1});return}if(p.key==="Enter"){const T=O||(M&&D.length?D[0]:null);if(!T)return;p.preventDefault(),A(T.value)}};return e.jsxs(Ns,{open:j,onOpenChange:p=>{w(p),y(-1),p||x("")},children:[e.jsxs(Ss,{disabled:_,"aria-label":f,className:$("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",s!==o?"text-oai-black dark:text-white":"text-oai-gray-700 dark:text-oai-gray-200",k),children:[e.jsx(zs,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0}),e.jsx("span",{className:"truncate",children:q}),e.jsx(ws,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(Cs,{children:e.jsx(Ms,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(Ts,{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(Ke,{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":v,"aria-activedescendant":O?`${v}-${b}`:void 0,value:g,onChange:p=>{x(p.target.value),y(-1)},onKeyDown:se,placeholder:h,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:R,id:v,role:"listbox","aria-label":f,className:"max-h-64 overflow-y-auto",children:[C.map((p,T)=>e.jsxs("button",{id:`${v}-${T}`,type:"button",role:"option","aria-selected":s===p.value,"data-active":T===b?"true":void 0,onMouseEnter:()=>y(T),onClick:()=>A(p.value),className:$(qs,s===p.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:p.label}),s===p.value?e.jsx(vs,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},p.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:l}):null]})]})})})]})}const Us="tokentracker-sessions";async function Gs(a={}){const s=new URL(`/functions/${Us}`,window.location.origin);if(a.from&&s.searchParams.set("from",a.from),a.to&&s.searchParams.set("to",a.to),a.limit&&s.searchParams.set("limit",String(a.limit)),a.refresh&&s.searchParams.set("refresh","1"),a.includeBuckets===!1&&s.searchParams.set("include_buckets","0"),a.includeModelDetail===!1&&s.searchParams.set("include_model_detail","0"),a.from||a.to){const u=fs();u&&s.searchParams.set("tz",u),s.searchParams.set("tz_offset_minutes",String(bs()))}const r=await fetch(s.toString(),{headers:{Accept:"application/json"},cache:"no-store"}),o=await r.json().catch(()=>null);if(!r.ok){const u=r.status===404?t("sessions.error.outdated_app"):`Request failed with HTTP ${r.status}`,h=new Error(o?.error||u);throw h.status=r.status,h}return o}function Ve(a,s,{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(s||void 0,u)}catch{const h=new Date(o).toISOString();return r?h.slice(11,16):h.slice(0,16).replace("T"," ")}}function Qe(a){const s=Number(a);if(!Number.isFinite(s)||s<=0)return null;const r=Math.round(s/6e4);if(r<60)return t("sessions.duration.minutes",{minutes:r});const o=Math.floor(r/60),u=r%60;return t("sessions.duration.hours",{hours:o,minutes:u})}function V(a){return P(a?.own_total_tokens??a?.total_tokens)}function Ks(a,s=0,r=1/0){if(!s&&r===1/0)return a;const o=a.map(l=>{if(!Array.isArray(l.usage_buckets))return{...l};const f=l.usage_buckets.filter(g=>{const x=Date.parse(g.timestamp);return x>=s&&x<=r}),_=new Map,k=Object.fromEntries([...me,..._e].map(g=>[g,0]));let j=0,w=0;for(const g of f){j+=P(g.total_tokens),w+=P(g.cost_usd);const x=_.get(g.model)||{...(l.model_usage||[]).find(b=>b.model===g.model),model:g.model,...Object.fromEntries([...me,..._e].map(b=>[b,0])),cost_usd:0,selected_models:[],reroute_reasons:[],model_attribution:"selected"};for(const b of[...me,..._e]){const y=P(g[b]);k[b]+=y,x[b]+=y}x.cost_usd+=P(g.cost_usd);for(const b of["selected_models","reroute_reasons"])Array.isArray(g[b])&&(x[b]=[...new Set([...x[b],...g[b]])]);g.model_attribution==="effective"&&(x.model_attribution="effective"),_.set(g.model,x)}return{...l,...k,total_tokens:j,own_total_tokens:j,cost_usd:w,own_cost_usd:w,model_usage:[..._.values()]}}).filter(l=>!Array.isArray(l.usage_buckets)||V(l)>0),u=new Map;for(const l of o){if(!l.parent_session_hash)continue;const f=u.get(l.parent_session_hash)||[];f.push(l),u.set(l.parent_session_hash,f)}const h=(l,f=new Set)=>{if(f.has(l.session_hash))return{tokens:0,cost:0};const _=new Set(f).add(l.session_hash);let k=V(l),j=J(l);for(const w of u.get(l.session_hash)||[]){const g=h(w,_);k+=g.tokens,j+=g.cost}return{tokens:k,cost:j}};for(const l of o){const f=h(l);l.combined_total_tokens=f.tokens,l.combined_cost_usd=f.cost,l.subagent_total_tokens=f.tokens-V(l),l.subagent_cost_usd=f.cost-J(l)}return o}function J(a){return P(a?.own_cost_usd??a?.cost_usd)}function P(a){const s=Number(a);return Number.isFinite(s)&&s>=0?s:0}const me=["input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","total_tokens"],_e=["long_context_","priority_","priority_long_context_","ultrafast_","ultrafast_long_context_"].flatMap(a=>me.filter(s=>s!=="total_tokens").map(s=>a+s));function X(a){const s=Array.isArray(a?.model_usage)?a.model_usage.filter(r=>r&&typeof r.model=="string"&&r.model):[];return s.length?s:[{model:a?.model||"",total_tokens:V(a),cost_usd:J(a),performance:a?.performance}]}function Ws(a){const s={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=P(o.estimated_duration_ms),h=P(o.estimated_output_tokens),l=P(o.estimated_request_count);u>0&&h>0&&l>0&&(s.estimated_output_tokens+=h,s.estimated_duration_ms+=u,s.estimated_request_count+=l);const f=P(o.first_response_sample_count),_=P(o.first_response_total_ms);f>0&&_>0&&(s.first_response_total_ms+=_,s.first_response_sample_count+=f)}return s.estimated_duration_ms>0&&(s.estimated_tokens_per_second=s.estimated_output_tokens*1e3/s.estimated_duration_ms),s.first_response_sample_count>0&&(s.first_response_ms=s.first_response_total_ms/s.first_response_sample_count),s}function Ze(a){const s=new Set,r=a.filter(o=>s.has(o.session_hash)?!1:(s.add(o.session_hash),!0));return{count:r.length,tokens:r.reduce((o,u)=>o+V(u),0),cost:r.reduce((o,u)=>o+J(u),0),costIsPartial:r.some(o=>o.cost_is_partial),performance:Ws(r)}}function ve(a){const s=Date.parse(a?.ended_at||a?.started_at||"");return Number.isFinite(s)?s:0}function Bs(a,s){return[...a].sort((r,o)=>(s==="cost"?J(o)-J(r):s==="tokens"?V(o)-V(r):0)||ve(o)-ve(r))}function xe(a){const s=ve(a);if(!s)return"";const r=new Date(s);return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`}function Hs(a,s){const r=new Map;for(const o of a){const u=s==="project"?o.project_key||"":xe(o),h=r.get(u)||{key:u,sessions:[]};h.sessions.push(o),r.set(u,h)}return[...r.values()]}function Vs(a){const s=new URLSearchParams(a),r=s.get("source"),o=l=>{const f=s.get(l)||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(f))return"";const _=new Date(`${f}T00:00:00`);return Number.isFinite(_.getTime())&&xe({ended_at:_.toISOString()})===f?f:""},u=o("from"),h=o("to");return{source:["claude","codex","grok","zcode","opencode","kimi","omp","dsh"].includes(r)?r:"all",model:s.get("model")||"all",from:u,to:h}}function Qs(a,s,r){let o=s?new Date(`${s}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(`${s}T23:59:59.999`).getTime());const h=Date.parse(a.ended_at||a.started_at||""),l=Date.parse(a.started_at||a.ended_at||"");return(!Number.isFinite(h)||h>=o)&&(!Number.isFinite(l)||l<=u)}function oe({performance:a,className:s=""}){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:s,title:`${t("sessions.performance.samples",{count:o})}
|
|
2
2
|
${t("sessions.performance.method")}`,children:t("sessions.performance.speed",{speed:Number(r.toFixed(1))})})}const Zs=[{key:"input_tokens",label:()=>t("dashboard.projects.detail.comp_input")},{key:"cached_input_tokens",label:()=>t("dashboard.projects.detail.comp_cached")},{key:"cache_creation_input_tokens",label:()=>t("dashboard.projects.detail.comp_cache_write")},{key:"output_tokens",label:()=>t("dashboard.projects.detail.comp_output")},{key:"reasoning_output_tokens",label:()=>t("dashboard.projects.detail.comp_reasoning")}],Ys=[{key:"turns",label:()=>t("sessions.col.turns")},{key:"edit_turns",label:()=>t("sessions.col.edits")},{key:"retry_turns",label:()=>t("sessions.detail.retries")},{key:"subagent_calls",label:()=>t("sessions.card.subagents")},{key:"tool_calls",grokOnly:!0,label:()=>t("sessions.detail.tools")},{key:"tool_failures",grokOnly:!0,label:()=>t("sessions.detail.tool_failures")},{key:"error_count",grokOnly:!0,label:()=>t("sessions.detail.errors")},{key:"model_calls",grokOnly:!0,label:()=>t("sessions.detail.model_calls")},{key:"compaction_count",grokOnly:!0,label:()=>t("sessions.detail.compactions")}];function Xs(a){return a==="provider_reported"?t("sessions.detail.cost_reported"):a==="model_pricing"?t("sessions.detail.cost_estimated"):a==="mixed"?t("sessions.detail.cost_mixed"):t("sessions.detail.cost_unknown")}function Re(a){return String(a||"").startsWith("litellm")?t("sessions.detail.pricing_litellm"):String(a||"").startsWith("curated")?t("sessions.detail.pricing_curated"):null}function Js(a,s){return s||Number(a)>0}function Ie({label:a,children:s}){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:s})]})}function ue({label:a,title:s,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:s,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 et({session:a,subagents:s=[],onClose:r}){const o=i.useRef(null),u=i.useRef(null),{currency:h,rate:l}=Se(),{resolvedLocale:f}=Ue(),_=m=>Ne(m,{currency:h,rate:l}),k=X(a),j=i.useMemo(()=>Ze(s),[s]),w=V(a),g=J(a),x=Number(a.subagent_total_tokens??j.tokens),b=Number(a.subagent_cost_usd??j.cost),y=a.performance,R=Number(y?.estimated_tokens_per_second)>0&&Number(y?.estimated_request_count)>0,v=Number(y?.first_response_sample_count)>0&&y?.first_response_ms!=null&&Number.isFinite(Number(y.first_response_ms)),q=v?{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 m=document.activeElement,E=document.body.style.overflow;document.body.style.overflow="hidden",o.current?.focus();const z=I=>{if(I.key==="Escape"&&(I.preventDefault(),r()),I.key!=="Tab")return;const K=Array.from(u.current?.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), summary, [tabindex="0"]')||[]),te=K[0],ae=K[K.length-1];te?I.shiftKey&&(document.activeElement===te||!u.current?.contains(document.activeElement))?(I.preventDefault(),ae.focus()):!I.shiftKey&&(document.activeElement===ae||!u.current?.contains(document.activeElement))&&(I.preventDefault(),te.focus()):(I.preventDefault(),u.current?.focus())};return window.addEventListener("keydown",z),()=>{window.removeEventListener("keydown",z),document.body.style.overflow=E,m instanceof HTMLElement&&m.isConnected&&m.focus()}},[r]);const O=x>0||b>0,A=a.cost_is_partial||O&&j.costIsPartial,se=[{label:t("sessions.detail.own"),tokens:w,cost:g,partial:a.cost_is_partial},{label:t("sessions.detail.subagents"),tokens:x,cost:b,partial:j.costIsPartial}],p=a.agent_nickname||a.title||a.project_key||t("sessions.project.unknown"),T=Qe(a.duration_ms),L=[a.project_key&&a.project_key!==p?a.project_key:null,Ve(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:m=>{m.target===m.currentTarget&&r()},children:e.jsxs("div",{ref:u,role:"dialog","aria-modal":"true","aria-label":t("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(We,{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:p}),e.jsx("p",{className:"mt-0.5 break-words text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:L.join(" · ")})]}),e.jsx("button",{ref:o,type:"button",onClick:r,"aria-label":t("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(Ge,{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":t("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(ue,{label:t("sessions.col.tokens"),children:S(w+x)}),e.jsx(ue,{label:t("sessions.col.cost"),className:"border-l",children:A&&g+b===0?t("dashboard.cost_breakdown.unpriced_label"):e.jsxs(e.Fragment,{children:[A?"≥":"",_(g+b)]})}),e.jsx(ue,{label:t("sessions.summary.speed"),className:"border-t",title:R?t("sessions.performance.samples",{count:y.estimated_request_count}):t("sessions.detail.no_speed"),children:R?e.jsx(oe,{performance:y}):"—"}),e.jsx(ue,{label:t("sessions.performance.first_response"),className:"border-l border-t",title:t("sessions.performance.first_response_method"),children:v?Number(y.first_response_sample_count)===1?t("sessions.performance.first_response_value_single",q):t("sessions.performance.first_response_value",q):"—"})]}),O?e.jsx("dl",{className:"mt-3 space-y-1.5",children:se.map(m=>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:m.label}),e.jsx("dd",{className:"text-right tabular-nums",children:S(m.tokens)}),e.jsx("dd",{className:"text-right tabular-nums",children:m.partial&&m.cost===0?t("dashboard.cost_breakdown.unpriced_label"):e.jsxs(e.Fragment,{children:[m.partial?"≥":"",_(m.cost)]})})]},m.label))}):null,e.jsxs("p",{className:"mt-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:[t("sessions.detail.cost_source")," · ",Xs(a.cost_source),a.cost_is_partial?e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[" · ",t("sessions.cost.partial_title")]}):null,a.usage_is_incomplete?e.jsxs("span",{className:"text-amber-700 dark:text-amber-300",children:[" · ",t("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:t("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:Zs.map(({key:m,label:E})=>e.jsx(Ie,{label:E(),children:a[m]==null?"—":S(a[m])},m))})]}),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:t("sessions.detail.models")}),e.jsx("span",{className:"text-right text-xs text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0,children:t("sessions.col.tokens")}),e.jsx("span",{className:"text-right text-xs text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0,children:t("sessions.col.cost")})]}),e.jsx("ul",{className:"mt-1 divide-y divide-oai-gray-100 dark:divide-oai-gray-800/70",children:k.map(m=>{const E=m.pricing?.status==="unpriced",z=a.cost_source==="provider_reported"&&k.length===1,I=z?g:m.cost_usd,K=Js(I,z);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:m.model||t("sessions.model.unknown")}),e.jsx("span",{className:"text-right tabular-nums",children:S(m.total_tokens)}),e.jsx("span",{className:"text-right tabular-nums",children:E&&!K?"—":_(I)})]}),m.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(oe,{performance:m.performance,className:"tabular-nums"}),e.jsx("span",{className:"underline decoration-dotted underline-offset-4 group-open:no-underline",children:t("sessions.detail.pricing_details")})]}),e.jsxs("div",{className:"space-y-1 pt-1.5 leading-5",children:[E?e.jsx("p",{children:t("sessions.detail.pricing_unpriced")}):null,m.pricing.status==="free"?e.jsx("p",{children:t("sessions.detail.pricing_free")}):null,m.pricing.status==="priced"?e.jsx("p",{children:t("sessions.detail.pricing_rates",{input:m.pricing.input,output:m.pricing.output,cacheRead:m.pricing.cache_read,cacheWrite:m.pricing.cache_write})}):null,Re(m.pricing.source)?e.jsx("p",{children:Re(m.pricing.source)}):null]})]}):e.jsx(oe,{performance:m.performance,className:"block pt-1 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400"})]},m.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:t("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:Ys.map(({key:m,label:E,grokOnly:z})=>e.jsx(Ie,{label:E(),children:typeof a[m]=="number"&&(!z||D)?S(a[m]):t("sessions.detail.not_recorded")},m))}),D&&a.usage_precision?e.jsx("p",{className:"pb-3 text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:t("sessions.grok.runtime_breakdown",{calls:S(a.model_calls),seconds:(Number(a.api_duration_ms||0)/1e3).toFixed(1),tools:S(a.tool_calls),errors:S(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:t("sessions.grok.context_breakdown",{used:S(a.context_tokens_used),window:S(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:t("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:t("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:t("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:t("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:[R?e.jsx("p",{children:t("sessions.performance.method")}):null,M?e.jsx("p",{children:t("sessions.detail.reasoning_note")}):null,e.jsx("p",{children:t("sessions.privacy")})]})]})]})})}const Le=Fs(),Oe=[],Ee=Object.freeze({}),ke=100,st=[{id:"all",label:()=>t("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:()=>t("leaderboard.column.kimi")},{id:"omp",label:()=>"oh-my-pi"},{id:"dsh",label:()=>t("provider.display.deepseek_harness")}],Ye=[{id:"all",days:0,label:()=>t("sessions.filter.range_label_all")},{id:"7d",days:7,label:()=>t("sessions.filter.range_7d")},{id:"30d",days:30,label:()=>t("sessions.filter.range_30d")},{id:"90d",days:90,label:()=>t("sessions.filter.range_90d")}];function je(a){const s=Ye.find(o=>o.id===a)?.days||0;if(!s)return 0;const r=new Date;return r.setDate(r.getDate()-(s-1)),r.setHours(0,0,0,0),r.getTime()}function Pe(a){const s=new Date(a),r=String(s.getMonth()+1).padStart(2,"0"),o=String(s.getDate()).padStart(2,"0");return`${s.getFullYear()}-${r}-${o}`}function tt(a,s){if(!s)return!0;const r=Date.parse(a.ended_at||a.started_at||"");return Number.isFinite(r)?r>=s:!0}function at(a){const s=Date.parse(a.started_at||"");return!Number.isFinite(s)||xe({started_at:a.started_at})===xe(a)}function $e(a){const s=X(a);return s.length===1?s[0].model||t("sessions.model.unknown"):s.map(r=>`${r.model} ${S(Number(r.total_tokens||0))}`).join(" · ")}async function Ae(a){if(navigator?.clipboard?.writeText)return await navigator.clipboard.writeText(a),!0;const s=document.createElement("textarea");s.value=a,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s),s.select();const r=document.execCommand("copy");return document.body.removeChild(s),r}function rt(){const[a,s]=i.useState(!1),r=i.useId();return e.jsxs(Ls,{open:a,onOpenChange:s,children:[e.jsx(Os,{delay:150,closeDelay:100,closeOnClick:!1,onClick:()=>s(!0),"aria-label":t("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(Rs,{className:"h-3.5 w-3.5","aria-hidden":!0})}),e.jsx(Es,{children:e.jsx(Ps,{side:"bottom",align:"end",sideOffset:12,className:"z-[60]",children:e.jsx($s,{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:t("sessions.summary.scope")})})})]})}function F({className:a}){return e.jsx("span",{className:$("block rounded bg-oai-gray-200/70 animate-pulse dark:bg-oai-gray-800/70",a),"aria-hidden":"true"})}function ot({index:a}){const s=["w-44","w-32","w-52","w-36","w-48","w-40"],r=["w-24","w-32","w-20"];return e.jsxs("li",{className:"sessions-row sessions-row-grid py-3","aria-hidden":"true",children:[e.jsxs("div",{className:"sessions-row-identity min-w-0",children:[e.jsx(F,{className:"h-4 w-4 rounded-full"}),e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsx(F,{className:$("h-4",s[a%s.length])}),e.jsx("div",{className:"flex min-w-0 flex-wrap gap-2",children:r.map((o,u)=>e.jsx(F,{className:$("h-3",o)},u))})]})]}),e.jsxs("dl",{className:"sessions-row-metrics",children:[e.jsx("div",{className:"sessions-row-value",children:e.jsx(F,{className:"ml-auto h-4 w-14"})}),e.jsx("div",{className:"sessions-row-value",children:e.jsx(F,{className:"ml-auto h-4 w-12"})}),e.jsx("div",{className:"sessions-row-value",children:e.jsx(F,{className:"ml-auto h-4 w-16"})})]}),e.jsx(F,{className:"sessions-row-action h-8 w-8 rounded-md"})]})}function nt({rows:a=6}){return e.jsxs("div",{"data-testid":"sessions-skeleton",role:"status","aria-busy":"true","aria-live":"polite",children:[e.jsx("span",{className:"sr-only",children:t("sessions.loading")}),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","aria-hidden":"true",children:e.jsx("dl",{className:"sessions-kpis grid min-w-0 flex-1 grid-cols-2 gap-y-3 sm:grid-cols-4",children:Array.from({length:4},(s,r)=>e.jsxs("div",{children:[e.jsx(F,{className:"h-3 w-16"}),e.jsx(F,{className:$("mt-2 h-6",r===2?"w-20":"w-14")})]},r))})}),e.jsxs("div",{className:"sessions-row-grid sessions-list-header border-b border-oai-gray-200 py-2 dark:border-oai-gray-800","aria-hidden":"true",children:[e.jsx(F,{className:"h-3 w-16"}),e.jsx(F,{className:"ml-auto h-3 w-10"}),e.jsx(F,{className:"ml-auto h-3 w-9"}),e.jsx(F,{className:"ml-auto h-3 w-10"}),e.jsx("span",{})]}),e.jsxs("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800","aria-hidden":"true",children:[e.jsx("li",{className:"pb-2 pt-5",children:e.jsx(F,{className:"h-3 w-24"})}),Array.from({length:a},(s,r)=>e.jsx(ot,{index:r},r))]})]})}const ze=we.memo(function({session:s,locale:r,nested:o=!1,timeOnly:u=!1,childCount:h=0,expanded:l=!1,onToggle:f,onDetail:_}){const{currency:k,rate:j}=Se(),w=String(s.source||"").toUpperCase(),g=Qe(s.duration_ms),x=s.resume_command,b=s.project_key||t("sessions.project.unknown"),y=o||s.thread_kind==="subagent",R=y?s.agent_nickname||s.agent_role||s.title||b:s.title||b,v=s.usage_is_incomplete?t("sessions.badge.partial_usage"):s.cost_is_partial?t("sessions.badge.partial_cost"):null,q=s.project_ref?`${s.project_ref}
|
|
3
3
|
${t("sessions.project.copy_hint")}`:void 0,M=async()=>{if(s.project_ref)try{await Ae(s.project_ref)?ee({title:t("sessions.project.copied")}):ee({title:t("sessions.project.copy_failed")})}catch{ee({title:t("sessions.project.copy_failed")})}},D=O=>e.jsxs("span",{className:"group relative inline-flex min-w-0 max-w-full",children:[e.jsx(Ds,{text:q,placement:"bottom"}),e.jsx("button",{type:"button",onClick:M,"aria-label":t("sessions.project.copy_aria",{project:b}),className:$("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(x)try{await Ae(x)?ee({title:t("sessions.resume.copied")}):ee({title:t("sessions.resume.copy_failed")})}catch{ee({title:t("sessions.resume.copy_failed")})}};return e.jsxs("li",{className:$("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(We,{provider:w,size:o?16:18})}),e.jsxs("div",{className:"contents",children:[e.jsx("button",{type:"button",onClick:()=>_(s),"aria-label":t("sessions.detail.open_aria",{title:R}),title:R,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:R}),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:s.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:$e(s),children:$e(s)}),e.jsx("span",{className:"sessions-meta-item tabular-nums",children:Ve(s.started_at,r,{timeOnly:u&&at(s)})}),g?e.jsx("span",{className:"sessions-meta-item tabular-nums",children:g}):null,Number.isFinite(s.session_store_bytes)?e.jsx("span",{className:"sessions-meta-item tabular-nums",title:t("sessions.storage.tooltip",{metric:t(s.session_store_metric==="allocated"?"sessions.storage.allocated":"sessions.storage.logical"),ratio:Math.round(s.bytes_per_1k_tokens||0).toLocaleString(r)}),children:t("sessions.storage.label",{size:t("sessions.storage.size",{value:(s.session_store_bytes/1024/1024).toLocaleString(r,{maximumFractionDigits:2})})})}):null,y?e.jsxs("span",{className:"sessions-meta-item",children:[t("sessions.badge.subagent"),s.agent_role?` · ${s.agent_role}`:""]}):null,s.first_pass?e.jsx("span",{className:"sessions-meta-item text-emerald-700 dark:text-emerald-300",children:t("sessions.badge.first_pass")}):null,v?e.jsx("span",{className:"sessions-meta-item text-amber-700 dark:text-amber-300",children:v}):null,s.cost_source==="provider_reported"?e.jsx("span",{className:"sessions-meta-item",children:t("sessions.badge.reported_cost")}):null,h?e.jsxs("button",{type:"button",onClick:()=>f(s.session_hash),"aria-expanded":l,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(_s,{className:$("h-3.5 w-3.5 transition-transform",l&&"rotate-90"),"aria-hidden":!0}),l?t("sessions.thread.collapse",{count:h}):t("sessions.thread.expand",{count:h})]}):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:t("sessions.col.tokens")}),e.jsxs("dd",{title:Number(s.subagent_total_tokens)?t("sessions.thread.tokens_summary",{own:S(s.own_total_tokens),subagents:S(s.subagent_total_tokens),combined:S(s.combined_total_tokens)}):void 0,className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",children:[S(s.total_tokens),Number(s.subagent_total_tokens)?e.jsxs("span",{className:"mt-0.5 block text-xs text-oai-gray-500 dark:text-oai-gray-400",children:["Σ ",S(s.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:t("sessions.col.cost")}),e.jsx("dd",{className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",title:s.cost_is_partial?t("sessions.cost.partial_title"):void 0,children:s.cost_is_partial&&Number(s.cost_usd)===0?t("dashboard.cost_breakdown.unpriced_label"):e.jsxs(e.Fragment,{children:[s.cost_is_partial?"≥":"",Ne(s.cost_usd,{currency:k,rate:j})]})})]}),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:t("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(oe,{performance:s.performance})})]})]}),e.jsx("button",{type:"button",onClick:C,disabled:!x,title:x||t("sessions.resume.unavailable"),"aria-label":x?t("sessions.resume.copy_aria",{command:x}):t("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(Is,{className:"h-4 w-4","aria-hidden":!0})})]})});function it({sessions:a,selectedModel:s,onSelect:r}){const{groups:o,totalTokens:u}=i.useMemo(()=>{const l=new Map;let f=0;for(const _ of a)for(const k of X(_)){const j=k.model||t("sessions.model.unknown"),w=Number(k.total_tokens||0),g=l.get(j)||{model:j,count:0,tokens:0};g.count+=1,g.tokens+=w,f+=w,l.set(j,g)}return{groups:[...l.values()].sort((_,k)=>k.tokens-_.tokens),totalTokens:f}},[a]);function h(l){return $("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",l?"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:t("sessions.thread.model_usage")}),e.jsx("button",{type:"button","aria-pressed":s==="all",onClick:()=>r("all"),className:h(s==="all"),children:t("sessions.thread.model_all",{count:a.length,tokens:S(u)})}),o.map(l=>e.jsx("button",{type:"button","aria-pressed":s===l.model,onClick:()=>r(l.model),className:h(s===l.model),children:t("sessions.thread.model_item",{model:l.model,count:l.count,tokens:S(l.tokens)})},l.model))]})})}function Tt(){const[a]=i.useState(()=>Vs(window.location.search)),[s,r]=i.useState(null),[o,u]=i.useState(null),[h,l]=i.useState(!0),[f,_]=i.useState(!1),[k,j]=i.useState(a.source),[w,g]=i.useState(a.model),[x,b]=i.useState(a.from||a.to?"custom":"all"),[y,R]=i.useState(a.from),[v,q]=i.useState(a.to),[M,D]=i.useState("all"),[C,O]=i.useState("time"),[A,se]=i.useState("recent"),[p,T]=i.useState(null),[L,m]=i.useState(""),[E,z]=i.useState(ke),[I,K]=i.useState(()=>new Set),[te,ae]=i.useState(()=>new Map),ne=i.useRef(0),ie=i.useRef(null),Q=i.useRef({projects:[],models:[]}),{resolvedLocale:Z}=Ue(),{currency:Xe,rate:Je}=Se(),[Ce,es]=i.useState(0);i.useEffect(()=>{const n=new Date;n.setHours(24,0,0,250);const c=setTimeout(()=>es(d=>d+1),Math.max(1e3,n.getTime()-Date.now()));return()=>clearTimeout(c)},[Ce]);const Me=i.useMemo(()=>{if(x==="custom"){let c=y,d=v;return c&&d&&c>d&&([c,d]=[d,c]),!c&&!d?Ee:{...c?{from:c}:{},...d?{to:d}:{}}}const n=je(x);return n?{from:Pe(n),to:Pe(Date.now())}:Ee},[x,y,v,Ce]),le=i.useCallback(async(n=!1)=>{const c=++ne.current;n||ie.current?_(!0):l(!0),u(null);try{const d=await Gs({refresh:n,includeBuckets:!1,includeModelDetail:!1,...Me});c===ne.current&&(ie.current=d,r(d),u(null))}catch(d){if(c!==ne.current)return;const N=d?.message||String(d);u(N),ie.current&&(ie.current=null,r(null))}finally{c===ne.current&&(l(!1),_(!1))}},[Me]);i.useEffect(()=>{Le||De()?le(!1):l(!1)},[le]);const U=s?.sessions||Oe,ss=i.useMemo(()=>{if(Number.isFinite(Number(s?.lifetime_session_count))){const c=Number(s.lifetime_session_count);return Q.current.count=c,c}const n=Math.max(U.length,Q.current.count||0);return Q.current.count=n,n},[s,U]),ts=i.useMemo(()=>{if(Array.isArray(s?.facets?.projects))return s.facets.projects.map(c=>({value:c,label:c}));const n=new Set(Q.current.projects);for(const c of U){const d=c.project_key;d&&n.add(d)}return Q.current.projects=[...n],[...n].sort((c,d)=>c.localeCompare(d)).map(c=>({value:c,label:c}))},[s,U]),as=i.useMemo(()=>{if(Array.isArray(s?.facets?.models))return s.facets.models.map(c=>({value:c,label:c}));const n=new Set(Q.current.models);for(const c of U)for(const d of X(c))d.model&&n.add(d.model);return Q.current.models=[...n],[...n].sort().map(c=>({value:c,label:c}))},[s,U]),he=i.useDeferredValue(L),ce=i.useMemo(()=>{let c=je(x),d=1/0;return x==="custom"&&(c=y?new Date(`${y}T00:00:00`).getTime():0,d=v?new Date(`${v}T23:59:59.999`).getTime():1/0,c>d&&(c=new Date(`${v}T00:00:00`).getTime(),d=new Date(`${y}T23:59:59.999`).getTime())),Ks(U,c,d)},[U,x,y,v]),W=i.useMemo(()=>{const n=he.trim().toLowerCase(),c=je(x);return ce.filter(d=>{if(k!=="all"&&d.source!==k||M!=="all"&&d.project_key!==M||w!=="all"&&!X(d).some(H=>H.model===w))return!1;if(x==="custom"){if(!Qs(d,y,v))return!1}else if(!tt(d,c))return!1;if(!n)return!0;const N=X(d).map(H=>H.model).join(" ");return`${d.title||""} ${d.project_key||""} ${N} ${d.agent_nickname||""} ${d.agent_role||""} ${d.project_ref||""} ${d.session_id||""}`.toLowerCase().includes(n)})},[ce,k,M,w,x,y,v,he]),B=i.useMemo(()=>Ze(W),[W]),Y=i.useMemo(()=>{const n=new Set(W.map(N=>N.session_hash)),c=new Map,d=[];for(const N of Bs(W,A)){const G=N.root_session_hash||N.parent_session_hash;if(N.parent_session_hash&&G&&n.has(G)){const H=c.get(G)||[];H.push(N),c.set(G,H)}else d.push(N)}return{roots:d,childrenByRoot:c,foldedCount:W.length-d.length}},[W,A]),ge=k!=="all"||w!=="all"||x!=="all"||M!=="all"||L.trim()!=="";i.useEffect(()=>{z(ke),K(new Set),ae(new Map)},[k,M,w,x,y,v,he,A,C,U]);const pe=i.useMemo(()=>Y.roots.slice(0,E),[Y.roots,E]),rs=i.useMemo(()=>Hs(pe,C),[pe,C]),os=i.useMemo(()=>p?ce.filter(n=>n.session_hash!==p.session_hash&&(n.root_session_hash===p.session_hash||n.parent_session_hash===p.session_hash)):Oe,[ce,p]),ns=i.useCallback(()=>T(null),[]),fe=i.useCallback(n=>{b(n),n!=="custom"&&(R(""),q(""))},[]),is=i.useCallback(()=>{j("all"),g("all"),D("all"),m(""),fe("all")},[fe]),be=Y.roots.length>pe.length,ye=i.useCallback(()=>z(n=>n+ke),[]),ls=i.useCallback(n=>{K(c=>{const d=new Set(c);return d.has(n)?d.delete(n):d.add(n),d})},[]),cs=i.useCallback((n,c)=>{ae(d=>{const N=new Map(d);return c==="all"?N.delete(n):N.set(n,c),N})},[]),Te=i.useRef(null);i.useEffect(()=>{if(!be||typeof IntersectionObserver>"u")return;const n=Te.current;if(!n)return;const c=new IntersectionObserver(d=>{d.some(N=>N.isIntersecting)&&ye()},{rootMargin:"400px"});return c.observe(n),()=>c.disconnect()},[be,ye]);const ds=i.useMemo(()=>st.map(n=>({value:n.id,label:n.label()})),[Z]),us=i.useMemo(()=>[...Ye.map(n=>({value:n.id,label:n.label()})),{value:"custom",label:t("sessions.filter.range_custom")}],[Z]),ms=i.useMemo(()=>[{value:"time",label:t("sessions.group.time")},{value:"project",label:t("sessions.group.project")}],[Z]),xs=i.useMemo(()=>[{value:"recent",label:t("sessions.sort.recent")},{value:"cost",label:t("sessions.sort.cost")},{value:"tokens",label:t("sessions.sort.tokens")}],[Z]),hs=Number(s?.session_count)>Number(s?.returned_count);return!Le&&!De()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(ks,{})}):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:t("nav.sessions")}),e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:t("sessions.page.summary")})]}),e.jsx("button",{type:"button",onClick:()=>{le(!0)},disabled:f||h,"aria-label":t("sessions.page.refresh"),title:t("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(ys,{className:$("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(Ke,{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(js,{type:"search",value:L,onChange:n=>m(n.target.value),onKeyDown:n=>{n.key==="Escape"&&L&&(n.preventDefault(),m(""))},"aria-label":t("sessions.action.search_aria"),placeholder:t("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"}),L?e.jsx("button",{type:"button",onMouseDown:n=>n.preventDefault(),onClick:()=>m(""),"aria-label":t("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(Ge,{className:"h-4 w-4","aria-hidden":!0})}):null]}),e.jsx(de,{ariaLabel:t("sessions.filter.source_aria"),options:ds,value:k,onValueChange:j,className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(de,{ariaLabel:t("sessions.filter.range_aria"),options:us,value:x,onValueChange:fe,leadingIcon:e.jsx(As,{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(Fe,{options:ts,value:M,onChange:D,allLabel:t("sessions.filter.project_all"),searchPlaceholder:t("sessions.filter.project_search"),emptyLabel:t("sessions.filter.project_empty"),ariaLabel:t("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(Fe,{options:as,value:w,onChange:g,allLabel:t("sessions.filter.model_all"),searchPlaceholder:t("sessions.filter.model_search"),emptyLabel:t("sessions.filter.model_empty"),ariaLabel:t("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"})]}),x==="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:t("sessions.filter.from")}),e.jsx("input",{type:"date","aria-label":t("sessions.filter.from"),value:y,onChange:n=>R(n.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:t("sessions.filter.to")}),e.jsx("input",{type:"date","aria-label":t("sessions.filter.to"),value:v,onChange:n=>q(n.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]}),!h&&s?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:t("sessions.summary.count")}),e.jsx("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:S(B.count)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("sessions.col.tokens")}),e.jsx("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:S(B.tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("sessions.col.cost")}),e.jsx("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:B.costIsPartial&&B.cost===0?t("dashboard.cost_breakdown.unpriced_label"):e.jsxs(e.Fragment,{children:[B.costIsPartial?"≥":"",Ne(B.cost,{currency:Xe,rate:Je})]})})]}),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:t("sessions.summary.speed")}),e.jsx(rt,{})]}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[e.jsx(oe,{performance:B.performance}),B.performance.estimated_tokens_per_second==null?"—":null]})]})]})}):null,!h&&s?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:Y.foldedCount>0?t("sessions.thread.result_count",{roots:Y.roots.length,subagents:Y.foldedCount}):t("sessions.filter.result_count",{filtered:W.length,total:ss})}),ge?e.jsx("button",{type:"button",onClick:is,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:t("sessions.filter.clear")}):null]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(de,{ariaLabel:t("sessions.group.aria"),options:ms,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(de,{ariaLabel:t("sessions.sort.aria"),options:xs,value:A,onValueChange:se,className:"sessions-filter-trigger h-11 min-w-0 max-w-44 px-2.5 text-xs sm:h-8",align:"end"})]})]}):null,!h&&hs?e.jsx("p",{className:"mb-4 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t("sessions.truncated",{shown:s.returned_count,total:s.session_count})}):null,o&&!s?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:t("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:()=>{le(!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:t("sessions.error.retry")})]}):h?e.jsx(nt,{}):W.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:ge?t("sessions.empty.filtered_title"):t("sessions.empty.title")}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:ge?t("sessions.empty.filtered_body"):t("sessions.empty.body")})]}):e.jsxs(e.Fragment,{children:[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:t("sessions.col.session")}),e.jsx("span",{className:"text-right",children:t("sessions.col.tokens")}),e.jsx("span",{className:"text-right",children:t("sessions.col.cost")}),e.jsx("span",{className:"text-right",children:t("sessions.col.speed")}),e.jsx("span",{className:"sr-only",children:t("sessions.col.actions")})]}),e.jsx("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:rs.map(n=>e.jsxs(we.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"?n.key||t("sessions.project.unknown"):n.key?new Date(`${n.key}T12:00:00`).toLocaleDateString(Z||void 0,{year:"numeric",month:"short",day:"numeric"}):t("sessions.group.unknown_date")})}),n.sessions.map(c=>{const d=Y.childrenByRoot.get(c.session_hash)||[],N=I.has(c.session_hash),G=te.get(c.session_hash)||"all",H=G==="all"?d:d.filter(function(gs){return X(gs).some(ps=>ps.model===G)});return e.jsxs(we.Fragment,{children:[e.jsx(ze,{session:c,locale:Z,timeOnly:C==="time",childCount:d.length,expanded:N,onToggle:ls,onDetail:T}),N&&d.length?e.jsx(it,{sessions:d,selectedModel:G,onSelect:re=>cs(c.session_hash,re)}):null,N?H.map(re=>e.jsx(ze,{session:re,locale:Z,nested:!0,timeOnly:C==="time",onDetail:T},re.session_hash)):null]},c.session_hash)})]},n.key))}),be?e.jsx("div",{ref:Te,className:"flex justify-center pt-6",children:e.jsx("button",{type:"button",onClick:ye,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:t("sessions.action.load_more")})}):null]}),h?null:e.jsx("p",{className:"mt-8 max-w-3xl text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:t("sessions.privacy")})]})}),p?e.jsx(et,{session:p,subagents:os,onClose:ns}):null]})}export{Tt as SessionsPage};
|