free-coding-models 0.3.36 → 0.3.40

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 (58) hide show
  1. package/CHANGELOG.md +10 -1798
  2. package/README.md +4 -1
  3. package/bin/free-coding-models.js +1 -1
  4. package/package.json +11 -2
  5. package/src/app.js +3 -0
  6. package/src/cli-help.js +2 -0
  7. package/src/command-palette.js +3 -0
  8. package/src/endpoint-installer.js +1 -1
  9. package/src/tool-bootstrap.js +34 -0
  10. package/src/tool-launchers.js +137 -1
  11. package/src/tool-metadata.js +9 -0
  12. package/src/utils.js +8 -2
  13. package/web/index.html +2 -300
  14. package/web/server.js +80 -15
  15. package/web/src/App.jsx +150 -0
  16. package/web/src/components/analytics/AnalyticsView.jsx +109 -0
  17. package/web/src/components/analytics/AnalyticsView.module.css +186 -0
  18. package/web/src/components/atoms/Sparkline.jsx +44 -0
  19. package/web/src/components/atoms/StabilityCell.jsx +18 -0
  20. package/web/src/components/atoms/StabilityCell.module.css +8 -0
  21. package/web/src/components/atoms/StatusDot.jsx +10 -0
  22. package/web/src/components/atoms/StatusDot.module.css +17 -0
  23. package/web/src/components/atoms/TierBadge.jsx +10 -0
  24. package/web/src/components/atoms/TierBadge.module.css +18 -0
  25. package/web/src/components/atoms/Toast.jsx +25 -0
  26. package/web/src/components/atoms/Toast.module.css +35 -0
  27. package/web/src/components/atoms/ToastContainer.jsx +16 -0
  28. package/web/src/components/atoms/ToastContainer.module.css +10 -0
  29. package/web/src/components/atoms/VerdictBadge.jsx +13 -0
  30. package/web/src/components/atoms/VerdictBadge.module.css +19 -0
  31. package/web/src/components/dashboard/DetailPanel.jsx +131 -0
  32. package/web/src/components/dashboard/DetailPanel.module.css +99 -0
  33. package/web/src/components/dashboard/ExportModal.jsx +79 -0
  34. package/web/src/components/dashboard/ExportModal.module.css +99 -0
  35. package/web/src/components/dashboard/FilterBar.jsx +73 -0
  36. package/web/src/components/dashboard/FilterBar.module.css +43 -0
  37. package/web/src/components/dashboard/ModelTable.jsx +86 -0
  38. package/web/src/components/dashboard/ModelTable.module.css +46 -0
  39. package/web/src/components/dashboard/StatsBar.jsx +40 -0
  40. package/web/src/components/dashboard/StatsBar.module.css +28 -0
  41. package/web/src/components/layout/Footer.jsx +19 -0
  42. package/web/src/components/layout/Footer.module.css +10 -0
  43. package/web/src/components/layout/Header.jsx +38 -0
  44. package/web/src/components/layout/Header.module.css +73 -0
  45. package/web/src/components/layout/Sidebar.jsx +41 -0
  46. package/web/src/components/layout/Sidebar.module.css +76 -0
  47. package/web/src/components/settings/SettingsView.jsx +264 -0
  48. package/web/src/components/settings/SettingsView.module.css +377 -0
  49. package/web/src/global.css +199 -0
  50. package/web/src/hooks/useFilter.js +83 -0
  51. package/web/src/hooks/useSSE.js +49 -0
  52. package/web/src/hooks/useTheme.js +27 -0
  53. package/web/src/main.jsx +15 -0
  54. package/web/src/utils/download.js +15 -0
  55. package/web/src/utils/format.js +42 -0
  56. package/web/src/utils/ranks.js +37 -0
  57. /package/web/{app.js → app.legacy.js} +0 -0
  58. /package/web/{styles.css → styles.legacy.css} +0 -0
@@ -0,0 +1,377 @@
1
+ .page {
2
+ padding: 24px;
3
+ max-width: 900px;
4
+ }
5
+
6
+ .pageHeader {
7
+ margin-bottom: 24px;
8
+ }
9
+
10
+ .pageTitle {
11
+ font-size: 24px;
12
+ font-weight: 800;
13
+ margin: 0 0 6px;
14
+ }
15
+
16
+ .pageSubtitle {
17
+ font-size: 13px;
18
+ color: var(--color-text-muted);
19
+ line-height: 1.5;
20
+ margin: 0;
21
+ }
22
+
23
+ .pageSubtitle code {
24
+ font-family: var(--font-mono);
25
+ font-size: 12px;
26
+ background: var(--color-surface);
27
+ padding: 2px 6px;
28
+ border-radius: 4px;
29
+ }
30
+
31
+ .loading {
32
+ text-align: center;
33
+ padding: 60px 0;
34
+ color: var(--color-text-muted);
35
+ }
36
+
37
+ .toolbar {
38
+ display: flex;
39
+ align-items: center;
40
+ gap: 12px;
41
+ margin-bottom: 20px;
42
+ flex-wrap: wrap;
43
+ }
44
+
45
+ .toolbarSearch {
46
+ display: flex;
47
+ align-items: center;
48
+ gap: 8px;
49
+ background: var(--color-surface);
50
+ border: 1px solid var(--color-border);
51
+ border-radius: var(--radius-md);
52
+ padding: 0 12px;
53
+ height: 36px;
54
+ flex: 1;
55
+ min-width: 200px;
56
+ }
57
+
58
+ .toolbarSearch svg {
59
+ color: var(--color-text-dim);
60
+ flex-shrink: 0;
61
+ }
62
+
63
+ .toolbarSearch input {
64
+ flex: 1;
65
+ background: none;
66
+ border: none;
67
+ outline: none;
68
+ color: var(--color-text);
69
+ font-size: 13px;
70
+ font-family: var(--font-sans);
71
+ }
72
+
73
+ .toolbarSearch input::placeholder {
74
+ color: var(--color-text-dim);
75
+ }
76
+
77
+ .toolbarActions {
78
+ display: flex;
79
+ gap: 8px;
80
+ }
81
+
82
+ .toolbarBtn {
83
+ display: inline-flex;
84
+ align-items: center;
85
+ gap: 6px;
86
+ border: 1px solid var(--color-border);
87
+ border-radius: var(--radius-sm);
88
+ padding: 6px 14px;
89
+ font-size: 13px;
90
+ font-weight: 500;
91
+ cursor: pointer;
92
+ background: var(--color-surface);
93
+ color: var(--color-text);
94
+ transition: all var(--transition-fast);
95
+ font-family: var(--font-sans);
96
+ }
97
+
98
+ .toolbarBtn:hover {
99
+ background: var(--color-bg-hover);
100
+ border-color: var(--color-border-hover);
101
+ }
102
+
103
+ .providers {
104
+ display: flex;
105
+ flex-direction: column;
106
+ gap: 12px;
107
+ }
108
+
109
+ .card {
110
+ background: var(--color-bg-card);
111
+ backdrop-filter: blur(12px);
112
+ border: 1px solid var(--color-border);
113
+ border-radius: var(--radius-lg);
114
+ overflow: hidden;
115
+ transition: border-color var(--transition-fast);
116
+ }
117
+
118
+ .card:hover {
119
+ border-color: var(--color-border-hover);
120
+ }
121
+
122
+ .cardHeader {
123
+ display: flex;
124
+ align-items: center;
125
+ gap: 12px;
126
+ padding: 16px 20px;
127
+ cursor: pointer;
128
+ transition: background var(--transition-fast);
129
+ }
130
+
131
+ .cardHeader:hover {
132
+ background: var(--color-bg-hover);
133
+ }
134
+
135
+ .cardIcon {
136
+ width: 36px;
137
+ height: 36px;
138
+ display: flex;
139
+ align-items: center;
140
+ justify-content: center;
141
+ border-radius: var(--radius-sm);
142
+ font-size: 18px;
143
+ background: var(--color-accent-dim);
144
+ flex-shrink: 0;
145
+ }
146
+
147
+ .cardInfo {
148
+ flex: 1;
149
+ min-width: 0;
150
+ }
151
+
152
+ .cardName {
153
+ font-weight: 700;
154
+ font-size: 14px;
155
+ }
156
+
157
+ .cardMeta {
158
+ font-size: 11px;
159
+ color: var(--color-text-muted);
160
+ margin-top: 2px;
161
+ }
162
+
163
+ .cardStatus {
164
+ font-size: 11px;
165
+ font-weight: 700;
166
+ padding: 3px 10px;
167
+ border-radius: 999px;
168
+ flex-shrink: 0;
169
+ }
170
+
171
+ .statusConfigured {
172
+ background: var(--color-success-dim);
173
+ color: var(--color-success);
174
+ }
175
+
176
+ .statusMissing {
177
+ background: var(--color-warning-dim);
178
+ color: var(--color-warning);
179
+ }
180
+
181
+ .toggleIcon {
182
+ color: var(--color-text-dim);
183
+ transition: transform var(--transition-fast);
184
+ font-size: 18px;
185
+ flex-shrink: 0;
186
+ }
187
+
188
+ .toggleIconExpanded {
189
+ transform: rotate(180deg);
190
+ }
191
+
192
+ .cardBody {
193
+ max-height: 0;
194
+ overflow: hidden;
195
+ transition: max-height var(--transition-medium);
196
+ border-top: 0px solid transparent;
197
+ }
198
+
199
+ .cardExpanded .cardBody {
200
+ max-height: 500px;
201
+ border-top: 1px solid var(--color-border);
202
+ }
203
+
204
+ .cardContent {
205
+ padding: 16px 20px;
206
+ }
207
+
208
+ .keyGroup {
209
+ margin-bottom: 12px;
210
+ }
211
+
212
+ .keyLabel {
213
+ display: block;
214
+ font-size: 11px;
215
+ font-weight: 600;
216
+ color: var(--color-text-muted);
217
+ text-transform: uppercase;
218
+ letter-spacing: 0.5px;
219
+ margin-bottom: 6px;
220
+ }
221
+
222
+ .keyDisplay {
223
+ display: flex;
224
+ align-items: center;
225
+ gap: 8px;
226
+ background: var(--color-surface);
227
+ border: 1px solid var(--color-border);
228
+ border-radius: var(--radius-sm);
229
+ padding: 8px 12px;
230
+ margin-bottom: 8px;
231
+ }
232
+
233
+ .keyDisplayValue {
234
+ flex: 1;
235
+ font-family: var(--font-mono);
236
+ font-size: 13px;
237
+ color: var(--color-text-muted);
238
+ word-break: break-all;
239
+ }
240
+
241
+ .keyDisplayActions {
242
+ display: flex;
243
+ gap: 4px;
244
+ flex-shrink: 0;
245
+ }
246
+
247
+ .actionBtn {
248
+ display: inline-flex;
249
+ align-items: center;
250
+ justify-content: center;
251
+ padding: 4px 8px;
252
+ border: 1px solid var(--color-border);
253
+ border-radius: var(--radius-sm);
254
+ background: var(--color-surface);
255
+ color: var(--color-text);
256
+ cursor: pointer;
257
+ font-size: 12px;
258
+ transition: all var(--transition-fast);
259
+ }
260
+
261
+ .actionBtn:hover {
262
+ background: var(--color-bg-hover);
263
+ }
264
+
265
+ .actionBtnDanger {
266
+ background: var(--color-danger-dim);
267
+ color: var(--color-danger);
268
+ border-color: rgba(255, 68, 68, 0.2);
269
+ }
270
+
271
+ .actionBtnDanger:hover {
272
+ background: rgba(255, 68, 68, 0.2);
273
+ }
274
+
275
+ .keyInputRow {
276
+ display: flex;
277
+ gap: 8px;
278
+ align-items: center;
279
+ }
280
+
281
+ .keyInput {
282
+ flex: 1;
283
+ background: var(--color-surface);
284
+ border: 1px solid var(--color-border);
285
+ border-radius: var(--radius-sm);
286
+ padding: 8px 12px;
287
+ font-size: 13px;
288
+ font-family: var(--font-mono);
289
+ color: var(--color-text);
290
+ outline: none;
291
+ transition: border-color var(--transition-fast);
292
+ }
293
+
294
+ .keyInput:focus {
295
+ border-color: var(--color-accent);
296
+ }
297
+
298
+ .keyInput::placeholder {
299
+ color: var(--color-text-dim);
300
+ }
301
+
302
+ .saveBtn {
303
+ display: inline-flex;
304
+ align-items: center;
305
+ gap: 6px;
306
+ padding: 8px 14px;
307
+ font-size: 13px;
308
+ font-weight: 600;
309
+ border: 1px solid rgba(0, 255, 136, 0.2);
310
+ border-radius: var(--radius-sm);
311
+ background: var(--color-success-dim);
312
+ color: var(--color-success);
313
+ cursor: pointer;
314
+ font-family: var(--font-sans);
315
+ transition: all var(--transition-fast);
316
+ }
317
+
318
+ .saveBtn:hover {
319
+ background: rgba(0, 255, 136, 0.15);
320
+ }
321
+
322
+ .enabledRow {
323
+ display: flex;
324
+ align-items: center;
325
+ justify-content: space-between;
326
+ padding-top: 12px;
327
+ border-top: 1px solid var(--color-border);
328
+ margin-top: 12px;
329
+ }
330
+
331
+ .enabledLabel {
332
+ font-size: 12px;
333
+ color: var(--color-text-muted);
334
+ font-weight: 500;
335
+ }
336
+
337
+ .toggleSwitch {
338
+ position: relative;
339
+ width: 44px;
340
+ height: 24px;
341
+ cursor: pointer;
342
+ }
343
+
344
+ .toggleSwitch input {
345
+ display: none;
346
+ }
347
+
348
+ .toggleSlider {
349
+ position: absolute;
350
+ inset: 0;
351
+ background: var(--color-surface);
352
+ border: 1px solid var(--color-border);
353
+ border-radius: 12px;
354
+ transition: all var(--transition-fast);
355
+ }
356
+
357
+ .toggleSlider::after {
358
+ content: '';
359
+ position: absolute;
360
+ left: 3px;
361
+ top: 3px;
362
+ width: 16px;
363
+ height: 16px;
364
+ background: var(--color-text-dim);
365
+ border-radius: 50%;
366
+ transition: all var(--transition-fast);
367
+ }
368
+
369
+ .toggleSwitch input:checked + .toggleSlider {
370
+ background: var(--color-accent-dim);
371
+ border-color: var(--color-accent);
372
+ }
373
+
374
+ .toggleSwitch input:checked + .toggleSlider::after {
375
+ transform: translateX(20px);
376
+ background: var(--color-accent);
377
+ }
@@ -0,0 +1,199 @@
1
+ /**
2
+ * @file web/src/global.css
3
+ * @description Global CSS with design tokens, base reset, background effects, and shared styles.
4
+ * 📖 Contains all CSS custom properties (--color-*, --font-*, --radius-*, etc.),
5
+ * light theme overrides, reset rules, background grid/glow effects,
6
+ * app-content layout, view visibility, scrollbar, and responsive breakpoints.
7
+ */
8
+
9
+ /* ─── CSS Custom Properties (Design Tokens) ─── */
10
+ :root {
11
+ --color-bg: #0a0a0f;
12
+ --color-bg-elevated: #12121a;
13
+ --color-bg-card: rgba(18, 18, 30, 0.7);
14
+ --color-bg-hover: rgba(30, 30, 50, 0.8);
15
+ --color-bg-active: rgba(40, 40, 65, 0.9);
16
+ --color-surface: #1a1a2e;
17
+ --color-border: rgba(255, 255, 255, 0.06);
18
+ --color-border-hover: rgba(255, 255, 255, 0.12);
19
+
20
+ --color-text: #e8e8f0;
21
+ --color-text-muted: #8888a8;
22
+ --color-text-dim: #555570;
23
+
24
+ --color-accent: #76b900;
25
+ --color-accent-hover: #8ad100;
26
+ --color-accent-glow: rgba(118, 185, 0, 0.25);
27
+ --color-accent-dim: rgba(118, 185, 0, 0.08);
28
+
29
+ --color-danger: #ff4444;
30
+ --color-danger-dim: rgba(255, 68, 68, 0.1);
31
+ --color-warning: #ffaa00;
32
+ --color-warning-dim: rgba(255, 170, 0, 0.1);
33
+ --color-success: #00ff88;
34
+ --color-success-dim: rgba(0, 255, 136, 0.1);
35
+ --color-info: #06b6d4;
36
+ --color-info-dim: rgba(6, 182, 212, 0.1);
37
+
38
+ --tier-splus: #ffd700;
39
+ --tier-s: #ff8c00;
40
+ --tier-aplus: #00c8ff;
41
+ --tier-a: #3ddc84;
42
+ --tier-aminus: #7ecf7e;
43
+ --tier-bplus: #a8a8c8;
44
+ --tier-b: #808098;
45
+ --tier-c: #606078;
46
+
47
+ --verdict-perfect: #00ff88;
48
+ --verdict-normal: #76b900;
49
+ --verdict-slow: #ffaa00;
50
+ --verdict-spiky: #ff6600;
51
+ --verdict-veryslow: #ff4444;
52
+ --verdict-overloaded: #ff2222;
53
+ --verdict-unstable: #cc0000;
54
+ --verdict-notactive: #555570;
55
+ --verdict-pending: #444460;
56
+
57
+ --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
58
+ --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
59
+
60
+ --header-h: 60px;
61
+ --sidebar-w: 64px;
62
+ --sidebar-w-expanded: 200px;
63
+ --radius-sm: 6px;
64
+ --radius-md: 10px;
65
+ --radius-lg: 16px;
66
+ --radius-xl: 20px;
67
+
68
+ --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
69
+ --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
70
+ --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
71
+ --shadow-glow: 0 0 30px var(--color-accent-glow);
72
+
73
+ --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
74
+ --transition-fast: 150ms var(--ease-out);
75
+ --transition-medium: 250ms var(--ease-out);
76
+ --transition-slow: 400ms var(--ease-out);
77
+ }
78
+
79
+ /* ─── Light Theme ─── */
80
+ [data-theme="light"] {
81
+ --color-bg: #f5f5fa;
82
+ --color-bg-elevated: #ffffff;
83
+ --color-bg-card: rgba(255, 255, 255, 0.85);
84
+ --color-bg-hover: rgba(240, 240, 248, 0.9);
85
+ --color-bg-active: rgba(230, 230, 242, 0.95);
86
+ --color-surface: #eeeef4;
87
+ --color-border: rgba(0, 0, 0, 0.08);
88
+ --color-border-hover: rgba(0, 0, 0, 0.15);
89
+ --color-text: #1a1a2e;
90
+ --color-text-muted: #666688;
91
+ --color-text-dim: #9999aa;
92
+ --color-accent-glow: rgba(118, 185, 0, 0.15);
93
+ --color-accent-dim: rgba(118, 185, 0, 0.05);
94
+ --color-danger-dim: rgba(255, 68, 68, 0.08);
95
+ --color-warning-dim: rgba(255, 170, 0, 0.08);
96
+ --color-success-dim: rgba(0, 255, 136, 0.08);
97
+ --color-info-dim: rgba(6, 182, 212, 0.08);
98
+ --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
99
+ --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
100
+ --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
101
+ }
102
+
103
+ /* ─── Reset & Base ─── */
104
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
105
+
106
+ html {
107
+ font-size: 14px;
108
+ scroll-behavior: smooth;
109
+ -webkit-font-smoothing: antialiased;
110
+ -moz-osx-font-smoothing: grayscale;
111
+ }
112
+
113
+ body {
114
+ font-family: var(--font-sans);
115
+ background: var(--color-bg);
116
+ color: var(--color-text);
117
+ min-height: 100vh;
118
+ overflow-x: hidden;
119
+ position: relative;
120
+ display: flex;
121
+ }
122
+
123
+ a { color: var(--color-accent); text-decoration: none; }
124
+ a:hover { color: var(--color-accent-hover); }
125
+ code { font-family: var(--font-mono); font-size: 12px; background: var(--color-surface); padding: 2px 6px; border-radius: 4px; }
126
+
127
+ /* ─── Background Effects ─── */
128
+ .bg-grid {
129
+ position: fixed; inset: 0; z-index: 0; pointer-events: none;
130
+ background-image:
131
+ linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
132
+ linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
133
+ background-size: 60px 60px;
134
+ }
135
+
136
+ .bg-glow {
137
+ position: fixed; z-index: 0; pointer-events: none;
138
+ border-radius: 50%;
139
+ filter: blur(120px);
140
+ opacity: 0.3;
141
+ animation: float 20s ease-in-out infinite;
142
+ }
143
+ .bg-glow--1 {
144
+ width: 600px; height: 600px;
145
+ background: radial-gradient(circle, var(--color-accent) 0%, transparent 70%);
146
+ top: -200px; left: -200px;
147
+ }
148
+ .bg-glow--2 {
149
+ width: 400px; height: 400px;
150
+ background: radial-gradient(circle, #6366f1 0%, transparent 70%);
151
+ top: 50%; right: -150px; animation-delay: -7s;
152
+ }
153
+ .bg-glow--3 {
154
+ width: 500px; height: 500px;
155
+ background: radial-gradient(circle, #06b6d4 0%, transparent 70%);
156
+ bottom: -200px; left: 30%; animation-delay: -14s;
157
+ }
158
+
159
+ @keyframes float {
160
+ 0%, 100% { transform: translate(0, 0) scale(1); }
161
+ 33% { transform: translate(30px, -30px) scale(1.05); }
162
+ 66% { transform: translate(-20px, 20px) scale(0.95); }
163
+ }
164
+
165
+ [data-theme="light"] .bg-glow { opacity: 0.12; }
166
+ [data-theme="light"] .bg-grid {
167
+ background-image:
168
+ linear-gradient(rgba(0,0,0,0.04) 1px, transparent 1px),
169
+ linear-gradient(90deg, rgba(0,0,0,0.04) 1px, transparent 1px);
170
+ }
171
+
172
+ /* ─── App Layout ─── */
173
+ .app-content {
174
+ flex: 1;
175
+ margin-left: var(--sidebar-w);
176
+ position: relative;
177
+ z-index: 1;
178
+ min-height: 100vh;
179
+ display: flex;
180
+ flex-direction: column;
181
+ transition: margin-left var(--transition-medium);
182
+ }
183
+
184
+ .view {
185
+ display: flex;
186
+ flex-direction: column;
187
+ flex: 1;
188
+ }
189
+
190
+ /* ─── Scrollbar ─── */
191
+ ::-webkit-scrollbar { width: 6px; }
192
+ ::-webkit-scrollbar-track { background: transparent; }
193
+ ::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
194
+ ::-webkit-scrollbar-thumb:hover { background: var(--color-text-dim); }
195
+
196
+ /* ─── Responsive ─── */
197
+ @media (max-width: 768px) {
198
+ .app-content { margin-left: 0; }
199
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @file web/src/hooks/useFilter.js
3
+ * @description React hook for model filtering and sorting state.
4
+ * 📖 Manages tier/status/provider/text filters + sort column/direction.
5
+ * → useFilter
6
+ */
7
+ import { useState, useMemo, useCallback } from 'react'
8
+ import { tierRank, verdictRank, parseSwe } from '../utils/ranks.js'
9
+ import { formatCtx } from '../utils/format.js'
10
+
11
+ export function useFilter(models) {
12
+ const [filterTier, setFilterTier] = useState('all')
13
+ const [filterStatus, setFilterStatus] = useState('all')
14
+ const [filterProvider, setFilterProvider] = useState('all')
15
+ const [searchQuery, setSearchQuery] = useState('')
16
+ const [sortColumn, setSortColumn] = useState('avg')
17
+ const [sortDirection, setSortDirection] = useState('asc')
18
+
19
+ const toggleSort = useCallback((col) => {
20
+ setSortColumn((prevCol) => {
21
+ if (prevCol === col) {
22
+ setSortDirection((prevDir) => (prevDir === 'asc' ? 'desc' : 'asc'))
23
+ } else {
24
+ setSortDirection('asc')
25
+ }
26
+ return col
27
+ })
28
+ }, [])
29
+
30
+ const filtered = useMemo(() => {
31
+ let result = [...models]
32
+
33
+ if (filterTier !== 'all') result = result.filter((m) => m.tier === filterTier)
34
+ if (filterStatus !== 'all') {
35
+ result = result.filter((m) => {
36
+ if (filterStatus === 'up') return m.status === 'up'
37
+ if (filterStatus === 'down') return m.status === 'down' || m.status === 'timeout'
38
+ if (filterStatus === 'pending') return m.status === 'pending'
39
+ return true
40
+ })
41
+ }
42
+ if (filterProvider !== 'all') result = result.filter((m) => m.providerKey === filterProvider)
43
+ if (searchQuery) {
44
+ const q = searchQuery.toLowerCase()
45
+ result = result.filter(
46
+ (m) =>
47
+ m.label.toLowerCase().includes(q) ||
48
+ m.modelId.toLowerCase().includes(q) ||
49
+ m.origin.toLowerCase().includes(q) ||
50
+ m.tier.toLowerCase().includes(q) ||
51
+ (m.verdict || '').toLowerCase().includes(q)
52
+ )
53
+ }
54
+
55
+ result.sort((a, b) => {
56
+ let cmp = 0
57
+ const col = sortColumn
58
+ if (col === 'idx') cmp = a.idx - b.idx
59
+ else if (col === 'tier') cmp = tierRank(a.tier) - tierRank(b.tier)
60
+ else if (col === 'label') cmp = a.label.localeCompare(b.label)
61
+ else if (col === 'origin') cmp = a.origin.localeCompare(b.origin)
62
+ else if (col === 'sweScore') cmp = parseSwe(a.sweScore) - parseSwe(b.sweScore)
63
+ else if (col === 'ctx') cmp = formatCtx(a.ctx) - formatCtx(b.ctx)
64
+ else if (col === 'latestPing') cmp = (a.latestPing ?? Infinity) - (b.latestPing ?? Infinity)
65
+ else if (col === 'avg') cmp = (a.avg === Infinity ? 99999 : a.avg) - (b.avg === Infinity ? 99999 : b.avg)
66
+ else if (col === 'stability') cmp = (a.stability ?? -1) - (b.stability ?? -1)
67
+ else if (col === 'verdict') cmp = verdictRank(a.verdict) - verdictRank(b.verdict)
68
+ else if (col === 'uptime') cmp = (a.uptime ?? 0) - (b.uptime ?? 0)
69
+ return sortDirection === 'asc' ? cmp : -cmp
70
+ })
71
+
72
+ return result
73
+ }, [models, filterTier, filterStatus, filterProvider, searchQuery, sortColumn, sortDirection])
74
+
75
+ return {
76
+ filtered,
77
+ filterTier, setFilterTier,
78
+ filterStatus, setFilterStatus,
79
+ filterProvider, setFilterProvider,
80
+ searchQuery, setSearchQuery,
81
+ sortColumn, sortDirection, toggleSort,
82
+ }
83
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @file web/src/hooks/useSSE.js
3
+ * @description React hook for SSE (Server-Sent Events) connection.
4
+ * 📖 Connects to /api/events, auto-reconnects on failure, returns live model data.
5
+ * → useSSE
6
+ */
7
+ import { useState, useEffect, useRef, useCallback } from 'react'
8
+
9
+ export function useSSE(url = '/api/events') {
10
+ const [models, setModels] = useState([])
11
+ const [connected, setConnected] = useState(false)
12
+ const [updateCount, setUpdateCount] = useState(0)
13
+ const esRef = useRef(null)
14
+ const reconnectTimer = useRef(null)
15
+
16
+ const connect = useCallback(() => {
17
+ if (esRef.current) esRef.current.close()
18
+
19
+ const es = new EventSource(url)
20
+ esRef.current = es
21
+
22
+ es.onopen = () => setConnected(true)
23
+ es.onmessage = (event) => {
24
+ try {
25
+ const data = JSON.parse(event.data)
26
+ setModels(data)
27
+ setUpdateCount((c) => c + 1)
28
+ } catch (e) {
29
+ console.error('SSE parse error:', e)
30
+ }
31
+ }
32
+ es.onerror = () => {
33
+ setConnected(false)
34
+ es.close()
35
+ clearTimeout(reconnectTimer.current)
36
+ reconnectTimer.current = setTimeout(connect, 3000)
37
+ }
38
+ }, [url])
39
+
40
+ useEffect(() => {
41
+ connect()
42
+ return () => {
43
+ esRef.current?.close()
44
+ clearTimeout(reconnectTimer.current)
45
+ }
46
+ }, [connect])
47
+
48
+ return { models, connected, updateCount }
49
+ }