Commit b6b2de3
authored
🤖 Add collapsed token meter sidebar (#271)
## Summary
Adds a collapsed token meter sidebar that displays the last request's
token usage as a thin vertical bar when space is constrained.
## Features
### Responsive Collapse/Expand
- **Full view (300px)**: Shows tabs for Costs and Tools with detailed
breakdowns
- **Collapsed view (20px)**: Shows vertical token meter bar
- **Hysteresis thresholds**: Collapses at ≤800px ChatArea width, expands
at ≥1100px
- **Smooth transition**: 0.2s ease animation between states
### Vertical Token Meter
- **Proportional bar height**: Scales 0-100% based on context window
usage (e.g., 18% usage = 18% bar height)
- **Colored segments**: Shows token composition
(cached/input/output/reasoning) with proper colors
- **Context percentage label**: Displays usage number at top (e.g.,
"18")
- **Always visible**: Uses sticky positioning to stay pinned to right
edge, even when window < 770px
- **Hover tooltip**: Shows detailed breakdown with token counts and
costs
### Technical Implementation
- **ResizeObserver**: Measures ChatArea width with requestAnimationFrame
throttling
- **React.memo**: Prevents unnecessary re-renders of TokenMeter
components
- **useMemo**: Caches expensive vertical meter calculations
- **Flex layout**: Proper vertical segment distribution without
overlapping
- **Sticky positioning**: Keeps collapsed bar visible during horizontal
scroll
## Layout Behavior
### Window Width Scenarios
| Window Width | ChatArea Width | Sidebar State | Behavior |
|--------------|----------------|---------------|----------|
| 1400px+ | 1100px+ | Full (300px) | All visible, no scroll |
| 1100-1399px | 800-1099px | Hysteresis zone | Maintains current state |
| 900-1099px | ~600-800px | Collapsed (20px) | Vertical bar visible |
| 770-899px | 750px | Collapsed (20px) | Tight fit, all visible |
| < 770px | 750px (min) | Collapsed (20px) | Horizontal scroll, bar
sticky |
### Sticky Behavior (< 770px)
- ViewContainer allows horizontal scrolling
- Vertical bar (20px) stays pinned to right edge
- ChatArea scrolls underneath with subtle shadow
- Bar covers rightmost 20px of chat (minimal impact)
## Files Changed
- - Responsive sidebar with collapse logic
- - Collapsed view component
- - Reusable bar renderer
- - Wrapper for horizontal use
- - ResizeObserver integration, sticky container support
- - Throttled size observation
- - Shared calculations and color constants
## Testing
- [x] Verify collapse/expand at correct thresholds
- [x] Test hysteresis prevents oscillation
- [x] Confirm vertical bar scales with context usage
- [x] Check segment colors match TOKEN_COMPONENT_COLORS
- [x] Validate tooltip shows correct breakdown
- [x] Test horizontal scroll behavior < 770px
- [x] Verify sticky bar stays visible when scrolling
- [x] Confirm no performance degradation or memory leaks
_Generated with `cmux`_1 parent c63c6c4 commit b6b2de3
File tree
7 files changed
+541
-64
lines changed- src
- components
- ChatMetaSidebar
- hooks
- utils/tokens
7 files changed
+541
-64
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| 207 | + | |
| 208 | + | |
206 | 209 | | |
207 | 210 | | |
208 | 211 | | |
| |||
346 | 349 | | |
347 | 350 | | |
348 | 351 | | |
349 | | - | |
| 352 | + | |
350 | 353 | | |
351 | 354 | | |
352 | 355 | | |
| |||
405 | 408 | | |
406 | 409 | | |
407 | 410 | | |
408 | | - | |
| 411 | + | |
409 | 412 | | |
410 | 413 | | |
411 | 414 | | |
| |||
532 | 535 | | |
533 | 536 | | |
534 | 537 | | |
535 | | - | |
| 538 | + | |
536 | 539 | | |
537 | 540 | | |
538 | 541 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
| 9 | + | |
| 10 | + | |
6 | 11 | | |
7 | | - | |
8 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
9 | 18 | | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
13 | 22 | | |
| 23 | + | |
| 24 | + | |
14 | 25 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
18 | 46 | | |
19 | 47 | | |
20 | 48 | | |
| |||
56 | 84 | | |
57 | 85 | | |
58 | 86 | | |
| 87 | + | |
59 | 88 | | |
60 | 89 | | |
61 | | - | |
| 90 | + | |
62 | 91 | | |
63 | 92 | | |
64 | 93 | | |
65 | 94 | | |
66 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
67 | 100 | | |
68 | 101 | | |
69 | 102 | | |
70 | 103 | | |
71 | 104 | | |
72 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
73 | 137 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
111 | 184 | | |
112 | 185 | | |
113 | 186 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | 90 | | |
98 | 91 | | |
99 | 92 | | |
| |||
111 | 104 | | |
112 | 105 | | |
113 | 106 | | |
114 | | - | |
| 107 | + | |
115 | 108 | | |
116 | 109 | | |
117 | 110 | | |
118 | 111 | | |
119 | 112 | | |
120 | 113 | | |
121 | | - | |
| 114 | + | |
122 | 115 | | |
123 | 116 | | |
124 | 117 | | |
125 | 118 | | |
126 | 119 | | |
127 | 120 | | |
128 | | - | |
| 121 | + | |
129 | 122 | | |
130 | 123 | | |
131 | 124 | | |
132 | 125 | | |
133 | 126 | | |
134 | 127 | | |
135 | | - | |
| 128 | + | |
136 | 129 | | |
137 | 130 | | |
138 | 131 | | |
| |||
452 | 445 | | |
453 | 446 | | |
454 | 447 | | |
455 | | - | |
| 448 | + | |
456 | 449 | | |
457 | 450 | | |
458 | 451 | | |
459 | 452 | | |
460 | 453 | | |
461 | 454 | | |
462 | | - | |
| 455 | + | |
463 | 456 | | |
464 | 457 | | |
465 | 458 | | |
466 | 459 | | |
467 | 460 | | |
468 | 461 | | |
469 | | - | |
| 462 | + | |
470 | 463 | | |
471 | 464 | | |
472 | 465 | | |
473 | 466 | | |
474 | 467 | | |
475 | 468 | | |
476 | | - | |
| 469 | + | |
477 | 470 | | |
478 | 471 | | |
479 | 472 | | |
480 | 473 | | |
481 | 474 | | |
482 | 475 | | |
483 | | - | |
| 476 | + | |
484 | 477 | | |
485 | 478 | | |
486 | 479 | | |
| |||
0 commit comments