tokentracker-cli 0.65.0 → 0.65.1

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.
Files changed (53) hide show
  1. package/README.de.md +476 -0
  2. package/README.ja.md +1 -1
  3. package/README.ko.md +1 -1
  4. package/README.md +1 -1
  5. package/README.zh-CN.md +1 -1
  6. package/dashboard/dist/assets/{ActivityHeatmap-Ccf0I3uP.js → ActivityHeatmap-N0MiuKiD.js} +1 -1
  7. package/dashboard/dist/assets/{Card-BSF8dYEt.js → Card-C-UUcB6K.js} +1 -1
  8. package/dashboard/dist/assets/{ConfirmModal-Bjp6eg2f.js → ConfirmModal-Ck7qQwqO.js} +1 -1
  9. package/dashboard/dist/assets/{DashboardPage-BInQkoDe.js → DashboardPage-BdZPqztW.js} +2 -2
  10. package/dashboard/dist/assets/{DevicePage-B0yxbDDR.js → DevicePage-Wr-LIowe.js} +1 -1
  11. package/dashboard/dist/assets/{DialogTitle-uw-Oa5Qv.js → DialogTitle-BNVIjz-M.js} +1 -1
  12. package/dashboard/dist/assets/{FadeIn-DPIBqXRl.js → FadeIn-D8XF2ui8.js} +1 -1
  13. package/dashboard/dist/assets/{HeaderGithubStar-DDXfJ1uC.js → HeaderGithubStar-Dv3PacNv.js} +1 -1
  14. package/dashboard/dist/assets/{IpCheckPage-KC93tPlt.js → IpCheckPage-DfDXn5N1.js} +1 -1
  15. package/dashboard/dist/assets/{LandingPage-Itx2uPWI.js → LandingPage-QlEpH3fR.js} +1 -1
  16. package/dashboard/dist/assets/{LeaderboardAvatar-Bv44b_Kl.js → LeaderboardAvatar-CEV0WCgO.js} +1 -1
  17. package/dashboard/dist/assets/{LeaderboardPage-DDq5gzyz.js → LeaderboardPage-Bte3fdxj.js} +2 -2
  18. package/dashboard/dist/assets/{LeaderboardProfileModal-LQyYrCf1.js → LeaderboardProfileModal-DBSiwRmn.js} +1 -1
  19. package/dashboard/dist/assets/{LeaderboardProfilePage-3you3mbA.js → LeaderboardProfilePage-DL1xrz2u.js} +1 -1
  20. package/dashboard/dist/assets/{LimitsPage-CrLvR8vE.js → LimitsPage-CU71xh0N.js} +1 -1
  21. package/dashboard/dist/assets/{LocalOnlyNotice-Di1gnfIi.js → LocalOnlyNotice-B0O7VftN.js} +1 -1
  22. package/dashboard/dist/assets/{LoginPage-f9QHz_uZ.js → LoginPage-R_gddHQq.js} +1 -1
  23. package/dashboard/dist/assets/{PopoverPopup-7rjAxAqk.js → PopoverPopup-Dt3vUklH.js} +1 -1
  24. package/dashboard/dist/assets/{ResetPasswordPage-DKA7HGpJ.js → ResetPasswordPage-C9OkcYCJ.js} +1 -1
  25. package/dashboard/dist/assets/{Select-2gikPo1a.js → Select-hvb85wtR.js} +1 -1
  26. package/dashboard/dist/assets/{SelectItemText-DZx33XF1.js → SelectItemText-BkSrV5-F.js} +1 -1
  27. package/dashboard/dist/assets/SettingsPage-D6NSX-54.js +1 -0
  28. package/dashboard/dist/assets/{SkillsPage-B6BJ9UZp.js → SkillsPage-CjrVT_6o.js} +1 -1
  29. package/dashboard/dist/assets/{WidgetsPage-D8p3Tx7E.js → WidgetsPage-BA7CYY1i.js} +1 -1
  30. package/dashboard/dist/assets/{WrappedPage-cXEfhti9.js → WrappedPage-BxxXLdaK.js} +1 -1
  31. package/dashboard/dist/assets/{agent-logos-D3iFlaWg.js → agent-logos-DW_otOmk.js} +1 -1
  32. package/dashboard/dist/assets/{arrow-up-right-D87Aw_ZN.js → arrow-up-right-BNZE25jN.js} +1 -1
  33. package/dashboard/dist/assets/{download-BtcEs1OB.js → download-B3dZN1Qo.js} +1 -1
  34. package/dashboard/dist/assets/{main-CGx8BJ4O.css → main-BHwig9Um.css} +1 -1
  35. package/dashboard/dist/assets/{main-DqnXui98.js → main-XJt43zJ1.js} +21 -20
  36. package/dashboard/dist/assets/{use-limits-display-prefs-DAxlRSu2.js → use-limits-display-prefs-CILTJ0ib.js} +1 -1
  37. package/dashboard/dist/assets/{use-native-settings-CgvB_B6W.js → use-native-settings-CMJ5wI4Y.js} +1 -1
  38. package/dashboard/dist/assets/{use-ordered-list-DOfX6aSy.js → use-ordered-list-Bvt0pvNt.js} +1 -1
  39. package/dashboard/dist/assets/{use-quality-per-dollar-pref-kEbwQwk2.js → use-quality-per-dollar-pref-D634C_GV.js} +1 -1
  40. package/dashboard/dist/assets/{use-usage-limits-la-KPfJj.js → use-usage-limits-DU_6J0Y3.js} +1 -1
  41. package/dashboard/dist/assets/{useCurrency-LDRg7ST0.js → useCurrency-DInjo-qq.js} +1 -1
  42. package/dashboard/dist/assets/{useScrollLock-lP1Is9IY.js → useScrollLock-DTTYcDSy.js} +1 -1
  43. package/dashboard/dist/index.html +2 -2
  44. package/dashboard/dist/share.html +2 -2
  45. package/package.json +1 -1
  46. package/src/commands/init.js +3 -2
  47. package/src/commands/status.js +26 -17
  48. package/src/commands/sync.js +672 -98
  49. package/src/lib/openclaw-session-plugin.js +2 -2
  50. package/src/lib/pricing/seed-snapshot.json +1 -1
  51. package/src/lib/rollout.js +602 -178
  52. package/src/lib/wsl-probe.js +181 -0
  53. package/dashboard/dist/assets/SettingsPage-CwHPmuZV.js +0 -1
@@ -0,0 +1,181 @@
1
+ const fssync = require("node:fs");
2
+ const path = require("node:path");
3
+
4
+ const DEFAULT_EXEC_OPTS = { timeout: 15000, windowsHide: true, maxBuffer: 1024 * 1024, stdio: ["ignore", "pipe", "ignore"] };
5
+
6
+ let _cachedDistros = null;
7
+ const _cachedWslUsers = new Map();
8
+
9
+ function resetWslProbeCache() {
10
+ _cachedDistros = null;
11
+ _cachedWslUsers.clear();
12
+ }
13
+
14
+ const WSL_MODES = new Set([
15
+ "wsl-first",
16
+ "native-first",
17
+ "wsl-only",
18
+ "native-only",
19
+ ]);
20
+
21
+ function defaultRunWsl(args, { utf16 = false } = {}) {
22
+ const { execFileSync } = require("node:child_process");
23
+ const buf = execFileSync("wsl.exe", args, DEFAULT_EXEC_OPTS);
24
+ return utf16 ? buf.toString("utf16le") : buf.toString("utf8");
25
+ }
26
+
27
+ function parseWslListVerbose(raw) {
28
+ if (typeof raw !== "string") return [];
29
+ const distros = [];
30
+ for (const line of raw.split(/\r?\n/)) {
31
+ const clean = line.replace(/\0/g, "").replace(/\uFEFF/g, "").trim();
32
+ if (!clean) continue;
33
+ const cells = clean.split(/\s+/);
34
+ let isDefault = false;
35
+ let idx = 0;
36
+ if (cells[0] === "*") {
37
+ isDefault = true;
38
+ idx = 1;
39
+ }
40
+ const name = cells[idx];
41
+ if (!name || name === "NAME") continue;
42
+ const version = parseInt(cells[cells.length - 1], 10);
43
+ distros.push({ name, version: Number.isFinite(version) ? version : null, isDefault });
44
+ }
45
+ return distros;
46
+ }
47
+
48
+ function probeWslDistros(deps = {}) {
49
+ const hasDeps = Object.keys(deps).length > 0;
50
+ if (!hasDeps && _cachedDistros) return _cachedDistros;
51
+ const runWsl = deps.runWsl || defaultRunWsl;
52
+ let raw;
53
+ try {
54
+ raw = runWsl(["-l", "-v"], { utf16: true });
55
+ } catch (_e) {
56
+ if (!hasDeps) _cachedDistros = [];
57
+ return [];
58
+ }
59
+ const distros = parseWslListVerbose(raw);
60
+ const sorted = distros.sort((a, b) => (b.isDefault ? 1 : 0) - (a.isDefault ? 1 : 0));
61
+ if (!hasDeps) _cachedDistros = sorted;
62
+ return sorted;
63
+ }
64
+
65
+ function normalizeWslMode(value) {
66
+ return String(value ?? "")
67
+ .trim()
68
+ .toLowerCase()
69
+ .replaceAll("_", "-");
70
+ }
71
+
72
+ function getWslMode(env = process.env) {
73
+ const raw = normalizeWslMode(env.TOKENTRACKER_WSL_MODE);
74
+ return WSL_MODES.has(raw) ? raw : "wsl-first";
75
+ }
76
+
77
+ function isInvalidWslMode(env = process.env) {
78
+ const value = env.TOKENTRACKER_WSL_MODE;
79
+ if (value == null || String(value).trim() === "") return false;
80
+ return !WSL_MODES.has(normalizeWslMode(value));
81
+ }
82
+
83
+ function shouldProbeWsl(env = process.env) {
84
+ return getWslMode(env) !== "native-only";
85
+ }
86
+
87
+ function shouldProbeNative(env = process.env) {
88
+ return getWslMode(env) !== "wsl-only";
89
+ }
90
+
91
+ function pickWin32Path({
92
+ wslValue,
93
+ nativeValue,
94
+ env = process.env,
95
+ platform = process.platform,
96
+ }) {
97
+ if (platform !== "win32") return null;
98
+
99
+ const mode = getWslMode(env);
100
+
101
+ if (mode === "wsl-only") return wslValue ?? null;
102
+ if (mode === "native-only") return nativeValue ?? null;
103
+ if (mode === "native-first") return nativeValue ?? wslValue ?? null;
104
+
105
+ return wslValue ?? nativeValue ?? null;
106
+ }
107
+
108
+ function lookupWslUser(distroName, runWsl, useCache) {
109
+ if (useCache && _cachedWslUsers.has(distroName)) {
110
+ return _cachedWslUsers.get(distroName);
111
+ }
112
+ let user = "";
113
+ try {
114
+ user = String(runWsl(["-d", distroName, "-e", "whoami"], { utf16: false }) || "").trim();
115
+ } catch (_e) { }
116
+ if (useCache) _cachedWslUsers.set(distroName, user);
117
+ return user;
118
+ }
119
+
120
+ function discoverWslHome(providerDir, deps = {}) {
121
+ if (!shouldProbeWsl(deps.env)) return null;
122
+
123
+ const runWsl = deps.runWsl || defaultRunWsl;
124
+ const existsSync = deps.existsSync || fssync.existsSync;
125
+ const distros = deps.runWsl ? probeWslDistros({ runWsl: deps.runWsl }) : probeWslDistros();
126
+ const useCache = !deps.runWsl;
127
+ for (const distro of distros) {
128
+ const user = lookupWslUser(distro.name, runWsl, useCache);
129
+ if (!user) continue;
130
+ const roots = distro.version === 1
131
+ ? ["\\\\wsl.localhost\\", "\\\\wsl$\\"]
132
+ : ["\\\\wsl$\\", "\\\\wsl.localhost\\"];
133
+ for (const root of roots) {
134
+ const candidate = `${root}${distro.name}\\home\\${user}\\${providerDir}`;
135
+ try {
136
+ if (existsSync(candidate)) return candidate;
137
+ } catch (_e) { }
138
+ }
139
+ }
140
+ return null;
141
+ }
142
+
143
+ function isUncPath(p) {
144
+ return typeof p === "string" && (p.startsWith("\\\\") || p.startsWith("//"));
145
+ }
146
+
147
+ function snapshotSqliteDb(dbPath) {
148
+ const tmpRoot = fssync.mkdtempSync(
149
+ path.join(require("node:os").tmpdir(), "tokentracker-wsl-snap-"),
150
+ );
151
+ const target = path.join(tmpRoot, path.basename(dbPath));
152
+ fssync.copyFileSync(dbPath, target);
153
+ for (const suffix of ["-wal", "-shm", "-journal"]) {
154
+ const src = dbPath + suffix;
155
+ try {
156
+ if (fssync.existsSync(src)) fssync.copyFileSync(src, target + suffix);
157
+ } catch (_e) { }
158
+ }
159
+ return {
160
+ path: target,
161
+ cleanup() {
162
+ try { fssync.rmSync(tmpRoot, { recursive: true, force: true }); } catch (_e) { }
163
+ },
164
+ };
165
+ }
166
+
167
+ module.exports = {
168
+ defaultRunWsl,
169
+ parseWslListVerbose,
170
+ probeWslDistros,
171
+ resetWslProbeCache,
172
+ discoverWslHome,
173
+ isUncPath,
174
+ snapshotSqliteDb,
175
+ getWslMode,
176
+ isInvalidWslMode,
177
+ shouldProbeWsl,
178
+ shouldProbeNative,
179
+ pickWin32Path,
180
+ normalizeWslMode,
181
+ };
@@ -1 +0,0 @@
1
- import{c as N,r as c,as as te,am as ne,aP as E,j as t,m as D,U as ae,V as k,G as a,Y as ie,ay as se,aQ as oe,aC as re,aD as le,aE as T,aR as ce,aS as ue,W as de,R as C,S as ge,T as he,a5 as U,aT as pe,aU as me,a1 as be,aV as fe,K as xe,aW as ye,aX as ve,aY as je,aZ as ke,a_ as Ne,a$ as Se,b0 as we,ak as Ce,b1 as A}from"./main-DqnXui98.js";import{b as I,l as P,u as Le,L as _}from"./use-limits-display-prefs-DAxlRSu2.js";import{S,T as j,a as x,b as M,u as R}from"./use-native-settings-CgvB_B6W.js";import{u as Ge,P as Ee}from"./use-quality-per-dollar-pref-kEbwQwk2.js";import{C as Ae}from"./useScrollLock-lP1Is9IY.js";import{u as Ie}from"./useCurrency-LDRg7ST0.js";import{S as F}from"./Select-2gikPo1a.js";import{I as Pe}from"./DialogTitle-uw-Oa5Qv.js";import{C as _e}from"./ConfirmModal-Bjp6eg2f.js";import{D as Oe}from"./download-BtcEs1OB.js";import"./Card-BSF8dYEt.js";import"./SelectItemText-DZx33XF1.js";const De=[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]],Te=N("activity",De);const Ue=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Me=N("copy",Ue);const Re=[["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"}]],Fe=N("grip-vertical",Re);const He=[["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"}]],Ve=N("languages",He);const $e=[["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"}]],Be=N("log-out",$e),ze=e=>!e.isLayoutDirty&&e.willUpdate(!1);function O(){const e=new Set,n=new WeakMap,i=()=>e.forEach(ze);return{add:s=>{e.add(s),n.set(s,s.addEventListener("willUpdate",i))},remove:s=>{e.delete(s);const o=n.get(s);o&&(o(),n.delete(s)),i()},dirty:i}}const We=c.createContext(null);function Ze(){const e=c.useRef(!1);return te(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function Ke(){const e=Ze(),[n,i]=c.useState(0),s=c.useCallback(()=>{e.current&&i(n+1)},[n]);return[c.useCallback(()=>ne.postRender(s),[s]),n]}const H=e=>e===!0,qe=e=>H(e===!0)||e==="id",Ye=({children:e,id:n,inherit:i=!0})=>{const s=c.useContext(E),o=c.useContext(We),[r,l]=Ke(),u=c.useRef(null),g=s.id||o;u.current===null&&(qe(i)&&g&&(n=n?g+"-"+n:g),u.current={id:n,group:H(i)&&s.group||O()});const p=c.useMemo(()=>({...u.current,forceRender:r}),[l]);return t.jsx(E.Provider,{value:p,children:e})},Qe="shrink-0 text-oai-gray-900 dark:text-oai-gray-200";function Je({checked:e,onChange:n,ariaLabel:i}){return t.jsx("button",{type:"button",role:"switch","aria-checked":e,"aria-label":i,onClick:n,className:k("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:k("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",e?"translate-x-[18px]":"translate-x-[3px]")})})}function Xe({prefs:e}){const{order:n,visibility:i,toggle:s,moveToward:o}=e,[r,l]=c.useState(null),[u,g]=c.useState(null),p=d=>m=>{l(d),m.dataTransfer.effectAllowed="move",m.dataTransfer.setData("text/plain",d)},b=d=>m=>{m.preventDefault(),m.dataTransfer.dropEffect="move",r&&r!==d&&u!==d&&(g(d),o(r,d))},f=()=>{l(null),g(null)},y=d=>{d.preventDefault(),l(null),g(null)};return t.jsx(Ye,{children:t.jsx("div",{className:"flex flex-col",children:n.map(d=>{const m=i[d]!==!1,h=r===d;return t.jsxs(D.div,{layout:!0,transition:{duration:.28,ease:[.22,1,.36,1]},draggable:!0,onDragStart:p(d),onDragOver:b(d),onDragEnd:f,onDrop:y,className:k("flex items-center gap-3 py-2 rounded-md","hover:bg-oai-gray-100/60 dark:hover:bg-oai-gray-800/60",h&&"opacity-40"),style:{cursor:h?"grabbing":"grab"},children:[t.jsx(Fe,{className:"h-4 w-4 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",strokeWidth:1.75,"aria-hidden":!0}),I(d)?t.jsx(ae,{provider:I(d),size:18,className:k("pointer-events-none",Qe)}):null,t.jsx("span",{className:"flex-1 text-sm text-oai-gray-900 dark:text-oai-gray-200 select-none",children:P(d)}),t.jsx("div",{onMouseDown:v=>v.stopPropagation(),draggable:!1,children:t.jsx(Je,{checked:m,onChange:()=>s(d),ariaLabel:`${a("limits.settings.toggle_visible")}: ${P(d)}`})})]},d)})})})}function et(e){if(!e||typeof e!="object")return"";const n=e.user_metadata&&typeof e.user_metadata=="object"?e.user_metadata:{},i=e.profile&&typeof e.profile=="object"?e.profile:{},s=n.full_name||n.name||i.name||n.user_name||n.preferred_username;return typeof s=="string"&&s.trim()?s.trim():typeof e.email=="string"&&e.email.includes("@")?e.email.split("@")[0].trim()||e.email.trim():typeof e.email=="string"?e.email.trim():""}function tt(e){return!e||typeof e!="object"?"":typeof e.email=="string"?e.email.trim():""}function nt(e){const n=typeof e=="string"?e.trim():"";if(!n)return null;const i=n.match(/^@?([A-Za-z0-9][A-Za-z0-9-]{0,38})$/),s=n.match(/^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/?$/i),o=i?.[1]||s?.[1];return o?`https://github.com/${o}`:null}function L(e,n){console.warn(`[tokentracker] settings ${e}:`,n)}function at(e,n,i){const[s,o]=c.useState(()=>se()),r=n&&i&&oe(),l=c.useCallback(async()=>{const u=!s;if(re(u),o(u),!!u)try{await le(()=>e())}catch(g){L("cloud sync",g)}},[s,e]);return{cloudSyncOn:s,handleCloudSyncToggle:l,showLocalCloudSync:r}}function it(e){const[n,i]=c.useState(!1),[s,o]=c.useState(!1),[r,l]=c.useState(!1),[u,g]=c.useState(!1),[p,b]=c.useState(null),[f,y]=c.useState(!1),[d,m]=c.useState(""),[h,v]=c.useState(!1),[w,G]=c.useState(""),[z,W]=c.useState(""),[Z,K]=c.useState(!1),[q,Y]=c.useState(null),Q=c.useMemo(()=>et(e),[e]),J=c.useMemo(()=>tt(e),[e]),X=c.useMemo(()=>typeof e?.id=="string"?e.id.trim():"",[e]),ee=c.useMemo(()=>({setAnonymousOn:o,setCustomDisplayName:b,setGithubUrl:G,setProfileLoading:l,setPublicProfileOn:i,setShowGithubOn:v}),[]);return{anonymousOn:s,customDisplayName:p,displayName:Q,editingGithub:Z,editingName:f,email:J,githubError:q,githubInput:z,githubUrl:w,loadSetters:ee,nameInput:d,profileLoading:r,profileSaving:u,publicProfileOn:n,setAnonymousOn:o,setCustomDisplayName:b,setEditingGithub:K,setEditingName:y,setGithubError:Y,setGithubInput:W,setGithubUrl:G,setNameInput:m,setProfileLoading:l,setProfileSaving:g,setPublicProfileOn:i,setShowGithubOn:v,showGithubOn:h,userId:X}}function st(e,n,i){c.useEffect(()=>{if(!n)return;let s=!0;return i.setProfileLoading(!0),(async()=>{try{const o=await T({getAccessToken:e});if(!s||!o)return;const r=await ce({accessToken:o});if(!s)return;i.setPublicProfileOn(!!r?.enabled),i.setAnonymousOn(!!r?.anonymous),r?.display_name&&i.setCustomDisplayName(r.display_name),i.setShowGithubOn(!!r?.show_github_url),i.setGithubUrl(r?.github_url||"")}catch(o){L("load public profile",o)}finally{s&&i.setProfileLoading(!1)}})(),()=>{s=!1}},[e,n,i])}function ot(e,n){return c.useCallback(async(i,{label:s,onError:o,onSuccess:r}={})=>{if(n.profileSaving)return!1;n.setProfileSaving(!0);try{const l=await T({getAccessToken:e});if(!l)return!1;const u=await ue({accessToken:l,...i});return r?.(u),!0}catch(l){return o?o(l):L(s||"mutate profile",l),!1}finally{n.setProfileSaving(!1)}},[e,n])}function rt(e,n){return{anonymousOn:e.anonymousOn,customDisplayName:e.customDisplayName,displayName:e.displayName,editingName:e.editingName,handleAnonymousToggle:n.handleAnonymousToggle,handleSaveName:n.handleSaveName,nameInput:e.nameInput,profileLoading:e.profileLoading,profileSaving:e.profileSaving,setEditingName:e.setEditingName,setNameInput:e.setNameInput,startEditingName:n.startEditingName}}function lt(e,n){return{editingGithub:e.editingGithub,githubError:e.githubError,githubInput:e.githubInput,githubUrl:e.githubUrl,handleSaveGithub:n.handleSaveGithub,handleShowGithubToggle:n.handleShowGithubToggle,profileLoading:e.profileLoading,profileSaving:e.profileSaving,setEditingGithub:e.setEditingGithub,setGithubError:e.setGithubError,setGithubInput:e.setGithubInput,showGithubOn:e.showGithubOn,startEditingGithub:n.startEditingGithub}}function ct(e,n){const i=c.useCallback(async()=>{const o=!e.publicProfileOn;await n({enabled:o},{label:"toggle public profile",onSuccess:()=>e.setPublicProfileOn(o)})},[n,e]);return{handleAnonymousToggle:c.useCallback(async()=>{const o=!e.anonymousOn;await n({anonymous:o},{label:"toggle anonymous",onSuccess:()=>e.setAnonymousOn(o)})},[n,e]),handlePublicProfileToggle:i}}function ut(e,n,i){const s=c.useCallback(async()=>{const r=e.nameInput.trim().slice(0,50);r&&await n({display_name:r},{label:"save display name",onSuccess:()=>{e.setCustomDisplayName(r),e.setEditingName(!1),i?.()}})},[n,e,i]),o=c.useCallback(()=>{e.setNameInput(e.customDisplayName||e.displayName),e.setEditingName(!0)},[e]);return{handleSaveName:s,startEditingName:o}}function dt(e,n){const i=c.useCallback(async()=>{if(!e.showGithubOn&&!e.githubUrl){e.setEditingGithub(!0),e.setGithubInput(""),e.setGithubError(null);return}const r=!e.showGithubOn;await n({show_github_url:r},{label:"toggle GitHub profile",onSuccess:()=>e.setShowGithubOn(r)})},[n,e]),s=c.useCallback(async()=>{const r=nt(e.githubInput);if(e.githubInput.trim()&&!r){e.setGithubError(a("settings.account.githubUrlInvalid"));return}e.setGithubError(null),await n({github_url:r,show_github_url:!!r},{label:"save GitHub profile",onError:l=>e.setGithubError(l?.message||a("settings.account.githubUrlInvalid")),onSuccess:l=>{e.setGithubUrl(l?.github_url||r||""),e.setShowGithubOn(!!r),e.setEditingGithub(!1)}})},[n,e]),o=c.useCallback(()=>{e.setGithubInput(e.githubUrl),e.setGithubError(null),e.setEditingGithub(!0)},[e]);return{handleSaveGithub:s,handleShowGithubToggle:i,startEditingGithub:o}}function gt(){const e=ie(),n=it(e.user),i=at(e.getAccessToken,e.enabled,e.signedIn);st(e.getAccessToken,e.signedIn,n.loadSetters);const s=ot(e.getAccessToken,n),o=ct(n,s),r=ut(n,s,e.refreshDisplayName),l=dt(n,s);return{...e,...i,email:n.email,handlePublicProfileToggle:o.handlePublicProfileToggle,userId:n.userId,name:rt(n,{...o,...r}),github:lt(n,l),profileLoading:n.profileLoading,profileSaving:n.profileSaving,publicProfileOn:n.publicProfileOn}}function V({disabled:e,onCancel:n,onSave:i,saveLabel:s=a("settings.account.save")}){return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:i,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:s}),t.jsx("button",{type:"button",onClick:n,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:a("settings.account.cancel")})]})}function ht({nameInput:e,setEditingName:n,setNameInput:i,profileSaving:s,handleSaveName:o}){return t.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[t.jsx("input",{type:"text",value:e,onChange:r=>i(r.target.value),onKeyDown:r=>{r.key==="Enter"&&o(),r.key==="Escape"&&n(!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:a("settings.account.displayName")}),t.jsx(V,{disabled:s||!e.trim(),onCancel:()=>n(!1),onSave:o,saveLabel:s?a("settings.account.saving"):void 0})]})}function pt({githubError:e,githubInput:n,handleSaveGithub:i,profileSaving:s,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:n,onChange:u=>{l(u.target.value),e&&r(null)},onKeyDown:u=>{u.key==="Enter"&&i(),u.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:a("settings.account.githubUrlPlaceholder")}),t.jsx(V,{disabled:s,onCancel:()=>{o(!1),r(null)},onSave:i,saveLabel:s?a("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 $({disabled:e=!1,label:n,onClick:i,title:s}){return t.jsxs("button",{type:"button",onClick:i,disabled:e,title:s,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(Ee,{className:"h-3.5 w-3.5","aria-hidden":!0}),n]})}function B({actions:e,editing:n,editor:i,hint:s,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}),n?i:t.jsx("div",{className:"mt-0.5 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:s})]}),n?null:e]})})}function mt({name:e}){const n=e.anonymousOn?a("settings.account.displayNameDisabledWhileAnon"):void 0;return t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx($,{disabled:e.anonymousOn,label:a("settings.account.edit"),onClick:e.startEditingName,title:n}),t.jsx(j,{checked:!e.anonymousOn,onChange:e.handleAnonymousToggle,disabled:e.profileLoading||e.profileSaving,ariaLabel:a("settings.account.displayName")})]})}function bt({name:e}){const{anonymousOn:n,customDisplayName:i,displayName:s,editingName:o,handleAnonymousToggle:r,handleSaveName:l,nameInput:u,profileLoading:g,profileSaving:p,setEditingName:b,setNameInput:f,startEditingName:y}=e,d=n?a("settings.account.displayNameAnonymousHint"):i||s;return t.jsx(B,{label:a("settings.account.displayName"),editing:o,hint:d,editor:t.jsx(ht,{nameInput:u,setEditingName:b,setNameInput:f,profileSaving:p,handleSaveName:l}),actions:t.jsx(mt,{name:e})})}function ft({github:e}){const{editingGithub:n,githubError:i,githubInput:s,githubUrl:o,handleSaveGithub:r,handleShowGithubToggle:l,profileLoading:u,profileSaving:g,setEditingGithub:p,setGithubError:b,setGithubInput:f,showGithubOn:y,startEditingGithub:d}=e,{enabled:m,toggle:h}=Ge();return t.jsxs(t.Fragment,{children:[t.jsx(B,{label:a("settings.account.githubUrl"),editing:n,hint:o||a("settings.account.githubUrlHint"),editor:t.jsx(pt,{githubError:i,githubInput:s,handleSaveGithub:r,profileSaving:g,setEditingGithub:p,setGithubError:b,setGithubInput:f}),actions:t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx($,{label:a("settings.account.edit"),onClick:d}),t.jsx(j,{checked:y,onChange:l,disabled:u||g,ariaLabel:a("settings.account.githubUrl")})]})}),o&&t.jsx(x,{label:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{children:a("settings.labs.qpd.label")}),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:a("qpd.card.badge")})]}),hint:a("settings.labs.qpd.hint"),control:t.jsx(j,{checked:m,onChange:h,ariaLabel:a("settings.labs.qpd.aria")})})]})}function xt(){const{openLoginModal:e}=de();return t.jsx(S,{title:a("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:a("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:a("settings.account.signIn")})]})})}function yt({name:e,github:n}){return t.jsxs(t.Fragment,{children:[t.jsx(bt,{name:e}),t.jsx(ft,{github:n})]})}function vt(){const e=gt();return e.enabled?e.signedIn?t.jsxs(S,{title:a("settings.section.account"),subtitle:e.email||e.name.customDisplayName||e.name.displayName,action:t.jsx(kt,{onSignOut:e.signOut}),children:[t.jsx(jt,{userId:e.userId}),t.jsx(Nt,{settings:e}),t.jsx(St,{checked:e.publicProfileOn,disabled:e.profileLoading||e.profileSaving,onChange:e.handlePublicProfileToggle}),t.jsx(wt,{visible:e.publicProfileOn,name:e.name,github:e.github})]}):t.jsx(xt,{}):null}function jt({userId:e}){const[n,i]=C.useState(!1);if(!e)return null;const s=async()=>{try{if(typeof navigator>"u"||!navigator.clipboard?.writeText)return;await navigator.clipboard.writeText(e),i(!0),globalThis.setTimeout(()=>i(!1),1200)}catch{i(!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:a("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:s,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":a("settings.account.copyUserId"),children:[n?t.jsx(Ae,{className:"h-3.5 w-3.5","aria-hidden":!0}):t.jsx(Me,{className:"h-3.5 w-3.5","aria-hidden":!0}),n?a("settings.account.copied"):a("settings.account.copy")]})]})}function kt({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(Be,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.account.signOut")]})}function Nt({settings:e}){return e.showLocalCloudSync?t.jsx(x,{label:a("settings.account.cloudSync"),hint:a("settings.account.cloudSyncHint"),control:t.jsx(j,{checked:e.cloudSyncOn,onChange:e.handleCloudSyncToggle,ariaLabel:a("settings.account.cloudSync")})}):null}function St({checked:e,disabled:n,onChange:i}){return t.jsx(x,{label:a("settings.account.publicProfile"),hint:a("settings.account.publicProfileHint"),control:t.jsx(j,{checked:e,onChange:i,disabled:n,ariaLabel:a("settings.account.publicProfile")})})}function wt({visible:e,name:n,github:i}){return t.jsx(ge,{initial:!1,children:e?t.jsx(D.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(yt,{name:n,github:i})},"public-profile-fields"):null})}function Ct(){return[{value:"light",label:a("settings.appearance.theme.light"),Icon:pe},{value:"dark",label:a("settings.appearance.theme.dark"),Icon:me},{value:"system",label:a("settings.appearance.theme.system"),Icon:be}]}function Lt(){return[{value:ye,label:a("settings.appearance.language.system")},{value:ve,label:a("settings.appearance.language.english")},{value:je,label:a("settings.appearance.language.chinese")},{value:ke,label:a("settings.appearance.language.traditional_chinese")},{value:Ne,label:a("settings.appearance.language.japanese")},{value:Se,label:a("settings.appearance.language.korean")}]}function Gt(e){if(!e)return null;try{const n=new Date(e);return Number.isNaN(n.getTime())?null:n.toLocaleString()}catch{return null}}function Et(e,n){const i=a(`settings.appearance.currency.rate_source.${e}`),s=Gt(n),o=s?a("settings.appearance.currency.rate_updated",{when:s}):a("settings.appearance.currency.rate_never");return`${i} · ${o}`}function At({locale:e,setLocale:n}){const i=Lt();return t.jsx(F,{value:e,onValueChange:n,options:i,ariaLabel:a("settings.appearance.language.label"),className:"px-2.5 py-1.5 text-xs font-medium",leadingIcon:t.jsx(Ve,{className:"h-3.5 w-3.5 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})})}function It({currency:e,setCurrency:n}){const i=fe().map(s=>({value:s.code,label:a(s.labelKey)}));return t.jsx(F,{value:e,onValueChange:n,options:i,ariaLabel:a("settings.appearance.currency.label"),className:"px-3 py-1.5 text-xs font-medium"})}function Pt({currency:e,rate:n,rateSource:i,rateFetchedAt:s}){if(e===xe)return t.jsx(t.Fragment,{children:a("settings.appearance.currency.hint")});const o=Et(i,s);return t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx("span",{children:`1 USD = ${n.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(Pe,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function _t(){const{theme:e,setTheme:n}=he(),{locale:i,setLocale:s}=U(),{currency:o,rate:r,rateSource:l,rateFetchedAt:u,setCurrency:g}=Ie();return t.jsxs(S,{title:a("settings.section.appearance"),children:[t.jsx(x,{label:a("settings.appearance.theme.label"),hint:a("settings.appearance.theme.hint"),control:t.jsx(M,{options:Ct(),value:e,onChange:n})}),t.jsx(x,{label:a("settings.appearance.language.label"),hint:a("settings.appearance.language.hint"),control:t.jsx(At,{locale:i,setLocale:s})}),t.jsx(x,{label:a("settings.appearance.currency.label"),hint:t.jsx(Pt,{currency:o,rate:r,rateSource:l,rateFetchedAt:u}),control:t.jsx(It,{currency:o,setCurrency:g})})]})}function Ot(){const{available:e,settings:n,setSetting:i,runAction:s}=R();if(!e)return null;const o=!!n?.launchAtLogin,r=n?.launchAtLoginSupported!==!1,l=n?.updateStatus||null,u=!!n?.updateBusy,g=!!n?.isSyncing;return t.jsxs(S,{title:a("settings.section.menubar"),children:[r?t.jsx(x,{label:a("settings.menubar.launchAtLogin"),hint:a("settings.menubar.launchAtLoginHint"),control:t.jsx(j,{checked:o,onChange:()=>i("launchAtLogin",!o),ariaLabel:a("settings.menubar.launchAtLogin")})}):null,t.jsx(x,{label:a("settings.menubar.syncNow"),hint:a("settings.menubar.syncNowHint"),control:t.jsxs("button",{type:"button",onClick:()=>s("syncNow"),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(we,{className:k("h-3.5 w-3.5",g&&"animate-spin"),"aria-hidden":!0}),g?a("settings.menubar.syncing"):a("settings.menubar.syncNow")]})}),t.jsx(x,{label:a("settings.menubar.updates"),hint:l||void 0,control:t.jsxs("button",{type:"button",onClick:()=>s("checkForUpdates"),disabled:u,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(Oe,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.menubar.checkUpdates")]})})]})}function Dt(e,n){function i(r){return r.replace(/^v/,"").split(".").map(Number)}const s=i(e),o=i(n);for(let r=0;r<Math.max(s.length,o.length);r++){const l=s[r]||0,u=o[r]||0;if(l<u)return!0;if(l>u)return!1}return!1}function Tt(){const{available:e,settings:n,runAction:i}=R(),s=e&&n?.version,[o,r]=C.useState(!1),[l,u]=C.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:g}=U(),p="0.65.0",b=async()=>{r(!0);try{const h=await fetch("https://api.github.com/repos/mm7894215/TokenTracker/releases/latest");if(!h.ok)throw new Error("Failed to fetch");const v=await h.json(),w=v.tag_name;Dt(p,w)?u({open:!0,latestVersion:w,htmlUrl:v.html_url}):A({title:a("settings.menubar.updates.upToDate")})}catch(h){console.error("Check updates failed:",h),A({title:a("settings.menubar.updates.failed")})}finally{r(!1)}},f=a("settings.menubar.updates.modalTitle"),y=a("settings.menubar.updates.modalDescription",{version:l.latestVersion}),d=a("settings.menubar.updates.modalConfirm"),m=a("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:[s?t.jsxs(t.Fragment,{children:[t.jsx("span",{children:a("settings.menubar.updates.footerCombined",{barVersion:n.version,coreVersion:p})}),t.jsx("span",{"aria-hidden":!0,children:"·"}),t.jsx("button",{type:"button",onClick:()=>i("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:a("settings.menubar.updates.footerCore",{version:p})}),t.jsx("span",{"aria-hidden":!0,children:"·"}),t.jsx("button",{type:"button",onClick:b,disabled:o,className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300 disabled:opacity-50",children:o?a("settings.menubar.updates.checking"):a("settings.menubar.checkUpdates")}),t.jsx("span",{"aria-hidden":!0,children:"·"})]}),t.jsxs("a",{href:Ce,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(Te,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.footer.statusPage")]})]}),t.jsx(_e,{open:l.open,title:f,description:y,confirmLabel:d,cancelLabel:m,onConfirm:()=>{window.open(l.htmlUrl,"_blank"),u(h=>({...h,open:!1}))},onCancel:()=>u(h=>({...h,open:!1}))})]})}function Ut({prefs:e}){return t.jsx(M,{options:[{value:_.USED,label:a("limits.settings.display_mode_used")},{value:_.REMAINING,label:a("limits.settings.display_mode_remaining")}],value:e.displayMode,onChange:e.setDisplayMode})}function Yt(){const e=Le();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 max-w-3xl px-4 sm:px-6",children:[t.jsxs("div",{className:"mb-8",children:[t.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:a("settings.page.title")}),t.jsx("p",{className:"mt-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.page.subtitle")})]}),t.jsxs("div",{className:"space-y-4",children:[t.jsx(_t,{}),t.jsx(Ot,{}),t.jsx(vt,{}),t.jsx(S,{title:a("settings.section.limits"),action:t.jsx(Ut,{prefs:e}),children:t.jsx(Xe,{prefs:e})})]}),t.jsx(Tt,{})]})})})}export{Yt as SettingsPage};