tokentracker-cli 1.2.1 → 1.2.2
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-DPlXNqoK.js → AchievementBadge-B67_Cp1T.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-B49wjdK_.js → AchievementsPage-DNJ5n0Bn.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-DoYMz2Rr.js → AchievementsSection-BDqKRGyL.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-DUCS6K1n.js → BadgeDetailModal-DFL1MPcg.js} +1 -1
- package/dashboard/dist/assets/{BotAnimated-C21PdYSf.js → BotAnimated-OQbsVw1O.js} +1 -1
- package/dashboard/dist/assets/{Card-BU2CqxfU.js → Card-dqzakOoX.js} +1 -1
- package/dashboard/dist/assets/{CommandPalette-O3pOLyJo.js → CommandPalette-8B38qUs0.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-Bt82neQ7.js → CommunityStatsModal-DnbCiGms.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-zUljpLNe.js → ConfirmModal-Dhu_qmiM.js} +1 -1
- package/dashboard/dist/assets/{Controls-D56v-YJw.js → Controls-BgQflA-3.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-CKEuFzuc.js → DashboardPage-DeLRhWU_.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-CCIyAYH3.js → DevicePage-Bvz7JJwt.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-C-QK97qp.js → DialogClose-DUxjaRqf.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-h6XMtzIU.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-6q0jyME6.js → DialogTitle-C8vpXqg8.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-BUm1z22V.js → FadeIn-DDF5PqTX.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-CxdmloMy.js → HeaderGithubStar-CNzQFPol.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-CrMdGYZj.js → HoverTooltip-BKg9Z6gg.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-w6UUK_1K.js → IpCheckPage-BTdrLt08.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-DLDE7wdR.js → LandingPage-cjoagPAb.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardAvatar-BqD4dEvQ.js → LeaderboardAvatar-CJdG51hR.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardPage-kgHSryiT.js → LeaderboardPage-D-yf2rOQ.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProfileModal-zLdeOiA3.js → LeaderboardProfileModal--hrfpUPF.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-Fljho5RP.js → LeaderboardProfilePage-CoqcDSTw.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-Do_uJqdQ.js → LimitsPage-3RuSFnn-.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-RIj2XT_X.js → LocalOnlyNotice-D-OrIXty.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-Dx6MmGjU.js → LoginCard-BiMyV2Uf.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-BWaZVRnT.js → LoginModal-D79CMZmf.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-BNkU-riS.js → LoginPage-BLyGuPlG.js} +1 -1
- package/dashboard/dist/assets/{PetPage-CyEgU2Vm.js → PetPage-Bv0K4k2t.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-CmUIY8lF.js → PopoverPopup-3eucO8QU.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-BSI-1Cy8.js → ProviderIcon-BTYVbUti.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-CUXKkLb4.js → ResetPasswordPage-VYMl84_-.js} +1 -1
- package/dashboard/dist/assets/{Select-B6CM0ico.js → Select-D8N2TJz1.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-CZ7puxuB.js → SelectItemText-CoTR0Uwm.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-B4lIs2fc.js → ServiceStatusPage-Cb3k_C4g.js} +1 -1
- package/dashboard/dist/assets/{SessionsPage-D99UfBgy.js → SessionsPage-BtH5iLbi.js} +3 -3
- package/dashboard/dist/assets/{SettingsPage-DT3rld91.js → SettingsPage-huGkex5G.js} +2 -2
- package/dashboard/dist/assets/{SkillsPage-Dv47kVCB.js → SkillsPage-B9usVOTU.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-Bk3kGSGi.js → TokenGalaxy-BGRF4I_8.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-mB1x3c_o.js → TrendMonitor-B8SKBsWO.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-BhUArowe.js → WidgetsPage-o_91L3Zi.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-DHRmP4Ey.js → WrappedPage-BqyB7ezg.js} +1 -1
- package/dashboard/dist/assets/{__vite-browser-external-BW1rxvYq.js → __vite-browser-external-Cj9D7QBh.js} +2 -2
- package/dashboard/dist/assets/{agent-logos-D7f7AMF-.js → agent-logos-CEcgxIBU.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-c39fdiDQ.js → arrow-up-right-CdzAw406.js} +1 -1
- package/dashboard/dist/assets/{check-8LQ7IvkH.js → check-DhEiHlwq.js} +1 -1
- package/dashboard/dist/assets/{composite-BgLSXWKA.js → composite-DO7_ilHE.js} +1 -1
- package/dashboard/dist/assets/{download-x3Gmv-wu.js → download-kGPw24XQ.js} +1 -1
- package/dashboard/dist/assets/{external-link-daw-XTjZ.js → external-link-SOFbVRrH.js} +1 -1
- package/dashboard/dist/assets/{flame-B9o0_EF8.js → flame-BRdc7HDz.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-o9atQGtV.js → format-tokens-DhIeweGK.js} +1 -1
- package/dashboard/dist/assets/{host-mode-GPY2DxE4.js → host-mode-APftzzvz.js} +1 -1
- package/dashboard/dist/assets/{icons-CmM2z-Jt.js → icons-D-wu8eUg.js} +1 -1
- package/dashboard/dist/assets/{index-Bfgblk6o.js → index-CZ3D1Q7c.js} +1 -1
- package/dashboard/dist/assets/{index-CtQOew7C.js → index-CiWf_0mc.js} +1 -1
- package/dashboard/dist/assets/{index-CPcJP0uH.js → index-D2g1tPGl.js} +1 -1
- package/dashboard/dist/assets/{info-BaK8Hoi2.js → info-Qgc5VctK.js} +1 -1
- package/dashboard/dist/assets/{link-2-CV3uvMH3.js → link-2-Cg6bEvjQ.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-DYpa-xTZ.js → loader-circle-Cd7h4LcE.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-Ds4Uh7JO.js → modifiers.esm-B7hOvflM.js} +1 -1
- package/dashboard/dist/assets/{monitor-smartphone-BbeYHvY-.js → monitor-smartphone-wFv5VQQf.js} +1 -1
- package/dashboard/dist/assets/{plus-C9qGVLFv.js → plus-0xHQei42.js} +1 -1
- package/dashboard/dist/assets/{provider-display-BWYNyitK.js → provider-display-DNqVkqfp.js} +1 -1
- package/dashboard/dist/assets/{react-CO1HovF5.js → react-CfB5zBqR.js} +1 -1
- package/dashboard/dist/assets/{search-DBnhkzG_.js → search-DMtc6bBy.js} +1 -1
- package/dashboard/dist/assets/{skills-api-BSkbxC8-.js → skills-api-BeN184fz.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-SVl6OixH.js → sortable.esm-O7ntEYCi.js} +1 -1
- package/dashboard/dist/assets/{store-DrEEdO_u.js → store-D-FZbBaC.js} +1 -1
- package/dashboard/dist/assets/{terminal-kUMdPZhq.js → terminal-Y3qDL50U.js} +1 -1
- package/dashboard/dist/assets/{trash-Dd_vbrYo.js → trash-D_PaPrXq.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-Bmlmv4H-.js → use-community-stats-DGTBo_4v.js} +1 -1
- package/dashboard/dist/assets/{use-latest-request-guard-CqZwzrCW.js → use-latest-request-guard-BpfCferm.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-CDC0MZRY.js → use-limits-display-prefs-Drs82lSi.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-DvBI7mUU.js → use-ordered-list-CClTBWi0.js} +1 -1
- package/dashboard/dist/assets/{use-pet-settings-C_FrqySO.js → use-pet-settings-DvaQ7XrL.js} +2 -2
- package/dashboard/dist/assets/use-reduced-motion-Dg10dVuu.js +1 -0
- package/dashboard/dist/assets/{use-session-efficiency-pref-D8cAb4A9.js → use-session-efficiency-pref-BiYRXVlN.js} +1 -1
- package/dashboard/dist/assets/{use-transform-uSKYTYaW.js → use-transform-CA5mW4u8.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-DFgOKTtv.js → use-usage-limits-B0uafB4O.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-t1iy_pC3.js → useCurrency-CaOhUMcm.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-0bPjtaaM.js → useTokenFormat-JjQCKdIr.js} +1 -1
- package/dashboard/dist/assets/{zap-DFM6AsYo.js → zap-Cqur2X5s.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-COXweCuc.js +0 -1
- package/dashboard/dist/assets/use-reduced-motion-BEOENqBa.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{q as Te,r as n,j as e,e as B,c as s,J as Le,X as Fe,l as _,ac as be,H as ke,R as cs,d as pe,aB as ds,ak as Z}from"./__vite-browser-external-
|
|
2
|
-
${s("sessions.performance.method")}`,children:s("sessions.performance.speed",{speed:Number(r.toFixed(1))})})}const Ts=[{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")}],Ls=[{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 Fs(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 ve(a){return String(a||"").startsWith("litellm")?s("sessions.detail.pricing_litellm"):String(a||"").startsWith("curated")?s("sessions.detail.pricing_curated"):null}function Rs(a,t){return t||Number(a)>0}function we({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 ie({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 Os({session:a,subagents:t=[],onClose:r}){const o=n.useRef(null),d=n.useRef(null),{currency:g,rate:m}=ye(),{resolvedLocale:b}=Le(),y=l=>be(l,{currency:g,rate:m}),j=V(a),v=n.useMemo(()=>Ge(t),[t]),w=te(a),N=ae(a),f=Number(a.subagent_total_tokens??v.tokens),k=Number(a.subagent_cost_usd??v.cost),p=a.performance,L=Number(p?.estimated_tokens_per_second)>0&&Number(p?.estimated_request_count)>0,C=Number(p?.first_response_sample_count)>0&&p?.first_response_ms!=null&&Number.isFinite(Number(p.first_response_ms)),P=C?{seconds:(Number(p.first_response_ms)/1e3).toFixed(2),count:p.first_response_sample_count}:null,M=Number(a.reasoning_output_tokens)>0,T=a.source==="grok",S=T&&Number(a.context_window_tokens)>0;n.useEffect(()=>{const l=document.activeElement,E=document.body.style.overflow;document.body.style.overflow="hidden",o.current?.focus();const I=F=>{if(F.key==="Escape"&&(F.preventDefault(),r()),F.key!=="Tab")return;const K=Array.from(d.current?.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), summary, [tabindex="0"]')||[]),X=K[0],Y=K[K.length-1];X?F.shiftKey&&(document.activeElement===X||!d.current?.contains(document.activeElement))?(F.preventDefault(),Y.focus()):!F.shiftKey&&(document.activeElement===Y||!d.current?.contains(document.activeElement))&&(F.preventDefault(),X.focus()):(F.preventDefault(),d.current?.focus())};return window.addEventListener("keydown",I),()=>{window.removeEventListener("keydown",I),document.body.style.overflow=E,l instanceof HTMLElement&&l.isConnected&&l.focus()}},[r]);const O=f>0||k>0,A=a.cost_is_partial||O&&v.costIsPartial,J=[{label:s("sessions.detail.own"),tokens:w,cost:N,partial:a.cost_is_partial},{label:s("sessions.detail.subagents"),tokens:f,cost:k,partial:v.costIsPartial}],u=a.agent_nickname||a.title||a.project_key||s("sessions.project.unknown"),D=ze(a.duration_ms),R=[a.project_key&&a.project_key!==u?a.project_key:null,Ue(a.started_at,b),D].filter(Boolean);return e.jsx("div",{className:"fixed inset-0 z-50 flex justify-end bg-black/20 dark:bg-black/40",onClick:l=>{l.target===l.currentTarget&&r()},children:e.jsxs("div",{ref:d,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("header",{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(Ae,{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:u}),e.jsx("p",{className:"mt-0.5 break-words text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:R.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(Fe,{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(ie,{label:s("sessions.col.tokens"),children:_(w+f)}),e.jsxs(ie,{label:s("sessions.col.cost"),className:"border-l",children:[A?"≥":"",y(N+k)]}),e.jsx(ie,{label:s("sessions.summary.speed"),className:"border-t",title:L?s("sessions.performance.samples",{count:p.estimated_request_count}):s("sessions.detail.no_speed"),children:L?e.jsx(se,{performance:p}):"—"}),e.jsx(ie,{label:s("sessions.performance.first_response"),className:"border-l border-t",title:s("sessions.performance.first_response_method"),children:C?Number(p.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(l=>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:l.label}),e.jsx("dd",{className:"text-right tabular-nums",children:_(l.tokens)}),e.jsxs("dd",{className:"text-right tabular-nums",children:[l.partial?"≥":"",y(l.cost)]})]},l.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")," · ",Fs(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:Ts.map(({key:l,label:E})=>e.jsx(we,{label:E(),children:a[l]==null?"—":_(a[l])},l))})]}),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(l=>{const E=l.pricing?.status==="unpriced",I=a.cost_source==="provider_reported"&&j.length===1,F=I?N:l.cost_usd,K=Rs(F,I);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:l.model||s("sessions.model.unknown")}),e.jsx("span",{className:"text-right tabular-nums",children:_(l.total_tokens)}),e.jsx("span",{className:"text-right tabular-nums",children:E&&!K?"—":y(F)})]}),l.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(se,{performance:l.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:[E?e.jsx("p",{children:s("sessions.detail.pricing_unpriced")}):null,l.pricing.status==="free"?e.jsx("p",{children:s("sessions.detail.pricing_free")}):null,l.pricing.status==="priced"?e.jsx("p",{children:s("sessions.detail.pricing_rates",{input:l.pricing.input,output:l.pricing.output,cacheRead:l.pricing.cache_read,cacheWrite:l.pricing.cache_write})}):null,ve(l.pricing.source)?e.jsx("p",{children:ve(l.pricing.source)}):null]})]}):e.jsx(se,{performance:l.performance,className:"block pt-1 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400"})]},l.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:Ls.map(({key:l,label:E,grokOnly:I})=>e.jsx(we,{label:E(),children:typeof a[l]=="number"&&(!I||T)?_(a[l]):s("sessions.detail.not_recorded")},l))}),T&&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:_(a.model_calls),seconds:(Number(a.api_duration_ms||0)/1e3).toFixed(1),tools:_(a.tool_calls),errors:_(a.error_count)})}):null,S?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:_(a.context_tokens_used),window:_(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 Ne=ps(),Se=[],he=100,Es=[{id:"all",label:()=>s("usage.filter.source_all")},{id:"claude",label:()=>"Claude Code"},{id:"codex",label:()=>"Codex"},{id:"grok",label:()=>"Grok"}],He=[{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 Is(a){const t=He.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 $s(a,t){if(!t)return!0;const r=Date.parse(a.ended_at||a.started_at||"");return Number.isFinite(r)?r>=t:!0}function Ps(a){const t=Date.parse(a.started_at||"");return!Number.isFinite(t)||le({started_at:a.started_at})===le(a)}function Ce(a){const t=V(a);return t.length===1?t[0].model||s("sessions.model.unknown"):t.map(r=>`${r.model} ${_(Number(r.total_tokens||0))}`).join(" · ")}async function Me(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}const De=pe.memo(function({session:t,locale:r,nested:o=!1,timeOnly:d=!1,childCount:g=0,expanded:m=!1,onToggle:b,onDetail:y}){const{currency:j,rate:v}=ye(),w=String(t.source||"").toUpperCase(),N=ze(t.duration_ms),f=t.resume_command,k=t.project_key||s("sessions.project.unknown"),p=o||t.thread_kind==="subagent",L=p?t.agent_nickname||t.agent_role||t.title||k:t.title||k,C=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
|
-
${s("sessions.project.copy_hint")}`:void 0,M=async()=>{if(t.project_ref)try{await Me(t.project_ref)?Z({title:s("sessions.project.copied")}):Z({title:s("sessions.project.copy_failed")})}catch{Z({title:s("sessions.project.copy_failed")})}},T=O=>e.jsxs("span",{className:"group relative inline-flex min-w-0 max-w-full",children:[e.jsx(hs,{text:P,placement:"bottom"}),e.jsx("button",{type:"button",onClick:M,"aria-label":s("sessions.project.copy_aria",{project:k}),className:B("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:k})]}),S=async()=>{if(f)try{await Me(f)?Z({title:s("sessions.resume.copied")}):Z({title:s("sessions.resume.copy_failed")})}catch{Z({title:s("sessions.resume.copy_failed")})}};return e.jsxs("li",{className:B("sessions-row sessions-row-grid py-3",o&&"sessions-row-nested"),children:[e.jsxs("div",{className:"sessions-row-identity flex min-w-0 items-start gap-3",children:[e.jsx("span",{className:"shrink-0 pt-2 text-oai-gray-600 dark:text-oai-gray-300 md:pt-0.5",children:e.jsx(Ae,{provider:w,size:o?16:18})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("button",{type:"button",onClick:()=>y(t),"aria-label":s("sessions.detail.open_aria",{title:L}),title:L,className:"min-h-9 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-0",children:L}),e.jsxs("div",{className:"sessions-row-meta mt-0.5 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?T("min-h-6 inline-flex items-center md:min-h-0"):e.jsx("span",{className:"truncate",children:k})}),e.jsx("span",{className:"sessions-meta-item min-w-0 max-w-full truncate",title:Ce(t),children:Ce(t)}),e.jsx("span",{className:"sessions-meta-item tabular-nums",children:Ue(t.started_at,r,{timeOnly:d&&Ps(t)})}),N?e.jsx("span",{className:"sessions-meta-item tabular-nums",children:N}):null,p?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,C?e.jsx("span",{className:"sessions-meta-item text-amber-700 dark:text-amber-300",children:C}):null,t.cost_source==="provider_reported"?e.jsx("span",{className:"sessions-meta-item",children:s("sessions.badge.reported_cost")}):null,g?e.jsxs("button",{type:"button",onClick:()=>b(t.session_hash),"aria-expanded":m,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(ds,{className:B("h-3.5 w-3.5 transition-transform",m&&"rotate-90"),"aria-hidden":!0}),m?s("sessions.thread.collapse",{count:g}):s("sessions.thread.expand",{count:g})]}):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:_(t.own_total_tokens),subagents:_(t.subagent_total_tokens),combined:_(t.combined_total_tokens)}):void 0,className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",children:[_(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:["Σ ",_(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?"≥":"",be(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(se,{performance:t.performance})})]})]}),e.jsx("button",{type:"button",onClick:S,disabled:!f,title:f||s("sessions.resume.unavailable"),"aria-label":f?s("sessions.resume.copy_aria",{command:f}):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(fs,{className:"h-4 w-4","aria-hidden":!0})})]})});function As({sessions:a,selectedModel:t,onSelect:r}){const{groups:o,totalTokens:d}=n.useMemo(()=>{const m=new Map;let b=0;for(const y of a)for(const j of V(y)){const v=j.model||s("sessions.model.unknown"),w=Number(j.total_tokens||0),N=m.get(v)||{model:v,count:0,tokens:0};N.count+=1,N.tokens+=w,b+=w,m.set(v,N)}return{groups:[...m.values()].sort((y,j)=>j.tokens-y.tokens),totalTokens:b}},[a]);function g(m){return B("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",m?"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:g(t==="all"),children:s("sessions.thread.model_all",{count:a.length,tokens:_(d)})}),o.map(m=>e.jsx("button",{type:"button","aria-pressed":t===m.model,onClick:()=>r(m.model),className:g(t===m.model),children:s("sessions.thread.model_item",{model:m.model,count:m.count,tokens:_(m.tokens)})},m.model))]})})}function at(){const[a]=n.useState(()=>Ms(window.location.search)),[t,r]=n.useState(null),[o,d]=n.useState(null),[g,m]=n.useState(!0),[b,y]=n.useState(!1),[j,v]=n.useState(a.source),[w,N]=n.useState(a.model),[f,k]=n.useState(a.from||a.to?"custom":"all"),[p,L]=n.useState(a.from),[C,P]=n.useState(a.to),[M,T]=n.useState("all"),[S,O]=n.useState("time"),[A,J]=n.useState("recent"),[u,D]=n.useState(null),[R,l]=n.useState(""),[E,I]=n.useState(he),[F,K]=n.useState(()=>new Set),[X,Y]=n.useState(()=>new Map),re=n.useRef(0),{resolvedLocale:G}=Le(),{currency:We,rate:Ve}=ye(),oe=n.useCallback(async(i=!1)=>{const x=++re.current;i?y(!0):m(!0),d(null);try{const c=await ws({refresh:i});x===re.current&&r(c)}catch(c){x===re.current&&d(c?.message||String(c))}finally{x===re.current&&(m(!1),y(!1))}},[]);n.useEffect(()=>{Ne||ke()?oe(!1):m(!1)},[oe]);const $=t?.sessions||Se,Be=n.useMemo(()=>{const i=new Set,x=[];for(const c of $){const h=c.project_key;!h||i.has(h)||(i.add(h),x.push({value:h,label:h}))}return x.sort((c,h)=>c.label.localeCompare(h.label))},[$]),Qe=n.useMemo(()=>{const i=new Set;for(const x of $)for(const c of V(x))c.model&&i.add(c.model);return[...i].sort().map(x=>({value:x,label:x}))},[$]),ce=n.useDeferredValue(R),U=n.useMemo(()=>{const i=ce.trim().toLowerCase(),x=Is(f);return $.filter(c=>{if(j!=="all"&&c.source!==j||M!=="all"&&c.project_key!==M||w!=="all"&&!V(c).some(z=>z.model===w))return!1;if(f==="custom"){if(!Ds(c,p,C))return!1}else if(!$s(c,x))return!1;if(!i)return!0;const h=V(c).map(z=>z.model).join(" ");return`${c.title||""} ${c.project_key||""} ${h} ${c.agent_nickname||""} ${c.agent_role||""} ${c.project_ref||""} ${c.session_id||""}`.toLowerCase().includes(i)})},[$,j,M,w,f,p,C,ce]),Q=n.useMemo(()=>Ge(U),[U]),H=n.useMemo(()=>{const i=new Set(U.map(h=>h.session_hash)),x=new Map,c=[];for(const h of Ss(U,A)){const q=h.root_session_hash||h.parent_session_hash;if(h.parent_session_hash&&q&&i.has(q)){const z=x.get(q)||[];z.push(h),x.set(q,z)}else c.push(h)}return{roots:c,childrenByRoot:x,foldedCount:U.length-c.length}},[U,A]),de=j!=="all"||w!=="all"||f!=="all"||M!=="all"||R.trim()!=="";n.useEffect(()=>{I(he),K(new Set),Y(new Map)},[j,M,w,f,p,C,ce,A,S,$]);const ue=n.useMemo(()=>H.roots.slice(0,E),[H.roots,E]),Ze=n.useMemo(()=>Cs(ue,S),[ue,S]),Je=n.useMemo(()=>u?$.filter(i=>i.session_hash!==u.session_hash&&(i.root_session_hash===u.session_hash||i.parent_session_hash===u.session_hash)):Se,[$,u]),Xe=n.useCallback(()=>D(null),[]),me=n.useCallback(i=>{k(i),i!=="custom"&&(L(""),P(""))},[]),Ye=n.useCallback(()=>{v("all"),N("all"),T("all"),l(""),me("all")},[me]),xe=H.roots.length>ue.length,ge=n.useCallback(()=>I(i=>i+he),[]),es=n.useCallback(i=>{K(x=>{const c=new Set(x);return c.has(i)?c.delete(i):c.add(i),c})},[]),ss=n.useCallback((i,x)=>{Y(c=>{const h=new Map(c);return x==="all"?h.delete(i):h.set(i,x),h})},[]),_e=n.useRef(null);n.useEffect(()=>{if(!xe||typeof IntersectionObserver>"u")return;const i=_e.current;if(!i)return;const x=new IntersectionObserver(c=>{c.some(h=>h.isIntersecting)&&ge()},{rootMargin:"400px"});return x.observe(i),()=>x.disconnect()},[xe,ge]);const ts=n.useMemo(()=>Es.map(i=>({value:i.id,label:i.label()})),[G]),as=n.useMemo(()=>[...He.map(i=>({value:i.id,label:i.label()})),{value:"custom",label:s("sessions.filter.range_custom")}],[G]),rs=n.useMemo(()=>[{value:"time",label:s("sessions.group.time")},{value:"project",label:s("sessions.group.project")}],[G]),os=n.useMemo(()=>[{value:"recent",label:s("sessions.sort.recent")},{value:"cost",label:s("sessions.sort.cost")},{value:"tokens",label:s("sessions.sort.tokens")}],[G]),ns=Number(t?.session_count)>Number(t?.returned_count);return!Ne&&!ke()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(us,{})}):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("header",{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:b||g,"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(cs,{className:B("h-4 w-4",b&&"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(Re,{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(ms,{type:"search",value:R,onChange:i=>l(i.target.value),onKeyDown:i=>{i.key==="Escape"&&R&&(i.preventDefault(),l(""))},"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"}),R?e.jsx("button",{type:"button",onMouseDown:i=>i.preventDefault(),onClick:()=>l(""),"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(Fe,{className:"h-4 w-4","aria-hidden":!0})}):null]}),e.jsx(ne,{ariaLabel:s("sessions.filter.source_aria"),options:ts,value:j,onValueChange:v,className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(ne,{ariaLabel:s("sessions.filter.range_aria"),options:as,value:f,onValueChange:me,leadingIcon:e.jsx(_s,{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(je,{options:Be,value:M,onChange:T,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(je,{options:Qe,value:w,onChange:N,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"})]}),f==="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:p,onChange:i=>L(i.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:C,onChange:i=>P(i.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]}),!g&&t?e.jsxs("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:_(Q.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:_(Q.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:[Q.costIsPartial?"≥":"",be(Q.cost,{currency:We,rate:Ve})]})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.summary.speed")}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[e.jsx(se,{performance:Q.performance}),Q.performance.estimated_tokens_per_second==null?"—":null]})]})]}),e.jsxs(Oe,{children:[e.jsx(Ee,{"aria-label":s("sessions.summary.scope_help"),className:"-mr-2 flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-oai-gray-500 hover:bg-oai-gray-100 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 sm:h-8 sm:w-8",children:e.jsx(bs,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx(Ie,{children:e.jsx($e,{side:"bottom",align:"end",sideOffset:8,className:"z-[60]",children:e.jsx(Pe,{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")})})})]})]}):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:H.foldedCount>0?s("sessions.thread.result_count",{roots:H.roots.length,subagents:H.foldedCount}):s("sessions.filter.result_count",{filtered:U.length,total:$.length})}),de?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(ne,{ariaLabel:s("sessions.group.aria"),options:rs,value:S,onValueChange:O,className:"sessions-filter-trigger h-11 min-w-0 max-w-40 px-2.5 text-xs sm:h-8"}),e.jsx(ne,{ariaLabel:s("sessions.sort.aria"),options:os,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"})]})]}),ns?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")})]}):g?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(ys,{className:"h-4 w-4 animate-spin","aria-hidden":!0}),s("sessions.loading")]}):U.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:de?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:de?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:Ze.map(i=>e.jsxs(pe.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:S==="project"?i.key||s("sessions.project.unknown"):i.key?new Date(`${i.key}T12:00:00`).toLocaleDateString(G||void 0,{year:"numeric",month:"short",day:"numeric"}):s("sessions.group.unknown_date")})}),i.sessions.map(x=>{const c=H.childrenByRoot.get(x.session_hash)||[],h=F.has(x.session_hash),q=X.get(x.session_hash)||"all",z=q==="all"?c:c.filter(function(is){return V(is).some(ls=>ls.model===q)});return e.jsxs(pe.Fragment,{children:[e.jsx(De,{session:x,locale:G,timeOnly:S==="time",childCount:c.length,expanded:h,onToggle:es,onDetail:D}),h&&c.length?e.jsx(As,{sessions:c,selectedModel:q,onSelect:ee=>ss(x.session_hash,ee)}):null,h?z.map(ee=>e.jsx(De,{session:ee,locale:G,nested:!0,timeOnly:S==="time",onDetail:D},ee.session_hash)):null]},x.session_hash)})]},i.key))}),xe?e.jsx("div",{ref:_e,className:"flex justify-center pt-6",children:e.jsx("button",{type:"button",onClick:ge,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")})]})}),u?e.jsx(Os,{session:u,subagents:Je,onClose:Xe}):null]})}export{at as SessionsPage};
|
|
1
|
+
import{q as Te,r as n,j as e,e as B,c as s,J as Le,X as Fe,l as _,ac as be,H as ke,R as cs,d as pe,aB as ds,ak as Z}from"./__vite-browser-external-Cj9D7QBh.js";import{L as us,I as ms}from"./LocalOnlyNotice-D-OrIXty.js";import{S as ne}from"./Select-D8N2TJz1.js";import{C as xs}from"./SelectItemText-CoTR0Uwm.js";import{S as Re}from"./search-DMtc6bBy.js";import{C as gs}from"./check-DhEiHlwq.js";import{P as Oe,a as Ee,b as Ie,c as $e,d as Pe}from"./PopoverPopup-3eucO8QU.js";import{P as Ae}from"./ProviderIcon-BTYVbUti.js";import{H as hs}from"./HoverTooltip-BKg9Z6gg.js";import{u as ye}from"./useCurrency-CaOhUMcm.js";import{i as ps,C as fs}from"./host-mode-APftzzvz.js";import{I as bs}from"./info-Qgc5VctK.js";import{L as ys}from"./loader-circle-Cd7h4LcE.js";import"./arrow-up-right-CdzAw406.js";import"./download-kGPw24XQ.js";import"./composite-DO7_ilHE.js";import"./store-D-FZbBaC.js";const qe={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"}]]};qe.node;const _s=Te(qe);const Ke={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"}]]};Ke.node;const ks=Te(Ke),js="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 je({options:a,value:t,onChange:r,allValue:o="all",allLabel:d,searchPlaceholder:g,emptyLabel:m,ariaLabel:b,disabled:y=!1,className:j=""}){const[v,w]=n.useState(!1),[N,f]=n.useState(""),[k,p]=n.useState(-1),L=n.useRef(null),C=`${n.useId()}-listbox`,P=t===o?d:a.find(u=>u.value===t)?.label??t,M=N.trim().toLowerCase(),T=n.useMemo(()=>M?a.filter(u=>u.label.toLowerCase().includes(M)):a,[a,M]),S=n.useMemo(()=>[{value:o,label:d},...T],[o,d,T]),O=k>=0&&k<S.length?S[k]:null,A=u=>{r(u),w(!1),f(""),p(-1)};n.useEffect(()=>{v&&L.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[v,k]);const J=u=>{if(u.key==="ArrowDown"||u.key==="ArrowUp"){u.preventDefault();const D=u.key==="ArrowDown";p(R=>{const l=S.length;return l?D?R>=l-1?0:R+1:R<=0?l-1:R-1:-1});return}if(u.key==="Enter"){const D=O||(M&&T.length?T[0]:null);if(!D)return;u.preventDefault(),A(D.value)}};return e.jsxs(Oe,{open:v,onOpenChange:u=>{w(u),p(-1),u||f("")},children:[e.jsxs(Ee,{disabled:y,"aria-label":b,className:B("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(ks,{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(xs,{className:"h-3.5 w-3.5 shrink-0 text-oai-gray-400","aria-hidden":!0})]}),e.jsx(Ie,{children:e.jsx($e,{sideOffset:4,side:"bottom",align:"start",className:"z-[60]",children:e.jsxs(Pe,{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(Re,{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":C,"aria-activedescendant":O?`${C}-${k}`:void 0,value:N,onChange:u=>{f(u.target.value),p(-1)},onKeyDown:J,placeholder:g,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:C,role:"listbox","aria-label":b,className:"max-h-64 overflow-y-auto",children:[S.map((u,D)=>e.jsxs("button",{id:`${C}-${D}`,type:"button",role:"option","aria-selected":t===u.value,"data-active":D===k?"true":void 0,onMouseEnter:()=>p(D),onClick:()=>A(u.value),className:B(js,t===u.value&&"bg-oai-gray-100 dark:bg-oai-gray-800",D===k&&"ring-1 ring-inset ring-oai-gray-300 dark:ring-oai-gray-600"),children:[e.jsx("span",{className:"flex-1 truncate",children:u.label}),t===u.value?e.jsx(gs,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null]},u.value)),T.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-oai-gray-400 dark:text-oai-gray-500",children:m}):null]})]})})})]})}const vs="tokentracker-sessions";async function ws(a={}){const t=new URL(`/functions/${vs}`,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 d=r.status===404?s("sessions.error.outdated_app"):`Request failed with HTTP ${r.status}`,g=new Error(o?.error||d);throw g.status=r.status,g}return o}function Ue(a,t,{timeOnly:r=!1}={}){if(!a)return"—";const o=Date.parse(a);if(!Number.isFinite(o))return"—";const d=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,d)}catch{const g=new Date(o).toISOString();return r?g.slice(11,16):g.slice(0,16).replace("T"," ")}}function ze(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),d=r%60;return s("sessions.duration.hours",{hours:o,minutes:d})}function te(a){return W(a?.own_total_tokens??a?.total_tokens)}function ae(a){return W(a?.own_cost_usd??a?.cost_usd)}function W(a){const t=Number(a);return Number.isFinite(t)&&t>=0?t:0}function V(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:te(a),cost_usd:ae(a),performance:a?.performance}]}function Ns(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 d=W(o.estimated_duration_ms),g=W(o.estimated_output_tokens),m=W(o.estimated_request_count);d>0&&g>0&&m>0&&(t.estimated_output_tokens+=g,t.estimated_duration_ms+=d,t.estimated_request_count+=m);const b=W(o.first_response_sample_count),y=W(o.first_response_total_ms);b>0&&y>0&&(t.first_response_total_ms+=y,t.first_response_sample_count+=b)}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 Ge(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,d)=>o+te(d),0),cost:r.reduce((o,d)=>o+ae(d),0),costIsPartial:r.some(o=>o.cost_is_partial),performance:Ns(r)}}function fe(a){const t=Date.parse(a?.ended_at||a?.started_at||"");return Number.isFinite(t)?t:0}function Ss(a,t){return[...a].sort((r,o)=>(t==="cost"?ae(o)-ae(r):t==="tokens"?te(o)-te(r):0)||fe(o)-fe(r))}function le(a){const t=fe(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 Cs(a,t){const r=new Map;for(const o of a){const d=t==="project"?o.project_key||"":le(o),g=r.get(d)||{key:d,sessions:[]};g.sessions.push(o),r.set(d,g)}return[...r.values()]}function Ms(a){const t=new URLSearchParams(a),r=t.get("source"),o=m=>{const b=t.get(m)||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(b))return"";const y=new Date(`${b}T00:00:00`);return Number.isFinite(y.getTime())&&le({ended_at:y.toISOString()})===b?b:""},d=o("from"),g=o("to");return{source:["claude","codex","grok"].includes(r)?r:"all",model:t.get("model")||"all",from:d,to:g}}function Ds(a,t,r){let o=t?new Date(`${t}T00:00:00`).getTime():0,d=r?new Date(`${r}T23:59:59.999`).getTime():1/0;o>d&&(o=new Date(`${r}T00:00:00`).getTime(),d=new Date(`${t}T23:59:59.999`).getTime());const g=Date.parse(a.ended_at||a.started_at||""),m=Date.parse(a.started_at||a.ended_at||"");return(!Number.isFinite(g)||g>=o)&&(!Number.isFinite(m)||m<=d)}function se({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
|
+
${s("sessions.performance.method")}`,children:s("sessions.performance.speed",{speed:Number(r.toFixed(1))})})}const Ts=[{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")}],Ls=[{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 Fs(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 ve(a){return String(a||"").startsWith("litellm")?s("sessions.detail.pricing_litellm"):String(a||"").startsWith("curated")?s("sessions.detail.pricing_curated"):null}function Rs(a,t){return t||Number(a)>0}function we({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 ie({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 Os({session:a,subagents:t=[],onClose:r}){const o=n.useRef(null),d=n.useRef(null),{currency:g,rate:m}=ye(),{resolvedLocale:b}=Le(),y=l=>be(l,{currency:g,rate:m}),j=V(a),v=n.useMemo(()=>Ge(t),[t]),w=te(a),N=ae(a),f=Number(a.subagent_total_tokens??v.tokens),k=Number(a.subagent_cost_usd??v.cost),p=a.performance,L=Number(p?.estimated_tokens_per_second)>0&&Number(p?.estimated_request_count)>0,C=Number(p?.first_response_sample_count)>0&&p?.first_response_ms!=null&&Number.isFinite(Number(p.first_response_ms)),P=C?{seconds:(Number(p.first_response_ms)/1e3).toFixed(2),count:p.first_response_sample_count}:null,M=Number(a.reasoning_output_tokens)>0,T=a.source==="grok",S=T&&Number(a.context_window_tokens)>0;n.useEffect(()=>{const l=document.activeElement,E=document.body.style.overflow;document.body.style.overflow="hidden",o.current?.focus();const I=F=>{if(F.key==="Escape"&&(F.preventDefault(),r()),F.key!=="Tab")return;const K=Array.from(d.current?.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), summary, [tabindex="0"]')||[]),X=K[0],Y=K[K.length-1];X?F.shiftKey&&(document.activeElement===X||!d.current?.contains(document.activeElement))?(F.preventDefault(),Y.focus()):!F.shiftKey&&(document.activeElement===Y||!d.current?.contains(document.activeElement))&&(F.preventDefault(),X.focus()):(F.preventDefault(),d.current?.focus())};return window.addEventListener("keydown",I),()=>{window.removeEventListener("keydown",I),document.body.style.overflow=E,l instanceof HTMLElement&&l.isConnected&&l.focus()}},[r]);const O=f>0||k>0,A=a.cost_is_partial||O&&v.costIsPartial,J=[{label:s("sessions.detail.own"),tokens:w,cost:N,partial:a.cost_is_partial},{label:s("sessions.detail.subagents"),tokens:f,cost:k,partial:v.costIsPartial}],u=a.agent_nickname||a.title||a.project_key||s("sessions.project.unknown"),D=ze(a.duration_ms),R=[a.project_key&&a.project_key!==u?a.project_key:null,Ue(a.started_at,b),D].filter(Boolean);return e.jsx("div",{className:"fixed inset-0 z-50 flex justify-end bg-black/20 dark:bg-black/40",onClick:l=>{l.target===l.currentTarget&&r()},children:e.jsxs("div",{ref:d,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(Ae,{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:u}),e.jsx("p",{className:"mt-0.5 break-words text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:R.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(Fe,{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(ie,{label:s("sessions.col.tokens"),children:_(w+f)}),e.jsxs(ie,{label:s("sessions.col.cost"),className:"border-l",children:[A?"≥":"",y(N+k)]}),e.jsx(ie,{label:s("sessions.summary.speed"),className:"border-t",title:L?s("sessions.performance.samples",{count:p.estimated_request_count}):s("sessions.detail.no_speed"),children:L?e.jsx(se,{performance:p}):"—"}),e.jsx(ie,{label:s("sessions.performance.first_response"),className:"border-l border-t",title:s("sessions.performance.first_response_method"),children:C?Number(p.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(l=>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:l.label}),e.jsx("dd",{className:"text-right tabular-nums",children:_(l.tokens)}),e.jsxs("dd",{className:"text-right tabular-nums",children:[l.partial?"≥":"",y(l.cost)]})]},l.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")," · ",Fs(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:Ts.map(({key:l,label:E})=>e.jsx(we,{label:E(),children:a[l]==null?"—":_(a[l])},l))})]}),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(l=>{const E=l.pricing?.status==="unpriced",I=a.cost_source==="provider_reported"&&j.length===1,F=I?N:l.cost_usd,K=Rs(F,I);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:l.model||s("sessions.model.unknown")}),e.jsx("span",{className:"text-right tabular-nums",children:_(l.total_tokens)}),e.jsx("span",{className:"text-right tabular-nums",children:E&&!K?"—":y(F)})]}),l.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(se,{performance:l.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:[E?e.jsx("p",{children:s("sessions.detail.pricing_unpriced")}):null,l.pricing.status==="free"?e.jsx("p",{children:s("sessions.detail.pricing_free")}):null,l.pricing.status==="priced"?e.jsx("p",{children:s("sessions.detail.pricing_rates",{input:l.pricing.input,output:l.pricing.output,cacheRead:l.pricing.cache_read,cacheWrite:l.pricing.cache_write})}):null,ve(l.pricing.source)?e.jsx("p",{children:ve(l.pricing.source)}):null]})]}):e.jsx(se,{performance:l.performance,className:"block pt-1 text-xs tabular-nums text-oai-gray-500 dark:text-oai-gray-400"})]},l.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:Ls.map(({key:l,label:E,grokOnly:I})=>e.jsx(we,{label:E(),children:typeof a[l]=="number"&&(!I||T)?_(a[l]):s("sessions.detail.not_recorded")},l))}),T&&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:_(a.model_calls),seconds:(Number(a.api_duration_ms||0)/1e3).toFixed(1),tools:_(a.tool_calls),errors:_(a.error_count)})}):null,S?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:_(a.context_tokens_used),window:_(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 Ne=ps(),Se=[],he=100,Es=[{id:"all",label:()=>s("usage.filter.source_all")},{id:"claude",label:()=>"Claude Code"},{id:"codex",label:()=>"Codex"},{id:"grok",label:()=>"Grok"}],He=[{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 Is(a){const t=He.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 $s(a,t){if(!t)return!0;const r=Date.parse(a.ended_at||a.started_at||"");return Number.isFinite(r)?r>=t:!0}function Ps(a){const t=Date.parse(a.started_at||"");return!Number.isFinite(t)||le({started_at:a.started_at})===le(a)}function Ce(a){const t=V(a);return t.length===1?t[0].model||s("sessions.model.unknown"):t.map(r=>`${r.model} ${_(Number(r.total_tokens||0))}`).join(" · ")}async function Me(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}const De=pe.memo(function({session:t,locale:r,nested:o=!1,timeOnly:d=!1,childCount:g=0,expanded:m=!1,onToggle:b,onDetail:y}){const{currency:j,rate:v}=ye(),w=String(t.source||"").toUpperCase(),N=ze(t.duration_ms),f=t.resume_command,k=t.project_key||s("sessions.project.unknown"),p=o||t.thread_kind==="subagent",L=p?t.agent_nickname||t.agent_role||t.title||k:t.title||k,C=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
|
+
${s("sessions.project.copy_hint")}`:void 0,M=async()=>{if(t.project_ref)try{await Me(t.project_ref)?Z({title:s("sessions.project.copied")}):Z({title:s("sessions.project.copy_failed")})}catch{Z({title:s("sessions.project.copy_failed")})}},T=O=>e.jsxs("span",{className:"group relative inline-flex min-w-0 max-w-full",children:[e.jsx(hs,{text:P,placement:"bottom"}),e.jsx("button",{type:"button",onClick:M,"aria-label":s("sessions.project.copy_aria",{project:k}),className:B("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:k})]}),S=async()=>{if(f)try{await Me(f)?Z({title:s("sessions.resume.copied")}):Z({title:s("sessions.resume.copy_failed")})}catch{Z({title:s("sessions.resume.copy_failed")})}};return e.jsxs("li",{className:B("sessions-row sessions-row-grid py-3",o&&"sessions-row-nested"),children:[e.jsxs("div",{className:"sessions-row-identity flex min-w-0 items-start gap-3",children:[e.jsx("span",{className:"shrink-0 pt-2 text-oai-gray-600 dark:text-oai-gray-300 md:pt-0.5",children:e.jsx(Ae,{provider:w,size:o?16:18})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("button",{type:"button",onClick:()=>y(t),"aria-label":s("sessions.detail.open_aria",{title:L}),title:L,className:"min-h-9 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-0",children:L}),e.jsxs("div",{className:"sessions-row-meta mt-0.5 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?T("min-h-6 inline-flex items-center md:min-h-0"):e.jsx("span",{className:"truncate",children:k})}),e.jsx("span",{className:"sessions-meta-item min-w-0 max-w-full truncate",title:Ce(t),children:Ce(t)}),e.jsx("span",{className:"sessions-meta-item tabular-nums",children:Ue(t.started_at,r,{timeOnly:d&&Ps(t)})}),N?e.jsx("span",{className:"sessions-meta-item tabular-nums",children:N}):null,p?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,C?e.jsx("span",{className:"sessions-meta-item text-amber-700 dark:text-amber-300",children:C}):null,t.cost_source==="provider_reported"?e.jsx("span",{className:"sessions-meta-item",children:s("sessions.badge.reported_cost")}):null,g?e.jsxs("button",{type:"button",onClick:()=>b(t.session_hash),"aria-expanded":m,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(ds,{className:B("h-3.5 w-3.5 transition-transform",m&&"rotate-90"),"aria-hidden":!0}),m?s("sessions.thread.collapse",{count:g}):s("sessions.thread.expand",{count:g})]}):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:_(t.own_total_tokens),subagents:_(t.subagent_total_tokens),combined:_(t.combined_total_tokens)}):void 0,className:"mt-1 text-sm tabular-nums text-oai-black dark:text-white md:mt-0",children:[_(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:["Σ ",_(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?"≥":"",be(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(se,{performance:t.performance})})]})]}),e.jsx("button",{type:"button",onClick:S,disabled:!f,title:f||s("sessions.resume.unavailable"),"aria-label":f?s("sessions.resume.copy_aria",{command:f}):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(fs,{className:"h-4 w-4","aria-hidden":!0})})]})});function As({sessions:a,selectedModel:t,onSelect:r}){const{groups:o,totalTokens:d}=n.useMemo(()=>{const m=new Map;let b=0;for(const y of a)for(const j of V(y)){const v=j.model||s("sessions.model.unknown"),w=Number(j.total_tokens||0),N=m.get(v)||{model:v,count:0,tokens:0};N.count+=1,N.tokens+=w,b+=w,m.set(v,N)}return{groups:[...m.values()].sort((y,j)=>j.tokens-y.tokens),totalTokens:b}},[a]);function g(m){return B("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",m?"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:g(t==="all"),children:s("sessions.thread.model_all",{count:a.length,tokens:_(d)})}),o.map(m=>e.jsx("button",{type:"button","aria-pressed":t===m.model,onClick:()=>r(m.model),className:g(t===m.model),children:s("sessions.thread.model_item",{model:m.model,count:m.count,tokens:_(m.tokens)})},m.model))]})})}function at(){const[a]=n.useState(()=>Ms(window.location.search)),[t,r]=n.useState(null),[o,d]=n.useState(null),[g,m]=n.useState(!0),[b,y]=n.useState(!1),[j,v]=n.useState(a.source),[w,N]=n.useState(a.model),[f,k]=n.useState(a.from||a.to?"custom":"all"),[p,L]=n.useState(a.from),[C,P]=n.useState(a.to),[M,T]=n.useState("all"),[S,O]=n.useState("time"),[A,J]=n.useState("recent"),[u,D]=n.useState(null),[R,l]=n.useState(""),[E,I]=n.useState(he),[F,K]=n.useState(()=>new Set),[X,Y]=n.useState(()=>new Map),re=n.useRef(0),{resolvedLocale:G}=Le(),{currency:We,rate:Ve}=ye(),oe=n.useCallback(async(i=!1)=>{const x=++re.current;i?y(!0):m(!0),d(null);try{const c=await ws({refresh:i});x===re.current&&r(c)}catch(c){x===re.current&&d(c?.message||String(c))}finally{x===re.current&&(m(!1),y(!1))}},[]);n.useEffect(()=>{Ne||ke()?oe(!1):m(!1)},[oe]);const $=t?.sessions||Se,Be=n.useMemo(()=>{const i=new Set,x=[];for(const c of $){const h=c.project_key;!h||i.has(h)||(i.add(h),x.push({value:h,label:h}))}return x.sort((c,h)=>c.label.localeCompare(h.label))},[$]),Qe=n.useMemo(()=>{const i=new Set;for(const x of $)for(const c of V(x))c.model&&i.add(c.model);return[...i].sort().map(x=>({value:x,label:x}))},[$]),ce=n.useDeferredValue(R),U=n.useMemo(()=>{const i=ce.trim().toLowerCase(),x=Is(f);return $.filter(c=>{if(j!=="all"&&c.source!==j||M!=="all"&&c.project_key!==M||w!=="all"&&!V(c).some(z=>z.model===w))return!1;if(f==="custom"){if(!Ds(c,p,C))return!1}else if(!$s(c,x))return!1;if(!i)return!0;const h=V(c).map(z=>z.model).join(" ");return`${c.title||""} ${c.project_key||""} ${h} ${c.agent_nickname||""} ${c.agent_role||""} ${c.project_ref||""} ${c.session_id||""}`.toLowerCase().includes(i)})},[$,j,M,w,f,p,C,ce]),Q=n.useMemo(()=>Ge(U),[U]),H=n.useMemo(()=>{const i=new Set(U.map(h=>h.session_hash)),x=new Map,c=[];for(const h of Ss(U,A)){const q=h.root_session_hash||h.parent_session_hash;if(h.parent_session_hash&&q&&i.has(q)){const z=x.get(q)||[];z.push(h),x.set(q,z)}else c.push(h)}return{roots:c,childrenByRoot:x,foldedCount:U.length-c.length}},[U,A]),de=j!=="all"||w!=="all"||f!=="all"||M!=="all"||R.trim()!=="";n.useEffect(()=>{I(he),K(new Set),Y(new Map)},[j,M,w,f,p,C,ce,A,S,$]);const ue=n.useMemo(()=>H.roots.slice(0,E),[H.roots,E]),Ze=n.useMemo(()=>Cs(ue,S),[ue,S]),Je=n.useMemo(()=>u?$.filter(i=>i.session_hash!==u.session_hash&&(i.root_session_hash===u.session_hash||i.parent_session_hash===u.session_hash)):Se,[$,u]),Xe=n.useCallback(()=>D(null),[]),me=n.useCallback(i=>{k(i),i!=="custom"&&(L(""),P(""))},[]),Ye=n.useCallback(()=>{v("all"),N("all"),T("all"),l(""),me("all")},[me]),xe=H.roots.length>ue.length,ge=n.useCallback(()=>I(i=>i+he),[]),es=n.useCallback(i=>{K(x=>{const c=new Set(x);return c.has(i)?c.delete(i):c.add(i),c})},[]),ss=n.useCallback((i,x)=>{Y(c=>{const h=new Map(c);return x==="all"?h.delete(i):h.set(i,x),h})},[]),_e=n.useRef(null);n.useEffect(()=>{if(!xe||typeof IntersectionObserver>"u")return;const i=_e.current;if(!i)return;const x=new IntersectionObserver(c=>{c.some(h=>h.isIntersecting)&&ge()},{rootMargin:"400px"});return x.observe(i),()=>x.disconnect()},[xe,ge]);const ts=n.useMemo(()=>Es.map(i=>({value:i.id,label:i.label()})),[G]),as=n.useMemo(()=>[...He.map(i=>({value:i.id,label:i.label()})),{value:"custom",label:s("sessions.filter.range_custom")}],[G]),rs=n.useMemo(()=>[{value:"time",label:s("sessions.group.time")},{value:"project",label:s("sessions.group.project")}],[G]),os=n.useMemo(()=>[{value:"recent",label:s("sessions.sort.recent")},{value:"cost",label:s("sessions.sort.cost")},{value:"tokens",label:s("sessions.sort.tokens")}],[G]),ns=Number(t?.session_count)>Number(t?.returned_count);return!Ne&&!ke()?e.jsx("div",{className:"flex flex-col flex-1 text-oai-black dark:text-oai-white font-oai antialiased",children:e.jsx(us,{})}):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:b||g,"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(cs,{className:B("h-4 w-4",b&&"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(Re,{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(ms,{type:"search",value:R,onChange:i=>l(i.target.value),onKeyDown:i=>{i.key==="Escape"&&R&&(i.preventDefault(),l(""))},"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"}),R?e.jsx("button",{type:"button",onMouseDown:i=>i.preventDefault(),onClick:()=>l(""),"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(Fe,{className:"h-4 w-4","aria-hidden":!0})}):null]}),e.jsx(ne,{ariaLabel:s("sessions.filter.source_aria"),options:ts,value:j,onValueChange:v,className:"sessions-filter-trigger h-11 min-w-0 px-3 text-sm sm:h-9",matchTriggerWidth:!0}),e.jsx(ne,{ariaLabel:s("sessions.filter.range_aria"),options:as,value:f,onValueChange:me,leadingIcon:e.jsx(_s,{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(je,{options:Be,value:M,onChange:T,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(je,{options:Qe,value:w,onChange:N,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"})]}),f==="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:p,onChange:i=>L(i.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:C,onChange:i=>P(i.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]}),!g&&t?e.jsxs("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:_(Q.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:_(Q.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:[Q.costIsPartial?"≥":"",be(Q.cost,{currency:We,rate:Ve})]})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s("sessions.summary.speed")}),e.jsxs("dd",{className:"mt-1 text-lg font-medium tabular-nums",children:[e.jsx(se,{performance:Q.performance}),Q.performance.estimated_tokens_per_second==null?"—":null]})]})]}),e.jsxs(Oe,{children:[e.jsx(Ee,{"aria-label":s("sessions.summary.scope_help"),className:"-mr-2 flex h-11 w-11 shrink-0 items-center justify-center rounded-md text-oai-gray-500 hover:bg-oai-gray-100 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 sm:h-8 sm:w-8",children:e.jsx(bs,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx(Ie,{children:e.jsx($e,{side:"bottom",align:"end",sideOffset:8,className:"z-[60]",children:e.jsx(Pe,{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")})})})]})]}):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:H.foldedCount>0?s("sessions.thread.result_count",{roots:H.roots.length,subagents:H.foldedCount}):s("sessions.filter.result_count",{filtered:U.length,total:$.length})}),de?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(ne,{ariaLabel:s("sessions.group.aria"),options:rs,value:S,onValueChange:O,className:"sessions-filter-trigger h-11 min-w-0 max-w-40 px-2.5 text-xs sm:h-8"}),e.jsx(ne,{ariaLabel:s("sessions.sort.aria"),options:os,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"})]})]}),ns?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")})]}):g?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(ys,{className:"h-4 w-4 animate-spin","aria-hidden":!0}),s("sessions.loading")]}):U.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:de?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:de?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:Ze.map(i=>e.jsxs(pe.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:S==="project"?i.key||s("sessions.project.unknown"):i.key?new Date(`${i.key}T12:00:00`).toLocaleDateString(G||void 0,{year:"numeric",month:"short",day:"numeric"}):s("sessions.group.unknown_date")})}),i.sessions.map(x=>{const c=H.childrenByRoot.get(x.session_hash)||[],h=F.has(x.session_hash),q=X.get(x.session_hash)||"all",z=q==="all"?c:c.filter(function(is){return V(is).some(ls=>ls.model===q)});return e.jsxs(pe.Fragment,{children:[e.jsx(De,{session:x,locale:G,timeOnly:S==="time",childCount:c.length,expanded:h,onToggle:es,onDetail:D}),h&&c.length?e.jsx(As,{sessions:c,selectedModel:q,onSelect:ee=>ss(x.session_hash,ee)}):null,h?z.map(ee=>e.jsx(De,{session:ee,locale:G,nested:!0,timeOnly:S==="time",onDetail:D},ee.session_hash)):null]},x.session_hash)})]},i.key))}),xe?e.jsx("div",{ref:_e,className:"flex justify-center pt-6",children:e.jsx("button",{type:"button",onClick:ge,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")})]})}),u?e.jsx(Os,{session:u,subagents:Je,onClose:Xe}):null]})}export{at as SessionsPage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-
|
|
2
|
-
import{q as I,j as t,e as _,c as n,a as ye,r as d,at as ve,az as ke,aA as je,a9 as X,aY as Se,aZ as we,a_ as Ne,u as Ce,d as H,a2 as Ee,J as ee,n as U,a$ as V,m as B,b0 as Ae,b1 as Pe,Z as te,b2 as Oe,t as Le,b3 as _e,b4 as Te,b5 as Ie,b6 as Ge,b7 as Re,b8 as De,b9 as Ue,ba as ne,L as Me,R as He,bb as Fe,bc as $e,ak as z,_ as Ve,h as Be,f as ze,bd as Ke,be as qe,aD as We}from"./__vite-browser-external-BW1rxvYq.js";import{a as Ze,b as K,s as Ye,K as Je,P as Qe,D as Xe,c as et,S as tt,v as nt,u as at,C as st}from"./sortable.esm-SVl6OixH.js";import{a as it}from"./modifiers.esm-Ds4Uh7JO.js";import{d as q,l as W,u as ot,b as Z}from"./use-limits-display-prefs-CDC0MZRY.js";import{P as rt}from"./ProviderIcon-BSI-1Cy8.js";import{m as ae}from"./react-CO1HovF5.js";import{a as O,T as j,b,S as T,u as R}from"./Controls-D56v-YJw.js";import{P as lt,u as ct,a as ut}from"./use-session-efficiency-pref-D8cAb4A9.js";import{C as dt}from"./check-8LQ7IvkH.js";import{C as gt,i as pt}from"./host-mode-GPY2DxE4.js";import{A as se}from"./index-CPcJP0uH.js";import{u as ht}from"./useCurrency-t1iy_pC3.js";import{u as mt}from"./useTokenFormat-0bPjtaaM.js";import{S as F}from"./Select-B6CM0ico.js";import{I as bt}from"./info-BaK8Hoi2.js";import{C as ft}from"./ConfirmModal-zUljpLNe.js";import{A as xt}from"./arrow-up-right-c39fdiDQ.js";import{D as yt}from"./download-x3Gmv-wu.js";import"./Card-BU2CqxfU.js";import"./SelectItemText-CZ7puxuB.js";import"./composite-BgLSXWKA.js";import"./DialogTitle-6q0jyME6.js";import"./store-DrEEdO_u.js";import"./DialogDescription-COXweCuc.js";const ie={name:"flask-conical",size:24,node:[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]]};ie.node;const vt=I(ie);const oe={name:"grip-vertical",size:24,node:[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]};oe.node;const kt=I(oe);const re={name:"languages",size:24,node:[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]};re.node;const jt=I(re);const le={name:"log-out",size:24,node:[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]]};le.node;const St=I(le);const ce={name:"palette",size:24,node:[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]]};ce.node;const wt=I(ce);const ue={name:"user-round",size:24,node:[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],aliases:["user-2"]};ue.node;const Nt=I(ue),Ct="shrink-0 text-oai-gray-900 dark:text-oai-gray-200";function Et({checked:e,onChange:a,ariaLabel:s}){return t.jsx("button",{type:"button",role:"switch","aria-checked":e,"aria-label":s,onClick:a,className:_("relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",e?"bg-oai-brand-500":"bg-oai-gray-300 dark:bg-oai-gray-700"),children:t.jsx("span",{className:_("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",e?"translate-x-[18px]":"translate-x-[3px]")})})}function At({id:e,visible:a,onToggle:s}){const{attributes:i,listeners:o,setNodeRef:r,transform:l,transition:c,isDragging:u}=at({id:e}),h={transform:st.Transform.toString(l)||void 0,transition:c,zIndex:u?20:void 0};return t.jsxs("div",{ref:r,style:h,className:_("flex items-center gap-3 py-2 rounded-md select-none touch-none","cursor-grab active:cursor-grabbing","hover:bg-oai-gray-100/60 dark:hover:bg-oai-gray-800/60","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",u&&"relative bg-oai-gray-100 dark:bg-oai-gray-800"),...i,...o,children:[t.jsx(kt,{className:"h-4 w-4 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",strokeWidth:1.75,"aria-hidden":!0}),q(e)?t.jsx(rt,{provider:q(e),size:18,className:_("pointer-events-none",Ct)}):null,t.jsx("span",{className:"flex-1 text-sm text-oai-gray-900 dark:text-oai-gray-200",children:W(e)}),t.jsx("div",{onPointerDown:p=>p.stopPropagation(),children:t.jsx(Et,{checked:a,onChange:s,ariaLabel:`${n("limits.settings.toggle_visible")}: ${W(e)}`})})]})}function Pt({prefs:e}){const{order:a,visibility:s,toggle:i,moveToward:o}=e,r=Ze(K(Qe,{activationConstraint:{distance:6}}),K(Je,{coordinateGetter:Ye})),l=({active:c,over:u})=>{u&&c.id!==u.id&&o(c.id,u.id)};return t.jsx(Xe,{sensors:r,collisionDetection:et,modifiers:[it],onDragEnd:l,children:t.jsx(tt,{items:a,strategy:nt,children:t.jsx("div",{className:"flex flex-col",children:a.map(c=>t.jsx(At,{id:c,visible:s[c]!==!1,onToggle:()=>i(c)},c))})})})}function Ot(e){if(!e||typeof e!="object")return"";const a=e.user_metadata&&typeof e.user_metadata=="object"?e.user_metadata:{},s=e.profile&&typeof e.profile=="object"?e.profile:{},i=a.full_name||a.name||s.name||a.user_name||a.preferred_username;return typeof i=="string"&&i.trim()?i.trim():typeof e.email=="string"&&e.email.includes("@")?e.email.split("@")[0].trim()||e.email.trim():typeof e.email=="string"?e.email.trim():""}function Lt(e){return!e||typeof e!="object"?"":typeof e.email=="string"?e.email.trim():""}function _t(e){const a=typeof e=="string"?e.trim():"";if(!a)return null;const s=a.match(/^@?([A-Za-z0-9][A-Za-z0-9-]{0,38})$/),i=a.match(/^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/?$/i),o=s?.[1]||i?.[1];return o?`https://github.com/${o}`:null}function $(e,a){console.warn(`[tokentracker] settings ${e}:`,a)}function Tt(e,a,s){const[i,o]=d.useState(()=>ve()),r=a&&s&&Ne(),l=d.useCallback(async()=>{const c=!i;if(ke(c),o(c),!!c)try{await je(()=>e())}catch(u){$("cloud sync",u)}},[i,e]);return{cloudSyncOn:i,handleCloudSyncToggle:l,showLocalCloudSync:r}}function It(e){const[a,s]=d.useState(!1),[i,o]=d.useState(!1),[r,l]=d.useState(!1),[c,u]=d.useState(!1),[h,p]=d.useState(null),[g,m]=d.useState(!1),[v,k]=d.useState(""),[P,y]=d.useState(!1),[w,N]=d.useState(""),[f,S]=d.useState(""),[L,x]=d.useState(!1),[E,D]=d.useState(null),G=d.useMemo(()=>Ot(e),[e]),be=d.useMemo(()=>Lt(e),[e]),fe=d.useMemo(()=>typeof e?.id=="string"?e.id.trim():"",[e]),xe=d.useMemo(()=>({setAnonymousOn:o,setCustomDisplayName:p,setGithubUrl:N,setProfileLoading:l,setPublicProfileOn:s,setShowGithubOn:y}),[]);return{anonymousOn:i,customDisplayName:h,displayName:G,editingGithub:L,editingName:g,email:be,githubError:E,githubInput:f,githubUrl:w,loadSetters:xe,nameInput:v,profileLoading:r,profileSaving:c,publicProfileOn:a,setAnonymousOn:o,setCustomDisplayName:p,setEditingGithub:x,setEditingName:m,setGithubError:D,setGithubInput:S,setGithubUrl:N,setNameInput:k,setProfileLoading:l,setProfileSaving:u,setPublicProfileOn:s,setShowGithubOn:y,showGithubOn:P,userId:fe}}function Gt(e,a,s){d.useEffect(()=>{if(!a)return;let i=!0;return s.setProfileLoading(!0),(async()=>{try{const o=await X({getAccessToken:e});if(!i||!o)return;const r=await Se({accessToken:o});if(!i)return;s.setPublicProfileOn(!!r?.enabled),s.setAnonymousOn(!!r?.anonymous),r?.display_name&&s.setCustomDisplayName(r.display_name),s.setShowGithubOn(!!r?.show_github_url),s.setGithubUrl(r?.github_url||"")}catch(o){$("load public profile",o)}finally{i&&s.setProfileLoading(!1)}})(),()=>{i=!1}},[e,a,s])}function Rt(e,a){return d.useCallback(async(s,{label:i,onError:o,onSuccess:r}={})=>{if(a.profileSaving)return!1;a.setProfileSaving(!0);try{const l=await X({getAccessToken:e});if(!l)return!1;const c=await we({accessToken:l,...s});return r?.(c),!0}catch(l){return o?o(l):$(i||"mutate profile",l),!1}finally{a.setProfileSaving(!1)}},[e,a])}function Dt(e,a){return{anonymousOn:e.anonymousOn,customDisplayName:e.customDisplayName,displayName:e.displayName,editingName:e.editingName,handleAnonymousToggle:a.handleAnonymousToggle,handleSaveName:a.handleSaveName,nameInput:e.nameInput,profileLoading:e.profileLoading,profileSaving:e.profileSaving,setEditingName:e.setEditingName,setNameInput:e.setNameInput,startEditingName:a.startEditingName}}function Ut(e,a){return{editingGithub:e.editingGithub,githubError:e.githubError,githubInput:e.githubInput,githubUrl:e.githubUrl,handleSaveGithub:a.handleSaveGithub,handleShowGithubToggle:a.handleShowGithubToggle,profileLoading:e.profileLoading,profileSaving:e.profileSaving,setEditingGithub:e.setEditingGithub,setGithubError:e.setGithubError,setGithubInput:e.setGithubInput,showGithubOn:e.showGithubOn,startEditingGithub:a.startEditingGithub}}function Mt(e,a){const s=d.useCallback(async()=>{const o=!e.publicProfileOn;await a({enabled:o},{label:"toggle public profile",onSuccess:()=>e.setPublicProfileOn(o)})},[a,e]);return{handleAnonymousToggle:d.useCallback(async()=>{const o=!e.anonymousOn;await a({anonymous:o},{label:"toggle anonymous",onSuccess:()=>e.setAnonymousOn(o)})},[a,e]),handlePublicProfileToggle:s}}function Ht(e,a,s){const i=d.useCallback(async()=>{const r=e.nameInput.trim().slice(0,50);r&&await a({display_name:r},{label:"save display name",onSuccess:()=>{e.setCustomDisplayName(r),e.setEditingName(!1),s?.()}})},[a,e,s]),o=d.useCallback(()=>{e.setNameInput(e.customDisplayName||e.displayName),e.setEditingName(!0)},[e]);return{handleSaveName:i,startEditingName:o}}function Ft(e,a){const s=d.useCallback(async()=>{if(!e.showGithubOn&&!e.githubUrl){e.setEditingGithub(!0),e.setGithubInput(""),e.setGithubError(null);return}const r=!e.showGithubOn;await a({show_github_url:r},{label:"toggle GitHub profile",onSuccess:()=>e.setShowGithubOn(r)})},[a,e]),i=d.useCallback(async()=>{const r=_t(e.githubInput);if(e.githubInput.trim()&&!r){e.setGithubError(n("settings.account.githubUrlInvalid"));return}e.setGithubError(null),await a({github_url:r,show_github_url:!!r},{label:"save GitHub profile",onError:l=>e.setGithubError(l?.message||n("settings.account.githubUrlInvalid")),onSuccess:l=>{e.setGithubUrl(l?.github_url||r||""),e.setShowGithubOn(!!r),e.setEditingGithub(!1)}})},[a,e]),o=d.useCallback(()=>{e.setGithubInput(e.githubUrl),e.setGithubError(null),e.setEditingGithub(!0)},[e]);return{handleSaveGithub:i,handleShowGithubToggle:s,startEditingGithub:o}}function $t(){const e=ye(),a=It(e.user),s=Tt(e.getAccessToken,e.enabled,e.signedIn);Gt(e.getAccessToken,e.signedIn,a.loadSetters);const i=Rt(e.getAccessToken,a),o=Mt(a,i),r=Ht(a,i,e.refreshDisplayName),l=Ft(a,i);return{...e,...s,email:a.email,handlePublicProfileToggle:o.handlePublicProfileToggle,userId:a.userId,name:Dt(a,{...o,...r}),github:Ut(a,l),profileLoading:a.profileLoading,profileSaving:a.profileSaving,publicProfileOn:a.publicProfileOn}}function de({disabled:e,onCancel:a,onSave:s,saveLabel:i=n("settings.account.save")}){return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:s,disabled:e,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:i}),t.jsx("button",{type:"button",onClick:a,className:"rounded-md px-2 py-1.5 text-xs text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:n("settings.account.cancel")})]})}function Vt({nameInput:e,setEditingName:a,setNameInput:s,profileSaving:i,handleSaveName:o}){return t.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[t.jsx("input",{type:"text",value:e,onChange:r=>s(r.target.value),onKeyDown:r=>{r.key==="Enter"&&o(),r.key==="Escape"&&a(!1)},maxLength:50,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:n("settings.account.displayName")}),t.jsx(de,{disabled:i||!e.trim(),onCancel:()=>a(!1),onSave:o,saveLabel:i?n("settings.account.saving"):void 0})]})}function Bt({githubError:e,githubInput:a,handleSaveGithub:s,profileSaving:i,setEditingGithub:o,setGithubError:r,setGithubInput:l}){return t.jsxs("div",{className:"mt-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{type:"text",value:a,onChange:c=>{l(c.target.value),e&&r(null)},onKeyDown:c=>{c.key==="Enter"&&s(),c.key==="Escape"&&(o(!1),r(null))},maxLength:100,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:n("settings.account.githubUrlPlaceholder")}),t.jsx(de,{disabled:i,onCancel:()=>{o(!1),r(null)},onSave:s,saveLabel:i?n("settings.account.saving"):void 0})]}),e?t.jsx("div",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400",children:e}):null]})}function ge({disabled:e=!1,label:a,onClick:s,title:i}){return t.jsxs("button",{type:"button",onClick:s,disabled:e,title:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-40 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[t.jsx(lt,{className:"h-3.5 w-3.5","aria-hidden":!0}),a]})}function pe({actions:e,editing:a,editor:s,hint:i,label:o}){return t.jsx("div",{className:"py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:o}),a?s:t.jsx("div",{className:"mt-0.5 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:i})]}),a?null:e]})})}function zt({name:e}){const a=e.anonymousOn?n("settings.account.displayNameDisabledWhileAnon"):void 0;return t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx(ge,{disabled:e.anonymousOn,label:n("settings.account.edit"),onClick:e.startEditingName,title:a}),t.jsx(j,{checked:!e.anonymousOn,onChange:e.handleAnonymousToggle,disabled:e.profileLoading||e.profileSaving,ariaLabel:n("settings.account.displayName")})]})}function Kt({name:e}){const{anonymousOn:a,customDisplayName:s,displayName:i,editingName:o,handleAnonymousToggle:r,handleSaveName:l,nameInput:c,profileLoading:u,profileSaving:h,setEditingName:p,setNameInput:g,startEditingName:m}=e,v=a?n("settings.account.displayNameAnonymousHint"):s||i;return t.jsx(pe,{label:n("settings.account.displayName"),editing:o,hint:v,editor:t.jsx(Vt,{nameInput:c,setEditingName:p,setNameInput:g,profileSaving:h,handleSaveName:l}),actions:t.jsx(zt,{name:e})})}function qt({github:e}){const{editingGithub:a,githubError:s,githubInput:i,githubUrl:o,handleSaveGithub:r,handleShowGithubToggle:l,profileLoading:c,profileSaving:u,setEditingGithub:h,setGithubError:p,setGithubInput:g,showGithubOn:m,startEditingGithub:v}=e;return t.jsx(t.Fragment,{children:t.jsx(pe,{label:n("settings.account.githubUrl"),editing:a,hint:o||n("settings.account.githubUrlHint"),editor:t.jsx(Bt,{githubError:s,githubInput:i,handleSaveGithub:r,profileSaving:u,setEditingGithub:h,setGithubError:p,setGithubInput:g}),actions:t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx(ge,{label:n("settings.account.edit"),onClick:v}),t.jsx(j,{checked:m,onChange:l,disabled:c||u,ariaLabel:n("settings.account.githubUrl")})]})})})}function Wt(){const{openLoginModal:e}=Ce();return t.jsx(O,{title:n("settings.section.account"),children:t.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[t.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:n("settings.account.signedOutHint")}),t.jsx("button",{type:"button",onClick:e,className:"inline-flex h-8 shrink-0 items-center justify-center rounded-md bg-oai-gray-900 px-4 text-xs font-medium text-white transition-colors hover:bg-oai-gray-800 dark:bg-white dark:text-oai-gray-900 dark:hover:bg-oai-gray-100",children:n("settings.account.signIn")})]})})}function Zt({name:e,github:a}){return t.jsxs(t.Fragment,{children:[t.jsx(Kt,{name:e}),t.jsx(qt,{github:a})]})}function Yt(){const e=$t();return e.enabled?e.signedIn?t.jsxs(O,{title:n("settings.section.account"),subtitle:e.email||e.name.customDisplayName||e.name.displayName,action:t.jsx(Qt,{onSignOut:e.signOut}),children:[t.jsx(Jt,{userId:e.userId}),t.jsx(Xt,{settings:e}),t.jsx(en,{checked:e.publicProfileOn,disabled:e.profileLoading||e.profileSaving,onChange:e.handlePublicProfileToggle}),t.jsx(tn,{visible:e.publicProfileOn,name:e.name,github:e.github})]}):t.jsx(Wt,{}):null}function Jt({userId:e}){const[a,s]=H.useState(!1);if(!e)return null;const i=async()=>{try{if(typeof navigator>"u"||!navigator.clipboard?.writeText)return;await navigator.clipboard.writeText(e),s(!0),globalThis.setTimeout(()=>s(!1),1200)}catch{s(!1)}};return t.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:n("settings.account.userId")}),t.jsx("div",{className:"mt-0.5 truncate font-mono text-xs text-oai-gray-500 dark:text-oai-gray-400",children:e})]}),t.jsxs("button",{type:"button",onClick:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800","aria-label":n("settings.account.copyUserId"),children:[a?t.jsx(dt,{className:"h-3.5 w-3.5","aria-hidden":!0}):t.jsx(gt,{className:"h-3.5 w-3.5","aria-hidden":!0}),a?n("settings.account.copied"):n("settings.account.copy")]})]})}function Qt({onSignOut:e}){return t.jsxs("button",{type:"button",onClick:()=>e(),className:"inline-flex h-7 items-center gap-1.5 text-xs font-medium text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:[t.jsx(St,{className:"h-3.5 w-3.5","aria-hidden":!0}),n("settings.account.signOut")]})}function Xt({settings:e}){return e.showLocalCloudSync?t.jsx(b,{label:n("settings.account.cloudSync"),hint:n("settings.account.cloudSyncHint"),control:t.jsx(j,{checked:e.cloudSyncOn,onChange:e.handleCloudSyncToggle,ariaLabel:n("settings.account.cloudSync")})}):null}function en({checked:e,disabled:a,onChange:s}){return t.jsx(b,{label:n("settings.account.publicProfile"),hint:n("settings.account.publicProfileHint"),control:t.jsx(j,{checked:e,onChange:s,disabled:a,ariaLabel:n("settings.account.publicProfile")})})}function tn({visible:e,name:a,github:s}){return t.jsx(se,{initial:!1,children:e?t.jsx(ae.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:t.jsx(Zt,{name:a,github:s})},"public-profile-fields"):null})}function nn(){return[{value:"light",label:n("settings.appearance.theme.light"),Icon:Ae},{value:"dark",label:n("settings.appearance.theme.dark"),Icon:Pe},{value:"system",label:n("settings.appearance.theme.system"),Icon:te}]}function an(){return[{value:_e,label:n("settings.appearance.language.system")},{value:Te,label:n("settings.appearance.language.english")},{value:Ie,label:n("settings.appearance.language.chinese")},{value:Ge,label:n("settings.appearance.language.traditional_chinese")},{value:Re,label:n("settings.appearance.language.japanese")},{value:De,label:n("settings.appearance.language.korean")},{value:Ue,label:n("settings.appearance.language.german")}]}function sn(e){if(!e)return null;try{const a=new Date(e);return Number.isNaN(a.getTime())?null:a.toLocaleString()}catch{return null}}function on(e,a){const s=n(`settings.appearance.currency.rate_source.${e}`),i=sn(a),o=i?n("settings.appearance.currency.rate_updated",{when:i}):n("settings.appearance.currency.rate_never");return`${s} · ${o}`}function rn({locale:e,setLocale:a}){const s=an();return t.jsx(F,{value:e,onValueChange:a,options:s,ariaLabel:n("settings.appearance.language.label"),className:"px-2.5 py-1.5 text-xs font-medium",leadingIcon:t.jsx(jt,{className:"h-3.5 w-3.5 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})})}function ln({currency:e,setCurrency:a}){const s=Oe().map(i=>({value:i.code,label:n(i.labelKey)}));return t.jsx(F,{value:e,onValueChange:a,options:s,ariaLabel:n("settings.appearance.currency.label"),className:"px-3 py-1.5 text-xs font-medium"})}function cn({currency:e,rate:a,rateSource:s,rateFetchedAt:i}){if(e===Le)return t.jsx(t.Fragment,{children:n("settings.appearance.currency.hint")});const o=on(s,i);return t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx("span",{children:`1 USD = ${a.toFixed(4)} ${e}`}),t.jsx("span",{role:"img","aria-label":o,title:o,className:"inline-flex h-4 w-4 cursor-help items-center justify-center text-oai-gray-400 hover:text-oai-gray-600 dark:text-oai-gray-500 dark:hover:text-oai-gray-300",children:t.jsx(bt,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function un(){const{theme:e,setTheme:a}=Ee(),{locale:s,setLocale:i}=ee(),{currency:o,rate:r,rateSource:l,rateFetchedAt:c,setCurrency:u}=ht(),{mode:h,setMode:p,unitSystem:g,setUnitSystem:m,grouping:v,setGrouping:k}=mt();return t.jsxs(O,{title:n("settings.section.appearance"),children:[t.jsx(b,{label:n("settings.appearance.theme.label"),hint:n("settings.appearance.theme.hint"),control:t.jsx(T,{options:nn(),value:e,onChange:a})}),t.jsx(b,{label:n("settings.appearance.language.label"),hint:n("settings.appearance.language.hint"),control:t.jsx(rn,{locale:s,setLocale:i})}),t.jsx(b,{label:n("settings.appearance.currency.label"),hint:t.jsx(cn,{currency:o,rate:r,rateSource:l,rateFetchedAt:c}),control:t.jsx(ln,{currency:o,setCurrency:u})}),t.jsx(b,{label:n("settings.appearance.token_format.label"),hint:n("settings.appearance.token_format.hint"),control:t.jsx(T,{options:[{value:U.COMPACT,label:n("settings.appearance.token_format.compact")},{value:U.FULL,label:n("settings.appearance.token_format.full")}],value:h,onChange:p})}),t.jsx(b,{label:n("settings.appearance.token_unit.label"),hint:n("settings.appearance.token_unit.hint"),control:t.jsx(T,{disabled:h!==U.COMPACT,options:[{value:V.ENGLISH,label:n("settings.appearance.token_unit.english")},{value:V.CHINESE,label:n("settings.appearance.token_unit.chinese")}],value:g,onChange:m})}),t.jsx(b,{label:n("settings.appearance.token_grouping.label"),hint:n("settings.appearance.token_grouping.hint"),control:t.jsx(T,{options:[{value:B.THOUSAND,label:n("settings.appearance.token_grouping.thousand")},{value:B.WAN,label:n("settings.appearance.token_grouping.wan")}],value:v,onChange:k})})]})}function M({labelKey:e}){return t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{children:n(e)}),t.jsx("span",{className:"px-1.5 py-0.5 text-[8px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase scale-90 origin-left",children:n("qpd.card.badge")})]})}function dn(){const{enabled:e,toggle:a}=ct(),{enabled:s,toggle:i}=ut(),{available:o,settings:r,setSetting:l}=R(),c=o&&!!r?.dynamicIslandSupported,u=!!r?.dynamicIslandEnabled;return t.jsxs(O,{title:n("settings.section.labs"),children:[c&&t.jsxs(t.Fragment,{children:[t.jsx(b,{label:t.jsx(M,{labelKey:"settings.labs.island.label"}),hint:n("settings.labs.island.hint"),control:t.jsx(j,{checked:u,onChange:()=>l("dynamicIslandEnabled",!u),ariaLabel:n("settings.labs.island.aria")})}),u&&t.jsx(b,{label:n("settings.labs.island_hide_menubar.label"),hint:n("settings.labs.island_hide_menubar.hint"),control:t.jsx(j,{checked:!!r?.hideMenuBarIcon,onChange:()=>l("hideMenuBarIcon",!r?.hideMenuBarIcon),ariaLabel:n("settings.labs.island_hide_menubar.aria")})})]}),t.jsx(b,{label:t.jsx(M,{labelKey:"settings.labs.qpd.label"}),hint:n("settings.labs.qpd.hint"),control:t.jsx(j,{checked:e,onChange:a,ariaLabel:n("settings.labs.qpd.aria")})}),t.jsx(b,{label:t.jsx(M,{labelKey:"settings.labs.sessions.label"}),hint:n("settings.labs.sessions.hint"),control:t.jsx(j,{checked:s,onChange:i,ariaLabel:n("settings.labs.sessions.aria")})})]})}function gn(){const{available:e,settings:a,setSetting:s,runAction:i}=R();if(!e)return null;const o=ne(),r=!!a?.launchAtLogin,l=a?.toastOnReset!==!1,c=a?.confettiOnReset!==!1,u=a?.launchAtLoginSupported!==!1,h=a?.autoUpdateEnabled!==!1,p=a?.updateStatus||null,g=!!a?.updateBusy,m=!!a?.isSyncing;return t.jsxs(O,{title:n("settings.section.menubar"),children:[o?null:t.jsxs(t.Fragment,{children:[t.jsx(b,{label:n("settings.menubar.appearance"),hint:n("settings.menubar.appearanceHint"),control:t.jsxs(Me,{to:"/widgets",className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 no-underline transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[n("settings.menubar.appearanceLink"),t.jsx(xt,{className:"h-3.5 w-3.5","aria-hidden":!0})]})}),t.jsx(b,{label:n("settings.menubar.toastOnReset"),hint:n("settings.menubar.toastOnResetHint"),control:t.jsx(j,{checked:l,onChange:()=>s("toastOnReset",!l),ariaLabel:n("settings.menubar.toastOnReset")})}),t.jsx(b,{label:n("settings.menubar.confettiOnReset"),hint:n("settings.menubar.confettiOnResetHint"),control:t.jsx(j,{checked:c,onChange:()=>s("confettiOnReset",!c),ariaLabel:n("settings.menubar.confettiOnReset")})})]}),u?t.jsx(b,{label:n("settings.menubar.launchAtLogin"),hint:n("settings.menubar.launchAtLoginHint"),control:t.jsx(j,{checked:r,onChange:()=>s("launchAtLogin",!r),ariaLabel:n("settings.menubar.launchAtLogin")})}):null,t.jsx(b,{label:n("settings.menubar.syncNow"),hint:n("settings.menubar.syncNowHint"),control:t.jsxs("button",{type:"button",onClick:()=>i("syncNow"),disabled:m,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[t.jsx(He,{className:_("h-3.5 w-3.5",m&&"animate-spin"),"aria-hidden":!0}),m?n("settings.menubar.syncing"):n("settings.menubar.syncNow")]})}),t.jsx(b,{label:n("settings.menubar.autoUpdate"),hint:n("settings.menubar.autoUpdateHint"),control:t.jsx(j,{checked:h,onChange:()=>s("autoUpdateEnabled",!h),ariaLabel:n("settings.menubar.autoUpdate")})}),t.jsx(b,{label:n("settings.menubar.updates"),hint:p||void 0,control:t.jsxs("button",{type:"button",onClick:()=>i("checkForUpdates"),disabled:g,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[t.jsx(yt,{className:"h-3.5 w-3.5","aria-hidden":!0}),n("settings.menubar.checkUpdates")]})})]})}function pn(e,a){function s(r){return r.replace(/^v/,"").split(".").map(Number)}const i=s(e),o=s(a);for(let r=0;r<Math.max(i.length,o.length);r++){const l=i[r]||0,c=o[r]||0;if(l<c)return!0;if(l>c)return!1}return!1}function hn(){const{available:e,settings:a,runAction:s}=R(),i=e&&a?.version,o=a?.platform||"macos",[r,l]=H.useState(!1),[c,u]=H.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:h}=ee(),p="1.2.1",g=async()=>{l(!0);try{const y=await fetch("https://api.github.com/repos/xiufengsun/TokenTracker/releases/latest");if(!y.ok)throw new Error("Failed to fetch");const w=await y.json(),N=w.tag_name;pn(p,N)?u({open:!0,latestVersion:N,htmlUrl:w.html_url}):z({title:n("settings.menubar.updates.upToDate")})}catch(y){console.error("Check updates failed:",y),z({title:n("settings.menubar.updates.failed")})}finally{l(!1)}},m=n("settings.menubar.updates.modalTitle"),v=n("settings.menubar.updates.modalDescription",{version:c.latestVersion}),k=n("settings.menubar.updates.modalConfirm"),P=n("settings.menubar.updates.modalCancel");return t.jsxs("div",{className:"mt-6 flex flex-col items-center justify-center gap-4 text-xs text-oai-gray-500 dark:text-oai-gray-500",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[i?t.jsxs(t.Fragment,{children:[t.jsx("span",{children:o==="windows"?n("settings.menubar.updates.footerCore",{version:a.version}):n("settings.menubar.updates.footerCombined",{barVersion:a.version,coreVersion:p})}),t.jsx("span",{"aria-hidden":!0,children:"·"}),t.jsx("button",{type:"button",onClick:()=>s("openAbout"),className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:"GitHub"}),t.jsx("span",{"aria-hidden":!0,children:"·"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{children:n("settings.menubar.updates.footerCore",{version:p})}),t.jsx("span",{"aria-hidden":!0,children:"·"}),t.jsx("button",{type:"button",onClick:g,disabled:r,className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300 disabled:opacity-50",children:r?n("settings.menubar.updates.checking"):n("settings.menubar.checkUpdates")}),t.jsx("span",{"aria-hidden":!0,children:"·"})]}),t.jsxs("a",{href:Fe,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:[t.jsx($e,{className:"h-3.5 w-3.5","aria-hidden":!0}),n("settings.footer.statusPage")]})]}),t.jsx(ft,{open:c.open,title:m,description:v,confirmLabel:k,cancelLabel:P,onConfirm:()=>{window.open(c.htmlUrl,"_blank"),u(y=>({...y,open:!1}))},onCancel:()=>u(y=>({...y,open:!1}))})]})}const mn=()=>[{value:"system",label:n("settings.network.mode.system")},{value:"manual",label:n("settings.network.mode.manual")},{value:"off",label:n("settings.network.mode.off")}],bn=()=>[{value:"http",label:n("settings.network.protocol.http")},{value:"https",label:n("settings.network.protocol.https")},{value:"socks5",label:n("settings.network.protocol.socks5")}],Y="w-full rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white";function J(e){const a={},s=String(e.host||"").trim();(!s||/:\/\//.test(s)||s.includes("/"))&&(a.host=n("settings.network.error.host"));const i=String(e.port??"").trim(),o=Number(i);return(!i||!/^\d+$/.test(i)||!Number.isInteger(o)||o<1||o>65535)&&(a.port=n("settings.network.error.port")),a}function fn({proxySettings:e}){const{config:a,save:s,testConnection:i}=e,[o,r]=d.useState(()=>({mode:a.mode,protocol:a.protocol||"http",host:a.host||"",port:a.port||""})),[l,c]=d.useState({}),[u,h]=d.useState(!1),[p,g]=d.useState(""),[m,v]=d.useState(null),[k,P]=d.useState(!1),[y,w]=d.useState(null);d.useEffect(()=>{r({mode:a.mode,protocol:a.protocol||"http",host:a.host||"",port:a.port||""})},[a.mode,a.protocol,a.host,a.port]);const N=d.useMemo(()=>a.effective==="manual"?n("settings.network.effective.manual"):a.effective==="env"?n("settings.network.effective.env"):a.effective==="system"?n("settings.network.effective.system"):a.effective==="blocked"?n("settings.network.effective.blocked"):n("settings.network.effective.none"),[a.effective]),f=x=>{r(E=>({...E,...x})),c({}),g(""),v(null),w(null)},S=async()=>{if(o.mode==="manual"){const x=J(o);if(Object.keys(x).length){c(x);return}}h(!0),g(""),v(null);try{await s(o),g("saved")}catch(x){g("error"),v(x)}finally{h(!1)}},L=async()=>{const x=J(o);if(Object.keys(x).length){c(x);return}P(!0),w(null);try{const E=await i(o);w(E)}catch(E){w({ok:!1,error:E?.message||String(E)})}finally{P(!1)}};return t.jsxs(O,{title:n("settings.section.network"),subtitle:N,children:[a.applyError?t.jsx("p",{role:"alert",className:"mb-3 text-xs text-red-600 dark:text-red-400",children:n("settings.network.apply_error",{error:a.applyError})}):null,t.jsx(b,{label:n("settings.network.mode.label"),hint:n("settings.network.mode.hint"),control:t.jsx(T,{options:mn(),value:o.mode,onChange:x=>f({mode:x})})}),t.jsx(se,{initial:!1,children:o.mode==="manual"?t.jsxs(ae.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:[t.jsx(b,{label:n("settings.network.protocol.label"),control:t.jsx(F,{value:o.protocol,onValueChange:x=>f({protocol:x}),options:bn(),ariaLabel:n("settings.network.protocol.label"),className:"px-2.5 py-1.5 text-xs font-medium"})}),t.jsx(b,{label:n("settings.network.host.label"),hint:l.host,control:t.jsx("input",{type:"text",value:o.host,onChange:x=>f({host:x.target.value}),placeholder:n("settings.network.host.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":l.host?!0:void 0,"aria-label":n("settings.network.host.label"),className:Y})}),t.jsx(b,{label:n("settings.network.port.label"),hint:l.port,control:t.jsx("input",{type:"text",inputMode:"numeric",value:o.port,onChange:x=>f({port:x.target.value}),placeholder:n("settings.network.port.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":l.port?!0:void 0,"aria-label":n("settings.network.port.label"),className:Y})}),t.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 py-3",children:[t.jsx("button",{type:"button",onClick:L,disabled:k||u,className:"rounded-md border border-oai-gray-200 px-3 py-1.5 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:k?n("settings.network.test.testing"):n("settings.network.test")}),t.jsx("button",{type:"button",onClick:S,disabled:u||k,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:u?n("settings.network.saving"):n("settings.network.save")})]}),y?t.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:y.ok?n("settings.network.test.ok",{status:String(y.status??"")}):n("settings.network.test.fail",{error:y.error||""})}):null]},"manual-proxy-fields"):t.jsx("div",{className:"flex justify-end py-3",children:t.jsx("button",{type:"button",onClick:S,disabled:u,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:u?n("settings.network.saving"):n("settings.network.save")})},"non-manual-save")}),p==="saved"?t.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:n("settings.network.saved")}):null,p==="error"?t.jsx("p",{role:"alert",className:"py-2 text-xs text-red-600 dark:text-red-400",children:m?.unprotected?n("settings.network.save_error_unprotected",{error:m?.message||String(m||"")}):n("settings.network.save_error",{error:m?.message||String(m||"")})}):null]})}const he="/functions/tokentracker-proxy-config",xn="/functions/tokentracker-proxy-test",yn={mode:"system",protocol:"http",host:"",port:"",effective:"none",applyError:null};function me(e){return!e||typeof e.mode!="string"?null:{mode:e.mode,protocol:typeof e.protocol=="string"?e.protocol:"http",host:typeof e.host=="string"?e.host:"",port:e.port==null||e.port===0?"":String(e.port),effective:typeof e.effective=="string"?e.effective:"none",applyError:typeof e.applyError=="string"&&e.applyError.trim()?e.applyError:null}}async function vn(){const e=await fetch(he,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!e.ok)return null;const a=await e.json().catch(()=>null);return me(a)}async function Q(){const{getLocalApiAuthHeaders:e}=await Ve(async()=>{const{getLocalApiAuthHeaders:a}=await import("./__vite-browser-external-BW1rxvYq.js").then(s=>s.dg);return{getLocalApiAuthHeaders:a}},__vite__mapDeps([0,1]));return e()}function kn(){const[e,a]=d.useState(!1),[s,i]=d.useState(!0),[o,r]=d.useState(yn);d.useEffect(()=>{if(!pt()){a(!1),i(!1);return}let u=!1;return(async()=>{try{const h=await vn();if(u)return;if(!h){a(!1),i(!1);return}r(h),a(!0),i(!1)}catch{u||(a(!1),i(!1))}})(),()=>{u=!0}},[]);const l=d.useCallback(async u=>{const h=await Q(),p=await fetch(he,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...h},cache:"no-store",body:JSON.stringify({mode:u.mode,protocol:u.protocol,host:u.host,port:u.port===""?0:Number(u.port)})}),g=await p.json().catch(()=>null);if(!p.ok){const v=g&&typeof g.error=="string"?g.error:`HTTP ${p.status}`;throw new Error(v)}const m=me(g);if(m&&r(m),g&&g.ok===!1){const v=g&&typeof g.applyError=="string"&&g.applyError||g&&typeof g.error=="string"&&g.error||`HTTP ${p.status}`,k=new Error(v);throw g.unprotected===!0&&(k.unprotected=!0),k}return m||g},[]),c=d.useCallback(async u=>{const h=await Q(),p=await fetch(xn,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...h},cache:"no-store",body:JSON.stringify({protocol:u.protocol,host:u.host,port:u.port===""?0:Number(u.port)})}),g=await p.json().catch(()=>null);if(!g||typeof g.ok!="boolean")throw new Error(g&&typeof g.error=="string"?g.error:`HTTP ${p.status}`);return g},[]);return{available:e,loading:s,config:o,save:l,testConnection:c}}const C={APPEARANCE:"appearance",NATIVE_APP:"native-app",NETWORK:"network",ACCOUNT:"account",LIMITS:"limits",LABS:"labs"},A={PERSONAL:"personal",APP:"app",DEVELOPER:"developer"};function jn({prefs:e}){return t.jsx(T,{options:[{value:Z.USED,label:n("limits.settings.display_mode_used")},{value:Z.REMAINING,label:n("limits.settings.display_mode_remaining")}],value:e.displayMode,onChange:e.setDisplayMode})}function qn(){const e=ot(),{available:a,settings:s,setSetting:i}=R(),o=kn(),{available:r}=o,l=s?.toastOnReset!==!1,c=s?.confettiOnReset!==!1,u=ne()||s?.platform==="windows",[h,p]=Be(),g=ze(),m=h.get("section"),k=Object.values(C).includes(m)&&(m!==C.NATIVE_APP||a)&&(m!==C.NETWORK||r)?m:C.APPEARANCE,P=f=>{const S=new URLSearchParams(h);f===C.APPEARANCE?S.delete("section"):S.set("section",f),p(S,{replace:!0})},y=[{id:C.APPEARANCE,label:n("settings.section.appearance"),description:n("settings.section.appearance.description"),group:A.PERSONAL,Icon:wt,content:t.jsx(un,{})},...a?[{id:C.NATIVE_APP,label:n("settings.section.menubar"),description:n("settings.section.menubar.description"),group:A.APP,Icon:te,content:t.jsx(gn,{})}]:[],...r?[{id:C.NETWORK,label:n("settings.section.network"),description:n("settings.section.network.description"),group:A.APP,Icon:Ke,content:t.jsx(fn,{proxySettings:o})}]:[],{id:C.ACCOUNT,label:n("settings.section.account"),description:n("settings.section.account.description"),group:A.PERSONAL,Icon:Nt,content:t.jsx(Yt,{})},{id:C.LIMITS,label:n("settings.section.limits"),description:n("settings.section.limits.description"),group:A.APP,Icon:qe,content:t.jsxs("div",{className:"space-y-4",children:[t.jsxs(O,{title:n("settings.section.limits"),children:[t.jsx(b,{label:n("limits.settings.display_mode_label"),control:t.jsx(jn,{prefs:e})}),u?null:t.jsxs(t.Fragment,{children:[t.jsx(b,{label:n("settings.menubar.toastOnReset"),hint:n("settings.menubar.toastOnResetHint"),control:t.jsx(j,{checked:l,disabled:!a,onChange:()=>i("toastOnReset",!l),ariaLabel:n("settings.menubar.toastOnReset")})}),t.jsx(b,{label:n("settings.menubar.confettiOnReset"),hint:n("settings.menubar.confettiOnResetHint"),control:t.jsx(j,{checked:c,disabled:!a,onChange:()=>i("confettiOnReset",!c),ariaLabel:n("settings.menubar.confettiOnReset")})})]}),t.jsx(b,{label:n("settings.limits.showSubscriptions"),hint:n("settings.limits.showSubscriptionsHint"),control:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{type:"button",onClick:()=>g("/limits?openSubscriptions=1"),"aria-label":n("limits.page.openSubscriptions"),title:n("limits.page.openSubscriptions"),className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:t.jsx(We,{size:14,"aria-hidden":!0})}),t.jsx(j,{checked:e.showSubscriptions!==!1,onChange:()=>e.setShowSubscriptions(!e.showSubscriptions),ariaLabel:n("settings.limits.showSubscriptions")})]})})]}),t.jsx(O,{title:n("settings.limits.providers"),children:t.jsx(Pt,{prefs:e})})]})},{id:C.LABS,label:n("settings.section.labs"),description:n("settings.section.labs.description"),group:A.DEVELOPER,Icon:vt,content:t.jsx(dn,{})}],w=[{id:A.PERSONAL,label:n("settings.nav.group.personal")},{id:A.APP,label:n("settings.nav.group.app")},{id:A.DEVELOPER,label:n("settings.nav.group.developer")}].map(f=>({...f,sections:y.filter(S=>S.group===f.id)})).filter(f=>f.sections.length>0);let N=y[0];for(const f of y)if(f.id===k){N=f;break}return t.jsx("div",{className:"flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",children:t.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:t.jsxs("div",{className:"mx-auto w-full max-w-5xl px-4 sm:px-6",children:[t.jsxs("div",{className:"mb-7 max-w-2xl",children:[t.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:n("settings.page.title")}),t.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:n("settings.page.subtitle")})]}),t.jsxs("div",{className:"grid min-w-0 gap-6 md:grid-cols-[14rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[15rem_minmax(0,1fr)]",children:[t.jsx("aside",{className:"min-w-0 rounded-xl border border-oai-gray-200 bg-oai-gray-50/70 p-2 dark:border-oai-gray-800 dark:bg-oai-gray-900/60 md:border-0 md:bg-transparent md:p-0 md:dark:bg-transparent",children:t.jsx("nav",{"aria-label":n("settings.page.title"),className:"flex gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden md:sticky md:top-6 md:flex-col md:gap-4 md:overflow-visible",children:w.map(({id:f,label:S,sections:L})=>t.jsxs("div",{className:"flex shrink-0 gap-1 md:block",children:[t.jsx("div",{className:"hidden px-3 pb-1 text-[10px] font-semibold uppercase tracking-[0.16em] text-oai-gray-400 dark:text-oai-gray-500 md:block",children:S}),t.jsx("div",{className:"flex gap-1 md:flex-col",children:L.map(({id:x,label:E,Icon:D})=>{const G=k===x;return t.jsxs("button",{id:`settings-nav-${x}`,type:"button","aria-current":G?"page":void 0,"aria-controls":`settings-panel-${x}`,onClick:()=>P(x),className:_("inline-flex min-h-10 min-w-max shrink-0 items-center gap-1.5 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand-500 md:w-full md:min-w-0 md:gap-2 md:px-3",G?"bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-white":"text-oai-gray-500 hover:bg-oai-gray-50 hover:text-oai-gray-900 dark:text-oai-gray-400 dark:hover:bg-oai-gray-900 dark:hover:text-oai-gray-200"),children:[t.jsx(D,{className:_("h-4 w-4 shrink-0",G?"text-oai-black dark:text-white":"text-oai-gray-400 dark:text-oai-gray-500"),"aria-hidden":!0}),t.jsx("span",{className:"truncate",children:E})]},x)})})]},f))})}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"mb-4 border-b border-oai-gray-200 pb-4 dark:border-oai-gray-800",children:[t.jsx("h2",{className:"text-xl font-semibold tracking-tight text-oai-black dark:text-white",children:N.label}),t.jsx("p",{className:"mt-1 text-sm leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:N.description})]}),y.map(({id:f,label:S,content:L})=>t.jsx("section",{id:`settings-panel-${f}`,"aria-labelledby":`settings-nav-${f}`,"aria-label":S,"data-settings-panel":f,hidden:k!==f,children:L},f)),t.jsx(hn,{})]})]})]})})})}export{qn as SettingsPage};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-Cj9D7QBh.js","assets/__vite-browser-external-gKkiQad5.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{q as I,j as t,e as _,c as n,a as ye,r as d,at as ve,az as ke,aA as je,a9 as X,aY as Se,aZ as we,a_ as Ne,u as Ce,d as H,a2 as Ee,J as ee,n as U,a$ as V,m as B,b0 as Ae,b1 as Pe,Z as te,b2 as Oe,t as Le,b3 as _e,b4 as Te,b5 as Ie,b6 as Ge,b7 as Re,b8 as De,b9 as Ue,ba as ne,L as Me,R as He,bb as Fe,bc as $e,ak as z,_ as Ve,h as Be,f as ze,bd as Ke,be as qe,aD as We}from"./__vite-browser-external-Cj9D7QBh.js";import{a as Ze,b as K,s as Ye,K as Je,P as Qe,D as Xe,c as et,S as tt,v as nt,u as at,C as st}from"./sortable.esm-O7ntEYCi.js";import{a as it}from"./modifiers.esm-B7hOvflM.js";import{d as q,l as W,u as ot,b as Z}from"./use-limits-display-prefs-Drs82lSi.js";import{P as rt}from"./ProviderIcon-BTYVbUti.js";import{m as ae}from"./react-CfB5zBqR.js";import{a as O,T as j,b,S as T,u as R}from"./Controls-BgQflA-3.js";import{P as lt,u as ct,a as ut}from"./use-session-efficiency-pref-BiYRXVlN.js";import{C as dt}from"./check-DhEiHlwq.js";import{C as gt,i as pt}from"./host-mode-APftzzvz.js";import{A as se}from"./index-D2g1tPGl.js";import{u as ht}from"./useCurrency-CaOhUMcm.js";import{u as mt}from"./useTokenFormat-JjQCKdIr.js";import{S as F}from"./Select-D8N2TJz1.js";import{I as bt}from"./info-Qgc5VctK.js";import{C as ft}from"./ConfirmModal-Dhu_qmiM.js";import{A as xt}from"./arrow-up-right-CdzAw406.js";import{D as yt}from"./download-kGPw24XQ.js";import"./Card-dqzakOoX.js";import"./SelectItemText-CoTR0Uwm.js";import"./composite-DO7_ilHE.js";import"./DialogTitle-C8vpXqg8.js";import"./store-D-FZbBaC.js";import"./DialogDescription-h6XMtzIU.js";const ie={name:"flask-conical",size:24,node:[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]]};ie.node;const vt=I(ie);const oe={name:"grip-vertical",size:24,node:[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]};oe.node;const kt=I(oe);const re={name:"languages",size:24,node:[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]};re.node;const jt=I(re);const le={name:"log-out",size:24,node:[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]]};le.node;const St=I(le);const ce={name:"palette",size:24,node:[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]]};ce.node;const wt=I(ce);const ue={name:"user-round",size:24,node:[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],aliases:["user-2"]};ue.node;const Nt=I(ue),Ct="shrink-0 text-oai-gray-900 dark:text-oai-gray-200";function Et({checked:e,onChange:a,ariaLabel:s}){return t.jsx("button",{type:"button",role:"switch","aria-checked":e,"aria-label":s,onClick:a,className:_("relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",e?"bg-oai-brand-500":"bg-oai-gray-300 dark:bg-oai-gray-700"),children:t.jsx("span",{className:_("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",e?"translate-x-[18px]":"translate-x-[3px]")})})}function At({id:e,visible:a,onToggle:s}){const{attributes:i,listeners:o,setNodeRef:r,transform:l,transition:c,isDragging:u}=at({id:e}),h={transform:st.Transform.toString(l)||void 0,transition:c,zIndex:u?20:void 0};return t.jsxs("div",{ref:r,style:h,className:_("flex items-center gap-3 py-2 rounded-md select-none touch-none","cursor-grab active:cursor-grabbing","hover:bg-oai-gray-100/60 dark:hover:bg-oai-gray-800/60","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",u&&"relative bg-oai-gray-100 dark:bg-oai-gray-800"),...i,...o,children:[t.jsx(kt,{className:"h-4 w-4 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",strokeWidth:1.75,"aria-hidden":!0}),q(e)?t.jsx(rt,{provider:q(e),size:18,className:_("pointer-events-none",Ct)}):null,t.jsx("span",{className:"flex-1 text-sm text-oai-gray-900 dark:text-oai-gray-200",children:W(e)}),t.jsx("div",{onPointerDown:p=>p.stopPropagation(),children:t.jsx(Et,{checked:a,onChange:s,ariaLabel:`${n("limits.settings.toggle_visible")}: ${W(e)}`})})]})}function Pt({prefs:e}){const{order:a,visibility:s,toggle:i,moveToward:o}=e,r=Ze(K(Qe,{activationConstraint:{distance:6}}),K(Je,{coordinateGetter:Ye})),l=({active:c,over:u})=>{u&&c.id!==u.id&&o(c.id,u.id)};return t.jsx(Xe,{sensors:r,collisionDetection:et,modifiers:[it],onDragEnd:l,children:t.jsx(tt,{items:a,strategy:nt,children:t.jsx("div",{className:"flex flex-col",children:a.map(c=>t.jsx(At,{id:c,visible:s[c]!==!1,onToggle:()=>i(c)},c))})})})}function Ot(e){if(!e||typeof e!="object")return"";const a=e.user_metadata&&typeof e.user_metadata=="object"?e.user_metadata:{},s=e.profile&&typeof e.profile=="object"?e.profile:{},i=a.full_name||a.name||s.name||a.user_name||a.preferred_username;return typeof i=="string"&&i.trim()?i.trim():typeof e.email=="string"&&e.email.includes("@")?e.email.split("@")[0].trim()||e.email.trim():typeof e.email=="string"?e.email.trim():""}function Lt(e){return!e||typeof e!="object"?"":typeof e.email=="string"?e.email.trim():""}function _t(e){const a=typeof e=="string"?e.trim():"";if(!a)return null;const s=a.match(/^@?([A-Za-z0-9][A-Za-z0-9-]{0,38})$/),i=a.match(/^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/?$/i),o=s?.[1]||i?.[1];return o?`https://github.com/${o}`:null}function $(e,a){console.warn(`[tokentracker] settings ${e}:`,a)}function Tt(e,a,s){const[i,o]=d.useState(()=>ve()),r=a&&s&&Ne(),l=d.useCallback(async()=>{const c=!i;if(ke(c),o(c),!!c)try{await je(()=>e())}catch(u){$("cloud sync",u)}},[i,e]);return{cloudSyncOn:i,handleCloudSyncToggle:l,showLocalCloudSync:r}}function It(e){const[a,s]=d.useState(!1),[i,o]=d.useState(!1),[r,l]=d.useState(!1),[c,u]=d.useState(!1),[h,p]=d.useState(null),[g,m]=d.useState(!1),[v,k]=d.useState(""),[P,y]=d.useState(!1),[w,N]=d.useState(""),[f,S]=d.useState(""),[L,x]=d.useState(!1),[E,D]=d.useState(null),G=d.useMemo(()=>Ot(e),[e]),be=d.useMemo(()=>Lt(e),[e]),fe=d.useMemo(()=>typeof e?.id=="string"?e.id.trim():"",[e]),xe=d.useMemo(()=>({setAnonymousOn:o,setCustomDisplayName:p,setGithubUrl:N,setProfileLoading:l,setPublicProfileOn:s,setShowGithubOn:y}),[]);return{anonymousOn:i,customDisplayName:h,displayName:G,editingGithub:L,editingName:g,email:be,githubError:E,githubInput:f,githubUrl:w,loadSetters:xe,nameInput:v,profileLoading:r,profileSaving:c,publicProfileOn:a,setAnonymousOn:o,setCustomDisplayName:p,setEditingGithub:x,setEditingName:m,setGithubError:D,setGithubInput:S,setGithubUrl:N,setNameInput:k,setProfileLoading:l,setProfileSaving:u,setPublicProfileOn:s,setShowGithubOn:y,showGithubOn:P,userId:fe}}function Gt(e,a,s){d.useEffect(()=>{if(!a)return;let i=!0;return s.setProfileLoading(!0),(async()=>{try{const o=await X({getAccessToken:e});if(!i||!o)return;const r=await Se({accessToken:o});if(!i)return;s.setPublicProfileOn(!!r?.enabled),s.setAnonymousOn(!!r?.anonymous),r?.display_name&&s.setCustomDisplayName(r.display_name),s.setShowGithubOn(!!r?.show_github_url),s.setGithubUrl(r?.github_url||"")}catch(o){$("load public profile",o)}finally{i&&s.setProfileLoading(!1)}})(),()=>{i=!1}},[e,a,s])}function Rt(e,a){return d.useCallback(async(s,{label:i,onError:o,onSuccess:r}={})=>{if(a.profileSaving)return!1;a.setProfileSaving(!0);try{const l=await X({getAccessToken:e});if(!l)return!1;const c=await we({accessToken:l,...s});return r?.(c),!0}catch(l){return o?o(l):$(i||"mutate profile",l),!1}finally{a.setProfileSaving(!1)}},[e,a])}function Dt(e,a){return{anonymousOn:e.anonymousOn,customDisplayName:e.customDisplayName,displayName:e.displayName,editingName:e.editingName,handleAnonymousToggle:a.handleAnonymousToggle,handleSaveName:a.handleSaveName,nameInput:e.nameInput,profileLoading:e.profileLoading,profileSaving:e.profileSaving,setEditingName:e.setEditingName,setNameInput:e.setNameInput,startEditingName:a.startEditingName}}function Ut(e,a){return{editingGithub:e.editingGithub,githubError:e.githubError,githubInput:e.githubInput,githubUrl:e.githubUrl,handleSaveGithub:a.handleSaveGithub,handleShowGithubToggle:a.handleShowGithubToggle,profileLoading:e.profileLoading,profileSaving:e.profileSaving,setEditingGithub:e.setEditingGithub,setGithubError:e.setGithubError,setGithubInput:e.setGithubInput,showGithubOn:e.showGithubOn,startEditingGithub:a.startEditingGithub}}function Mt(e,a){const s=d.useCallback(async()=>{const o=!e.publicProfileOn;await a({enabled:o},{label:"toggle public profile",onSuccess:()=>e.setPublicProfileOn(o)})},[a,e]);return{handleAnonymousToggle:d.useCallback(async()=>{const o=!e.anonymousOn;await a({anonymous:o},{label:"toggle anonymous",onSuccess:()=>e.setAnonymousOn(o)})},[a,e]),handlePublicProfileToggle:s}}function Ht(e,a,s){const i=d.useCallback(async()=>{const r=e.nameInput.trim().slice(0,50);r&&await a({display_name:r},{label:"save display name",onSuccess:()=>{e.setCustomDisplayName(r),e.setEditingName(!1),s?.()}})},[a,e,s]),o=d.useCallback(()=>{e.setNameInput(e.customDisplayName||e.displayName),e.setEditingName(!0)},[e]);return{handleSaveName:i,startEditingName:o}}function Ft(e,a){const s=d.useCallback(async()=>{if(!e.showGithubOn&&!e.githubUrl){e.setEditingGithub(!0),e.setGithubInput(""),e.setGithubError(null);return}const r=!e.showGithubOn;await a({show_github_url:r},{label:"toggle GitHub profile",onSuccess:()=>e.setShowGithubOn(r)})},[a,e]),i=d.useCallback(async()=>{const r=_t(e.githubInput);if(e.githubInput.trim()&&!r){e.setGithubError(n("settings.account.githubUrlInvalid"));return}e.setGithubError(null),await a({github_url:r,show_github_url:!!r},{label:"save GitHub profile",onError:l=>e.setGithubError(l?.message||n("settings.account.githubUrlInvalid")),onSuccess:l=>{e.setGithubUrl(l?.github_url||r||""),e.setShowGithubOn(!!r),e.setEditingGithub(!1)}})},[a,e]),o=d.useCallback(()=>{e.setGithubInput(e.githubUrl),e.setGithubError(null),e.setEditingGithub(!0)},[e]);return{handleSaveGithub:i,handleShowGithubToggle:s,startEditingGithub:o}}function $t(){const e=ye(),a=It(e.user),s=Tt(e.getAccessToken,e.enabled,e.signedIn);Gt(e.getAccessToken,e.signedIn,a.loadSetters);const i=Rt(e.getAccessToken,a),o=Mt(a,i),r=Ht(a,i,e.refreshDisplayName),l=Ft(a,i);return{...e,...s,email:a.email,handlePublicProfileToggle:o.handlePublicProfileToggle,userId:a.userId,name:Dt(a,{...o,...r}),github:Ut(a,l),profileLoading:a.profileLoading,profileSaving:a.profileSaving,publicProfileOn:a.publicProfileOn}}function de({disabled:e,onCancel:a,onSave:s,saveLabel:i=n("settings.account.save")}){return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:s,disabled:e,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:i}),t.jsx("button",{type:"button",onClick:a,className:"rounded-md px-2 py-1.5 text-xs text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:n("settings.account.cancel")})]})}function Vt({nameInput:e,setEditingName:a,setNameInput:s,profileSaving:i,handleSaveName:o}){return t.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[t.jsx("input",{type:"text",value:e,onChange:r=>s(r.target.value),onKeyDown:r=>{r.key==="Enter"&&o(),r.key==="Escape"&&a(!1)},maxLength:50,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:n("settings.account.displayName")}),t.jsx(de,{disabled:i||!e.trim(),onCancel:()=>a(!1),onSave:o,saveLabel:i?n("settings.account.saving"):void 0})]})}function Bt({githubError:e,githubInput:a,handleSaveGithub:s,profileSaving:i,setEditingGithub:o,setGithubError:r,setGithubInput:l}){return t.jsxs("div",{className:"mt-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{type:"text",value:a,onChange:c=>{l(c.target.value),e&&r(null)},onKeyDown:c=>{c.key==="Enter"&&s(),c.key==="Escape"&&(o(!1),r(null))},maxLength:100,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:n("settings.account.githubUrlPlaceholder")}),t.jsx(de,{disabled:i,onCancel:()=>{o(!1),r(null)},onSave:s,saveLabel:i?n("settings.account.saving"):void 0})]}),e?t.jsx("div",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400",children:e}):null]})}function ge({disabled:e=!1,label:a,onClick:s,title:i}){return t.jsxs("button",{type:"button",onClick:s,disabled:e,title:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-40 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[t.jsx(lt,{className:"h-3.5 w-3.5","aria-hidden":!0}),a]})}function pe({actions:e,editing:a,editor:s,hint:i,label:o}){return t.jsx("div",{className:"py-3",children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:o}),a?s:t.jsx("div",{className:"mt-0.5 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:i})]}),a?null:e]})})}function zt({name:e}){const a=e.anonymousOn?n("settings.account.displayNameDisabledWhileAnon"):void 0;return t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx(ge,{disabled:e.anonymousOn,label:n("settings.account.edit"),onClick:e.startEditingName,title:a}),t.jsx(j,{checked:!e.anonymousOn,onChange:e.handleAnonymousToggle,disabled:e.profileLoading||e.profileSaving,ariaLabel:n("settings.account.displayName")})]})}function Kt({name:e}){const{anonymousOn:a,customDisplayName:s,displayName:i,editingName:o,handleAnonymousToggle:r,handleSaveName:l,nameInput:c,profileLoading:u,profileSaving:h,setEditingName:p,setNameInput:g,startEditingName:m}=e,v=a?n("settings.account.displayNameAnonymousHint"):s||i;return t.jsx(pe,{label:n("settings.account.displayName"),editing:o,hint:v,editor:t.jsx(Vt,{nameInput:c,setEditingName:p,setNameInput:g,profileSaving:h,handleSaveName:l}),actions:t.jsx(zt,{name:e})})}function qt({github:e}){const{editingGithub:a,githubError:s,githubInput:i,githubUrl:o,handleSaveGithub:r,handleShowGithubToggle:l,profileLoading:c,profileSaving:u,setEditingGithub:h,setGithubError:p,setGithubInput:g,showGithubOn:m,startEditingGithub:v}=e;return t.jsx(t.Fragment,{children:t.jsx(pe,{label:n("settings.account.githubUrl"),editing:a,hint:o||n("settings.account.githubUrlHint"),editor:t.jsx(Bt,{githubError:s,githubInput:i,handleSaveGithub:r,profileSaving:u,setEditingGithub:h,setGithubError:p,setGithubInput:g}),actions:t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx(ge,{label:n("settings.account.edit"),onClick:v}),t.jsx(j,{checked:m,onChange:l,disabled:c||u,ariaLabel:n("settings.account.githubUrl")})]})})})}function Wt(){const{openLoginModal:e}=Ce();return t.jsx(O,{title:n("settings.section.account"),children:t.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[t.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:n("settings.account.signedOutHint")}),t.jsx("button",{type:"button",onClick:e,className:"inline-flex h-8 shrink-0 items-center justify-center rounded-md bg-oai-gray-900 px-4 text-xs font-medium text-white transition-colors hover:bg-oai-gray-800 dark:bg-white dark:text-oai-gray-900 dark:hover:bg-oai-gray-100",children:n("settings.account.signIn")})]})})}function Zt({name:e,github:a}){return t.jsxs(t.Fragment,{children:[t.jsx(Kt,{name:e}),t.jsx(qt,{github:a})]})}function Yt(){const e=$t();return e.enabled?e.signedIn?t.jsxs(O,{title:n("settings.section.account"),subtitle:e.email||e.name.customDisplayName||e.name.displayName,action:t.jsx(Qt,{onSignOut:e.signOut}),children:[t.jsx(Jt,{userId:e.userId}),t.jsx(Xt,{settings:e}),t.jsx(en,{checked:e.publicProfileOn,disabled:e.profileLoading||e.profileSaving,onChange:e.handlePublicProfileToggle}),t.jsx(tn,{visible:e.publicProfileOn,name:e.name,github:e.github})]}):t.jsx(Wt,{}):null}function Jt({userId:e}){const[a,s]=H.useState(!1);if(!e)return null;const i=async()=>{try{if(typeof navigator>"u"||!navigator.clipboard?.writeText)return;await navigator.clipboard.writeText(e),s(!0),globalThis.setTimeout(()=>s(!1),1200)}catch{s(!1)}};return t.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:n("settings.account.userId")}),t.jsx("div",{className:"mt-0.5 truncate font-mono text-xs text-oai-gray-500 dark:text-oai-gray-400",children:e})]}),t.jsxs("button",{type:"button",onClick:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800","aria-label":n("settings.account.copyUserId"),children:[a?t.jsx(dt,{className:"h-3.5 w-3.5","aria-hidden":!0}):t.jsx(gt,{className:"h-3.5 w-3.5","aria-hidden":!0}),a?n("settings.account.copied"):n("settings.account.copy")]})]})}function Qt({onSignOut:e}){return t.jsxs("button",{type:"button",onClick:()=>e(),className:"inline-flex h-7 items-center gap-1.5 text-xs font-medium text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:[t.jsx(St,{className:"h-3.5 w-3.5","aria-hidden":!0}),n("settings.account.signOut")]})}function Xt({settings:e}){return e.showLocalCloudSync?t.jsx(b,{label:n("settings.account.cloudSync"),hint:n("settings.account.cloudSyncHint"),control:t.jsx(j,{checked:e.cloudSyncOn,onChange:e.handleCloudSyncToggle,ariaLabel:n("settings.account.cloudSync")})}):null}function en({checked:e,disabled:a,onChange:s}){return t.jsx(b,{label:n("settings.account.publicProfile"),hint:n("settings.account.publicProfileHint"),control:t.jsx(j,{checked:e,onChange:s,disabled:a,ariaLabel:n("settings.account.publicProfile")})})}function tn({visible:e,name:a,github:s}){return t.jsx(se,{initial:!1,children:e?t.jsx(ae.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:t.jsx(Zt,{name:a,github:s})},"public-profile-fields"):null})}function nn(){return[{value:"light",label:n("settings.appearance.theme.light"),Icon:Ae},{value:"dark",label:n("settings.appearance.theme.dark"),Icon:Pe},{value:"system",label:n("settings.appearance.theme.system"),Icon:te}]}function an(){return[{value:_e,label:n("settings.appearance.language.system")},{value:Te,label:n("settings.appearance.language.english")},{value:Ie,label:n("settings.appearance.language.chinese")},{value:Ge,label:n("settings.appearance.language.traditional_chinese")},{value:Re,label:n("settings.appearance.language.japanese")},{value:De,label:n("settings.appearance.language.korean")},{value:Ue,label:n("settings.appearance.language.german")}]}function sn(e){if(!e)return null;try{const a=new Date(e);return Number.isNaN(a.getTime())?null:a.toLocaleString()}catch{return null}}function on(e,a){const s=n(`settings.appearance.currency.rate_source.${e}`),i=sn(a),o=i?n("settings.appearance.currency.rate_updated",{when:i}):n("settings.appearance.currency.rate_never");return`${s} · ${o}`}function rn({locale:e,setLocale:a}){const s=an();return t.jsx(F,{value:e,onValueChange:a,options:s,ariaLabel:n("settings.appearance.language.label"),className:"px-2.5 py-1.5 text-xs font-medium",leadingIcon:t.jsx(jt,{className:"h-3.5 w-3.5 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})})}function ln({currency:e,setCurrency:a}){const s=Oe().map(i=>({value:i.code,label:n(i.labelKey)}));return t.jsx(F,{value:e,onValueChange:a,options:s,ariaLabel:n("settings.appearance.currency.label"),className:"px-3 py-1.5 text-xs font-medium"})}function cn({currency:e,rate:a,rateSource:s,rateFetchedAt:i}){if(e===Le)return t.jsx(t.Fragment,{children:n("settings.appearance.currency.hint")});const o=on(s,i);return t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx("span",{children:`1 USD = ${a.toFixed(4)} ${e}`}),t.jsx("span",{role:"img","aria-label":o,title:o,className:"inline-flex h-4 w-4 cursor-help items-center justify-center text-oai-gray-400 hover:text-oai-gray-600 dark:text-oai-gray-500 dark:hover:text-oai-gray-300",children:t.jsx(bt,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function un(){const{theme:e,setTheme:a}=Ee(),{locale:s,setLocale:i}=ee(),{currency:o,rate:r,rateSource:l,rateFetchedAt:c,setCurrency:u}=ht(),{mode:h,setMode:p,unitSystem:g,setUnitSystem:m,grouping:v,setGrouping:k}=mt();return t.jsxs(O,{title:n("settings.section.appearance"),children:[t.jsx(b,{label:n("settings.appearance.theme.label"),hint:n("settings.appearance.theme.hint"),control:t.jsx(T,{options:nn(),value:e,onChange:a})}),t.jsx(b,{label:n("settings.appearance.language.label"),hint:n("settings.appearance.language.hint"),control:t.jsx(rn,{locale:s,setLocale:i})}),t.jsx(b,{label:n("settings.appearance.currency.label"),hint:t.jsx(cn,{currency:o,rate:r,rateSource:l,rateFetchedAt:c}),control:t.jsx(ln,{currency:o,setCurrency:u})}),t.jsx(b,{label:n("settings.appearance.token_format.label"),hint:n("settings.appearance.token_format.hint"),control:t.jsx(T,{options:[{value:U.COMPACT,label:n("settings.appearance.token_format.compact")},{value:U.FULL,label:n("settings.appearance.token_format.full")}],value:h,onChange:p})}),t.jsx(b,{label:n("settings.appearance.token_unit.label"),hint:n("settings.appearance.token_unit.hint"),control:t.jsx(T,{disabled:h!==U.COMPACT,options:[{value:V.ENGLISH,label:n("settings.appearance.token_unit.english")},{value:V.CHINESE,label:n("settings.appearance.token_unit.chinese")}],value:g,onChange:m})}),t.jsx(b,{label:n("settings.appearance.token_grouping.label"),hint:n("settings.appearance.token_grouping.hint"),control:t.jsx(T,{options:[{value:B.THOUSAND,label:n("settings.appearance.token_grouping.thousand")},{value:B.WAN,label:n("settings.appearance.token_grouping.wan")}],value:v,onChange:k})})]})}function M({labelKey:e}){return t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{children:n(e)}),t.jsx("span",{className:"px-1.5 py-0.5 text-[8px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase scale-90 origin-left",children:n("qpd.card.badge")})]})}function dn(){const{enabled:e,toggle:a}=ct(),{enabled:s,toggle:i}=ut(),{available:o,settings:r,setSetting:l}=R(),c=o&&!!r?.dynamicIslandSupported,u=!!r?.dynamicIslandEnabled;return t.jsxs(O,{title:n("settings.section.labs"),children:[c&&t.jsxs(t.Fragment,{children:[t.jsx(b,{label:t.jsx(M,{labelKey:"settings.labs.island.label"}),hint:n("settings.labs.island.hint"),control:t.jsx(j,{checked:u,onChange:()=>l("dynamicIslandEnabled",!u),ariaLabel:n("settings.labs.island.aria")})}),u&&t.jsx(b,{label:n("settings.labs.island_hide_menubar.label"),hint:n("settings.labs.island_hide_menubar.hint"),control:t.jsx(j,{checked:!!r?.hideMenuBarIcon,onChange:()=>l("hideMenuBarIcon",!r?.hideMenuBarIcon),ariaLabel:n("settings.labs.island_hide_menubar.aria")})})]}),t.jsx(b,{label:t.jsx(M,{labelKey:"settings.labs.qpd.label"}),hint:n("settings.labs.qpd.hint"),control:t.jsx(j,{checked:e,onChange:a,ariaLabel:n("settings.labs.qpd.aria")})}),t.jsx(b,{label:t.jsx(M,{labelKey:"settings.labs.sessions.label"}),hint:n("settings.labs.sessions.hint"),control:t.jsx(j,{checked:s,onChange:i,ariaLabel:n("settings.labs.sessions.aria")})})]})}function gn(){const{available:e,settings:a,setSetting:s,runAction:i}=R();if(!e)return null;const o=ne(),r=!!a?.launchAtLogin,l=a?.toastOnReset!==!1,c=a?.confettiOnReset!==!1,u=a?.launchAtLoginSupported!==!1,h=a?.autoUpdateEnabled!==!1,p=a?.updateStatus||null,g=!!a?.updateBusy,m=!!a?.isSyncing;return t.jsxs(O,{title:n("settings.section.menubar"),children:[o?null:t.jsxs(t.Fragment,{children:[t.jsx(b,{label:n("settings.menubar.appearance"),hint:n("settings.menubar.appearanceHint"),control:t.jsxs(Me,{to:"/widgets",className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 no-underline transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[n("settings.menubar.appearanceLink"),t.jsx(xt,{className:"h-3.5 w-3.5","aria-hidden":!0})]})}),t.jsx(b,{label:n("settings.menubar.toastOnReset"),hint:n("settings.menubar.toastOnResetHint"),control:t.jsx(j,{checked:l,onChange:()=>s("toastOnReset",!l),ariaLabel:n("settings.menubar.toastOnReset")})}),t.jsx(b,{label:n("settings.menubar.confettiOnReset"),hint:n("settings.menubar.confettiOnResetHint"),control:t.jsx(j,{checked:c,onChange:()=>s("confettiOnReset",!c),ariaLabel:n("settings.menubar.confettiOnReset")})})]}),u?t.jsx(b,{label:n("settings.menubar.launchAtLogin"),hint:n("settings.menubar.launchAtLoginHint"),control:t.jsx(j,{checked:r,onChange:()=>s("launchAtLogin",!r),ariaLabel:n("settings.menubar.launchAtLogin")})}):null,t.jsx(b,{label:n("settings.menubar.syncNow"),hint:n("settings.menubar.syncNowHint"),control:t.jsxs("button",{type:"button",onClick:()=>i("syncNow"),disabled:m,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[t.jsx(He,{className:_("h-3.5 w-3.5",m&&"animate-spin"),"aria-hidden":!0}),m?n("settings.menubar.syncing"):n("settings.menubar.syncNow")]})}),t.jsx(b,{label:n("settings.menubar.autoUpdate"),hint:n("settings.menubar.autoUpdateHint"),control:t.jsx(j,{checked:h,onChange:()=>s("autoUpdateEnabled",!h),ariaLabel:n("settings.menubar.autoUpdate")})}),t.jsx(b,{label:n("settings.menubar.updates"),hint:p||void 0,control:t.jsxs("button",{type:"button",onClick:()=>i("checkForUpdates"),disabled:g,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[t.jsx(yt,{className:"h-3.5 w-3.5","aria-hidden":!0}),n("settings.menubar.checkUpdates")]})})]})}function pn(e,a){function s(r){return r.replace(/^v/,"").split(".").map(Number)}const i=s(e),o=s(a);for(let r=0;r<Math.max(i.length,o.length);r++){const l=i[r]||0,c=o[r]||0;if(l<c)return!0;if(l>c)return!1}return!1}function hn(){const{available:e,settings:a,runAction:s}=R(),i=e&&a?.version,o=a?.platform||"macos",[r,l]=H.useState(!1),[c,u]=H.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:h}=ee(),p="1.2.2",g=async()=>{l(!0);try{const y=await fetch("https://api.github.com/repos/xiufengsun/TokenTracker/releases/latest");if(!y.ok)throw new Error("Failed to fetch");const w=await y.json(),N=w.tag_name;pn(p,N)?u({open:!0,latestVersion:N,htmlUrl:w.html_url}):z({title:n("settings.menubar.updates.upToDate")})}catch(y){console.error("Check updates failed:",y),z({title:n("settings.menubar.updates.failed")})}finally{l(!1)}},m=n("settings.menubar.updates.modalTitle"),v=n("settings.menubar.updates.modalDescription",{version:c.latestVersion}),k=n("settings.menubar.updates.modalConfirm"),P=n("settings.menubar.updates.modalCancel");return t.jsxs("div",{className:"mt-6 flex flex-col items-center justify-center gap-4 text-xs text-oai-gray-500 dark:text-oai-gray-500",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[i?t.jsxs(t.Fragment,{children:[t.jsx("span",{children:o==="windows"?n("settings.menubar.updates.footerCore",{version:a.version}):n("settings.menubar.updates.footerCombined",{barVersion:a.version,coreVersion:p})}),t.jsx("span",{"aria-hidden":!0,children:"·"}),t.jsx("button",{type:"button",onClick:()=>s("openAbout"),className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:"GitHub"}),t.jsx("span",{"aria-hidden":!0,children:"·"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{children:n("settings.menubar.updates.footerCore",{version:p})}),t.jsx("span",{"aria-hidden":!0,children:"·"}),t.jsx("button",{type:"button",onClick:g,disabled:r,className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300 disabled:opacity-50",children:r?n("settings.menubar.updates.checking"):n("settings.menubar.checkUpdates")}),t.jsx("span",{"aria-hidden":!0,children:"·"})]}),t.jsxs("a",{href:Fe,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:[t.jsx($e,{className:"h-3.5 w-3.5","aria-hidden":!0}),n("settings.footer.statusPage")]})]}),t.jsx(ft,{open:c.open,title:m,description:v,confirmLabel:k,cancelLabel:P,onConfirm:()=>{window.open(c.htmlUrl,"_blank"),u(y=>({...y,open:!1}))},onCancel:()=>u(y=>({...y,open:!1}))})]})}const mn=()=>[{value:"system",label:n("settings.network.mode.system")},{value:"manual",label:n("settings.network.mode.manual")},{value:"off",label:n("settings.network.mode.off")}],bn=()=>[{value:"http",label:n("settings.network.protocol.http")},{value:"https",label:n("settings.network.protocol.https")},{value:"socks5",label:n("settings.network.protocol.socks5")}],Y="w-full rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white";function J(e){const a={},s=String(e.host||"").trim();(!s||/:\/\//.test(s)||s.includes("/"))&&(a.host=n("settings.network.error.host"));const i=String(e.port??"").trim(),o=Number(i);return(!i||!/^\d+$/.test(i)||!Number.isInteger(o)||o<1||o>65535)&&(a.port=n("settings.network.error.port")),a}function fn({proxySettings:e}){const{config:a,save:s,testConnection:i}=e,[o,r]=d.useState(()=>({mode:a.mode,protocol:a.protocol||"http",host:a.host||"",port:a.port||""})),[l,c]=d.useState({}),[u,h]=d.useState(!1),[p,g]=d.useState(""),[m,v]=d.useState(null),[k,P]=d.useState(!1),[y,w]=d.useState(null);d.useEffect(()=>{r({mode:a.mode,protocol:a.protocol||"http",host:a.host||"",port:a.port||""})},[a.mode,a.protocol,a.host,a.port]);const N=d.useMemo(()=>a.effective==="manual"?n("settings.network.effective.manual"):a.effective==="env"?n("settings.network.effective.env"):a.effective==="system"?n("settings.network.effective.system"):a.effective==="blocked"?n("settings.network.effective.blocked"):n("settings.network.effective.none"),[a.effective]),f=x=>{r(E=>({...E,...x})),c({}),g(""),v(null),w(null)},S=async()=>{if(o.mode==="manual"){const x=J(o);if(Object.keys(x).length){c(x);return}}h(!0),g(""),v(null);try{await s(o),g("saved")}catch(x){g("error"),v(x)}finally{h(!1)}},L=async()=>{const x=J(o);if(Object.keys(x).length){c(x);return}P(!0),w(null);try{const E=await i(o);w(E)}catch(E){w({ok:!1,error:E?.message||String(E)})}finally{P(!1)}};return t.jsxs(O,{title:n("settings.section.network"),subtitle:N,children:[a.applyError?t.jsx("p",{role:"alert",className:"mb-3 text-xs text-red-600 dark:text-red-400",children:n("settings.network.apply_error",{error:a.applyError})}):null,t.jsx(b,{label:n("settings.network.mode.label"),hint:n("settings.network.mode.hint"),control:t.jsx(T,{options:mn(),value:o.mode,onChange:x=>f({mode:x})})}),t.jsx(se,{initial:!1,children:o.mode==="manual"?t.jsxs(ae.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:[t.jsx(b,{label:n("settings.network.protocol.label"),control:t.jsx(F,{value:o.protocol,onValueChange:x=>f({protocol:x}),options:bn(),ariaLabel:n("settings.network.protocol.label"),className:"px-2.5 py-1.5 text-xs font-medium"})}),t.jsx(b,{label:n("settings.network.host.label"),hint:l.host,control:t.jsx("input",{type:"text",value:o.host,onChange:x=>f({host:x.target.value}),placeholder:n("settings.network.host.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":l.host?!0:void 0,"aria-label":n("settings.network.host.label"),className:Y})}),t.jsx(b,{label:n("settings.network.port.label"),hint:l.port,control:t.jsx("input",{type:"text",inputMode:"numeric",value:o.port,onChange:x=>f({port:x.target.value}),placeholder:n("settings.network.port.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":l.port?!0:void 0,"aria-label":n("settings.network.port.label"),className:Y})}),t.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 py-3",children:[t.jsx("button",{type:"button",onClick:L,disabled:k||u,className:"rounded-md border border-oai-gray-200 px-3 py-1.5 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:k?n("settings.network.test.testing"):n("settings.network.test")}),t.jsx("button",{type:"button",onClick:S,disabled:u||k,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:u?n("settings.network.saving"):n("settings.network.save")})]}),y?t.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:y.ok?n("settings.network.test.ok",{status:String(y.status??"")}):n("settings.network.test.fail",{error:y.error||""})}):null]},"manual-proxy-fields"):t.jsx("div",{className:"flex justify-end py-3",children:t.jsx("button",{type:"button",onClick:S,disabled:u,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:u?n("settings.network.saving"):n("settings.network.save")})},"non-manual-save")}),p==="saved"?t.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:n("settings.network.saved")}):null,p==="error"?t.jsx("p",{role:"alert",className:"py-2 text-xs text-red-600 dark:text-red-400",children:m?.unprotected?n("settings.network.save_error_unprotected",{error:m?.message||String(m||"")}):n("settings.network.save_error",{error:m?.message||String(m||"")})}):null]})}const he="/functions/tokentracker-proxy-config",xn="/functions/tokentracker-proxy-test",yn={mode:"system",protocol:"http",host:"",port:"",effective:"none",applyError:null};function me(e){return!e||typeof e.mode!="string"?null:{mode:e.mode,protocol:typeof e.protocol=="string"?e.protocol:"http",host:typeof e.host=="string"?e.host:"",port:e.port==null||e.port===0?"":String(e.port),effective:typeof e.effective=="string"?e.effective:"none",applyError:typeof e.applyError=="string"&&e.applyError.trim()?e.applyError:null}}async function vn(){const e=await fetch(he,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!e.ok)return null;const a=await e.json().catch(()=>null);return me(a)}async function Q(){const{getLocalApiAuthHeaders:e}=await Ve(async()=>{const{getLocalApiAuthHeaders:a}=await import("./__vite-browser-external-Cj9D7QBh.js").then(s=>s.dg);return{getLocalApiAuthHeaders:a}},__vite__mapDeps([0,1]));return e()}function kn(){const[e,a]=d.useState(!1),[s,i]=d.useState(!0),[o,r]=d.useState(yn);d.useEffect(()=>{if(!pt()){a(!1),i(!1);return}let u=!1;return(async()=>{try{const h=await vn();if(u)return;if(!h){a(!1),i(!1);return}r(h),a(!0),i(!1)}catch{u||(a(!1),i(!1))}})(),()=>{u=!0}},[]);const l=d.useCallback(async u=>{const h=await Q(),p=await fetch(he,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...h},cache:"no-store",body:JSON.stringify({mode:u.mode,protocol:u.protocol,host:u.host,port:u.port===""?0:Number(u.port)})}),g=await p.json().catch(()=>null);if(!p.ok){const v=g&&typeof g.error=="string"?g.error:`HTTP ${p.status}`;throw new Error(v)}const m=me(g);if(m&&r(m),g&&g.ok===!1){const v=g&&typeof g.applyError=="string"&&g.applyError||g&&typeof g.error=="string"&&g.error||`HTTP ${p.status}`,k=new Error(v);throw g.unprotected===!0&&(k.unprotected=!0),k}return m||g},[]),c=d.useCallback(async u=>{const h=await Q(),p=await fetch(xn,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...h},cache:"no-store",body:JSON.stringify({protocol:u.protocol,host:u.host,port:u.port===""?0:Number(u.port)})}),g=await p.json().catch(()=>null);if(!g||typeof g.ok!="boolean")throw new Error(g&&typeof g.error=="string"?g.error:`HTTP ${p.status}`);return g},[]);return{available:e,loading:s,config:o,save:l,testConnection:c}}const C={APPEARANCE:"appearance",NATIVE_APP:"native-app",NETWORK:"network",ACCOUNT:"account",LIMITS:"limits",LABS:"labs"},A={PERSONAL:"personal",APP:"app",DEVELOPER:"developer"};function jn({prefs:e}){return t.jsx(T,{options:[{value:Z.USED,label:n("limits.settings.display_mode_used")},{value:Z.REMAINING,label:n("limits.settings.display_mode_remaining")}],value:e.displayMode,onChange:e.setDisplayMode})}function qn(){const e=ot(),{available:a,settings:s,setSetting:i}=R(),o=kn(),{available:r}=o,l=s?.toastOnReset!==!1,c=s?.confettiOnReset!==!1,u=ne()||s?.platform==="windows",[h,p]=Be(),g=ze(),m=h.get("section"),k=Object.values(C).includes(m)&&(m!==C.NATIVE_APP||a)&&(m!==C.NETWORK||r)?m:C.APPEARANCE,P=f=>{const S=new URLSearchParams(h);f===C.APPEARANCE?S.delete("section"):S.set("section",f),p(S,{replace:!0})},y=[{id:C.APPEARANCE,label:n("settings.section.appearance"),description:n("settings.section.appearance.description"),group:A.PERSONAL,Icon:wt,content:t.jsx(un,{})},...a?[{id:C.NATIVE_APP,label:n("settings.section.menubar"),description:n("settings.section.menubar.description"),group:A.APP,Icon:te,content:t.jsx(gn,{})}]:[],...r?[{id:C.NETWORK,label:n("settings.section.network"),description:n("settings.section.network.description"),group:A.APP,Icon:Ke,content:t.jsx(fn,{proxySettings:o})}]:[],{id:C.ACCOUNT,label:n("settings.section.account"),description:n("settings.section.account.description"),group:A.PERSONAL,Icon:Nt,content:t.jsx(Yt,{})},{id:C.LIMITS,label:n("settings.section.limits"),description:n("settings.section.limits.description"),group:A.APP,Icon:qe,content:t.jsxs("div",{className:"space-y-4",children:[t.jsxs(O,{title:n("settings.section.limits"),children:[t.jsx(b,{label:n("limits.settings.display_mode_label"),control:t.jsx(jn,{prefs:e})}),u?null:t.jsxs(t.Fragment,{children:[t.jsx(b,{label:n("settings.menubar.toastOnReset"),hint:n("settings.menubar.toastOnResetHint"),control:t.jsx(j,{checked:l,disabled:!a,onChange:()=>i("toastOnReset",!l),ariaLabel:n("settings.menubar.toastOnReset")})}),t.jsx(b,{label:n("settings.menubar.confettiOnReset"),hint:n("settings.menubar.confettiOnResetHint"),control:t.jsx(j,{checked:c,disabled:!a,onChange:()=>i("confettiOnReset",!c),ariaLabel:n("settings.menubar.confettiOnReset")})})]}),t.jsx(b,{label:n("settings.limits.showSubscriptions"),hint:n("settings.limits.showSubscriptionsHint"),control:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{type:"button",onClick:()=>g("/limits?openSubscriptions=1"),"aria-label":n("limits.page.openSubscriptions"),title:n("limits.page.openSubscriptions"),className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:t.jsx(We,{size:14,"aria-hidden":!0})}),t.jsx(j,{checked:e.showSubscriptions!==!1,onChange:()=>e.setShowSubscriptions(!e.showSubscriptions),ariaLabel:n("settings.limits.showSubscriptions")})]})})]}),t.jsx(O,{title:n("settings.limits.providers"),children:t.jsx(Pt,{prefs:e})})]})},{id:C.LABS,label:n("settings.section.labs"),description:n("settings.section.labs.description"),group:A.DEVELOPER,Icon:vt,content:t.jsx(dn,{})}],w=[{id:A.PERSONAL,label:n("settings.nav.group.personal")},{id:A.APP,label:n("settings.nav.group.app")},{id:A.DEVELOPER,label:n("settings.nav.group.developer")}].map(f=>({...f,sections:y.filter(S=>S.group===f.id)})).filter(f=>f.sections.length>0);let N=y[0];for(const f of y)if(f.id===k){N=f;break}return t.jsx("div",{className:"flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",children:t.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:t.jsxs("div",{className:"mx-auto w-full max-w-5xl px-4 sm:px-6",children:[t.jsxs("div",{className:"mb-7 max-w-2xl",children:[t.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:n("settings.page.title")}),t.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:n("settings.page.subtitle")})]}),t.jsxs("div",{className:"grid min-w-0 gap-6 md:grid-cols-[14rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[15rem_minmax(0,1fr)]",children:[t.jsx("aside",{className:"min-w-0 rounded-xl border border-oai-gray-200 bg-oai-gray-50/70 p-2 dark:border-oai-gray-800 dark:bg-oai-gray-900/60 md:border-0 md:bg-transparent md:p-0 md:dark:bg-transparent",children:t.jsx("nav",{"aria-label":n("settings.page.title"),className:"flex gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden md:sticky md:top-6 md:flex-col md:gap-4 md:overflow-visible",children:w.map(({id:f,label:S,sections:L})=>t.jsxs("div",{className:"flex shrink-0 gap-1 md:block",children:[t.jsx("div",{className:"hidden px-3 pb-1 text-[10px] font-semibold uppercase tracking-[0.16em] text-oai-gray-400 dark:text-oai-gray-500 md:block",children:S}),t.jsx("div",{className:"flex gap-1 md:flex-col",children:L.map(({id:x,label:E,Icon:D})=>{const G=k===x;return t.jsxs("button",{id:`settings-nav-${x}`,type:"button","aria-current":G?"page":void 0,"aria-controls":`settings-panel-${x}`,onClick:()=>P(x),className:_("inline-flex min-h-10 min-w-max shrink-0 items-center gap-1.5 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand-500 md:w-full md:min-w-0 md:gap-2 md:px-3",G?"bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-white":"text-oai-gray-500 hover:bg-oai-gray-50 hover:text-oai-gray-900 dark:text-oai-gray-400 dark:hover:bg-oai-gray-900 dark:hover:text-oai-gray-200"),children:[t.jsx(D,{className:_("h-4 w-4 shrink-0",G?"text-oai-black dark:text-white":"text-oai-gray-400 dark:text-oai-gray-500"),"aria-hidden":!0}),t.jsx("span",{className:"truncate",children:E})]},x)})})]},f))})}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"mb-4 border-b border-oai-gray-200 pb-4 dark:border-oai-gray-800",children:[t.jsx("h2",{className:"text-xl font-semibold tracking-tight text-oai-black dark:text-white",children:N.label}),t.jsx("p",{className:"mt-1 text-sm leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:N.description})]}),y.map(({id:f,label:S,content:L})=>t.jsx("section",{id:`settings-panel-${f}`,"aria-labelledby":`settings-nav-${f}`,"aria-label":S,"data-settings-panel":f,hidden:k!==f,children:L},f)),t.jsx(hn,{})]})]})]})})})}export{qn as SettingsPage};
|