token-contribution 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js ADDED
@@ -0,0 +1,1241 @@
1
+ window.__ModuleLoader__.load({ id: "token-contribution", factory: (require) => { var module = { exports: {} }; var exports = module.exports;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name2 in all)
10
+ __defProp(target, name2, { get: all[name2], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/client/index.tsx
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ apply: () => apply,
34
+ inject: () => inject,
35
+ name: () => name
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+ var import_react3 = __toESM(require("react"), 1);
39
+ var import_client = require("react-dom/client");
40
+
41
+ // src/client/HeatmapView.tsx
42
+ var import_react = __toESM(require("react"), 1);
43
+ function formatNumber(num) {
44
+ if (num >= 1e9) return (num / 1e9).toFixed(2) + "B";
45
+ if (num >= 1e6) return (num / 1e6).toFixed(1) + "M";
46
+ if (num >= 1e3) return (num / 1e3).toFixed(1) + "k";
47
+ return num.toLocaleString();
48
+ }
49
+ function formatExact(num) {
50
+ return num.toLocaleString();
51
+ }
52
+ var MONTH_NAMES = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
53
+ var DEEPSEEK_LEVELS = [
54
+ "#0f1117",
55
+ // Level 0: Black / dark void tile
56
+ "#152c6f",
57
+ // Level 1: Dark deep blue
58
+ "#1f4cdb",
59
+ // Level 2: Medium vibrant blue
60
+ "#336dfa",
61
+ // Level 3: Vibrant DeepSeek brand blue
62
+ "#4f85ff"
63
+ // Level 4: Bright electric DeepSeek blue
64
+ ];
65
+ function HeatmapInnerView() {
66
+ const [data, setData] = (0, import_react.useState)(null);
67
+ const [loading, setLoading] = (0, import_react.useState)(true);
68
+ const [error, setError] = (0, import_react.useState)(null);
69
+ const [selectedSessionId, setSelectedSessionId] = (0, import_react.useState)("all");
70
+ const [selectedDate, setSelectedDate] = (0, import_react.useState)(null);
71
+ const [chartRange, setChartRange] = (0, import_react.useState)(30);
72
+ const [hoveredDay, setHoveredDay] = (0, import_react.useState)(null);
73
+ const [hoveredBar, setHoveredBar] = (0, import_react.useState)(null);
74
+ const [tooltipPos, setTooltipPos] = (0, import_react.useState)(null);
75
+ const rootRef = (0, import_react.useRef)(null);
76
+ (0, import_react.useEffect)(() => {
77
+ if (typeof document === "undefined") return;
78
+ const findPanel = () => {
79
+ return rootRef.current?.closest('[class*="_panel"]') || document.querySelector(".VOzbGW_panel") || document.querySelector('[class*="_panel"]');
80
+ };
81
+ const panel = findPanel();
82
+ if (panel) {
83
+ const prevWidth = panel.style.width;
84
+ const prevMaxWidth = panel.style.maxWidth;
85
+ const prevTransition = panel.style.transition;
86
+ panel.style.transition = "width 0.25s cubic-bezier(0.16, 1, 0.3, 1), max-width 0.25s ease";
87
+ panel.style.setProperty("width", "min(1180px, calc(100vw - 32px))", "important");
88
+ panel.style.setProperty("max-width", "calc(100vw - 32px)", "important");
89
+ return () => {
90
+ panel.style.width = prevWidth;
91
+ panel.style.maxWidth = prevMaxWidth;
92
+ panel.style.transition = prevTransition;
93
+ };
94
+ }
95
+ }, []);
96
+ const fetchStats = () => {
97
+ setLoading(true);
98
+ fetch("/api/token-contribution/stats").then((r) => {
99
+ if (!r.ok) throw new Error(`HTTP error ${r.status}`);
100
+ return r.json();
101
+ }).then((res) => {
102
+ setData(res);
103
+ setLoading(false);
104
+ }).catch((err) => {
105
+ setError(err.message);
106
+ setLoading(false);
107
+ });
108
+ };
109
+ (0, import_react.useEffect)(() => {
110
+ fetchStats();
111
+ }, []);
112
+ const activeView = (0, import_react.useMemo)(() => {
113
+ if (!data) return null;
114
+ if (selectedSessionId === "all") {
115
+ return {
116
+ summary: data.summary,
117
+ days: data.days,
118
+ models: data.models || [],
119
+ sessionTitle: "All Sessions (Global)"
120
+ };
121
+ }
122
+ const session = (data.sessions || []).find((s) => s.id === selectedSessionId);
123
+ if (!session) {
124
+ return {
125
+ summary: data.summary,
126
+ days: data.days,
127
+ models: data.models || [],
128
+ sessionTitle: "All Sessions (Global)"
129
+ };
130
+ }
131
+ let totalTokens = session.totalTokens;
132
+ let totalInputTokens = session.inputTokens;
133
+ let totalOutputTokens = session.outputTokens;
134
+ let totalCacheReadTokens = session.cacheReadTokens;
135
+ let totalTurns = session.turns;
136
+ let activeDays = Object.values(session.days).filter((d) => d.totalTokens > 0).length;
137
+ let dailyAverage = activeDays > 0 ? Math.round(totalTokens / activeDays) : 0;
138
+ let peakDay = null;
139
+ for (const [date, stats] of Object.entries(session.days)) {
140
+ if (!peakDay || stats.totalTokens > peakDay.tokens) {
141
+ peakDay = { date, tokens: stats.totalTokens, turns: stats.turns };
142
+ }
143
+ }
144
+ const positiveValues = Object.values(session.days).map((d) => d.totalTokens).filter((t) => t > 0).sort((a, b) => a - b);
145
+ let q1 = 1e6;
146
+ let q2 = 5e6;
147
+ let q3 = 15e6;
148
+ if (positiveValues.length >= 4) {
149
+ q1 = positiveValues[Math.floor(positiveValues.length * 0.25)];
150
+ q2 = positiveValues[Math.floor(positiveValues.length * 0.5)];
151
+ q3 = positiveValues[Math.floor(positiveValues.length * 0.75)];
152
+ }
153
+ const leveledDays = {};
154
+ for (const [date, stats] of Object.entries(session.days)) {
155
+ let lvl = 0;
156
+ if (stats.totalTokens === 0) lvl = 0;
157
+ else if (stats.totalTokens <= q1) lvl = 1;
158
+ else if (stats.totalTokens <= q2) lvl = 2;
159
+ else if (stats.totalTokens <= q3) lvl = 3;
160
+ else lvl = 4;
161
+ leveledDays[date] = { ...stats, level: lvl };
162
+ }
163
+ const sessionModels = session.models ? Object.entries(session.models).map(([model, m]) => ({
164
+ model,
165
+ totalTokens: m.totalTokens,
166
+ inputTokens: m.inputTokens,
167
+ outputTokens: m.outputTokens,
168
+ cacheReadTokens: m.cacheReadTokens,
169
+ turns: m.turns,
170
+ percentage: totalTokens > 0 ? Math.round(m.totalTokens / totalTokens * 1e3) / 10 : 0
171
+ })).sort((a, b) => b.totalTokens - a.totalTokens) : [];
172
+ return {
173
+ summary: {
174
+ totalTokens,
175
+ totalInputTokens,
176
+ totalOutputTokens,
177
+ totalCacheReadTokens,
178
+ totalTurns,
179
+ activeDays,
180
+ currentStreak: 0,
181
+ longestStreak: 0,
182
+ peakDay,
183
+ dailyAverage
184
+ },
185
+ days: leveledDays,
186
+ models: sessionModels,
187
+ sessionTitle: session.title
188
+ };
189
+ }, [data, selectedSessionId]);
190
+ const calendarGrid = (0, import_react.useMemo)(() => {
191
+ if (!activeView) return null;
192
+ const weeks = [];
193
+ const now = /* @__PURE__ */ new Date();
194
+ const end = new Date(now);
195
+ const start = new Date(now);
196
+ start.setDate(start.getDate() - 364);
197
+ start.setDate(start.getDate() - start.getDay());
198
+ let current = new Date(start);
199
+ let currentWeek = [];
200
+ while (current <= end || currentWeek.length > 0) {
201
+ const dateKey = `${current.getFullYear()}-${String(current.getMonth() + 1).padStart(2, "0")}-${String(current.getDate()).padStart(2, "0")}`;
202
+ const dayStats = activeView.days[dateKey] || {
203
+ totalTokens: 0,
204
+ inputTokens: 0,
205
+ outputTokens: 0,
206
+ cacheReadTokens: 0,
207
+ cacheWriteTokens: 0,
208
+ turns: 0,
209
+ level: 0
210
+ };
211
+ if (current <= end) {
212
+ currentWeek.push({ date: dateKey, stats: dayStats });
213
+ } else {
214
+ currentWeek.push(null);
215
+ }
216
+ if (currentWeek.length === 7) {
217
+ weeks.push(currentWeek);
218
+ currentWeek = [];
219
+ }
220
+ current.setDate(current.getDate() + 1);
221
+ if (current > end && currentWeek.length === 0) break;
222
+ }
223
+ return weeks;
224
+ }, [activeView]);
225
+ const monthHeaders = (0, import_react.useMemo)(() => {
226
+ if (!calendarGrid) return [];
227
+ const headers = [];
228
+ let lastMonth = -1;
229
+ calendarGrid.forEach((week, colIdx) => {
230
+ const firstValidDay = week.find((d) => d !== null);
231
+ if (firstValidDay) {
232
+ const d = /* @__PURE__ */ new Date(firstValidDay.date + "T00:00:00");
233
+ const month = d.getMonth();
234
+ if (month !== lastMonth) {
235
+ headers.push({ label: MONTH_NAMES[month], col: colIdx });
236
+ lastMonth = month;
237
+ }
238
+ }
239
+ });
240
+ return headers;
241
+ }, [calendarGrid]);
242
+ const chartData = (0, import_react.useMemo)(() => {
243
+ if (!activeView) return [];
244
+ const now = /* @__PURE__ */ new Date();
245
+ const items = [];
246
+ for (let i = chartRange - 1; i >= 0; i--) {
247
+ const d = new Date(now);
248
+ d.setDate(d.getDate() - i);
249
+ const dateKey = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
250
+ const stats = activeView.days[dateKey] || {
251
+ totalTokens: 0,
252
+ inputTokens: 0,
253
+ outputTokens: 0,
254
+ cacheReadTokens: 0,
255
+ cacheWriteTokens: 0,
256
+ turns: 0
257
+ };
258
+ items.push({
259
+ date: dateKey,
260
+ label: `${MONTH_NAMES[d.getMonth()]} ${d.getDate()}`,
261
+ totalTokens: stats.totalTokens,
262
+ billedTokens: stats.inputTokens + stats.outputTokens,
263
+ cachedTokens: stats.cacheReadTokens,
264
+ turns: stats.turns
265
+ });
266
+ }
267
+ return items;
268
+ }, [activeView, chartRange]);
269
+ const maxChartTokens = (0, import_react.useMemo)(() => {
270
+ return Math.max(...chartData.map((d) => d.totalTokens), 1e6);
271
+ }, [chartData]);
272
+ if (loading && !data) {
273
+ return /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "40px 20px", textAlign: "center", color: "var(--dsw-alias-label-secondary)" } }, "Loading token usage statistics...");
274
+ }
275
+ if (error) {
276
+ return /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "20px", color: "var(--dsw-alias-state-error-primary, #ef4444)" } }, "Failed to load heatmap: ", error, /* @__PURE__ */ import_react.default.createElement(
277
+ "button",
278
+ {
279
+ onClick: fetchStats,
280
+ style: {
281
+ marginLeft: 12,
282
+ padding: "4px 10px",
283
+ background: "var(--dsw-alias-bg-layer-2)",
284
+ border: "1px solid var(--dsw-alias-border-l2)",
285
+ color: "var(--dsw-alias-label-primary)",
286
+ borderRadius: 6,
287
+ cursor: "pointer"
288
+ }
289
+ },
290
+ "Retry"
291
+ ));
292
+ }
293
+ if (!data || !activeView) return null;
294
+ const { summary } = activeView;
295
+ const cacheHitPercent = summary.totalTokens > 0 ? Math.round(summary.totalCacheReadTokens / summary.totalTokens * 100) : 0;
296
+ const inspectedDayStats = selectedDate ? activeView.days[selectedDate] : null;
297
+ return /* @__PURE__ */ import_react.default.createElement(
298
+ "div",
299
+ {
300
+ "data-dsh-heatmap": "true",
301
+ ref: rootRef,
302
+ style: {
303
+ boxSizing: "border-box",
304
+ width: "100%",
305
+ maxWidth: "1020px",
306
+ margin: "0 auto",
307
+ padding: "8px 0 40px",
308
+ fontFamily: "inherit",
309
+ color: "var(--dsw-alias-label-primary, #eeeeee)"
310
+ }
311
+ },
312
+ /* @__PURE__ */ import_react.default.createElement(
313
+ "div",
314
+ {
315
+ style: {
316
+ display: "flex",
317
+ alignItems: "center",
318
+ justifyContent: "space-between",
319
+ flexWrap: "wrap",
320
+ gap: 14,
321
+ marginBottom: 16
322
+ }
323
+ },
324
+ /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
325
+ "h2",
326
+ {
327
+ style: {
328
+ margin: 0,
329
+ fontSize: 20,
330
+ fontWeight: 650,
331
+ letterSpacing: "-0.02em",
332
+ display: "flex",
333
+ alignItems: "center",
334
+ gap: 10
335
+ }
336
+ },
337
+ "Token Usage Activity",
338
+ /* @__PURE__ */ import_react.default.createElement(
339
+ "span",
340
+ {
341
+ style: {
342
+ fontSize: 11,
343
+ fontWeight: 600,
344
+ padding: "2px 8px",
345
+ borderRadius: 12,
346
+ background: "rgba(51, 109, 250, 0.12)",
347
+ color: "#4f85ff",
348
+ border: "1px solid rgba(51, 109, 250, 0.35)"
349
+ }
350
+ },
351
+ "52 Weeks"
352
+ )
353
+ ), /* @__PURE__ */ import_react.default.createElement(
354
+ "p",
355
+ {
356
+ style: {
357
+ margin: "4px 0 0",
358
+ fontSize: 12,
359
+ color: "var(--dsw-alias-label-tertiary, #a0a0a0)"
360
+ }
361
+ },
362
+ "Daily token throughput and model breakdown across sessions"
363
+ )),
364
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 10 } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 6 } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { fontSize: 12, color: "var(--dsw-alias-label-tertiary)" } }, "Session:"), /* @__PURE__ */ import_react.default.createElement(
365
+ "select",
366
+ {
367
+ value: selectedSessionId,
368
+ onChange: (e) => {
369
+ setSelectedSessionId(e.target.value);
370
+ setSelectedDate(null);
371
+ },
372
+ style: {
373
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
374
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
375
+ color: "var(--dsw-alias-label-primary, #eeeeee)",
376
+ borderRadius: 8,
377
+ padding: "6px 12px",
378
+ fontSize: 12,
379
+ outline: "none",
380
+ cursor: "pointer",
381
+ maxWidth: 240
382
+ }
383
+ },
384
+ /* @__PURE__ */ import_react.default.createElement("option", { value: "all" }, "All Sessions (", (data.sessions || []).length, " total)"),
385
+ (data.sessions || []).map((s) => /* @__PURE__ */ import_react.default.createElement("option", { key: s.id, value: s.id }, new Date(s.createdAt).toLocaleDateString(), " \xB7 ", s.title.slice(0, 32)))
386
+ )), /* @__PURE__ */ import_react.default.createElement(
387
+ "button",
388
+ {
389
+ onClick: fetchStats,
390
+ title: "Refresh statistics",
391
+ style: {
392
+ display: "inline-flex",
393
+ alignItems: "center",
394
+ gap: 6,
395
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
396
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
397
+ color: "var(--dsw-alias-label-primary)",
398
+ borderRadius: 8,
399
+ padding: "6px 12px",
400
+ fontSize: 12,
401
+ fontWeight: 500,
402
+ cursor: "pointer"
403
+ }
404
+ },
405
+ "\u21BB Refresh"
406
+ ))
407
+ ),
408
+ /* @__PURE__ */ import_react.default.createElement(
409
+ "div",
410
+ {
411
+ style: {
412
+ textAlign: "center",
413
+ margin: "12px 0 20px",
414
+ padding: "16px 20px",
415
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
416
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
417
+ borderRadius: 12,
418
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
419
+ }
420
+ },
421
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, textTransform: "uppercase", letterSpacing: "0.08em", color: "var(--dsw-alias-label-tertiary, #a0a0a0)", fontWeight: 600 } }, "Total Tokens Processed"),
422
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 36, fontWeight: 800, margin: "6px 0 2px", color: "#4f85ff", letterSpacing: "-0.03em" } }, formatExact(summary.totalTokens)),
423
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 13, color: "var(--dsw-alias-label-secondary, #b9b9b9)" } }, /* @__PURE__ */ import_react.default.createElement("strong", null, formatNumber(summary.totalTokens)), " tokens across ", summary.activeDays, " active days (", summary.totalTurns, " total requests)")
424
+ ),
425
+ /* @__PURE__ */ import_react.default.createElement(
426
+ "div",
427
+ {
428
+ style: {
429
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
430
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
431
+ borderRadius: 12,
432
+ padding: "18px 20px",
433
+ position: "relative",
434
+ boxShadow: "0 4px 16px rgba(0, 0, 0, 0.2)"
435
+ }
436
+ },
437
+ /* @__PURE__ */ import_react.default.createElement(
438
+ "div",
439
+ {
440
+ style: {
441
+ display: "flex",
442
+ alignItems: "center",
443
+ justifyContent: "space-between",
444
+ marginBottom: 12,
445
+ fontSize: 13,
446
+ fontWeight: 600
447
+ }
448
+ },
449
+ /* @__PURE__ */ import_react.default.createElement("span", null, "Contribution Calendar"),
450
+ summary.peakDay && /* @__PURE__ */ import_react.default.createElement("span", { style: { fontSize: 12, fontWeight: 400, color: "var(--dsw-alias-label-secondary)" } }, "Peak day: ", /* @__PURE__ */ import_react.default.createElement("strong", { style: { color: "var(--dsw-alias-label-primary)" } }, summary.peakDay.date), " (", formatNumber(summary.peakDay.tokens), " tokens)")
451
+ ),
452
+ calendarGrid && /* @__PURE__ */ import_react.default.createElement("div", { style: { width: "100%", display: "flex", flexDirection: "column", alignItems: "center" } }, /* @__PURE__ */ import_react.default.createElement(
453
+ "svg",
454
+ {
455
+ viewBox: "0 0 880 136",
456
+ style: {
457
+ width: "100%",
458
+ maxWidth: "880px",
459
+ height: "auto",
460
+ display: "block",
461
+ overflow: "visible"
462
+ }
463
+ },
464
+ monthHeaders.map((m, i) => /* @__PURE__ */ import_react.default.createElement(
465
+ "text",
466
+ {
467
+ key: i,
468
+ x: 32 + m.col * 15.6,
469
+ y: 11,
470
+ fontSize: 11,
471
+ fill: "var(--dsw-alias-label-tertiary, #888888)",
472
+ fontFamily: "inherit"
473
+ },
474
+ m.label
475
+ )),
476
+ /* @__PURE__ */ import_react.default.createElement("text", { x: 2, y: 45, fontSize: 10, fill: "var(--dsw-alias-label-tertiary, #888888)", fontFamily: "inherit" }, "Mon"),
477
+ /* @__PURE__ */ import_react.default.createElement("text", { x: 2, y: 76, fontSize: 10, fill: "var(--dsw-alias-label-tertiary, #888888)", fontFamily: "inherit" }, "Wed"),
478
+ /* @__PURE__ */ import_react.default.createElement("text", { x: 2, y: 107, fontSize: 10, fill: "var(--dsw-alias-label-tertiary, #888888)", fontFamily: "inherit" }, "Fri"),
479
+ calendarGrid.map((week, colIdx) => /* @__PURE__ */ import_react.default.createElement("g", { key: colIdx, transform: `translate(${32 + colIdx * 15.6}, 18)` }, week.map((day, rowIdx) => {
480
+ if (!day) return null;
481
+ const lvl = day.stats.level || 0;
482
+ const bg = DEEPSEEK_LEVELS[lvl];
483
+ const isSelected = selectedDate === day.date;
484
+ const isHovered = hoveredDay?.date === day.date;
485
+ const strokeColor = isSelected ? "#ffffff" : isHovered ? "#5686fe" : lvl === 0 ? "rgba(255, 255, 255, 0.06)" : "transparent";
486
+ const strokeWidth = isSelected ? 1.8 : isHovered ? 1.4 : 1;
487
+ return /* @__PURE__ */ import_react.default.createElement(
488
+ "rect",
489
+ {
490
+ key: rowIdx,
491
+ x: 0,
492
+ y: rowIdx * 15.6,
493
+ width: 12,
494
+ height: 12,
495
+ rx: 2.5,
496
+ ry: 2.5,
497
+ fill: bg,
498
+ stroke: strokeColor,
499
+ strokeWidth,
500
+ style: {
501
+ cursor: "pointer",
502
+ transition: "fill 0.12s ease, stroke 0.12s ease",
503
+ filter: isSelected ? "drop-shadow(0 0 6px rgba(86, 134, 254, 0.9))" : isHovered ? "drop-shadow(0 0 4px rgba(86, 134, 254, 0.7))" : lvl === 4 ? "drop-shadow(0 0 3px rgba(79, 133, 255, 0.5))" : "none"
504
+ },
505
+ onClick: () => {
506
+ setSelectedDate(isSelected ? null : day.date);
507
+ },
508
+ onMouseEnter: (e) => {
509
+ setHoveredDay({ date: day.date, stats: day.stats });
510
+ const rect = e.currentTarget.getBoundingClientRect();
511
+ setTooltipPos({ x: rect.left + rect.width / 2, y: rect.top - 8 });
512
+ },
513
+ onMouseLeave: () => {
514
+ setHoveredDay(null);
515
+ setTooltipPos(null);
516
+ }
517
+ }
518
+ );
519
+ })))
520
+ ), /* @__PURE__ */ import_react.default.createElement(
521
+ "div",
522
+ {
523
+ style: {
524
+ width: "100%",
525
+ maxWidth: "880px",
526
+ display: "flex",
527
+ alignItems: "center",
528
+ justifyContent: "space-between",
529
+ marginTop: 12,
530
+ fontSize: 11,
531
+ color: "var(--dsw-alias-label-tertiary, #a0a0a0)"
532
+ }
533
+ },
534
+ /* @__PURE__ */ import_react.default.createElement("span", { style: { fontSize: 11 } }, "Tip: Click any day to inspect sessions and token breakdown"),
535
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 6 } }, /* @__PURE__ */ import_react.default.createElement("span", null, "Less"), DEEPSEEK_LEVELS.map((c, i) => /* @__PURE__ */ import_react.default.createElement(
536
+ "div",
537
+ {
538
+ key: i,
539
+ style: {
540
+ width: 12,
541
+ height: 12,
542
+ borderRadius: 2.5,
543
+ backgroundColor: c,
544
+ border: i === 0 ? "1px solid rgba(255, 255, 255, 0.06)" : "none",
545
+ filter: i === 4 ? "drop-shadow(0 0 3px rgba(79, 133, 255, 0.5))" : "none"
546
+ }
547
+ }
548
+ )), /* @__PURE__ */ import_react.default.createElement("span", null, "More"))
549
+ ))
550
+ ),
551
+ /* @__PURE__ */ import_react.default.createElement(
552
+ "div",
553
+ {
554
+ style: {
555
+ display: "grid",
556
+ gridTemplateColumns: "repeat(auto-fit, minmax(180px, 1fr))",
557
+ gap: 12,
558
+ marginTop: 18,
559
+ marginBottom: 18
560
+ }
561
+ },
562
+ /* @__PURE__ */ import_react.default.createElement(
563
+ "div",
564
+ {
565
+ style: {
566
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
567
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
568
+ borderRadius: 10,
569
+ padding: "14px 16px",
570
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
571
+ }
572
+ },
573
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-tertiary, #a0a0a0)", textTransform: "uppercase", letterSpacing: "0.06em", fontWeight: 600 } }, "Cache Hit Ratio"),
574
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 24, fontWeight: 700, margin: "6px 0 2px", color: "var(--dsw-alias-label-primary, #ffffff)" } }, cacheHitPercent, "%"),
575
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-secondary, #b9b9b9)" } }, formatNumber(summary.totalCacheReadTokens), " cached reads")
576
+ ),
577
+ /* @__PURE__ */ import_react.default.createElement(
578
+ "div",
579
+ {
580
+ style: {
581
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
582
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
583
+ borderRadius: 10,
584
+ padding: "14px 16px",
585
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
586
+ }
587
+ },
588
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-tertiary, #a0a0a0)", textTransform: "uppercase", letterSpacing: "0.06em", fontWeight: 600 } }, selectedSessionId === "all" ? "Daily Average" : "Total Steps"),
589
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 24, fontWeight: 700, margin: "6px 0 2px", color: "var(--dsw-alias-label-primary, #ffffff)" } }, selectedSessionId === "all" ? formatNumber(summary.dailyAverage) : summary.totalTurns),
590
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-secondary, #b9b9b9)" } }, selectedSessionId === "all" ? `Across ${summary.activeDays} active days` : `${formatNumber(summary.totalInputTokens + summary.totalOutputTokens)} billed`)
591
+ ),
592
+ /* @__PURE__ */ import_react.default.createElement(
593
+ "div",
594
+ {
595
+ style: {
596
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
597
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
598
+ borderRadius: 10,
599
+ padding: "14px 16px",
600
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
601
+ }
602
+ },
603
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-tertiary, #a0a0a0)", textTransform: "uppercase", letterSpacing: "0.06em", fontWeight: 600 } }, selectedSessionId === "all" ? "Active Streak" : "Active Days"),
604
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 24, fontWeight: 700, margin: "6px 0 2px", color: "var(--dsw-alias-label-primary, #ffffff)" } }, selectedSessionId === "all" ? `${summary.currentStreak} days` : `${summary.activeDays} days`),
605
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-secondary, #b9b9b9)" } }, selectedSessionId === "all" ? `Longest streak: ${summary.longestStreak} days` : `Session: ${activeView.sessionTitle.slice(0, 24)}`)
606
+ ),
607
+ /* @__PURE__ */ import_react.default.createElement(
608
+ "div",
609
+ {
610
+ style: {
611
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
612
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
613
+ borderRadius: 10,
614
+ padding: "14px 16px",
615
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
616
+ }
617
+ },
618
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-tertiary, #a0a0a0)", textTransform: "uppercase", letterSpacing: "0.06em", fontWeight: 600 } }, "Peak Volume Day"),
619
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 20, fontWeight: 700, margin: "6px 0 2px", color: "var(--dsw-alias-label-primary, #ffffff)" } }, summary.peakDay ? formatNumber(summary.peakDay.tokens) : "None"),
620
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-secondary, #b9b9b9)" } }, summary.peakDay ? summary.peakDay.date : "No activity")
621
+ )
622
+ ),
623
+ activeView.models && activeView.models.length > 0 && /* @__PURE__ */ import_react.default.createElement(
624
+ "div",
625
+ {
626
+ style: {
627
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
628
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
629
+ borderRadius: 12,
630
+ padding: "18px 20px",
631
+ marginBottom: 18,
632
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
633
+ }
634
+ },
635
+ /* @__PURE__ */ import_react.default.createElement(
636
+ "div",
637
+ {
638
+ style: {
639
+ display: "flex",
640
+ alignItems: "center",
641
+ justifyContent: "space-between",
642
+ marginBottom: 12
643
+ }
644
+ },
645
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 13, fontWeight: 650, color: "var(--dsw-alias-label-primary, #ffffff)" } }, "Model Usage Breakdown"),
646
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-tertiary, #a0a0a0)" } }, activeView.models.length, " model", activeView.models.length === 1 ? "" : "s", " tracked")
647
+ ),
648
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 10 } }, activeView.models.map((m) => /* @__PURE__ */ import_react.default.createElement("div", { key: m.model }, /* @__PURE__ */ import_react.default.createElement(
649
+ "div",
650
+ {
651
+ style: {
652
+ display: "flex",
653
+ justifyContent: "space-between",
654
+ fontSize: 12,
655
+ marginBottom: 5
656
+ }
657
+ },
658
+ /* @__PURE__ */ import_react.default.createElement("span", { style: { fontWeight: 600, color: "var(--dsw-alias-label-primary)" } }, m.model),
659
+ /* @__PURE__ */ import_react.default.createElement("span", { style: { color: "var(--dsw-alias-label-secondary)" } }, /* @__PURE__ */ import_react.default.createElement("strong", { style: { color: "#4f85ff" } }, formatNumber(m.totalTokens)), " (", m.percentage, "%) \xB7 ", m.turns, " requests")
660
+ ), /* @__PURE__ */ import_react.default.createElement(
661
+ "div",
662
+ {
663
+ style: {
664
+ width: "100%",
665
+ height: 6,
666
+ background: "rgba(255, 255, 255, 0.06)",
667
+ borderRadius: 3,
668
+ overflow: "hidden"
669
+ }
670
+ },
671
+ /* @__PURE__ */ import_react.default.createElement(
672
+ "div",
673
+ {
674
+ style: {
675
+ width: `${Math.max(1, m.percentage)}%`,
676
+ height: "100%",
677
+ background: "#336dfa",
678
+ borderRadius: 3,
679
+ transition: "width 0.3s ease"
680
+ }
681
+ }
682
+ )
683
+ ))))
684
+ ),
685
+ /* @__PURE__ */ import_react.default.createElement(
686
+ "div",
687
+ {
688
+ style: {
689
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
690
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
691
+ borderRadius: 12,
692
+ padding: "18px 20px",
693
+ position: "relative",
694
+ boxShadow: "0 4px 16px rgba(0, 0, 0, 0.2)"
695
+ }
696
+ },
697
+ /* @__PURE__ */ import_react.default.createElement(
698
+ "div",
699
+ {
700
+ style: {
701
+ display: "flex",
702
+ alignItems: "center",
703
+ justifyContent: "space-between",
704
+ flexWrap: "wrap",
705
+ gap: 12,
706
+ marginBottom: 16
707
+ }
708
+ },
709
+ /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 13, fontWeight: 650, color: "var(--dsw-alias-label-primary, #ffffff)" } }, "Token Usage Trends"), /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-tertiary, #a0a0a0)", marginTop: 2 } }, "Daily billed vs cached token volume over time")),
710
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 14, flexWrap: "wrap" } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 12, fontSize: 11, color: "var(--dsw-alias-label-secondary)" } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 5 } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { width: 8, height: 8, borderRadius: 2, background: "#4f85ff" } }), /* @__PURE__ */ import_react.default.createElement("span", null, "Billed Tokens")), /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 5 } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { width: 8, height: 8, borderRadius: 2, background: "#253b82" } }), /* @__PURE__ */ import_react.default.createElement("span", null, "Cache Reads"))), /* @__PURE__ */ import_react.default.createElement(
711
+ "div",
712
+ {
713
+ style: {
714
+ display: "inline-flex",
715
+ background: "var(--dsw-alias-bg-layer-1, #1e1e1e)",
716
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
717
+ borderRadius: 8,
718
+ padding: 2
719
+ }
720
+ },
721
+ [14, 30, 90].map((days) => /* @__PURE__ */ import_react.default.createElement(
722
+ "button",
723
+ {
724
+ key: days,
725
+ onClick: () => setChartRange(days),
726
+ style: {
727
+ border: 0,
728
+ background: chartRange === days ? "var(--dsw-alias-bg-layer-2, #2c2c2c)" : "transparent",
729
+ color: chartRange === days ? "#4f85ff" : "var(--dsw-alias-label-tertiary)",
730
+ fontSize: 11,
731
+ padding: "3px 8px",
732
+ borderRadius: 6,
733
+ cursor: "pointer",
734
+ fontWeight: chartRange === days ? 600 : 400
735
+ }
736
+ },
737
+ days,
738
+ "D"
739
+ ))
740
+ ))
741
+ ),
742
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { width: "100%", overflowX: "auto", WebkitOverflowScrolling: "touch" } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { minWidth: "680px", width: "100%" } }, /* @__PURE__ */ import_react.default.createElement(
743
+ "svg",
744
+ {
745
+ viewBox: "0 0 880 180",
746
+ style: { width: "100%", height: "180px", display: "block", overflow: "visible" }
747
+ },
748
+ [1, 0.66, 0.33, 0].map((ratio, i) => {
749
+ const y = 20 + (1 - ratio) * 125;
750
+ const tokenVal = Math.round(maxChartTokens * ratio);
751
+ return /* @__PURE__ */ import_react.default.createElement("g", { key: i }, /* @__PURE__ */ import_react.default.createElement(
752
+ "line",
753
+ {
754
+ x1: 45,
755
+ y1: y,
756
+ x2: 870,
757
+ y2: y,
758
+ stroke: "var(--dsw-alias-border-l1, rgba(255,255,255,0.08))",
759
+ strokeDasharray: "4 4"
760
+ }
761
+ ), /* @__PURE__ */ import_react.default.createElement(
762
+ "text",
763
+ {
764
+ x: 40,
765
+ y: y + 3,
766
+ fontSize: 9,
767
+ fill: "var(--dsw-alias-label-tertiary, #888888)",
768
+ textAnchor: "end",
769
+ fontFamily: "inherit"
770
+ },
771
+ formatNumber(tokenVal)
772
+ ));
773
+ }),
774
+ chartData.map((d, idx) => {
775
+ const totalBarWidth = 825 / chartData.length;
776
+ const barWidth = Math.max(5, Math.min(22, totalBarWidth - 5));
777
+ const x = 50 + idx * totalBarWidth + (totalBarWidth - barWidth) / 2;
778
+ const totalH = d.totalTokens / maxChartTokens * 125;
779
+ const cachedH = d.totalTokens > 0 ? d.cachedTokens / d.totalTokens * totalH : 0;
780
+ const billedH = totalH - cachedH;
781
+ const yBase = 145;
782
+ const isHovered = hoveredBar?.date === d.date;
783
+ return /* @__PURE__ */ import_react.default.createElement(
784
+ "g",
785
+ {
786
+ key: idx,
787
+ style: { cursor: "pointer" },
788
+ onMouseEnter: (e) => {
789
+ setHoveredBar(d);
790
+ const rect = e.currentTarget.getBoundingClientRect();
791
+ setTooltipPos({ x: rect.left + rect.width / 2, y: rect.top - 8 });
792
+ },
793
+ onMouseLeave: () => {
794
+ setHoveredBar(null);
795
+ setTooltipPos(null);
796
+ },
797
+ onClick: () => setSelectedDate(selectedDate === d.date ? null : d.date)
798
+ },
799
+ /* @__PURE__ */ import_react.default.createElement(
800
+ "rect",
801
+ {
802
+ x: x - 2,
803
+ y: 20,
804
+ width: barWidth + 4,
805
+ height: 125,
806
+ fill: isHovered ? "rgba(79, 133, 255, 0.08)" : "transparent",
807
+ rx: 3
808
+ }
809
+ ),
810
+ d.totalTokens === 0 ? /* @__PURE__ */ import_react.default.createElement(
811
+ "rect",
812
+ {
813
+ x,
814
+ y: yBase - 2,
815
+ width: barWidth,
816
+ height: 2,
817
+ fill: "rgba(255, 255, 255, 0.08)",
818
+ rx: 1
819
+ }
820
+ ) : /* @__PURE__ */ import_react.default.createElement("g", null, cachedH > 0 && /* @__PURE__ */ import_react.default.createElement(
821
+ "rect",
822
+ {
823
+ x,
824
+ y: yBase - cachedH,
825
+ width: barWidth,
826
+ height: cachedH,
827
+ fill: "#253b82",
828
+ rx: billedH <= 0 ? 2 : 0
829
+ }
830
+ ), billedH > 0 && /* @__PURE__ */ import_react.default.createElement(
831
+ "rect",
832
+ {
833
+ x,
834
+ y: yBase - totalH,
835
+ width: barWidth,
836
+ height: billedH,
837
+ fill: isHovered ? "#60a5fa" : "#4f85ff",
838
+ rx: 2,
839
+ style: {
840
+ filter: isHovered ? "drop-shadow(0 0 5px rgba(79, 133, 255, 0.8))" : "none"
841
+ }
842
+ }
843
+ )),
844
+ (chartRange === 14 || idx % (chartRange === 30 ? 3 : 7) === 0) && /* @__PURE__ */ import_react.default.createElement(
845
+ "text",
846
+ {
847
+ x: x + barWidth / 2,
848
+ y: 162,
849
+ fontSize: 9,
850
+ fill: "var(--dsw-alias-label-tertiary, #888888)",
851
+ textAnchor: "middle",
852
+ fontFamily: "inherit"
853
+ },
854
+ d.label
855
+ )
856
+ );
857
+ })
858
+ )))
859
+ ),
860
+ selectedDate && /* @__PURE__ */ import_react.default.createElement(
861
+ "div",
862
+ {
863
+ style: {
864
+ marginTop: 18,
865
+ background: "var(--dsw-alias-bg-layer-2, #2c2c2c)",
866
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
867
+ borderRadius: 12,
868
+ padding: "18px 20px",
869
+ boxShadow: "0 6px 20px rgba(0, 0, 0, 0.25)",
870
+ animation: "fadeIn 0.15s ease"
871
+ }
872
+ },
873
+ /* @__PURE__ */ import_react.default.createElement(
874
+ "div",
875
+ {
876
+ style: {
877
+ display: "flex",
878
+ alignItems: "center",
879
+ justifyContent: "space-between",
880
+ borderBottom: "1px solid var(--dsw-alias-border-l1, #3a3a3a)",
881
+ paddingBottom: 12,
882
+ marginBottom: 14
883
+ }
884
+ },
885
+ /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 16, fontWeight: 700, color: "var(--dsw-alias-label-primary, #ffffff)" } }, (/* @__PURE__ */ new Date(selectedDate + "T00:00:00")).toLocaleDateString(void 0, {
886
+ weekday: "long",
887
+ year: "numeric",
888
+ month: "long",
889
+ day: "numeric"
890
+ })), /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 12, color: "var(--dsw-alias-label-secondary, #b9b9b9)", marginTop: 2 } }, inspectedDayStats && inspectedDayStats.totalTokens > 0 ? /* @__PURE__ */ import_react.default.createElement("span", null, /* @__PURE__ */ import_react.default.createElement("strong", { style: { color: "#4f85ff" } }, formatExact(inspectedDayStats.totalTokens)), " total tokens across", " ", /* @__PURE__ */ import_react.default.createElement("strong", null, inspectedDayStats.turns), " turns") : "No activity recorded")),
891
+ /* @__PURE__ */ import_react.default.createElement(
892
+ "button",
893
+ {
894
+ onClick: () => setSelectedDate(null),
895
+ style: {
896
+ background: "transparent",
897
+ border: "none",
898
+ color: "var(--dsw-alias-label-tertiary)",
899
+ cursor: "pointer",
900
+ fontSize: 16,
901
+ padding: "4px 8px",
902
+ borderRadius: 4
903
+ },
904
+ title: "Close day view"
905
+ },
906
+ "\u2715"
907
+ )
908
+ ),
909
+ inspectedDayStats && inspectedDayStats.totalTokens > 0 && /* @__PURE__ */ import_react.default.createElement(
910
+ "div",
911
+ {
912
+ style: {
913
+ display: "flex",
914
+ gap: 12,
915
+ flexWrap: "wrap",
916
+ marginBottom: 16,
917
+ fontSize: 12
918
+ }
919
+ },
920
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "6px 12px", background: "var(--dsw-alias-bg-layer-1, #1e1e1e)", borderRadius: 6, border: "1px solid var(--dsw-alias-border-l1)" } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { color: "var(--dsw-alias-label-tertiary)" } }, "Billed Input: "), /* @__PURE__ */ import_react.default.createElement("strong", null, formatNumber(inspectedDayStats.inputTokens))),
921
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "6px 12px", background: "var(--dsw-alias-bg-layer-1, #1e1e1e)", borderRadius: 6, border: "1px solid var(--dsw-alias-border-l1)" } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { color: "var(--dsw-alias-label-tertiary)" } }, "Output Generated: "), /* @__PURE__ */ import_react.default.createElement("strong", null, formatNumber(inspectedDayStats.outputTokens))),
922
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "6px 12px", background: "var(--dsw-alias-bg-layer-1, #1e1e1e)", borderRadius: 6, border: "1px solid var(--dsw-alias-border-l1)" } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { color: "var(--dsw-alias-label-tertiary)" } }, "Cache Reads: "), /* @__PURE__ */ import_react.default.createElement("strong", null, formatNumber(inspectedDayStats.cacheReadTokens)), " (", Math.round(inspectedDayStats.cacheReadTokens / inspectedDayStats.totalTokens * 100), "%)")
923
+ ),
924
+ /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 13, fontWeight: 600, color: "var(--dsw-alias-label-primary)", marginBottom: 10 } }, "Sessions Active on this Day (", (inspectedDayStats?.sessions || []).length, ")"), inspectedDayStats?.sessions && inspectedDayStats.sessions.length > 0 ? /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 8, maxHeight: 320, overflowY: "auto" } }, inspectedDayStats.sessions.map((sess, idx) => /* @__PURE__ */ import_react.default.createElement(
925
+ "div",
926
+ {
927
+ key: idx,
928
+ style: {
929
+ display: "flex",
930
+ alignItems: "center",
931
+ justifyContent: "space-between",
932
+ padding: "10px 14px",
933
+ background: "var(--dsw-alias-bg-layer-1, #1e1e1e)",
934
+ border: "1px solid var(--dsw-alias-border-l1, #3a3a3a)",
935
+ borderRadius: 8
936
+ }
937
+ },
938
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { minWidth: 0, flex: 1, paddingRight: 16 } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { fontWeight: 600, fontSize: 13, color: "var(--dsw-alias-label-primary, #ffffff)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, sess.sessionTitle), /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-tertiary, #a0a0a0)", marginTop: 2 } }, "Started ", new Date(sess.createdAt).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), " \xB7 ID: ", sess.sessionId.slice(0, 10))),
939
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { textAlign: "right", flexShrink: 0 } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { fontWeight: 700, fontSize: 13, color: "#4f85ff" } }, formatNumber(sess.totalTokens), " tokens"), /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-secondary)", marginTop: 2 } }, sess.turns, " turns \xB7 ", formatNumber(sess.inputTokens + sess.outputTokens), " billed"))
940
+ ))) : /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "16px", textAlign: "center", color: "var(--dsw-alias-label-tertiary)", fontSize: 12, background: "var(--dsw-alias-bg-layer-1)", borderRadius: 8 } }, "No session records found for this date."))
941
+ ),
942
+ hoveredDay && tooltipPos && !selectedDate && /* @__PURE__ */ import_react.default.createElement(
943
+ "div",
944
+ {
945
+ style: {
946
+ position: "fixed",
947
+ left: tooltipPos.x,
948
+ top: tooltipPos.y,
949
+ transform: "translate(-50%, -100%)",
950
+ background: "var(--dsw-alias-bg-layer-1, #1e1e1e)",
951
+ border: "1px solid var(--dsw-alias-border-l3, #555555)",
952
+ borderRadius: 8,
953
+ padding: "8px 12px",
954
+ fontSize: 12,
955
+ lineHeight: 1.4,
956
+ boxShadow: "0 6px 18px rgba(0,0,0,0.35)",
957
+ pointerEvents: "none",
958
+ zIndex: 9999,
959
+ whiteSpace: "nowrap"
960
+ }
961
+ },
962
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontWeight: 650, color: "var(--dsw-alias-label-primary, #ffffff)", marginBottom: 4 } }, (/* @__PURE__ */ new Date(hoveredDay.date + "T00:00:00")).toLocaleDateString(void 0, {
963
+ weekday: "short",
964
+ year: "numeric",
965
+ month: "short",
966
+ day: "numeric"
967
+ })),
968
+ hoveredDay.stats.totalTokens === 0 ? /* @__PURE__ */ import_react.default.createElement("div", { style: { color: "var(--dsw-alias-label-tertiary)" } }, "No activity recorded") : /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { style: { color: "#4f85ff", fontWeight: 600 } }, formatExact(hoveredDay.stats.totalTokens), " tokens"), /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-secondary)", marginTop: 2 } }, hoveredDay.stats.turns, " requests / steps"), /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 10, color: "var(--dsw-alias-label-tertiary)", marginTop: 4 } }, "Click to inspect sessions on this day"))
969
+ ),
970
+ hoveredBar && tooltipPos && /* @__PURE__ */ import_react.default.createElement(
971
+ "div",
972
+ {
973
+ style: {
974
+ position: "fixed",
975
+ left: tooltipPos.x,
976
+ top: tooltipPos.y,
977
+ transform: "translate(-50%, -100%)",
978
+ background: "var(--dsw-alias-bg-layer-1, #1e1e1e)",
979
+ border: "1px solid var(--dsw-alias-border-l3, #555555)",
980
+ borderRadius: 8,
981
+ padding: "8px 12px",
982
+ fontSize: 12,
983
+ lineHeight: 1.4,
984
+ boxShadow: "0 6px 18px rgba(0,0,0,0.35)",
985
+ pointerEvents: "none",
986
+ zIndex: 9999,
987
+ whiteSpace: "nowrap"
988
+ }
989
+ },
990
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { fontWeight: 650, color: "var(--dsw-alias-label-primary, #ffffff)", marginBottom: 4 } }, (/* @__PURE__ */ new Date(hoveredBar.date + "T00:00:00")).toLocaleDateString(void 0, {
991
+ weekday: "short",
992
+ year: "numeric",
993
+ month: "short",
994
+ day: "numeric"
995
+ })),
996
+ hoveredBar.totalTokens === 0 ? /* @__PURE__ */ import_react.default.createElement("div", { style: { color: "var(--dsw-alias-label-tertiary)" } }, "No activity recorded") : /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { style: { color: "#4f85ff", fontWeight: 600 } }, formatExact(hoveredBar.totalTokens), " total tokens"), /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 11, color: "var(--dsw-alias-label-secondary)", marginTop: 2 } }, "Billed: ", formatNumber(hoveredBar.billedTokens), " \xB7 Cached: ", formatNumber(hoveredBar.cachedTokens)), /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 10, color: "var(--dsw-alias-label-tertiary)", marginTop: 4 } }, hoveredBar.turns, " turns \xB7 Click to inspect day"))
997
+ )
998
+ );
999
+ }
1000
+ var HeatmapErrorBoundary = class extends import_react.default.Component {
1001
+ constructor(props) {
1002
+ super(props);
1003
+ this.state = { hasError: false, error: null };
1004
+ }
1005
+ static getDerivedStateFromError(error) {
1006
+ return { hasError: true, error };
1007
+ }
1008
+ componentDidCatch(error, info) {
1009
+ console.error("Heatmap rendering error:", error, info);
1010
+ }
1011
+ render() {
1012
+ if (this.state.hasError) {
1013
+ return /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "30px 20px", color: "var(--dsw-alias-state-error-primary, #ef4444)" } }, /* @__PURE__ */ import_react.default.createElement("h3", { style: { margin: "0 0 10px 0" } }, "Token Heatmap Encountered an Error"), /* @__PURE__ */ import_react.default.createElement(
1014
+ "pre",
1015
+ {
1016
+ style: {
1017
+ fontSize: 12,
1018
+ background: "rgba(0,0,0,0.3)",
1019
+ padding: 12,
1020
+ borderRadius: 8,
1021
+ overflowX: "auto"
1022
+ }
1023
+ },
1024
+ String(this.state.error?.message || this.state.error)
1025
+ ), /* @__PURE__ */ import_react.default.createElement(
1026
+ "button",
1027
+ {
1028
+ onClick: () => this.setState({ hasError: false, error: null }),
1029
+ style: {
1030
+ marginTop: 12,
1031
+ padding: "6px 14px",
1032
+ background: "var(--dsw-alias-brand-primary, #3964fe)",
1033
+ color: "#fff",
1034
+ border: "none",
1035
+ borderRadius: 6,
1036
+ cursor: "pointer"
1037
+ }
1038
+ },
1039
+ "Retry"
1040
+ ));
1041
+ }
1042
+ return this.props.children;
1043
+ }
1044
+ };
1045
+ function HeatmapView() {
1046
+ return /* @__PURE__ */ import_react.default.createElement(HeatmapErrorBoundary, null, /* @__PURE__ */ import_react.default.createElement(HeatmapInnerView, null));
1047
+ }
1048
+
1049
+ // src/client/HeatmapModal.tsx
1050
+ var import_react2 = __toESM(require("react"), 1);
1051
+ function HeatmapModal({ open, onClose }) {
1052
+ if (!open) return null;
1053
+ return /* @__PURE__ */ import_react2.default.createElement(
1054
+ "div",
1055
+ {
1056
+ role: "dialog",
1057
+ "aria-modal": "true",
1058
+ "aria-label": "Token Usage Heatmap",
1059
+ onClick: onClose,
1060
+ style: {
1061
+ position: "fixed",
1062
+ inset: 0,
1063
+ zIndex: 1e4,
1064
+ backgroundColor: "rgba(0, 0, 0, 0.65)",
1065
+ backdropFilter: "blur(4px)",
1066
+ display: "flex",
1067
+ alignItems: "center",
1068
+ justifyContent: "center",
1069
+ padding: "20px",
1070
+ overflowY: "auto"
1071
+ }
1072
+ },
1073
+ /* @__PURE__ */ import_react2.default.createElement(
1074
+ "div",
1075
+ {
1076
+ onClick: (e) => e.stopPropagation(),
1077
+ style: {
1078
+ position: "relative",
1079
+ width: "100%",
1080
+ maxWidth: "1040px",
1081
+ maxHeight: "92vh",
1082
+ overflowY: "auto",
1083
+ background: "var(--dsw-alias-bg-layer-1, #1e1e1e)",
1084
+ border: "1px solid var(--dsw-alias-border-l2, #494949)",
1085
+ borderRadius: "14px",
1086
+ boxShadow: "0 16px 40px rgba(0, 0, 0, 0.5)",
1087
+ padding: "24px 28px"
1088
+ }
1089
+ },
1090
+ /* @__PURE__ */ import_react2.default.createElement(
1091
+ "button",
1092
+ {
1093
+ onClick: onClose,
1094
+ "aria-label": "Close dialog",
1095
+ style: {
1096
+ position: "absolute",
1097
+ top: "16px",
1098
+ right: "18px",
1099
+ background: "transparent",
1100
+ border: "none",
1101
+ color: "var(--dsw-alias-label-tertiary, #a0a0a0)",
1102
+ fontSize: "20px",
1103
+ cursor: "pointer",
1104
+ width: "32px",
1105
+ height: "32px",
1106
+ display: "flex",
1107
+ alignItems: "center",
1108
+ justifyContent: "center",
1109
+ borderRadius: "6px"
1110
+ }
1111
+ },
1112
+ "\u2715"
1113
+ ),
1114
+ /* @__PURE__ */ import_react2.default.createElement(HeatmapView, null)
1115
+ )
1116
+ );
1117
+ }
1118
+
1119
+ // src/client/index.tsx
1120
+ var name = "token-contribution-client";
1121
+ var inject = ["slots"];
1122
+ function apply(ctx) {
1123
+ if (ctx.slots && typeof ctx.slots.inject === "function") {
1124
+ ctx.slots.inject("settings.section", () => {
1125
+ return ctx.slots.register(
1126
+ {
1127
+ name: "settings.section",
1128
+ id: "token-contribution",
1129
+ order: 14,
1130
+ label: () => "Token Contribution",
1131
+ icon: "chart"
1132
+ },
1133
+ HeatmapView
1134
+ );
1135
+ });
1136
+ }
1137
+ if (typeof document !== "undefined") {
1138
+ let ModalController = function() {
1139
+ const [isOpen, setIsOpen] = (0, import_react3.useState)(false);
1140
+ (0, import_react3.useEffect)(() => {
1141
+ const handleOpen = () => setIsOpen(true);
1142
+ const handleClose = () => setIsOpen(false);
1143
+ window.addEventListener("dsh:open-token-contribution", handleOpen);
1144
+ window.addEventListener("dsh:open-token-heatmap", handleOpen);
1145
+ window.addEventListener("keydown", (e) => {
1146
+ if (e.key === "Escape") handleClose();
1147
+ });
1148
+ return () => {
1149
+ window.removeEventListener("dsh:open-token-contribution", handleOpen);
1150
+ window.removeEventListener("dsh:open-token-heatmap", handleOpen);
1151
+ };
1152
+ }, []);
1153
+ return /* @__PURE__ */ import_react3.default.createElement(HeatmapModal, { open: isOpen, onClose: () => setIsOpen(false) });
1154
+ };
1155
+ if (!document.getElementById("dsh-token-heatmap-panel-resize")) {
1156
+ const resizeStyle = document.createElement("style");
1157
+ resizeStyle.id = "dsh-token-heatmap-panel-resize";
1158
+ resizeStyle.textContent = `
1159
+ /* Dynamically widen DSH Settings panel when Token Heatmap is active */
1160
+ .VOzbGW_panel:has([data-dsh-heatmap]),
1161
+ [class*="_panel"]:has([data-dsh-heatmap]) {
1162
+ width: min(1180px, calc(100vw - 32px)) !important;
1163
+ max-width: calc(100vw - 32px) !important;
1164
+ transition: width 0.25s cubic-bezier(0.16, 1, 0.3, 1), max-width 0.25s ease !important;
1165
+ }
1166
+ `;
1167
+ document.head.appendChild(resizeStyle);
1168
+ }
1169
+ const modalContainer = document.createElement("div");
1170
+ modalContainer.id = "token-contribution-modal-root";
1171
+ document.body.appendChild(modalContainer);
1172
+ const root = (0, import_client.createRoot)(modalContainer);
1173
+ root.render(/* @__PURE__ */ import_react3.default.createElement(ModalController, null));
1174
+ const observer = new MutationObserver(() => {
1175
+ const usageList = document.querySelector("[data-session-stats-usage]");
1176
+ if (!usageList) return;
1177
+ const dialogContainer = usageList.closest('div[role="dialog"]') || usageList.parentElement;
1178
+ if (!dialogContainer) return;
1179
+ if (dialogContainer.querySelector(".dsh-heatmap-trigger-btn") || document.querySelector(".dsh-heatmap-trigger-btn")) {
1180
+ return;
1181
+ }
1182
+ const button = document.createElement("button");
1183
+ button.className = "dsh-heatmap-trigger-btn";
1184
+ button.type = "button";
1185
+ button.innerHTML = "<span>View Token Contribution \u2192</span>";
1186
+ button.style.cssText = `
1187
+ display: flex;
1188
+ align-items: center;
1189
+ justify-content: center;
1190
+ width: 100%;
1191
+ margin-top: 12px;
1192
+ padding: 8px 12px;
1193
+ background: rgba(51, 109, 250, 0.12);
1194
+ border: 1px solid rgba(51, 109, 250, 0.35);
1195
+ border-radius: 8px;
1196
+ color: #4f85ff;
1197
+ font-size: 12px;
1198
+ font-weight: 600;
1199
+ cursor: pointer;
1200
+ box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
1201
+ transition: all 0.15s ease;
1202
+ `;
1203
+ button.onmouseenter = () => {
1204
+ button.style.background = "rgba(51, 109, 250, 0.22)";
1205
+ button.style.borderColor = "#336dfa";
1206
+ button.style.boxShadow = "0 2px 8px rgba(51, 109, 250, 0.25)";
1207
+ };
1208
+ button.onmouseleave = () => {
1209
+ button.style.background = "rgba(51, 109, 250, 0.12)";
1210
+ button.style.borderColor = "rgba(51, 109, 250, 0.35)";
1211
+ button.style.boxShadow = "0 1px 4px rgba(0, 0, 0, 0.15)";
1212
+ };
1213
+ button.onclick = (e) => {
1214
+ e.preventDefault();
1215
+ e.stopPropagation();
1216
+ const settingsTrigger = document.querySelector(
1217
+ 'button[aria-label*="Setting" i], [data-sidebar-settings] button, button.settings'
1218
+ );
1219
+ if (settingsTrigger) {
1220
+ settingsTrigger.click();
1221
+ setTimeout(() => {
1222
+ const heatmapTab = Array.from(document.querySelectorAll("*")).find(
1223
+ (el) => (el.textContent?.trim() === "Token Contribution" || el.textContent?.trim() === "Token Heatmap") && (el.tagName === "BUTTON" || el.tagName === "DIV" || el.getAttribute("role") === "tab" || el.classList.contains("ant-list-item"))
1224
+ );
1225
+ if (heatmapTab) {
1226
+ heatmapTab.click();
1227
+ } else {
1228
+ window.dispatchEvent(new CustomEvent("dsh:open-token-contribution"));
1229
+ }
1230
+ }, 120);
1231
+ } else {
1232
+ window.dispatchEvent(new CustomEvent("dsh:open-token-contribution"));
1233
+ }
1234
+ };
1235
+ dialogContainer.appendChild(button);
1236
+ });
1237
+ observer.observe(document.body, { childList: true, subtree: true });
1238
+ }
1239
+ }
1240
+ return module.exports; } });
1241
+ //# sourceMappingURL=client.js.map