@ipv9/tokentracker-cli 0.39.38 → 0.39.39

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 (79) hide show
  1. package/README.md +41 -9
  2. package/dashboard/dist/assets/{Card-DD4s0V6T.js → Card-BbRYRVXf.js} +1 -1
  3. package/dashboard/dist/assets/DashboardPage-DYKHv0m3.js +60 -0
  4. package/dashboard/dist/assets/{FadeIn-CUSBK0jm.js → FadeIn-CjAacJ5t.js} +1 -1
  5. package/dashboard/dist/assets/{IpCheckPage-PHF4lPax.js → IpCheckPage-BGALK8Vy.js} +1 -1
  6. package/dashboard/dist/assets/{LimitsPage-dS9C9Vdt.js → LimitsPage-LkZGPYvg.js} +2 -2
  7. package/dashboard/dist/assets/{LocalOnlyNotice-DCmtS_j5.js → LocalOnlyNotice-Dxo2vFMQ.js} +1 -1
  8. package/dashboard/dist/assets/PopoverPopup-DP9fwdtl.js +1 -0
  9. package/dashboard/dist/assets/Select-DPE53NmM.js +1 -0
  10. package/dashboard/dist/assets/SelectItemText-D69v77is.js +12 -0
  11. package/dashboard/dist/assets/SettingsPage-Dxzqpi02.js +1 -0
  12. package/dashboard/dist/assets/SkillsPage-Bo7e39AB.js +1 -0
  13. package/dashboard/dist/assets/WidgetsPage-HHcIr_Eq.js +1 -0
  14. package/dashboard/dist/assets/WrappedPage-C-_jLXXU.js +1 -0
  15. package/dashboard/dist/assets/{arrow-up-right-CjaBQnwI.js → arrow-up-right-BJvJHUGj.js} +1 -1
  16. package/dashboard/dist/assets/{download-DLBqkSwp.js → download-CnzY_EgN.js} +1 -1
  17. package/dashboard/dist/assets/format-1w-q5n2f.js +1 -0
  18. package/dashboard/dist/assets/main-1kxAVM3m.css +1 -0
  19. package/dashboard/dist/assets/main-3gBEI6Jl.js +694 -0
  20. package/dashboard/dist/assets/mock-data-CJOMGcL9.js +1 -0
  21. package/dashboard/dist/assets/use-limits-display-prefs-D1nT9-mr.js +1 -0
  22. package/dashboard/dist/assets/use-native-settings-Dh6NzqjY.js +1 -0
  23. package/dashboard/dist/assets/use-usage-limits-BXR6lzGf.js +1 -0
  24. package/dashboard/dist/assets/useCurrency-Hhs5jbWw.js +1 -0
  25. package/dashboard/dist/index.html +15 -27
  26. package/dashboard/dist/llms.txt +0 -2
  27. package/dashboard/dist/sitemap.xml +0 -12
  28. package/package.json +7 -4
  29. package/src/cli.js +4 -13
  30. package/src/commands/doctor.js +1 -3
  31. package/src/commands/init.js +63 -53
  32. package/src/commands/serve.js +2 -50
  33. package/src/commands/status.js +1 -55
  34. package/src/commands/sync.js +134 -227
  35. package/src/lib/{browser-auth.js → browser-open.js} +3 -149
  36. package/src/lib/claude-categorizer.js +204 -32
  37. package/src/lib/codex-context-breakdown.js +83 -7
  38. package/src/lib/codex-rollout-parser.js +52 -10
  39. package/src/lib/diagnostics.js +1 -49
  40. package/src/lib/doctor.js +12 -87
  41. package/src/lib/file-identity.js +69 -0
  42. package/src/lib/init-flow.js +6 -3
  43. package/src/lib/local-api.js +6 -364
  44. package/src/lib/pricing/curated-overrides.json +1 -1
  45. package/src/lib/pricing/seed-snapshot.json +1 -1
  46. package/src/lib/rollout.js +392 -144
  47. package/src/lib/runtime-config.js +0 -32
  48. package/src/lib/sqlite-reader.js +83 -8
  49. package/dashboard/dist/assets/ActivityHeatmap-BrehqUIb.js +0 -42
  50. package/dashboard/dist/assets/DashboardPage-CyUShBRJ.js +0 -19
  51. package/dashboard/dist/assets/DevicePage-BA74Su1l.js +0 -1
  52. package/dashboard/dist/assets/DialogTitle-DoKsz5wi.js +0 -1
  53. package/dashboard/dist/assets/InsforgeUserHeaderControls-Bk_U2dHr.js +0 -1
  54. package/dashboard/dist/assets/LandingPage-Bbeu84Iu.js +0 -4356
  55. package/dashboard/dist/assets/LeaderboardAvatar-ByqeB6bM.js +0 -1
  56. package/dashboard/dist/assets/LeaderboardPage-BeWXF00S.js +0 -6
  57. package/dashboard/dist/assets/LeaderboardProfileModal-C4yvbZd_.js +0 -72
  58. package/dashboard/dist/assets/LeaderboardProfilePage-D3cbSh5o.js +0 -1
  59. package/dashboard/dist/assets/LoginPage-Ch3UQoWj.js +0 -1
  60. package/dashboard/dist/assets/PopoverPopup-DjG0gjlA.js +0 -1
  61. package/dashboard/dist/assets/Select-HzIjWJpE.js +0 -1
  62. package/dashboard/dist/assets/SelectItemText-f0tCwtvZ.js +0 -1
  63. package/dashboard/dist/assets/SettingsPage-DJOZAlZy.js +0 -1
  64. package/dashboard/dist/assets/SkillsPage-BQcyJIdx.js +0 -1
  65. package/dashboard/dist/assets/WidgetsPage-B_vxuV09.js +0 -1
  66. package/dashboard/dist/assets/WrappedPage-CZN9Y3Vz.js +0 -1
  67. package/dashboard/dist/assets/index-BeoRn2gJ.js +0 -2
  68. package/dashboard/dist/assets/info-BAIxlHIB.js +0 -1
  69. package/dashboard/dist/assets/main-DAcSUW2t.css +0 -1
  70. package/dashboard/dist/assets/main-pi07CfeC.js +0 -1004
  71. package/dashboard/dist/assets/use-limits-display-prefs-CMfASZsh.js +0 -1
  72. package/dashboard/dist/assets/use-native-settings-CfPik-Ao.js +0 -1
  73. package/dashboard/dist/assets/use-spring-wsmJQRqb.js +0 -1
  74. package/dashboard/dist/assets/use-usage-limits-Bt0Dp6kx.js +0 -1
  75. package/dashboard/dist/assets/useCurrency-CsaAMc3j.js +0 -1
  76. package/dashboard/dist/assets/useOpenInteractionType-CPzi5Z8M.js +0 -12
  77. package/dashboard/dist/share.html +0 -140
  78. package/src/commands/device-login.js +0 -161
  79. package/src/lib/upload-throttle.js +0 -148
@@ -1,28 +1,11 @@
1
- const DEFAULT_BASE_URL = "https://srctyff5.us-east.insforge.app";
2
- const DEFAULT_DASHBOARD_URL = "https://www.tokentracker.cc";
3
1
  const DEFAULT_HTTP_TIMEOUT_MS = 20_000;
4
2
 
5
3
  function resolveRuntimeConfig({ cli = {}, config = {}, env = process.env, defaults = {} } = {}) {
6
- const baseUrl = pickString(
7
- cli.baseUrl,
8
- config.baseUrl,
9
- env?.TOKENTRACKER_INSFORGE_BASE_URL,
10
- defaults.baseUrl,
11
- DEFAULT_BASE_URL,
12
- );
13
4
  const dashboardUrl = pickString(
14
5
  cli.dashboardUrl,
15
6
  config.dashboardUrl,
16
7
  env?.TOKENTRACKER_DASHBOARD_URL,
17
8
  defaults.dashboardUrl,
18
- DEFAULT_DASHBOARD_URL,
19
- );
20
- const deviceToken = pickString(
21
- cli.deviceToken,
22
- config.deviceToken,
23
- env?.TOKENTRACKER_DEVICE_TOKEN,
24
- defaults.deviceToken,
25
- null,
26
9
  );
27
10
  const httpTimeoutMs = pickHttpTimeoutMs(
28
11
  cli.httpTimeoutMs,
@@ -32,28 +15,15 @@ function resolveRuntimeConfig({ cli = {}, config = {}, env = process.env, defaul
32
15
  DEFAULT_HTTP_TIMEOUT_MS,
33
16
  );
34
17
  const debug = pickBoolean(cli.debug, config.debug, env?.TOKENTRACKER_DEBUG, defaults.debug, false);
35
- const autoRetryNoSpawn = pickBoolean(
36
- cli.autoRetryNoSpawn,
37
- config.autoRetryNoSpawn,
38
- env?.TOKENTRACKER_AUTO_RETRY_NO_SPAWN,
39
- defaults.autoRetryNoSpawn,
40
- false,
41
- );
42
18
 
43
19
  return {
44
- baseUrl: baseUrl.value,
45
20
  dashboardUrl: dashboardUrl.value,
46
- deviceToken: deviceToken.value,
47
21
  httpTimeoutMs: httpTimeoutMs.value,
48
22
  debug: debug.value,
49
- autoRetryNoSpawn: autoRetryNoSpawn.value,
50
23
  sources: {
51
- baseUrl: baseUrl.source,
52
24
  dashboardUrl: dashboardUrl.source,
53
- deviceToken: deviceToken.source,
54
25
  httpTimeoutMs: httpTimeoutMs.source,
55
26
  debug: debug.source,
56
- autoRetryNoSpawn: autoRetryNoSpawn.source,
57
27
  },
58
28
  };
59
29
  }
@@ -115,8 +85,6 @@ function clampInt(value, min, max) {
115
85
  }
116
86
 
117
87
  module.exports = {
118
- DEFAULT_BASE_URL,
119
- DEFAULT_DASHBOARD_URL,
120
88
  DEFAULT_HTTP_TIMEOUT_MS,
121
89
  resolveRuntimeConfig,
122
90
  };
@@ -51,6 +51,21 @@ function isSqliteCliUnavailable(err) {
51
51
  );
52
52
  }
53
53
 
54
+ // Positively identifies a statement-level failure: the database opened fine,
55
+ // the SQL did not apply to it. Anything we cannot positively identify is
56
+ // treated as a read failure instead — an unknown error must not be reported as
57
+ // "your query is wrong" when it might be a corrupt, locked, or unopenable file.
58
+ function isSqlStatementError(err) {
59
+ const message = formatError(err).toLowerCase();
60
+ return (
61
+ message.includes("no such table") ||
62
+ message.includes("no such column") ||
63
+ message.includes("no such function") ||
64
+ message.includes("syntax error") ||
65
+ message.includes("parse error")
66
+ );
67
+ }
68
+
54
69
  function isNodeSqliteUnavailable(err) {
55
70
  const message = formatError(err).toLowerCase();
56
71
  return (
@@ -75,12 +90,51 @@ function readSqliteRowsWithNode(dbPath, sql, { requireFn }) {
75
90
  }
76
91
  }
77
92
 
78
- function readSqliteJsonRows(dbPath, sql, options = {}) {
79
- if (!dbPath || !sql) return [];
93
+ // Why `rows` alone is not enough for some callers: an empty array is returned
94
+ // for six materially different situations — bad arguments, a path whose
95
+ // existence could not be determined, an absent database, a database that read
96
+ // cleanly and is genuinely empty, a database that could not be opened or read,
97
+ // and a database that rejected the statement. A caller that only ADDS what it
98
+ // finds may treat all six alike, because the worst case is doing nothing.
99
+ // A caller that RECONCILES (applies the delta between what it finds and what it
100
+ // previously recorded) must not: a failed read would look like "everything was
101
+ // deleted" and subtract real data. `reason` exists so such a caller can bail
102
+ // out instead.
103
+ //
104
+ // `ok` is true only for READ_OK, i.e. only when `rows` faithfully represents
105
+ // the database contents.
106
+ // UNREADABLE and QUERY_FAILED are deliberately distinct even though every
107
+ // consumer today treats both as "do not reconcile", because they call for
108
+ // different remedies: UNREADABLE covers no usable sqlite backend as well as a
109
+ // database that is corrupt, locked, or otherwise unopenable; QUERY_FAILED means
110
+ // the database was fine and the statement did not apply to it — the upstream
111
+ // schema moved. Only the missing-backend subset is worth warning about, so
112
+ // warning eligibility is decided separately from this classification.
113
+ const SQLITE_READ_OK = "read";
114
+ const SQLITE_READ_MISSING = "missing";
115
+ const SQLITE_READ_UNREADABLE = "unreadable";
116
+ const SQLITE_READ_QUERY_FAILED = "query-failed";
117
+ const SQLITE_READ_INVALID_ARGS = "invalid-args";
118
+ const SQLITE_READ_STAT_FAILED = "stat-failed";
119
+
120
+ function sqliteReadResult(reason, rows = []) {
121
+ return { ok: reason === SQLITE_READ_OK, reason, rows };
122
+ }
123
+
124
+ function readSqliteJsonRowsWithStatus(dbPath, sql, options = {}) {
125
+ if (!dbPath || !sql) return sqliteReadResult(SQLITE_READ_INVALID_ARGS);
126
+ // `existsSync` cannot be used to tell "absent" from "unstattable": it
127
+ // swallows every error and answers false, so a directory we lack +x on looks
128
+ // identical to a path that was never there. `statSync` keeps them apart.
80
129
  try {
81
- if (!fssync.existsSync(dbPath)) return [];
82
- } catch (_e) {
83
- return [];
130
+ if (!fssync.statSync(dbPath, { throwIfNoEntry: false })) {
131
+ return sqliteReadResult(SQLITE_READ_MISSING);
132
+ }
133
+ } catch (err) {
134
+ // ENOTDIR means a path component is a file, so the target genuinely cannot
135
+ // exist. Anything else — EACCES, ELOOP, a bad argument type — is a failure
136
+ // to determine existence, which is not the same as absence.
137
+ return sqliteReadResult(err?.code === "ENOTDIR" ? SQLITE_READ_MISSING : SQLITE_READ_STAT_FAILED);
84
138
  }
85
139
  const execFileSync = options.execFileSync || cp.execFileSync;
86
140
  const requireFn = options.requireFn || require;
@@ -91,14 +145,14 @@ function readSqliteJsonRows(dbPath, sql, options = {}) {
91
145
 
92
146
  let cliError = null;
93
147
  try {
94
- return readSqliteRowsWithCli(dbPath, sql, { execFileSync, timeout, maxBuffer });
148
+ return sqliteReadResult(SQLITE_READ_OK, readSqliteRowsWithCli(dbPath, sql, { execFileSync, timeout, maxBuffer }));
95
149
  } catch (err) {
96
150
  cliError = err;
97
151
  }
98
152
 
99
153
  let nodeSqliteError = null;
100
154
  try {
101
- return readSqliteRowsWithNode(dbPath, sql, { requireFn });
155
+ return sqliteReadResult(SQLITE_READ_OK, readSqliteRowsWithNode(dbPath, sql, { requireFn }));
102
156
  } catch (err) {
103
157
  nodeSqliteError = err;
104
158
  }
@@ -112,8 +166,22 @@ function readSqliteJsonRows(dbPath, sql, options = {}) {
112
166
  env,
113
167
  stderr: options.stderr,
114
168
  });
169
+ return sqliteReadResult(SQLITE_READ_UNREADABLE);
115
170
  }
116
- return [];
171
+ // Warning eligibility and reason classification are deliberately independent.
172
+ // The warning fires only for a missing backend, because only that is
173
+ // actionable by the user. The reason must additionally separate a rejected
174
+ // statement from a database that could not be opened, locked, or parsed —
175
+ // both reach this line, and only the former is the caller's own doing.
176
+ const rejectedStatement = isSqlStatementError(cliError) || isSqlStatementError(nodeSqliteError);
177
+ return sqliteReadResult(rejectedStatement ? SQLITE_READ_QUERY_FAILED : SQLITE_READ_UNREADABLE);
178
+ }
179
+
180
+ // Unchanged contract: rows only, empty array on every failure. Every existing
181
+ // caller keeps this behavior; only callers that must distinguish the failure
182
+ // modes reach for `readSqliteJsonRowsWithStatus`.
183
+ function readSqliteJsonRows(dbPath, sql, options = {}) {
184
+ return readSqliteJsonRowsWithStatus(dbPath, sql, options).rows;
117
185
  }
118
186
 
119
187
  function readSqliteFirstValue(dbPath, sql, column, options = {}) {
@@ -131,6 +199,13 @@ function resetSqliteReaderWarningsForTests() {
131
199
 
132
200
  module.exports = {
133
201
  readSqliteJsonRows,
202
+ readSqliteJsonRowsWithStatus,
134
203
  readSqliteFirstValue,
135
204
  resetSqliteReaderWarningsForTests,
205
+ SQLITE_READ_OK,
206
+ SQLITE_READ_MISSING,
207
+ SQLITE_READ_UNREADABLE,
208
+ SQLITE_READ_QUERY_FAILED,
209
+ SQLITE_READ_INVALID_ARGS,
210
+ SQLITE_READ_STAT_FAILED,
136
211
  };
@@ -1,42 +0,0 @@
1
- import{c as ue,r as i,j as e,A as n,H as We,l as Fe,C as He,X as Ie,ak as Ge,D as Oe}from"./main-pi07CfeC.js";import{u as qe}from"./useCurrency-CsaAMc3j.js";import{I as Ze}from"./info-BAIxlHIB.js";const Ke=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],Ve=ue("maximize-2",Ke);const Je=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1",key:"kaeet6"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1",key:"1wsw3u"}]],Qe=ue("pause",Je);const et=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],tt=ue("play",et);const at=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],rt=ue("rotate-ccw",at);const ot=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],nt=ue("terminal",ot),Q={emerald:{light:["#ebedf0","#a7f3d0","#6ee7b7","#34d399","#10b981"],dark:["#2d333b","#065f46","#059669","#10b981","#34d399"],gridColor:{light:"rgba(16, 185, 129, 0.12)",dark:"rgba(52, 211, 153, 0.08)"}},ocean:{light:["#f1f5f9","#93c5fd","#60a5fa","#3b82f6","#1d4ed8"],dark:["#1e293b","#1e3a8a","#2563eb","#3b82f6","#60a5fa"],gridColor:{light:"rgba(59, 130, 246, 0.12)",dark:"rgba(96, 165, 250, 0.08)"}},neon:{light:["#faf5ff","#ebd5ff","#c084fc","#a855f7","#7e22ce"],dark:["#2e1065","#581c87","#8b5cf6","#a855f7","#c084fc"],gridColor:{light:"rgba(168, 85, 247, 0.12)",dark:"rgba(192, 132, 252, 0.08)"}},amber:{light:["#fffbeb","#fde68a","#f59e0b","#d97706","#b45309"],dark:["#451a03","#78350f","#b45309","#d97706","#f59e0b"],gridColor:{light:"rgba(245, 158, 11, 0.12)",dark:"rgba(245, 158, 11, 0.08)"}}};function st(l,u){const f=/^#([0-9a-f]{6})$/i.exec(l);if(!f)return l;const c=parseInt(f[1],16),z=c>>16&255,P=c>>8&255,$=c&255,S=L=>Math.max(0,Math.min(255,Math.round(L*u)));return`rgb(${S(z)}, ${S(P)}, ${S($)})`}function O(l,u,f,c,z){const P=Math.cos(c),$=Math.sin(c),S=l*P-u*$,L=l*$+u*P,E=f,T=Math.cos(z),m=Math.sin(z),N=S,ee=L*T-E*m,te=L*m+E*T;return{x:N,y:ee,z:te}}function lt(l,u,f,c,z){return O(l,u,f,c,z)}function Se(l,u){const f=Number(u).toLocaleString();if(l>=4){const c=Math.floor(Math.random()*3)+1;return n(`heatmap.3d.voxel.joke.${c}`,{value:f})}else return l===3?n("heatmap.3d.voxel.level3",{value:f}):l===2?n("heatmap.3d.voxel.level2",{value:f}):l===1?n("heatmap.3d.voxel.level1",{value:f}):n("heatmap.3d.voxel.level0")}function Te({weeks:l,palette:u="auto",isDark:f=!1,interactive:c=!1,autoRotateInit:z=!1,onResetViewRef:P=null}){const $=Q[u]||(u==="auto"?Q.emerald:null),S=$?f?$.dark:$.light:Array.isArray(u)?u:f?Q.emerald.dark:Q.emerald.light,L=$?f?$.gridColor.dark:$.gridColor.light:f?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",E=-.2,T=.88,[m,N]=i.useState({yaw:E,pitch:T}),[ee,te]=i.useState(z),[he,R]=i.useState(1),w=c?13:10.5,pe=i.useMemo(()=>{const t=[],r=l.length;if(r===0||!c)return[];for(let s=0;s<=7;s++){const o=(s-3.5)*w,d=O(-r/2*w,o,0,m.yaw,m.pitch),x=O(r/2*w,o,0,m.yaw,m.pitch);t.push({d:`M${d.x},${d.y} L${x.x},${x.y}`,key:`horiz-${s}`})}for(let s=0;s<=r;s+=4){const o=(s-r/2)*w,d=O(o,-3.5*w,0,m.yaw,m.pitch),x=O(o,3.5*w,0,m.yaw,m.pitch);t.push({d:`M${d.x},${d.y} L${x.x},${x.y}`,key:`vert-${s}`})}if(r%4!==0){const s=(r-r/2)*w,o=O(s,-3.5*w,0,m.yaw,m.pitch),d=O(s,3.5*w,0,m.yaw,m.pitch);t.push({d:`M${o.x},${o.y} L${d.x},${d.y}`,key:"vert-last"})}return t},[l.length,m,w,c]);i.useEffect(()=>{P&&(P.current={reset:()=>{N({yaw:E,pitch:T}),te(!1),R(1),ye()},toggleAutoRotate:t=>{te(t)}})},[P]);const q=i.useRef(null),F=i.useRef(null),W=i.useRef(!1),ie=i.useRef({x:0,y:0}),Z=i.useRef({yaw:E,pitch:T}),Y=i.useRef({x:0,y:0}),oe=i.useRef({x:0,y:0,time:0}),ne=i.useRef(null),[fe,ge]=i.useState(0),K=i.useRef(null),se=i.useRef(!0);i.useEffect(()=>(se.current=!0,()=>{se.current=!1}),[]);const ye=()=>{K.current&&cancelAnimationFrame(K.current),ge(0);const t=performance.now(),r=1200,s=o=>{if(!se.current)return;const d=o-t,x=Math.min(1,d/r),v=1-Math.pow(1-x,3);ge(v),x<1?K.current=requestAnimationFrame(s):K.current=null};K.current=requestAnimationFrame(s)};i.useEffect(()=>(ye(),()=>{K.current&&cancelAnimationFrame(K.current)}),[c]),i.useEffect(()=>{if(!ee||W.current||typeof window>"u"||typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;let r;const s=()=>{if(typeof document<"u"&&document.visibilityState==="hidden"){r=requestAnimationFrame(s);return}N(o=>({yaw:o.yaw+.002,pitch:o.pitch})),r=requestAnimationFrame(s)};return r=requestAnimationFrame(s),()=>cancelAnimationFrame(r)},[ee]);const ce=(t,r)=>{c&&(W.current=!0,ie.current={x:t,y:r},Z.current={yaw:m.yaw,pitch:m.pitch},Y.current={x:0,y:0},oe.current={x:t,y:r,time:performance.now()},ne.current&&cancelAnimationFrame(ne.current))},U=(t,r)=>{if(!W.current)return;const s=t-ie.current.x,o=r-ie.current.y,d=performance.now(),x=d-oe.current.time;x>0&&(Y.current={x:(t-oe.current.x)/x,y:(r-oe.current.y)/x}),oe.current={x:t,y:r,time:d};const v=.005,p=Z.current.yaw-s*v,b=Math.PI/2.3,D=Math.max(-b,Math.min(b,Z.current.pitch-o*v));N({yaw:p,pitch:D})},be=()=>{if(!W.current)return;W.current=!1;let t=-Y.current.x*12,r=-Y.current.y*12;const s=.95,o=()=>{W.current||(t*=s,r*=s,!(Math.abs(t)<.01&&Math.abs(r)<.01)&&(N(d=>{const x=d.yaw+t*.005,v=Math.PI/2.3,p=Math.max(-v,Math.min(v,d.pitch+r*.005));return{yaw:x,pitch:p}}),ne.current=requestAnimationFrame(o)))};ne.current=requestAnimationFrame(o)},[g,de]=i.useState(null),[V,xe]=i.useState({x:0,y:0,shiftX:0}),y=i.useRef(null);i.useEffect(()=>()=>{y.current&&clearTimeout(y.current)},[]),i.useEffect(()=>{if(!c||!F.current)return;const t=s=>{s.preventDefault();const o=-s.deltaY*.0025;R(d=>{const x=d+o;return Math.max(.5,Math.min(3,x))})},r=F.current;return r.addEventListener("wheel",t,{passive:!1}),()=>{r.removeEventListener("wheel",t)}},[c]);const C=i.useMemo(()=>{const t=[];return l.forEach((r,s)=>{(Array.isArray(r)?r:[]).forEach((o,d)=>{o&&t.push({key:o.day||`${s}-${d}`,col:s,row:d,level:o.level||0,value:o.value||0,total_tokens:o.total_tokens||0,day:o.day,models:o.models||null})})}),t},[l]),ve=w-(c?1.8:1.5),ke=c?38:28,J=t=>Math.max(1.8,Number(t)/4*ke),ae=i.useMemo(()=>{if(C.length===0)return[];const t=l.length;return C.map(r=>{const s=J(r.level),o=Math.sqrt(Math.pow(r.col-t/2,2)+Math.pow(r.row-3.5,2)),d=Math.sqrt(Math.pow(t/2,2)+Math.pow(3.5,2)),x=o/d*.4,v=Math.min(1,Math.max(0,(fe-x)*(1/.6))),p=s*v,b=(r.col-t/2)*w,D=(r.row-3.5)*w,k=ve/2,H=[{x:b-k,y:D-k,z:0},{x:b+k,y:D-k,z:0},{x:b+k,y:D+k,z:0},{x:b-k,y:D+k,z:0},{x:b-k,y:D-k,z:p},{x:b+k,y:D-k,z:p},{x:b+k,y:D+k,z:p},{x:b-k,y:D+k,z:p}].map(B=>O(B.x,B.y,B.z,m.yaw,m.pitch)),me=O(b,D,p/2,m.yaw,m.pitch),Ee=[{name:"top",indices:[4,5,6,7],scale:1,normal:[0,0,1]},{name:"bottom",indices:[3,2,1,0],scale:.4,normal:[0,0,-1]},{name:"left",indices:[3,0,4,7],scale:.55,normal:[-1,0,0]},{name:"right",indices:[1,2,6,5],scale:.75,normal:[1,0,0]},{name:"front",indices:[0,1,5,4],scale:.85,normal:[0,-1,0]},{name:"back",indices:[2,3,7,6],scale:.65,normal:[0,1,0]}],Ae=S[Math.min(4,Math.max(0,Number(r.level)||0))],Ne=[],Re=.35,De=-.4,Pe=.83;return Ee.forEach(B=>{const we=lt(B.normal[0],B.normal[1],B.normal[2],m.yaw,m.pitch);if(we.z>.001){const Ce=H[B.indices[0]],ze=H[B.indices[1]],Me=H[B.indices[2]],_e=H[B.indices[3]],Ye=`M${Ce.x},${Ce.y} L${ze.x},${ze.y} L${Me.x},${Me.y} L${_e.x},${_e.y} Z`,Ue=we.x*Re+we.y*De+we.z*Pe,Xe=f?.18:0,Be=B.scale*(.82+.28*Math.max(0,Ue))+Xe;Ne.push({name:B.name,d:Ye,fill:st(Ae,Be)})}}),{...r,centerProj:me,renderedFaces:Ne}})},[C,m,S,l.length,fe,w,ve,ke]),le=i.useMemo(()=>[...ae].sort((t,r)=>t.centerProj.z-r.centerProj.z),[ae]),M=i.useMemo(()=>{if(le.length===0)return{minX:-100,minY:-100,maxX:100,maxY:100};let t=1/0,r=1/0,s=-1/0,o=-1/0;return le.forEach(d=>{const x=w*2,v=d.centerProj.x,p=d.centerProj.y;v-x<t&&(t=v-x),v+x>s&&(s=v+x),p-x<r&&(r=p-x),p+x>o&&(o=p+x)}),{minX:t,minY:r,maxX:s,maxY:o}},[le,w]),A=12,a=M.maxX-M.minX+A*2,h=M.maxY-M.minY+A*2,_=a/he,j=h/he,X=M.minX-A+(a-_)/2,I=M.minY-A+(h-j)/2,G=`${X} ${I} ${_} ${j}`;return C.length===0?e.jsx("div",{className:"py-8 text-center text-sm text-oai-gray-500",children:n("heatmap.empty")}):e.jsxs("div",{ref:F,className:`relative select-none outline-none ${c?"cursor-grab active:cursor-grabbing w-full h-full flex items-center justify-center":"w-full overflow-hidden flex justify-center"}`,onMouseDown:t=>{if(!c)return;ce(t.clientX,t.clientY);const r=o=>U(o.clientX,o.clientY),s=()=>{be(),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",r),window.addEventListener("mouseup",s)},onTouchStart:t=>{!c||t.touches.length===0||ce(t.touches[0].clientX,t.touches[0].clientY)},onTouchMove:t=>{!c||t.touches.length===0||U(t.touches[0].clientX,t.touches[0].clientY)},onTouchEnd:()=>{c&&be()},children:[e.jsxs("svg",{ref:q,viewBox:G,width:c?"95%":"100%",height:c?"95%":"auto",role:"img","aria-label":n("heatmap.iso.aria")||"3D interactive activity heatmap",style:{display:"block",width:"100%",height:"auto",maxWidth:c?"none":`${a}px`,maxHeight:c?"78vh":"none"},className:"transition-transform duration-300 ease-out",children:[c&&pe.map(t=>e.jsx("path",{d:t.d,fill:"none",stroke:L,strokeWidth:.25,strokeDasharray:"1.5 2.5",strokeLinecap:"round"},t.key)),le.map(t=>{const r=g&&g.key===t.key;return e.jsxs("g",{onMouseEnter:s=>{if(y.current&&(clearTimeout(y.current),y.current=null),de(t),c&&q.current){const o=O((t.col-l.length/2)*w,(t.row-3.5)*w,J(t.level),m.yaw,m.pitch);let d=0,x=0;const v=q.current;if(F.current&&typeof v.createSVGPoint=="function"&&typeof v.getScreenCTM=="function")try{const k=v.createSVGPoint();k.x=o.x,k.y=o.y;const re=v.getScreenCTM();if(re){const H=k.matrixTransform(re),me=F.current.getBoundingClientRect();d=H.x-me.left,x=H.y-me.top}}catch{const re=v.getBoundingClientRect(),H=M.maxX-M.minX+A*2,me=M.maxY-M.minY+A*2;d=(o.x-(M.minX-A))/H*re.width,x=(o.y-(M.minY-A))/me*re.height}else{const k=v.getBoundingClientRect(),re=M.maxX-M.minX+A*2,H=M.maxY-M.minY+A*2;d=(o.x-(M.minX-A))/re*k.width,x=(o.y-(M.minY-A))/H*k.height}const p=140;let b=0;const D=F.current?F.current.getBoundingClientRect().width:v.getBoundingClientRect().width;d<p?b=p-d:d>D-p&&(b=D-p-d),xe({x:d,y:x,shiftX:b})}},onMouseLeave:()=>{y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{de(null)},150)},className:"transition-all duration-200",style:{filter:r?"brightness(1.15) drop-shadow(0 4px 6px rgba(0,0,0,0.15))":"none",cursor:c?"pointer":"default"},children:[!c&&t.day&&e.jsx("title",{children:`${t.day}: ${Number(t.value).toLocaleString()} conversations`}),t.renderedFaces.map((s,o)=>e.jsx("path",{d:s.d,fill:s.fill,stroke:s.fill,strokeWidth:.25,strokeLinejoin:"round"},o))]},t.key)})]}),c&&g&&e.jsxs("div",{onMouseEnter:()=>{y.current&&(clearTimeout(y.current),y.current=null)},onMouseLeave:()=>{y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{de(null)},150)},className:"absolute z-[9999] w-0 h-0 transition-all duration-100 ease-out",style:{left:`${V.x}px`,top:`${V.y}px`},children:[e.jsxs("div",{className:"absolute left-0 bottom-[10px] backdrop-blur-md bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-xl rounded-xl p-3.5 max-w-[280px] min-w-[200px] flex flex-col gap-2 animate-in fade-in zoom-in-95 duration-100",style:{transform:`translateX(calc(-50% + ${V.shiftX}px))`},children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-oai-gray-100 dark:border-oai-gray-800/80 pb-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-oai-gray-500 dark:text-oai-gray-400",children:g.day}),(()=>{const t=g.level===0?f?"#9ca3af":"#6b7280":S[g.level];return e.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium",style:{backgroundColor:t+"22",color:t,border:`1px solid ${t}44`},children:["Level ",g.level]})})()]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:"text-lg font-bold text-oai-gray-900 dark:text-white leading-none tabular-nums",children:Number(g.value??0).toLocaleString()}),e.jsx("span",{className:"text-[10px] text-oai-gray-400 uppercase tracking-wider font-semibold",children:"Conversations"})]}),e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:"text-[11px] font-semibold text-oai-gray-500 dark:text-oai-gray-400 leading-none tabular-nums",children:Number(g.total_tokens??0).toLocaleString()}),e.jsx("span",{className:"text-[9px] text-oai-gray-400 uppercase tracking-wider",children:"tokens"})]})]}),g.models&&Object.keys(g.models).length>0?e.jsxs("div",{className:"mt-1.5 border-t border-oai-gray-100 dark:border-oai-gray-800/60 pt-2 flex flex-col gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-semibold text-oai-gray-400 dark:text-oai-gray-500 uppercase tracking-wider",children:"Model Breakdown"}),e.jsx("div",{className:"flex flex-col gap-2 max-h-[150px] overflow-y-auto pr-1.5 scrollbar-thin",children:Object.entries(g.models).map(([t,r])=>({name:t,val:Number(r)})).sort((t,r)=>r.val-t.val).map(({name:t,val:r})=>{const s=Number(g.total_tokens)||Object.values(g.models).reduce((d,x)=>d+Number(x||0),0)||1,o=Math.round(r/s*100);return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px] gap-3",children:[e.jsx("span",{className:"font-medium text-oai-gray-750 dark:text-oai-gray-200 truncate max-w-[120px]",title:t,children:t}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("span",{className:"font-mono text-oai-gray-900 dark:text-oai-gray-100 font-semibold",children:r.toLocaleString()}),e.jsxs("span",{className:"text-[9px] text-oai-gray-450 dark:text-oai-gray-500 min-w-[28px] text-right font-medium",children:[o,"%"]})]})]}),e.jsx("div",{className:"w-full h-1 bg-oai-gray-100 dark:bg-oai-gray-800/85 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${o}%`,backgroundColor:S[4],boxShadow:`0 0 4px ${S[4]}55`}})})]},t)})})]}):e.jsx("p",{className:"text-[11px] text-oai-gray-600 dark:text-oai-gray-300 leading-relaxed font-normal mt-1 border-t border-dashed border-oai-gray-100 dark:border-oai-gray-800/60 pt-1.5",children:Se(g.level,g.value)})]})]}),e.jsx("div",{className:"absolute bottom-[6px] left-0 -translate-x-1/2 w-2.5 h-2.5 rotate-45 bg-white dark:bg-oai-gray-900 border-r border-b border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-sm",style:{marginBottom:"1px"}})]})]})}const it=12,ct=3,dt=26,mt=["#ebedf0","#f7d08a","#f2b757","#eca02f","#d9861a"],xt=["#30363d","#7a4711","#bf7015","#eca02f","#f7c877"];function $e(l){const u=Number(l);return Number.isFinite(u)?u<1e3?u.toLocaleString():Oe(u,{decimals:2}):"0"}function ut(l){if(typeof l!="string")return null;const u=/^(\d{4})-(\d{2})-(\d{2})$/.exec(l.trim());if(!u)return null;const f=new Date(Date.UTC(Number(u[1]),Number(u[2])-1,Number(u[3])));return Number.isFinite(f.getTime())?f:null}function Le(l,u){return new Date(Date.UTC(l.getUTCFullYear(),l.getUTCMonth(),l.getUTCDate()+u))}function ht(l,u){return Math.floor((Date.UTC(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate())-Date.UTC(l.getUTCFullYear(),l.getUTCMonth(),l.getUTCDate()))/864e5)}function pt(l,u){const f=u==="mon"?1:0,c=l.getUTCDay();return Le(l,-((c-f+7)%7))}function ft(l,u,f,c){if(!l)return[];const z=ut(u)||new Date,P=[];for(let T=11;T>=0;T-=1)P.push(new Date(Date.UTC(z.getUTCFullYear(),z.getUTCMonth()-T,1)));const $=pt(z,f),S=Le($,-(l-1)*7),L=[],E=new Set;for(const T of P){const m=Math.floor(ht(S,T)/7);m<0||m>=l||E.has(m)||(E.add(m),L.push({label:c[T.getUTCMonth()],index:m}))}return L}function vt({heatmap:l,timeZoneLabel:u,timeZoneShortLabel:f,hideLegend:c=!1,embedded:z=!1}){const{resolvedTheme:P}=We(),{currency:$,rate:S}=qe(),L=P==="dark",E=L?xt:mt,T=i.useRef(null),m=i.useRef(null),[N,ee]=i.useState(null),[te,he]=i.useState({x:0,y:0,shiftX:0}),R=i.useRef(null);i.useEffect(()=>()=>{R.current&&clearTimeout(R.current)},[]);const[w,pe]=i.useState(!1),[q,F]=i.useState(!1),[W,ie]=i.useState(!1),Z=i.useRef(null),[Y,oe]=i.useState("amber"),ne=[n("heatmap.month.jan"),n("heatmap.month.feb"),n("heatmap.month.mar"),n("heatmap.month.apr"),n("heatmap.month.may"),n("heatmap.month.jun"),n("heatmap.month.jul"),n("heatmap.month.aug"),n("heatmap.month.sep"),n("heatmap.month.oct"),n("heatmap.month.nov"),n("heatmap.month.dec")],fe=(a,h)=>{if(!h||!h.day)return;R.current&&(clearTimeout(R.current),R.current=null),ee(h);const _=a.currentTarget.getBoundingClientRect(),j=typeof window<"u"?window.innerWidth:1024,X=_.left+_.width/2,I=_.top,G=140;let t=0;X<G?t=G-X:X>j-G&&(t=j-G-X),he({x:X,y:I,shiftX:t})},ge=()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{ee(null)},150)},K=()=>{F(!1),pe(!0)},se=()=>{F(!0)},ye=a=>{a.target===a.currentTarget&&q&&(pe(!1),F(!1))};i.useEffect(()=>{if(!w||q)return;const a=h=>{h.key==="Escape"&&se()};return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[w,q]);const ce=i.useMemo(()=>({emerald:{accentText:"text-emerald-500 dark:text-emerald-400",accentBg:"bg-emerald-500/10 dark:bg-emerald-400/10",accentBorder:"border-emerald-500/20 dark:border-emerald-400/15",hoverBorder:"hover:border-emerald-500/30 dark:hover:border-emerald-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(16,185,129,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(52,211,153,0.25)]",rawColor:"#10b981"},ocean:{accentText:"text-blue-500 dark:text-blue-400",accentBg:"bg-blue-500/10 dark:bg-blue-400/10",accentBorder:"border-blue-500/20 dark:border-blue-400/15",hoverBorder:"hover:border-blue-500/30 dark:hover:border-blue-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(59,130,246,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(96,165,250,0.25)]",rawColor:"#3b82f6"},neon:{accentText:"text-purple-500 dark:text-purple-400",accentBg:"bg-purple-500/10 dark:bg-purple-400/10",accentBorder:"border-purple-500/20 dark:border-purple-400/15",hoverBorder:"hover:border-purple-500/30 dark:hover:border-purple-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(168,85,247,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(192,132,252,0.25)]",rawColor:"#a855f7"},amber:{accentText:"text-amber-500 dark:text-amber-400",accentBg:"bg-amber-500/10 dark:bg-amber-400/10",accentBorder:"border-amber-500/20 dark:border-amber-400/15",hoverBorder:"hover:border-amber-500/30 dark:hover:border-amber-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(245,158,11,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(245,158,11,0.25)]",rawColor:"#f59e0b"}}),[]),U=ce[Y]||ce.emerald,be=Q[Y]?L?Q[Y].dark:Q[Y].light:L?Q.emerald.dark:Q.emerald.light,[g,de]=i.useState(()=>{if(z)return"2d";try{return window.localStorage?.getItem("tt:heatmap-view")==="3d"?"3d":"2d"}catch{return"2d"}});i.useEffect(()=>{if(!z)try{window.localStorage?.setItem("tt:heatmap-view",g)}catch{}},[g,z]),i.useEffect(()=>{if(g!=="2d")return;const a=T.current;a&&(a.scrollLeft=a.scrollWidth)},[l?.weeks,g]),i.useEffect(()=>{const a=T.current;if(!a)return;const h=()=>{R.current&&(clearTimeout(R.current),R.current=null),ee(null)};return a.addEventListener("scroll",h),()=>a.removeEventListener("scroll",h)},[]);const V=l?.week_starts_on==="mon"?"mon":"sun",xe=i.useMemo(()=>{const a=Array.isArray(l?.weeks)?l.weeks:[];if(!a.length)return{weeks:[]};const h=[];for(const _ of a)for(const j of Array.isArray(_)?_:[])j?.day&&h.push({day:j.day,conversation_count:j.conversation_count??0,total_tokens:j.total_tokens??0,billable_total_tokens:j.billable_total_tokens??j.total_tokens??0,models:j.models??null});return Fe({dailyRows:h,weeks:Math.max(52,a.length),to:l?.to,weekStartsOn:V})},[l?.to,l?.weeks,V]),y=xe?.weeks||[],C=i.useMemo(()=>{let a=0,h=0,_={day:"无数据",value:0},j=0,X=0;const I=[];y.forEach(p=>{(Array.isArray(p)?p:[]).forEach(b=>{b&&b.day&&I.push(b)})}),I.sort((p,b)=>p.day.localeCompare(b.day)),I.forEach(p=>{const b=Number(p.value)||0;a+=Number(p.total_tokens)||0,b>0?(h++,j++,j>X&&(X=j)):j=0,b>_.value&&(_={day:p.day,value:b})});const G=I.length||365,t=(h/G*100).toFixed(1);let r="heatmap.3d.modal.ai.eval.default",s="heatmap.3d.modal.ai.title.default";a>=15e6?(s="heatmap.3d.modal.ai.title.peak",r="heatmap.3d.modal.ai.eval.peak"):a>=5e6?(s="heatmap.3d.modal.ai.title.heavy",r="heatmap.3d.modal.ai.eval.heavy"):a>=1e6?(s="heatmap.3d.modal.ai.title.core",r="heatmap.3d.modal.ai.eval.core"):a>=2e4&&(s="heatmap.3d.modal.ai.title.steady",r="heatmap.3d.modal.ai.eval.steady");const o=l?.total_cost_usd,d=Number(o),v=o!=null&&(typeof o!="string"||o.trim()!=="")&&Number.isFinite(d)?d:a/15e5;return{totalTokens:a,activeDays:h,activeRate:t,maxSingleDay:_,maxStreak:X,aiEvaluationTitleKey:s,aiEvaluationKey:r,totalCostUsd:v}},[y,l?.total_cost_usd]),je=i.useMemo(()=>He(C.totalCostUsd,{currency:$,rate:S}),[C.totalCostUsd,$,S]),ve=V==="mon"?["Mon","Tue","Wed","Thu","Fri","Sat","Sun"].map(a=>n(`heatmap.day.${a.toLowerCase()}`)):["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(a=>n(`heatmap.day.${a.toLowerCase()}`)),ke=i.useMemo(()=>ft(y.length,xe?.to,V,ne),[xe?.to,y.length,V,ne]);if(!y.length)return e.jsx("div",{className:"py-8 text-center text-sm text-oai-gray-500",children:n("heatmap.empty")});const J=z?10:it,ae=z?2:ct,le=z?22:dt,M=le+y.length*J+Math.max(0,y.length-1)*ae,A=`${le}px repeat(${y.length}, ${J}px)`;return e.jsxs("div",{ref:m,className:z?"relative":"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-5",children:[!z&&e.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:n("heatmap.title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{role:"tablist","aria-label":"Heatmap view",className:"flex rounded-md border border-oai-gray-200 dark:border-oai-gray-800 p-0.5 text-[10px]",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":g==="2d",onClick:()=>de("2d"),className:g==="2d"?"px-2 py-0.5 rounded bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-oai-white font-medium":"px-2 py-0.5 rounded text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200",children:n("heatmap.view.2d")}),e.jsx("button",{type:"button",role:"tab","aria-selected":g==="3d",onClick:()=>de("3d"),className:g==="3d"?"px-2 py-0.5 rounded bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-oai-white font-medium":"px-2 py-0.5 rounded text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200",children:n("heatmap.view.3d")})]}),e.jsx("span",{className:"text-xs text-oai-gray-400 dark:text-oai-gray-450",children:f||n("heatmap.legend.utc")})]})]}),g==="3d"&&e.jsxs("div",{onClick:K,className:"cursor-pointer group relative overflow-hidden rounded-lg hover:border-oai-gray-350 dark:hover:border-oai-gray-700 border border-transparent transition-all",title:n("heatmap.3d.hover_tip"),children:[e.jsx(Te,{weeks:y,isDark:L,palette:Y}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-oai-gray-900/5 to-transparent pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity flex items-end justify-center pb-2",children:e.jsxs("span",{className:"text-[10px] bg-white/95 dark:bg-oai-gray-900/95 shadow border border-oai-gray-200/60 dark:border-oai-gray-800/80 px-2.5 py-1 rounded-full font-medium text-oai-gray-500 dark:text-oai-gray-400 flex items-center gap-1 transform translate-y-2 group-hover:translate-y-0 transition-transform duration-200",children:[e.jsx(Ve,{size:9}),n("heatmap.3d.hover_tip")]})})]}),g==="2d"&&e.jsx("div",{ref:T,className:"overflow-x-auto overflow-y-hidden heatmap-scroll-thin",children:e.jsxs("div",{style:{minWidth:M},children:[e.jsxs("div",{className:"grid text-[10px] uppercase text-oai-gray-400 dark:text-oai-gray-400 mb-1",style:{gridTemplateColumns:A,columnGap:ae},children:[e.jsx("span",{}),ke.map(a=>e.jsx("span",{style:{gridColumnStart:a.index+2},className:"whitespace-nowrap",children:a.label},`${a.label}-${a.index}`))]}),e.jsxs("div",{className:"grid",style:{gridTemplateColumns:A,columnGap:ae},children:[e.jsx("div",{className:"grid text-[10px] text-oai-gray-400 dark:text-oai-gray-400 sticky left-0 bg-white dark:bg-oai-gray-900 pr-2",style:{gridTemplateRows:`repeat(7, ${J}px)`,rowGap:ae},children:ve.map(a=>e.jsx("span",{className:"leading-none",children:a},a))}),e.jsx("div",{className:"grid",style:{gridAutoFlow:"column",gridTemplateRows:`repeat(7, ${J}px)`,gap:ae},children:y.map((a,h)=>(Array.isArray(a)?a:[]).map((_,j)=>{if(!_)return null;const X=_.day||`e-${h}-${j}`,I=Number(_.level)||0,G=E[I]||E[0];return e.jsx("span",{onMouseEnter:t=>fe(t,_),onMouseLeave:ge,className:"rounded-[2px] transition-transform hover:scale-125 hover:z-10 cursor-pointer",style:{width:J,height:J,background:G}},X)}))})]})]})}),!c&&e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[e.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-400",children:n("heatmap.legend.less")}),e.jsx("div",{className:"flex gap-0.5",children:E.map((a,h)=>e.jsx("span",{className:"rounded-[1px]",style:{width:10,height:10,background:a}},h))}),e.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-400",children:n("heatmap.legend.more")})]}),w&&e.jsx("div",{onAnimationEnd:ye,onClick:a=>{a.target===a.currentTarget&&se()},className:`fixed inset-0 z-50 flex items-center justify-center p-3 md:p-6 backdrop-blur-md bg-black/15 dark:bg-black/40 ${q?"animate-tt-fade-out":"animate-tt-fade-in"}`,children:e.jsxs("div",{className:`relative w-full max-w-6xl h-[88vh] backdrop-blur-2xl bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-white/10 shadow-2xl rounded-2xl flex flex-col md:flex-row overflow-hidden ${q?"animate-tt-modal-exit":"animate-tt-modal"}`,children:[e.jsx("button",{type:"button",onClick:se,className:"absolute top-4 right-4 z-50 p-2 rounded-full border border-oai-gray-200/60 dark:border-oai-gray-800/60 bg-white/50 dark:bg-oai-gray-900/50 text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:rotate-90 hover:scale-105 active:scale-95 transition-all duration-300",children:e.jsx(Ie,{size:16})}),e.jsxs("div",{className:"w-full md:w-[340px] border-b md:border-b-0 md:border-r border-zinc-200/50 dark:border-zinc-800/40 p-5 md:p-6 flex flex-col gap-6 overflow-y-auto backdrop-blur-md bg-zinc-50/50 dark:bg-zinc-950/50",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 select-none",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:U.rawColor}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:U.rawColor}})]}),e.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500",children:"3D Insight"})]}),e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-none mt-2 select-none",children:n("heatmap.3d.modal.title")}),e.jsx("p",{className:"text-[11px] leading-relaxed text-zinc-400 dark:text-zinc-500 mt-2 font-normal select-none",children:n("heatmap.3d.modal.desc")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-5 gap-y-5 border-y border-zinc-200/50 dark:border-zinc-800/50 py-5 select-none",children:[e.jsxs("div",{className:"flex flex-col gap-1 relative group cursor-help",children:[e.jsx("div",{className:"absolute left-0 bottom-full mb-2 pointer-events-none opacity-0 translate-y-1 group-hover:opacity-100 group-hover:translate-y-0 transition-all duration-200 z-50",children:e.jsxs("div",{className:"bg-white dark:bg-zinc-950 text-zinc-900 dark:text-zinc-50 text-[10px] font-semibold font-mono rounded-lg px-2.5 py-1.5 shadow-xl border border-zinc-200 dark:border-zinc-800/80 whitespace-nowrap flex flex-col",children:[e.jsx("span",{className:"text-[9px] text-zinc-400 dark:text-zinc-500",children:n("heatmap.3d.modal.stats.precision_total_tokens")}),e.jsxs("span",{className:"mt-0.5 font-bold text-zinc-900 dark:text-zinc-50",children:[C.totalTokens.toLocaleString()," Tokens"]})]})}),e.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:n("heatmap.3d.modal.stats.total_tokens")}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:$e(C.totalTokens)}),e.jsx("div",{className:"opacity-30 group-hover:opacity-60 transition-opacity",children:e.jsx("svg",{width:"24",height:"10",viewBox:"0 0 24 10",fill:"none",children:e.jsx("path",{d:"M1 9C3 7 5 7 7 4C9 1 11 0 13 2C15 4 17 0 23 0",stroke:U.rawColor,strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 group cursor-default",children:[e.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:n("heatmap.3d.modal.stats.estimated_cost")}),e.jsx("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:je})]}),e.jsxs("div",{className:"flex flex-col gap-1 group cursor-default",children:[e.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:n("heatmap.3d.modal.stats.active_rate_days")}),e.jsxs("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:[C.activeRate,"% ",e.jsxs("span",{className:"text-[10px] font-bold text-zinc-400 dark:text-zinc-500 font-mono",children:["(",C.activeDays,"D)"]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 group cursor-default",children:[e.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:n("heatmap.3d.modal.stats.max_streak")}),e.jsxs("span",{className:"text-xl font-black text-amber-500 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:[C.maxStreak," ",e.jsx("span",{className:"text-[10px] font-bold text-amber-500/80 font-mono",children:n("heatmap.3d.modal.stats.days_suffix")})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 col-span-2 relative group cursor-help",children:[e.jsx("div",{className:"absolute left-0 bottom-full mb-2 pointer-events-none opacity-0 translate-y-1 group-hover:opacity-100 group-hover:translate-y-0 transition-all duration-200 z-50",children:e.jsxs("div",{className:"bg-white dark:bg-zinc-950 text-zinc-900 dark:text-zinc-50 text-[10px] font-semibold font-mono rounded-lg px-2.5 py-1.5 shadow-xl border border-zinc-200 dark:border-zinc-800/80 whitespace-nowrap flex flex-col",children:[e.jsx("span",{className:"text-[9px] text-zinc-400 dark:text-zinc-500",children:n("heatmap.3d.modal.stats.precision_peak_value")}),e.jsxs("span",{className:"mt-0.5 font-bold text-zinc-900 dark:text-zinc-50",children:[C.maxSingleDay.value>0?C.maxSingleDay.value.toLocaleString():n("heatmap.3d.modal.stats.no_data")," conversations"]}),e.jsx("span",{className:"text-[8px] text-zinc-400 dark:text-zinc-500 mt-0.5",children:C.maxSingleDay.day!=="无数据"?C.maxSingleDay.day:n("heatmap.3d.modal.stats.no_data")})]})}),e.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:n("heatmap.3d.modal.stats.peak_day")}),e.jsxs("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:[C.maxSingleDay.value>0?$e(C.maxSingleDay.value):n("heatmap.3d.modal.stats.no_data")," ",e.jsxs("span",{className:"text-[10px] font-bold text-zinc-400 dark:text-zinc-500 font-mono",children:["(",C.maxSingleDay.day!=="无数据"?C.maxSingleDay.day:n("heatmap.3d.modal.stats.no_data"),")"]})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2.5 py-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 select-none",children:[e.jsx(nt,{size:11,style:{color:U.rawColor}}),e.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono",style:{color:U.rawColor},children:n(C.aiEvaluationTitleKey)})]}),e.jsxs("div",{className:"pl-3.5 border-l-2 relative transition-all duration-300 group",style:{borderColor:U.rawColor},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px] blur-[2px] opacity-15 pointer-events-none rounded-full",style:{backgroundColor:U.rawColor}}),e.jsx("p",{className:"text-[11px] leading-relaxed text-zinc-600 dark:text-zinc-400 font-normal",children:n(C.aiEvaluationKey)})]})]}),e.jsx("div",{className:"mt-auto border-t border-zinc-200/50 dark:border-zinc-800/50 pt-4 select-none",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:n("heatmap.3d.modal.legend.title")}),e.jsx("span",{className:"text-[10px] font-medium text-zinc-500 dark:text-zinc-400",children:n(`heatmap.3d.modal.palette.${Y}`)})]}),e.jsx("div",{className:"flex gap-1",children:be.map((a,h)=>e.jsx("div",{className:"flex-1 h-1 rounded-[2px]",style:{backgroundColor:a},title:`Level ${h}`},h))})]})})]}),e.jsxs("div",{className:"flex-1 h-full relative flex items-center justify-center overflow-hidden p-4",children:[e.jsx("div",{className:"absolute top-1/4 left-1/3 w-96 h-96 rounded-full blur-[130px] pointer-events-none -translate-x-1/2 -translate-y-1/2 transition-all duration-500",style:{backgroundColor:U.rawColor+"15"}}),e.jsx("div",{className:"absolute bottom-1/4 right-1/3 w-80 h-80 rounded-full blur-[120px] pointer-events-none translate-x-1/2 translate-y-1/2 bg-purple-500/[0.04] dark:bg-purple-500/[0.08]"}),e.jsxs("div",{className:"absolute top-4 left-1/2 -translate-x-1/2 flex items-center gap-3 p-1.5 backdrop-blur-md bg-white/70 dark:bg-oai-gray-900/75 border border-oai-gray-200/60 dark:border-oai-gray-800/80 rounded-full shadow-lg z-30 select-none",children:[e.jsx("div",{className:"flex items-center gap-1.5 px-2",children:Object.keys(ce).map(a=>{const h=Y===a;return e.jsx("button",{type:"button",onClick:()=>oe(a),title:n(`heatmap.3d.modal.palette.${a}`),className:`w-3.5 h-3.5 rounded-full transition-all duration-200 relative hover:scale-125 ${a==="emerald"?"bg-[#10b981]":a==="ocean"?"bg-[#3b82f6]":a==="neon"?"bg-[#a855f7]":"bg-[#f59e0b]"}`,children:h&&e.jsx("span",{className:"absolute inset-0 rounded-full ring-2 ring-offset-1 ring-offset-white dark:ring-offset-oai-gray-900 ring-oai-gray-900 dark:ring-white scale-110"})},a)})}),e.jsx("div",{className:"w-[1px] h-4 bg-oai-gray-200 dark:bg-oai-gray-800"}),e.jsxs("div",{className:"flex items-center gap-1 pr-1",children:[e.jsx("button",{type:"button",onClick:()=>{const a=!W;ie(a),Z.current&&Z.current.toggleAutoRotate(a)},title:W?n("heatmap.3d.modal.control.pause"):n("heatmap.3d.modal.control.play"),className:`p-1.5 rounded-full transition-all duration-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 ${W?U.accentText:"text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-250"}`,children:W?e.jsx(Qe,{size:12}):e.jsx(tt,{size:12})}),e.jsx("button",{type:"button",onClick:()=>{ie(!1),Z.current&&Z.current.reset()},title:n("heatmap.3d.modal.control.reset"),className:"p-1.5 rounded-full text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-250 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-all duration-200",children:e.jsx(rt,{size:12})})]})]}),e.jsx(Te,{weeks:y,isDark:L,interactive:!0,palette:Y,autoRotateInit:W,onResetViewRef:Z}),e.jsxs("div",{className:"absolute bottom-4 right-4 flex items-center gap-1.5 text-[9px] font-bold text-oai-gray-400 bg-white/80 dark:bg-oai-gray-900/80 border border-oai-gray-200/50 dark:border-oai-gray-800/80 rounded-md px-2.5 py-1.5 select-none pointer-events-none backdrop-blur-md shadow-sm",children:[e.jsx(Ze,{size:10,className:U.accentText}),e.jsx("span",{children:n("heatmap.3d.modal.footer.tip")})]})]})]})}),N&&!w&&typeof document<"u"&&Ge.createPortal(e.jsxs("div",{className:"fixed z-[9999] w-0 h-0 transition-all duration-100 ease-out pointer-events-none",style:{left:`${te.x}px`,top:`${te.y}px`},children:[e.jsxs("div",{className:"absolute left-0 bottom-[10px] backdrop-blur-md bg-white/95 dark:bg-oai-gray-900/95 border border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-xl rounded-xl p-3.5 max-w-[280px] min-w-[200px] flex flex-col gap-2 animate-in fade-in zoom-in-95 duration-100",style:{transform:`translateX(calc(-50% + ${te.shiftX}px))`},children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-oai-gray-100 dark:border-oai-gray-800/80 pb-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-oai-gray-500 dark:text-oai-gray-400",children:N.day}),(()=>{const a=N.level===0?L?"#9ca3af":"#6b7280":E[N.level];return e.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium",style:{backgroundColor:a+"22",color:a,border:`1px solid ${a}44`},children:["Level ",N.level]})})()]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:"text-lg font-bold text-oai-gray-900 dark:text-white leading-none tabular-nums",children:Number(N.value??0).toLocaleString()}),e.jsx("span",{className:"text-[10px] text-oai-gray-400 uppercase tracking-wider font-semibold",children:"Conversations"})]}),e.jsxs("div",{className:"flex items-baseline gap-1",children:[e.jsx("span",{className:"text-[11px] font-semibold text-oai-gray-500 dark:text-oai-gray-400 leading-none tabular-nums",children:Number(N.total_tokens??0).toLocaleString()}),e.jsx("span",{className:"text-[9px] text-oai-gray-400 uppercase tracking-wider",children:"tokens"})]})]}),N.models&&Object.keys(N.models).length>0?e.jsxs("div",{className:"mt-1.5 border-t border-oai-gray-100 dark:border-oai-gray-800/60 pt-2 flex flex-col gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-semibold text-oai-gray-400 dark:text-oai-gray-500 uppercase tracking-wider",children:"Model Breakdown"}),e.jsx("div",{className:"flex flex-col gap-2 max-h-[150px] overflow-y-auto pr-1.5 oai-scrollbar",children:Object.entries(N.models).map(([a,h])=>({name:a,val:Number(h)})).sort((a,h)=>h.val-a.val).map(({name:a,val:h})=>{const _=Number(N.total_tokens??N.value)||1,j=Math.round(h/_*100);return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px] gap-3",children:[e.jsx("span",{className:"font-medium text-oai-gray-750 dark:text-oai-gray-200 truncate max-w-[120px]",title:a,children:a}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("span",{className:"font-mono text-oai-gray-900 dark:text-oai-gray-100 font-semibold",children:h.toLocaleString()}),e.jsxs("span",{className:"text-[9px] text-oai-gray-450 dark:text-oai-gray-500 min-w-[28px] text-right font-medium",children:[j,"%"]})]})]}),e.jsx("div",{className:"w-full h-1 bg-oai-gray-100 dark:bg-oai-gray-800/85 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${j}%`,backgroundColor:E[4],boxShadow:`0 0 4px ${E[4]}55`}})})]},a)})})]}):e.jsx("p",{className:"text-[11px] text-oai-gray-600 dark:text-oai-gray-300 leading-relaxed font-normal mt-1 border-t border-dashed border-oai-gray-100 dark:border-oai-gray-800/60 pt-1.5",children:Se(N.level,N.total_tokens??N.value)})]})]}),e.jsx("div",{className:"absolute bottom-[6px] left-0 -translate-x-1/2 w-2.5 h-2.5 rotate-45 bg-white dark:bg-oai-gray-900 border-r border-b border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-sm",style:{marginBottom:"1px"}})]}),document.body),e.jsx("style",{children:`
2
- @keyframes tt-fade-in {
3
- from { opacity: 0; }
4
- to { opacity: 1; }
5
- }
6
- @keyframes tt-fade-out {
7
- from { opacity: 1; }
8
- to { opacity: 0; }
9
- }
10
- @keyframes tt-modal-entrance {
11
- from {
12
- opacity: 0;
13
- transform: scale(0.96) translateY(10px);
14
- }
15
- to {
16
- opacity: 1;
17
- transform: scale(1) translateY(0);
18
- }
19
- }
20
- @keyframes tt-modal-exit {
21
- from {
22
- opacity: 1;
23
- transform: scale(1) translateY(0);
24
- }
25
- to {
26
- opacity: 0;
27
- transform: scale(0.96) translateY(10px);
28
- }
29
- }
30
- .animate-tt-fade-in {
31
- animation: tt-fade-in 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
32
- }
33
- .animate-tt-fade-out {
34
- animation: tt-fade-out 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
35
- }
36
- .animate-tt-modal {
37
- animation: tt-modal-entrance 0.3s cubic-bezier(0.34, 1.3, 0.64, 1) forwards;
38
- }
39
- .animate-tt-modal-exit {
40
- animation: tt-modal-exit 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
41
- }
42
- `})]})}export{vt as A,Ve as M,nt as T};