@polderlabs/bizar 4.4.12 → 4.5.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/bizar-dash/CHANGELOG.md +37 -276
- package/bizar-dash/dist/assets/main-CDFKHzBg.css +1 -0
- package/bizar-dash/dist/assets/main-NYFpS2wY.js +312 -0
- package/bizar-dash/dist/assets/main-NYFpS2wY.js.map +1 -0
- package/bizar-dash/dist/assets/{mobile-DSb-t42Y.js → mobile--0FBIKX3.js} +2 -2
- package/bizar-dash/dist/assets/{mobile-DSb-t42Y.js.map → mobile--0FBIKX3.js.map} +1 -1
- package/bizar-dash/dist/assets/mobile-OgRp8VIb.js +352 -0
- package/bizar-dash/dist/assets/mobile-OgRp8VIb.js.map +1 -0
- package/bizar-dash/dist/index.html +3 -3
- package/bizar-dash/dist/mobile.html +2 -2
- package/bizar-dash/skills/agent-baseline/SKILL.md +80 -0
- package/bizar-dash/skills/bizar/SKILL.md +96 -0
- package/bizar-dash/skills/chat/SKILL.md +74 -0
- package/bizar-dash/skills/lightrag/SKILL.md +75 -0
- package/bizar-dash/skills/minimax/SKILL.md +80 -0
- package/bizar-dash/skills/obsidian/SKILL.md +55 -0
- package/bizar-dash/skills/providers/SKILL.md +75 -0
- package/bizar-dash/skills/sdk/SKILL.md +138 -0
- package/bizar-dash/skills/self-improvement/SKILL.md +53 -0
- package/bizar-dash/skills/skills-cli/SKILL.md +94 -0
- package/bizar-dash/skills/usage/SKILL.md +62 -0
- package/bizar-dash/src/server/api.mjs +12 -0
- package/bizar-dash/src/server/memory-lightrag.mjs +5 -2
- package/bizar-dash/src/server/memory-store.mjs +38 -0
- package/bizar-dash/src/server/minimax-usage-store.mjs +372 -0
- package/bizar-dash/src/server/minimax.mjs +427 -110
- package/bizar-dash/src/server/providers-store.mjs +966 -6
- package/bizar-dash/src/server/routes/config.mjs +52 -1
- package/bizar-dash/src/server/routes/env-vars.mjs +165 -0
- package/bizar-dash/src/server/routes/lightrag.mjs +154 -0
- package/bizar-dash/src/server/routes/memory.mjs +241 -1
- package/bizar-dash/src/server/routes/minimax.mjs +50 -57
- package/bizar-dash/src/server/routes/opencode-session-detail.mjs +14 -29
- package/bizar-dash/src/server/routes/opencode-sessions.mjs +205 -3
- package/bizar-dash/src/server/routes/providers.mjs +266 -5
- package/bizar-dash/src/server/routes/skills.mjs +32 -43
- package/bizar-dash/src/server/routes/update.mjs +340 -0
- package/bizar-dash/src/server/routes/usage.mjs +136 -0
- package/bizar-dash/src/server/serve-info.mjs +135 -4
- package/bizar-dash/src/server/server.mjs +4 -0
- package/bizar-dash/src/server/skills-store.mjs +152 -262
- package/bizar-dash/src/web/App.tsx +118 -29
- package/bizar-dash/src/web/components/EnvVarManager.tsx +247 -0
- package/bizar-dash/src/web/components/SettingsSearch.tsx +213 -0
- package/bizar-dash/src/web/components/Topbar.tsx +0 -1
- package/bizar-dash/src/web/components/UsageChart.tsx +250 -0
- package/bizar-dash/src/web/components/UsageTable.tsx +90 -0
- package/bizar-dash/src/web/components/chat/ChatComposer.tsx +21 -25
- package/bizar-dash/src/web/components/chat/ChatInfoPanel.tsx +199 -37
- package/bizar-dash/src/web/components/chat/ChatThread.tsx +29 -17
- package/bizar-dash/src/web/components/chat/FloatingComposer.tsx +7 -1
- package/bizar-dash/src/web/components/chat/InfoPanel.tsx +71 -6
- package/bizar-dash/src/web/components/chat/useChat.ts +751 -257
- package/bizar-dash/src/web/lib/api.ts +43 -0
- package/bizar-dash/src/web/main.tsx +1 -0
- package/bizar-dash/src/web/mobile/views/MobileChat.tsx +110 -35
- package/bizar-dash/src/web/styles/chat.css +135 -1
- package/bizar-dash/src/web/styles/main.css +46 -0
- package/bizar-dash/src/web/styles/minimax-usage.css +471 -0
- package/bizar-dash/src/web/styles/settings.css +418 -0
- package/bizar-dash/src/web/styles/skills.css +302 -0
- package/bizar-dash/src/web/styles/tasks.css +288 -0
- package/bizar-dash/src/web/views/Chat.tsx +276 -48
- package/bizar-dash/src/web/views/Config.tsx +3 -2065
- package/bizar-dash/src/web/views/MiniMaxUsage.tsx +620 -240
- package/bizar-dash/src/web/views/Settings.tsx +6 -0
- package/bizar-dash/src/web/views/Skills.tsx +208 -260
- package/bizar-dash/src/web/views/Tasks.tsx +348 -1119
- package/bizar-dash/tests/chat-session-create.test.mjs +391 -0
- package/bizar-dash/tests/chat-session-stream.test.mjs +308 -0
- package/bizar-dash/tests/env-vars-store.test.mjs +216 -0
- package/bizar-dash/tests/lightrag-defaults.node.test.mjs +118 -0
- package/bizar-dash/tests/minimax-chat-usage.test.mjs +178 -0
- package/bizar-dash/tests/minimax-usage-store.node.test.mjs +293 -0
- package/bizar-dash/tests/opencode-sessions-detail.test.mjs +12 -9
- package/bizar-dash/tests/providers-store-backup-keys.node.test.mjs +479 -3
- package/bizar-dash/tests/providers-store-search.node.test.mjs +166 -0
- package/bizar-dash/tests/skills-list.test.mjs +232 -0
- package/bizar-dash/tests/skills-search.test.mjs +222 -0
- package/bizar-dash/tests/tasks-create.test.mjs +187 -0
- package/bizar-dash/tests/update-check.test.mjs +127 -0
- package/bizar-dash/tests/update-run.test.mjs +266 -0
- package/cli/bin.mjs +345 -4
- package/cli/provision.mjs +118 -4
- package/config/agents/_shared/SKILLS.md +109 -0
- package/package.json +1 -1
- package/bizar-dash/dist/assets/main-BKXEqU1w.css +0 -1
- package/bizar-dash/dist/assets/main-EK_fzXn_.js +0 -352
- package/bizar-dash/dist/assets/main-EK_fzXn_.js.map +0 -1
- package/bizar-dash/dist/assets/mobile-Dl1q7Cyq.js +0 -354
- package/bizar-dash/dist/assets/mobile-Dl1q7Cyq.js.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// src/views/MiniMaxUsage.tsx — v4.
|
|
1
|
+
// src/views/MiniMaxUsage.tsx — v4.6.0
|
|
2
2
|
//
|
|
3
|
-
//
|
|
3
|
+
// Full rewrite with two tabs:
|
|
4
|
+
// 1. Token Plan — existing 5h + weekly remaining quota (unchanged)
|
|
5
|
+
// 2. Usage Analytics — charts, KPIs, per-model breakdown, per-key status
|
|
4
6
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// The
|
|
8
|
-
// trip needed) — the value is written to settings.json under
|
|
9
|
-
// `minimax.apiKey` and read back on next load.
|
|
7
|
+
// The usage data comes from the JSONL store at ~/.local/share/bizar/usage.jsonl
|
|
8
|
+
// (written by minimax.mjs after every chatCompletion / fetchRemains call).
|
|
9
|
+
// The Usage Analytics tab is only shown when the key is configured.
|
|
10
10
|
|
|
11
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
11
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
12
12
|
import {
|
|
13
13
|
Coins,
|
|
14
14
|
RefreshCw,
|
|
@@ -22,18 +22,27 @@ import {
|
|
|
22
22
|
Save,
|
|
23
23
|
Eye,
|
|
24
24
|
EyeOff,
|
|
25
|
+
Sparkles,
|
|
26
|
+
X,
|
|
27
|
+
ExternalLink,
|
|
28
|
+
ShieldCheck,
|
|
29
|
+
CircleCheck,
|
|
30
|
+
BarChart2,
|
|
25
31
|
} from 'lucide-react';
|
|
26
32
|
import { Card, CardTitle, CardMeta } from '../components/Card';
|
|
27
33
|
import { Button } from '../components/Button';
|
|
28
34
|
import { Spinner } from '../components/Spinner';
|
|
35
|
+
import { UsageChart } from '../components/UsageChart';
|
|
36
|
+
import { UsageTable, type PerModelRow } from '../components/UsageTable';
|
|
29
37
|
import { useToast } from '../components/Toast';
|
|
30
38
|
import { api } from '../lib/api';
|
|
31
39
|
import { cn } from '../lib/utils';
|
|
32
|
-
|
|
40
|
+
|
|
41
|
+
// ─── Types ───────────────────────────────────────────────────────────
|
|
33
42
|
|
|
34
43
|
type Props = {
|
|
35
|
-
snapshot:
|
|
36
|
-
settings:
|
|
44
|
+
snapshot: unknown;
|
|
45
|
+
settings: unknown;
|
|
37
46
|
activeTab: string;
|
|
38
47
|
setActiveTab: (id: string) => void;
|
|
39
48
|
refreshSnapshot: () => Promise<void>;
|
|
@@ -68,6 +77,7 @@ type RemainsSnapshot = {
|
|
|
68
77
|
cached?: boolean;
|
|
69
78
|
fetchedAt?: number;
|
|
70
79
|
apiKeyHint?: string;
|
|
80
|
+
keySource?: string;
|
|
71
81
|
groupId?: string;
|
|
72
82
|
baseUrl?: string;
|
|
73
83
|
models?: RemainsModel[];
|
|
@@ -77,15 +87,22 @@ type RemainsSnapshot = {
|
|
|
77
87
|
};
|
|
78
88
|
|
|
79
89
|
type Status = {
|
|
80
|
-
enabled: boolean;
|
|
81
90
|
configured: boolean;
|
|
82
91
|
apiKeyHint: string;
|
|
92
|
+
source: string;
|
|
83
93
|
groupId: string;
|
|
84
|
-
|
|
94
|
+
tokenBaseUrl: string;
|
|
85
95
|
chatBaseUrl: string;
|
|
96
|
+
knownModels: string[];
|
|
97
|
+
keyPatternValid: boolean | null;
|
|
86
98
|
cache: { fetchedAt: number; apiKeyHint: string; modelCount: number } | null;
|
|
87
99
|
};
|
|
88
100
|
|
|
101
|
+
type OnboardingState = {
|
|
102
|
+
dismissedAt: number | null;
|
|
103
|
+
hiddenModels: string[];
|
|
104
|
+
};
|
|
105
|
+
|
|
89
106
|
type TestResult = {
|
|
90
107
|
ok: boolean;
|
|
91
108
|
error?: string;
|
|
@@ -104,16 +121,128 @@ type TestResult = {
|
|
|
104
121
|
raw?: unknown;
|
|
105
122
|
};
|
|
106
123
|
|
|
107
|
-
|
|
124
|
+
// Usage analytics types.
|
|
125
|
+
type UsageTotals = {
|
|
126
|
+
requests: number;
|
|
127
|
+
errors: number;
|
|
128
|
+
promptTokens: number;
|
|
129
|
+
completionTokens: number;
|
|
130
|
+
totalTokens: number;
|
|
131
|
+
cachedTokens: number;
|
|
132
|
+
reasoningTokens: number;
|
|
133
|
+
avgLatencyMs: number;
|
|
134
|
+
p95LatencyMs: number;
|
|
135
|
+
costEstimate: number;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
type DailyBucket = {
|
|
139
|
+
date: string;
|
|
140
|
+
requests: number;
|
|
141
|
+
totalTokens: number;
|
|
142
|
+
promptTokens: number;
|
|
143
|
+
completionTokens: number;
|
|
144
|
+
errors: number;
|
|
145
|
+
avgLatencyMs: number;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
type PerModelBucket = {
|
|
149
|
+
providerId: string;
|
|
150
|
+
modelId: string;
|
|
151
|
+
requests: number;
|
|
152
|
+
totalTokens: number;
|
|
153
|
+
promptTokens: number;
|
|
154
|
+
completionTokens: number;
|
|
155
|
+
errors: number;
|
|
156
|
+
avgLatencyMs: number;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
type PerKeyBucket = {
|
|
160
|
+
keyEnvVar: string;
|
|
161
|
+
isBackup: boolean;
|
|
162
|
+
requests: number;
|
|
163
|
+
errors: number;
|
|
164
|
+
lastUsed: number | null;
|
|
165
|
+
status: 'active' | 'backup';
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
type UsageQueryResult = {
|
|
169
|
+
totals: UsageTotals;
|
|
170
|
+
daily: DailyBucket[];
|
|
171
|
+
perModel: PerModelBucket[];
|
|
172
|
+
perKey: PerKeyBucket[];
|
|
173
|
+
errors: { code: string; message: string; count: number; lastOccurred: number | null }[];
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
type RecentRecord = {
|
|
177
|
+
ts: number;
|
|
178
|
+
providerId: string;
|
|
179
|
+
modelId: string;
|
|
180
|
+
endpoint: string;
|
|
181
|
+
requestId: string;
|
|
182
|
+
promptTokens: number;
|
|
183
|
+
completionTokens: number;
|
|
184
|
+
totalTokens: number;
|
|
185
|
+
cachedTokens: number;
|
|
186
|
+
reasoningTokens: number;
|
|
187
|
+
latencyMs: number;
|
|
188
|
+
finishReason: string | null;
|
|
189
|
+
error: { code: string; message: string } | null;
|
|
190
|
+
keyEnvVar: string;
|
|
191
|
+
isBackup: boolean;
|
|
192
|
+
cached: boolean;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
type TimeRange = '24h' | '7d' | '30d' | 'custom';
|
|
196
|
+
|
|
197
|
+
// ─── Main component ────────────────────────────────────────────────────
|
|
198
|
+
|
|
199
|
+
export function MiniMaxUsage({ activeTab, setActiveTab }: Props) {
|
|
200
|
+
// Share state between tabs.
|
|
201
|
+
const [view, setView] = useState<'quota' | 'analytics'>('quota');
|
|
202
|
+
const toast = useToast();
|
|
203
|
+
|
|
204
|
+
// Load based on active view.
|
|
205
|
+
return (
|
|
206
|
+
<div className="view-container view-minimax-usage">
|
|
207
|
+
{/* Sub-tab switcher */}
|
|
208
|
+
<div className="minimax-sub-tabs">
|
|
209
|
+
<button
|
|
210
|
+
className={cn('minimax-sub-tab', view === 'quota' && 'is-active')}
|
|
211
|
+
onClick={() => setView('quota')}
|
|
212
|
+
>
|
|
213
|
+
<Coins size={13} /> Token Plan
|
|
214
|
+
</button>
|
|
215
|
+
<button
|
|
216
|
+
className={cn('minimax-sub-tab', view === 'analytics' && 'is-active')}
|
|
217
|
+
onClick={() => setView('analytics')}
|
|
218
|
+
>
|
|
219
|
+
<BarChart2 size={13} /> Usage Analytics
|
|
220
|
+
</button>
|
|
221
|
+
</div>
|
|
222
|
+
|
|
223
|
+
{view === 'quota'
|
|
224
|
+
? <QuotaView activeTab={activeTab} setActiveTab={setActiveTab} />
|
|
225
|
+
: <AnalyticsView toast={toast} />
|
|
226
|
+
}
|
|
227
|
+
</div>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ─── Token Plan view (existing functionality) ──────────────────────────
|
|
232
|
+
|
|
233
|
+
function QuotaView({ activeTab, setActiveTab }: Pick<Props, 'activeTab' | 'setActiveTab'>) {
|
|
108
234
|
const toast = useToast();
|
|
109
235
|
const [status, setStatus] = useState<Status | null>(null);
|
|
110
236
|
const [remains, setRemains] = useState<RemainsSnapshot | null>(null);
|
|
237
|
+
const [onboarding, setOnboarding] = useState<OnboardingState | null>(null);
|
|
111
238
|
const [loading, setLoading] = useState(true);
|
|
112
239
|
const [refreshing, setRefreshing] = useState(false);
|
|
113
240
|
const [error, setError] = useState<string | null>(null);
|
|
114
241
|
const [testResult, setTestResult] = useState<TestResult | null>(null);
|
|
115
242
|
const [testing, setTesting] = useState(false);
|
|
116
|
-
|
|
243
|
+
const [wizardStep, setWizardStep] = useState(0);
|
|
244
|
+
const [wizardVerifying, setWizardVerifying] = useState(false);
|
|
245
|
+
const [wizardVerifyResult, setWizardVerifyResult] = useState<TestResult | null>(null);
|
|
117
246
|
const [keyDraft, setKeyDraft] = useState('');
|
|
118
247
|
const [showKey, setShowKey] = useState(false);
|
|
119
248
|
const [savingKey, setSavingKey] = useState(false);
|
|
@@ -122,13 +251,15 @@ export function MiniMaxUsage({ snapshot, settings, setActiveTab, refreshSnapshot
|
|
|
122
251
|
setLoading(true);
|
|
123
252
|
setError(null);
|
|
124
253
|
try {
|
|
125
|
-
const [s, r] = await Promise.all([
|
|
254
|
+
const [s, r, o] = await Promise.all([
|
|
126
255
|
api.get<Status>('/minimax/status'),
|
|
127
256
|
api.get<RemainsSnapshot>('/minimax/remains'),
|
|
257
|
+
api.get<OnboardingState>('/minimax/onboarding'),
|
|
128
258
|
]);
|
|
129
259
|
setStatus(s);
|
|
130
260
|
setRemains(r);
|
|
131
|
-
|
|
261
|
+
setOnboarding(o);
|
|
262
|
+
if (s.configured) setWizardStep(4);
|
|
132
263
|
} catch (err) {
|
|
133
264
|
setError((err as Error).message || 'Failed to load MiniMax data');
|
|
134
265
|
} finally {
|
|
@@ -138,35 +269,56 @@ export function MiniMaxUsage({ snapshot, settings, setActiveTab, refreshSnapshot
|
|
|
138
269
|
|
|
139
270
|
useEffect(() => { load(); }, [load]);
|
|
140
271
|
|
|
272
|
+
const dismissWizard = useCallback(async () => {
|
|
273
|
+
try {
|
|
274
|
+
await api.post('/minimax/onboarding', { dismissedAt: Date.now() });
|
|
275
|
+
setOnboarding((o) => o ? { ...o, dismissedAt: Date.now() } : o);
|
|
276
|
+
} catch { /* best-effort */ }
|
|
277
|
+
}, []);
|
|
278
|
+
|
|
279
|
+
const verifyKeyBeforeSave = useCallback(async () => {
|
|
280
|
+
if (!keyDraft.trim()) { toast.error('Paste a Subscription Key first.'); return; }
|
|
281
|
+
setWizardVerifying(true);
|
|
282
|
+
setWizardVerifyResult(null);
|
|
283
|
+
try {
|
|
284
|
+
const r = await api.post<TestResult>('/minimax/test', {
|
|
285
|
+
prompt: 'Reply with a single word: pong',
|
|
286
|
+
model: 'MiniMax-M3',
|
|
287
|
+
maxTokens: 16,
|
|
288
|
+
});
|
|
289
|
+
setWizardVerifyResult(r);
|
|
290
|
+
if (r.ok) {
|
|
291
|
+
setWizardStep(3);
|
|
292
|
+
toast.success('Key works. Saving…');
|
|
293
|
+
try {
|
|
294
|
+
await api.post('/minimax/onboarding/save-key', { key: keyDraft.trim(), groupId: 'default' });
|
|
295
|
+
clearRemainsCacheClient();
|
|
296
|
+
toast.success('Subscription Key saved.');
|
|
297
|
+
} catch (err) { toast.error(`Save failed: ${(err as Error).message}`); }
|
|
298
|
+
void load();
|
|
299
|
+
} else {
|
|
300
|
+
toast.error(`Verification failed: ${r.message ?? r.error ?? 'unknown'}`);
|
|
301
|
+
}
|
|
302
|
+
} catch (err) { toast.error(`Test request failed: ${(err as Error).message}`); }
|
|
303
|
+
finally { setWizardVerifying(false); }
|
|
304
|
+
}, [keyDraft, toast, load]);
|
|
305
|
+
|
|
141
306
|
const saveKey = useCallback(async () => {
|
|
142
|
-
if (!keyDraft.trim()) {
|
|
143
|
-
toast.error('Paste a Subscription Key first.');
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
307
|
+
if (!keyDraft.trim()) { toast.error('Paste a Subscription Key first.'); return; }
|
|
146
308
|
setSavingKey(true);
|
|
147
309
|
try {
|
|
148
|
-
const r = await api.
|
|
149
|
-
minimax:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
// Wipe the in-memory draft + clear the remains cache so the
|
|
155
|
-
// next load picks up the new key.
|
|
310
|
+
const r = await api.post<{ ok: boolean; path?: string; apiKeyHint?: string; error?: string; message?: string }>(
|
|
311
|
+
'/minimax/onboarding/save-key', { key: keyDraft.trim(), groupId: 'default' },
|
|
312
|
+
);
|
|
313
|
+
if (!r.ok) { toast.error(`Save failed: ${r.message ?? r.error ?? 'unknown'}`); return; }
|
|
156
314
|
setKeyDraft('');
|
|
157
315
|
clearRemainsCacheClient();
|
|
158
|
-
toast.success('Subscription Key saved.
|
|
316
|
+
toast.success('Subscription Key saved. Loading quota…');
|
|
159
317
|
void load();
|
|
160
|
-
} catch (err) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
setSavingKey(false);
|
|
164
|
-
}
|
|
165
|
-
}, [keyDraft, settings, toast, load]);
|
|
318
|
+
} catch (err) { toast.error(`Save failed: ${(err as Error).message}`); }
|
|
319
|
+
finally { setSavingKey(false); }
|
|
320
|
+
}, [keyDraft, toast, load]);
|
|
166
321
|
|
|
167
|
-
// Clears the on-disk + in-memory cache via the dashboard's
|
|
168
|
-
// /api/minimax/cache DELETE endpoint. Wrapped in a helper so the
|
|
169
|
-
// success path can await the round-trip.
|
|
170
322
|
const clearRemainsCacheClient = useCallback(async () => {
|
|
171
323
|
try { await api.del('/minimax/cache'); } catch { /* best-effort */ }
|
|
172
324
|
}, []);
|
|
@@ -178,11 +330,8 @@ export function MiniMaxUsage({ snapshot, settings, setActiveTab, refreshSnapshot
|
|
|
178
330
|
await api.post('/minimax/remains/refresh');
|
|
179
331
|
await load();
|
|
180
332
|
toast.success('Refreshed');
|
|
181
|
-
} catch (err) {
|
|
182
|
-
|
|
183
|
-
} finally {
|
|
184
|
-
setRefreshing(false);
|
|
185
|
-
}
|
|
333
|
+
} catch (err) { toast.error(`Refresh failed: ${(err as Error).message}`); }
|
|
334
|
+
finally { setRefreshing(false); }
|
|
186
335
|
}, [load, toast]);
|
|
187
336
|
|
|
188
337
|
const sendTest = useCallback(async () => {
|
|
@@ -195,43 +344,41 @@ export function MiniMaxUsage({ snapshot, settings, setActiveTab, refreshSnapshot
|
|
|
195
344
|
maxTokens: 16,
|
|
196
345
|
});
|
|
197
346
|
setTestResult(r);
|
|
198
|
-
if (r.ok) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
} catch (err) {
|
|
204
|
-
toast.error(`Test request failed: ${(err as Error).message}`);
|
|
205
|
-
} finally {
|
|
206
|
-
setTesting(false);
|
|
207
|
-
}
|
|
347
|
+
if (r.ok) toast.success(`Test ok — used ${r.usage?.total_tokens ?? '?'} tokens`);
|
|
348
|
+
else toast.error(`Test failed: ${r.message ?? r.error ?? 'unknown'}`);
|
|
349
|
+
} catch (err) { toast.error(`Test request failed: ${(err as Error).message}`); }
|
|
350
|
+
finally { setTesting(false); }
|
|
208
351
|
}, [toast]);
|
|
209
352
|
|
|
210
353
|
if (loading && !status) {
|
|
211
|
-
return
|
|
212
|
-
<div className="view-container">
|
|
213
|
-
<Spinner /> Loading MiniMax data…
|
|
214
|
-
</div>
|
|
215
|
-
);
|
|
354
|
+
return <div className="view-container"><Spinner /> Loading MiniMax data…</div>;
|
|
216
355
|
}
|
|
217
|
-
|
|
218
356
|
if (!status) {
|
|
219
357
|
return (
|
|
220
358
|
<div className="view-container">
|
|
221
359
|
<div className="error-card">
|
|
222
360
|
<AlertTriangle size={20} />
|
|
223
|
-
<div>
|
|
224
|
-
<strong>Couldn't load MiniMax status</strong>
|
|
225
|
-
<pre>{error ?? 'unknown error'}</pre>
|
|
226
|
-
</div>
|
|
361
|
+
<div><strong>Couldn't load MiniMax status</strong><pre>{error ?? 'unknown error'}</pre></div>
|
|
227
362
|
</div>
|
|
228
363
|
</div>
|
|
229
364
|
);
|
|
230
365
|
}
|
|
231
366
|
|
|
367
|
+
const showWizard = !status.configured && (onboarding?.dismissedAt == null) && wizardStep < 4;
|
|
368
|
+
if (showWizard) {
|
|
369
|
+
return <OnboardingWizard
|
|
370
|
+
step={wizardStep} setStep={setWizardStep}
|
|
371
|
+
keyDraft={keyDraft} setKeyDraft={setKeyDraft}
|
|
372
|
+
showKey={showKey} setShowKey={setShowKey}
|
|
373
|
+
verifying={wizardVerifying} verifyResult={wizardVerifyResult}
|
|
374
|
+
onVerify={verifyKeyBeforeSave}
|
|
375
|
+
onSkip={async () => { await dismissWizard(); toast.success("Skipped."); }}
|
|
376
|
+
onManualKeySave={saveKey} savingKey={savingKey} status={status}
|
|
377
|
+
/>;
|
|
378
|
+
}
|
|
379
|
+
|
|
232
380
|
return (
|
|
233
|
-
|
|
234
|
-
{/* ── Header ─────────────────────────────────────────────────── */}
|
|
381
|
+
<>
|
|
235
382
|
<header className="view-header">
|
|
236
383
|
<div className="view-header-titles">
|
|
237
384
|
<h1 className="view-title">
|
|
@@ -244,145 +391,43 @@ export function MiniMaxUsage({ snapshot, settings, setActiveTab, refreshSnapshot
|
|
|
244
391
|
</p>
|
|
245
392
|
</div>
|
|
246
393
|
<div className="view-header-actions">
|
|
247
|
-
<Button
|
|
248
|
-
variant="secondary"
|
|
249
|
-
size="sm"
|
|
250
|
-
onClick={() => setActiveTab('settings')}
|
|
251
|
-
title="Configure your Subscription Key"
|
|
252
|
-
>
|
|
394
|
+
<Button variant="secondary" size="sm" onClick={() => setActiveTab('settings')} title="Configure your Subscription Key">
|
|
253
395
|
<KeyRound size={14} /> {status.configured ? `Key ${status.apiKeyHint}` : 'Add key'}
|
|
254
396
|
</Button>
|
|
255
397
|
<Button variant="secondary" size="sm" onClick={refresh} disabled={refreshing}>
|
|
256
|
-
{refreshing ? <Loader2 size={14} className="spin" /> : <RefreshCw size={14} />}
|
|
257
|
-
Refresh
|
|
398
|
+
{refreshing ? <Loader2 size={14} className="spin" /> : <RefreshCw size={14} />} Refresh
|
|
258
399
|
</Button>
|
|
259
400
|
</div>
|
|
260
401
|
</header>
|
|
261
402
|
|
|
262
|
-
{/* ── Status banners ─────────────────────────────────────────── */}
|
|
263
|
-
{!status.enabled && (
|
|
264
|
-
<div className="banner banner-warn">
|
|
265
|
-
<AlertTriangle size={16} />
|
|
266
|
-
<span>
|
|
267
|
-
MiniMax integration is <strong>disabled</strong> in settings. Enable it in Settings → MiniMax.
|
|
268
|
-
</span>
|
|
269
|
-
</div>
|
|
270
|
-
)}
|
|
271
|
-
|
|
272
|
-
{/* ── Subscription Key config (inline) ──────────────────── */}
|
|
273
|
-
{status.enabled && (
|
|
274
|
-
<Card id="minimax-key">
|
|
275
|
-
<CardTitle>
|
|
276
|
-
<KeyRound size={14} /> Subscription Key
|
|
277
|
-
</CardTitle>
|
|
278
|
-
<CardMeta>
|
|
279
|
-
Get it from{' '}
|
|
280
|
-
<a
|
|
281
|
-
href="https://platform.minimax.io/user-center/payment/token-plan"
|
|
282
|
-
target="_blank"
|
|
283
|
-
rel="noreferrer"
|
|
284
|
-
className="minimax-link"
|
|
285
|
-
>
|
|
286
|
-
platform.minimax.io/user-center/payment/token-plan
|
|
287
|
-
</a>
|
|
288
|
-
. Stored locally in <code>~/.config/bizar/settings.json</code>;
|
|
289
|
-
never sent to any other host. Status:{' '}
|
|
290
|
-
{status.configured ? (
|
|
291
|
-
<strong className="is-ok">configured ({status.apiKeyHint})</strong>
|
|
292
|
-
) : (
|
|
293
|
-
<strong className="is-warn">not configured</strong>
|
|
294
|
-
)}
|
|
295
|
-
.
|
|
296
|
-
</CardMeta>
|
|
297
|
-
<div className="minimax-key-row">
|
|
298
|
-
<div className="minimax-key-input-wrap">
|
|
299
|
-
<KeyRound size={12} className="minimax-key-icon" />
|
|
300
|
-
<input
|
|
301
|
-
type={showKey ? 'text' : 'password'}
|
|
302
|
-
value={keyDraft}
|
|
303
|
-
onChange={(e) => setKeyDraft(e.target.value)}
|
|
304
|
-
placeholder={status.configured ? '•••• paste a new key to replace' : 'eyJhbGciOi...'}
|
|
305
|
-
spellCheck={false}
|
|
306
|
-
autoComplete="off"
|
|
307
|
-
className="minimax-key-input"
|
|
308
|
-
/>
|
|
309
|
-
<button
|
|
310
|
-
type="button"
|
|
311
|
-
onClick={() => setShowKey((v) => !v)}
|
|
312
|
-
className="minimax-key-toggle"
|
|
313
|
-
aria-label={showKey ? 'Hide key' : 'Show key'}
|
|
314
|
-
title={showKey ? 'Hide key' : 'Show key'}
|
|
315
|
-
>
|
|
316
|
-
{showKey ? <EyeOff size={13} /> : <Eye size={13} />}
|
|
317
|
-
</button>
|
|
318
|
-
</div>
|
|
319
|
-
<Button onClick={saveKey} disabled={savingKey || !keyDraft.trim()} size="sm">
|
|
320
|
-
{savingKey ? <Loader2 size={14} className="spin" /> : <Save size={14} />}
|
|
321
|
-
Save key
|
|
322
|
-
</Button>
|
|
323
|
-
</div>
|
|
324
|
-
</Card>
|
|
325
|
-
)}
|
|
326
|
-
|
|
327
403
|
{remains && !remains.ok && (
|
|
328
404
|
<div className="banner banner-err">
|
|
329
405
|
<AlertTriangle size={16} />
|
|
330
|
-
<span>
|
|
331
|
-
<strong>Couldn't load quota</strong>: {remains.message ?? remains.error ?? 'unknown error'}
|
|
332
|
-
</span>
|
|
406
|
+
<span><strong>Couldn't load quota</strong>: {remains.message ?? remains.error ?? 'unknown error'}</span>
|
|
333
407
|
</div>
|
|
334
408
|
)}
|
|
335
409
|
|
|
336
|
-
{/* ── Summary stats ─────────────────────────────────────────── */}
|
|
337
410
|
{remains?.ok && remains.models && (
|
|
338
411
|
<>
|
|
339
412
|
<div className="minimax-stats-row">
|
|
340
|
-
<Stat
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
/>
|
|
345
|
-
<Stat
|
|
346
|
-
label="Last fetched"
|
|
347
|
-
value={remains.fetchedAt ? relativeTime(remains.fetchedAt) : '—'}
|
|
348
|
-
hint="Refreshed on demand + every 60s"
|
|
349
|
-
/>
|
|
350
|
-
<Stat
|
|
351
|
-
label="Group"
|
|
352
|
-
value={remains.groupId ?? '—'}
|
|
353
|
-
hint="Usually 'default' for an individual team"
|
|
354
|
-
/>
|
|
355
|
-
<Stat
|
|
356
|
-
label="API key"
|
|
357
|
-
value={remains.apiKeyHint ?? '—'}
|
|
358
|
-
hint="Masked; the real key never leaves settings.json"
|
|
359
|
-
/>
|
|
413
|
+
<Stat label="Models tracked" value={String(remains.models.length)} hint="Distinct model quotas returned by the API" />
|
|
414
|
+
<Stat label="Last fetched" value={remains.fetchedAt ? relativeTime(remains.fetchedAt) : '—'} hint="Refreshed on demand + every 60s" />
|
|
415
|
+
<Stat label="Group" value={remains.groupId ?? '—'} hint="Usually 'default' for an individual team" />
|
|
416
|
+
<Stat label="API key" value={remains.apiKeyHint ?? '—'} hint="Masked; the real key never leaves auth.json" />
|
|
360
417
|
</div>
|
|
361
|
-
|
|
362
|
-
{/* ── Per-model quota cards ──────────────────────────────── */}
|
|
363
418
|
<div className="minimax-models-grid">
|
|
364
|
-
{remains.models.map((m) =>
|
|
365
|
-
<ModelQuotaCard key={m.model_name} model={m} />
|
|
366
|
-
))}
|
|
419
|
+
{remains.models.map((m) => <ModelQuotaCard key={m.model_name} model={m} />)}
|
|
367
420
|
</div>
|
|
368
421
|
</>
|
|
369
422
|
)}
|
|
370
423
|
|
|
371
|
-
{/* ── Test prompt card ─────────────────────────────────────── */}
|
|
372
424
|
{status.configured && (
|
|
373
425
|
<Card id="minimax-test">
|
|
374
|
-
<CardTitle>
|
|
375
|
-
|
|
376
|
-
</CardTitle>
|
|
377
|
-
<CardMeta>
|
|
378
|
-
Sends a one-shot chat completion to{' '}
|
|
379
|
-
<code>{status.chatBaseUrl}/chat/completions</code> to verify the
|
|
380
|
-
key works and surface live token usage.
|
|
381
|
-
</CardMeta>
|
|
426
|
+
<CardTitle><Send size={14} /> Test the API key</CardTitle>
|
|
427
|
+
<CardMeta>One-shot chat completion to <code>{status.chatBaseUrl}/chat/completions</code>.</CardMeta>
|
|
382
428
|
<div className="minimax-test-actions">
|
|
383
429
|
<Button onClick={sendTest} disabled={testing} variant="primary" size="sm">
|
|
384
|
-
{testing ? <Loader2 size={14} className="spin" /> : <Send size={14} />}
|
|
385
|
-
Send test prompt
|
|
430
|
+
{testing ? <Loader2 size={14} className="spin" /> : <Send size={14} />} Send test prompt
|
|
386
431
|
</Button>
|
|
387
432
|
<code className="minimax-test-prompt">"Reply with a single word: pong"</code>
|
|
388
433
|
</div>
|
|
@@ -397,14 +442,11 @@ export function MiniMaxUsage({ snapshot, settings, setActiveTab, refreshSnapshot
|
|
|
397
442
|
<strong>finish:</strong> {testResult.finishReason ?? '—'}
|
|
398
443
|
</div>
|
|
399
444
|
{testResult.content && (
|
|
400
|
-
<div className="minimax-test-content">
|
|
401
|
-
<code>{testResult.content}</code>
|
|
402
|
-
</div>
|
|
445
|
+
<div className="minimax-test-content"><code>{testResult.content}</code></div>
|
|
403
446
|
)}
|
|
404
447
|
{testResult.usage && (
|
|
405
448
|
<div className="minimax-test-usage">
|
|
406
|
-
<strong>usage:</strong> total{' '}
|
|
407
|
-
<code>{testResult.usage.total_tokens ?? '?'}</code> · prompt{' '}
|
|
449
|
+
<strong>usage:</strong> total <code>{testResult.usage.total_tokens ?? '?'}</code> · prompt{' '}
|
|
408
450
|
<code>{testResult.usage.prompt_tokens ?? '?'}</code> · completion{' '}
|
|
409
451
|
<code>{testResult.usage.completion_tokens ?? '?'}</code>
|
|
410
452
|
{testResult.usage.prompt_tokens_details?.cached_tokens != null && (
|
|
@@ -421,11 +463,268 @@ export function MiniMaxUsage({ snapshot, settings, setActiveTab, refreshSnapshot
|
|
|
421
463
|
)}
|
|
422
464
|
</Card>
|
|
423
465
|
)}
|
|
466
|
+
</>
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// ─── Analytics view ────────────────────────────────────────────────────
|
|
471
|
+
|
|
472
|
+
function AnalyticsView({ toast }: { toast: ReturnType<typeof useToast> }) {
|
|
473
|
+
const [range, setRange] = useState<TimeRange>('24h');
|
|
474
|
+
const [customFrom, setCustomFrom] = useState('');
|
|
475
|
+
const [customTo, setCustomTo] = useState('');
|
|
476
|
+
const [loading, setLoading] = useState(true);
|
|
477
|
+
const [usage, setUsage] = useState<UsageQueryResult | null>(null);
|
|
478
|
+
const [recent, setRecent] = useState<RecentRecord[]>([]);
|
|
479
|
+
const [sortKey, setSortKey] = useState('requests');
|
|
480
|
+
const [sortDir, setSortDir] = useState<'asc' | 'desc'>('desc');
|
|
481
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
482
|
+
|
|
483
|
+
const load = useCallback(async (r: TimeRange, fromMs?: number, toMs?: number) => {
|
|
484
|
+
setLoading(true);
|
|
485
|
+
try {
|
|
486
|
+
const params = new URLSearchParams({ range: r });
|
|
487
|
+
if (r === 'custom' && fromMs && toMs) {
|
|
488
|
+
params.set('from', String(fromMs));
|
|
489
|
+
params.set('to', String(toMs));
|
|
490
|
+
}
|
|
491
|
+
const [u, rec] = await Promise.all([
|
|
492
|
+
api.get<UsageQueryResult>(`/usage?${params.toString()}`),
|
|
493
|
+
api.get<{ records: RecentRecord[]; total: number; returned: number }>('/usage/recent?limit=20'),
|
|
494
|
+
]);
|
|
495
|
+
setUsage(u);
|
|
496
|
+
setRecent(rec.records);
|
|
497
|
+
} catch (err) {
|
|
498
|
+
toast.error(`Failed to load usage data: ${(err as Error).message}`);
|
|
499
|
+
} finally {
|
|
500
|
+
setLoading(false);
|
|
501
|
+
}
|
|
502
|
+
}, [toast]);
|
|
503
|
+
|
|
504
|
+
useEffect(() => {
|
|
505
|
+
if (range === 'custom') {
|
|
506
|
+
const from = customFrom ? new Date(customFrom).getTime() : Date.now() - 7 * 86_400_000;
|
|
507
|
+
const to = customTo ? new Date(customTo).getTime() : Date.now();
|
|
508
|
+
void load('custom', from, to);
|
|
509
|
+
} else {
|
|
510
|
+
void load(range);
|
|
511
|
+
}
|
|
512
|
+
}, [range, load]);
|
|
513
|
+
|
|
514
|
+
const handleSort = useCallback((key: string) => {
|
|
515
|
+
if (sortKey === key) setSortDir(d => d === 'asc' ? 'desc' : 'asc');
|
|
516
|
+
else { setSortKey(key); setSortDir('desc'); }
|
|
517
|
+
}, [sortKey]);
|
|
518
|
+
|
|
519
|
+
const sortedModels = useMemo(() => {
|
|
520
|
+
if (!usage?.perModel) return [];
|
|
521
|
+
return [...usage.perModel].sort((a, b) => {
|
|
522
|
+
const av = (a as Record<string, unknown>)[sortKey] ?? 0;
|
|
523
|
+
const bv = (b as Record<string, unknown>)[sortKey] ?? 0;
|
|
524
|
+
const cmp = typeof av === 'number' && typeof bv === 'number' ? av - bv : String(av).localeCompare(String(bv));
|
|
525
|
+
return sortDir === 'asc' ? cmp : -cmp;
|
|
526
|
+
});
|
|
527
|
+
}, [usage?.perModel, sortKey, sortDir]);
|
|
528
|
+
|
|
529
|
+
const chartSeries = useMemo(() => {
|
|
530
|
+
if (!usage?.daily) return { labels: [] as string[], requests: [] as number[], tokens: [] as number[] };
|
|
531
|
+
return {
|
|
532
|
+
labels: usage.daily.map(d => d.date.slice(5)), // "MM-DD"
|
|
533
|
+
requests: usage.daily.map(d => d.requests),
|
|
534
|
+
tokens: usage.daily.map(d => d.totalTokens),
|
|
535
|
+
};
|
|
536
|
+
}, [usage?.daily]);
|
|
537
|
+
|
|
538
|
+
const refresh = useCallback(async () => {
|
|
539
|
+
setRefreshing(true);
|
|
540
|
+
await load(range === 'custom' ? 'custom' : range,
|
|
541
|
+
range === 'custom' && customFrom ? new Date(customFrom).getTime() : undefined,
|
|
542
|
+
range === 'custom' && customTo ? new Date(customTo).getTime() : undefined);
|
|
543
|
+
setRefreshing(false);
|
|
544
|
+
}, [load, range, customFrom, customTo]);
|
|
545
|
+
|
|
546
|
+
if (loading && !usage) {
|
|
547
|
+
return <div className="view-container"><Spinner /> Loading usage data…</div>;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const t = usage?.totals;
|
|
551
|
+
const errors = usage?.errors ?? [];
|
|
552
|
+
const perKey = usage?.perKey ?? [];
|
|
553
|
+
|
|
554
|
+
return (
|
|
555
|
+
<>
|
|
556
|
+
{/* Header */}
|
|
557
|
+
<header className="view-header">
|
|
558
|
+
<div className="view-header-titles">
|
|
559
|
+
<h1 className="view-title">
|
|
560
|
+
<BarChart2 size={20} style={{ verticalAlign: 'text-bottom', marginRight: 6 }} />
|
|
561
|
+
Usage Analytics
|
|
562
|
+
</h1>
|
|
563
|
+
<p className="view-subtitle">
|
|
564
|
+
Aggregated from <code>~/.local/share/bizar/usage.jsonl</code> —
|
|
565
|
+
every chatCompletion and fetchRemains call.
|
|
566
|
+
</p>
|
|
567
|
+
</div>
|
|
568
|
+
<div className="view-header-actions">
|
|
569
|
+
<Button variant="secondary" size="sm" onClick={refresh} disabled={refreshing}>
|
|
570
|
+
{refreshing ? <Loader2 size={14} className="spin" /> : <RefreshCw size={14} />} Refresh
|
|
571
|
+
</Button>
|
|
572
|
+
</div>
|
|
573
|
+
</header>
|
|
574
|
+
|
|
575
|
+
{/* Time range selector */}
|
|
576
|
+
<div className="usage-time-range">
|
|
577
|
+
{(['24h', '7d', '30d', 'custom'] as TimeRange[]).map(r => (
|
|
578
|
+
<button
|
|
579
|
+
key={r}
|
|
580
|
+
className={cn('usage-range-chip', range === r && 'is-active')}
|
|
581
|
+
onClick={() => setRange(r)}
|
|
582
|
+
>
|
|
583
|
+
{r === 'custom' ? 'Custom' : r.toUpperCase()}
|
|
584
|
+
</button>
|
|
585
|
+
))}
|
|
586
|
+
{range === 'custom' && (
|
|
587
|
+
<div className="usage-custom-dates">
|
|
588
|
+
<input
|
|
589
|
+
type="date"
|
|
590
|
+
className="usage-date-input"
|
|
591
|
+
value={customFrom}
|
|
592
|
+
onChange={e => setCustomFrom(e.target.value)}
|
|
593
|
+
/>
|
|
594
|
+
<span style={{ color: 'var(--text-muted)', fontSize: 12 }}>to</span>
|
|
595
|
+
<input
|
|
596
|
+
type="date"
|
|
597
|
+
className="usage-date-input"
|
|
598
|
+
value={customTo}
|
|
599
|
+
onChange={e => setCustomTo(e.target.value)}
|
|
600
|
+
/>
|
|
601
|
+
</div>
|
|
602
|
+
)}
|
|
603
|
+
</div>
|
|
604
|
+
|
|
605
|
+
{/* KPI row */}
|
|
606
|
+
<div className="usage-kpi-row">
|
|
607
|
+
<KpiCard
|
|
608
|
+
label="Total Requests"
|
|
609
|
+
value={t?.requests.toLocaleString() ?? '—'}
|
|
610
|
+
sub={t ? `${t.errors} errors` : undefined}
|
|
611
|
+
tone={t && t.errors > t.requests * 0.1 ? 'warn' : undefined}
|
|
612
|
+
/>
|
|
613
|
+
<KpiCard
|
|
614
|
+
label="Total Tokens"
|
|
615
|
+
value={t ? (t.totalTokens >= 1000 ? `${Math.round(t.totalTokens / 1000)}k` : String(t.totalTokens)) : '—'}
|
|
616
|
+
sub={t ? `${t.promptTokens.toLocaleString()} prompt · ${t.completionTokens.toLocaleString()} completion` : undefined}
|
|
617
|
+
/>
|
|
618
|
+
<KpiCard
|
|
619
|
+
label="Errors"
|
|
620
|
+
value={String(t?.errors ?? '—')}
|
|
621
|
+
sub={errors.length > 0 ? `${errors[0].code}: ${errors[0].count}` : undefined}
|
|
622
|
+
tone={t && t.errors > 0 ? 'err' : undefined}
|
|
623
|
+
/>
|
|
624
|
+
<KpiCard
|
|
625
|
+
label="Avg Latency"
|
|
626
|
+
value={t?.avgLatencyMs != null ? `${t.avgLatencyMs}ms` : '—'}
|
|
627
|
+
sub={t?.p95LatencyMs != null ? `p95 ${t.p95LatencyMs}ms` : undefined}
|
|
628
|
+
/>
|
|
629
|
+
<KpiCard
|
|
630
|
+
label="Est. Cost"
|
|
631
|
+
value={t?.costEstimate != null && t.costEstimate > 0 ? `$${t.costEstimate.toFixed(4)}` : '—'}
|
|
632
|
+
sub="approximate USD"
|
|
633
|
+
tone={undefined}
|
|
634
|
+
/>
|
|
635
|
+
</div>
|
|
636
|
+
|
|
637
|
+
{/* Chart */}
|
|
638
|
+
<Card className="usage-chart-card">
|
|
639
|
+
<div className="usage-chart-wrap">
|
|
640
|
+
<UsageChart series={chartSeries} height={280} />
|
|
641
|
+
</div>
|
|
642
|
+
<div className="usage-legend">
|
|
643
|
+
<div className="usage-legend-item">
|
|
644
|
+
<div className="usage-legend-bar" style={{ background: 'var(--accent)' }} />
|
|
645
|
+
<span>Requests (bar)</span>
|
|
646
|
+
</div>
|
|
647
|
+
<div className="usage-legend-item">
|
|
648
|
+
<div className="usage-legend-line" style={{ background: 'var(--warning, #d29922)' }} />
|
|
649
|
+
<span>Tokens (line)</span>
|
|
650
|
+
</div>
|
|
651
|
+
</div>
|
|
652
|
+
</Card>
|
|
653
|
+
|
|
654
|
+
{/* Per-model table */}
|
|
655
|
+
<Card>
|
|
656
|
+
<CardTitle>Per-model breakdown</CardTitle>
|
|
657
|
+
<UsageTable
|
|
658
|
+
rows={sortedModels as PerModelRow[]}
|
|
659
|
+
sortKey={sortKey}
|
|
660
|
+
sortDir={sortDir}
|
|
661
|
+
onSort={handleSort}
|
|
662
|
+
/>
|
|
663
|
+
</Card>
|
|
664
|
+
|
|
665
|
+
{/* Per-key status */}
|
|
666
|
+
{perKey.length > 0 && (
|
|
667
|
+
<Card>
|
|
668
|
+
<CardTitle>API Keys</CardTitle>
|
|
669
|
+
<div className="usage-key-row">
|
|
670
|
+
{perKey.map(k => (
|
|
671
|
+
<span
|
|
672
|
+
key={k.keyEnvVar}
|
|
673
|
+
className={cn('usage-key-badge', k.isBackup ? 'is-backup' : 'is-active')}
|
|
674
|
+
>
|
|
675
|
+
<span className="usage-key-dot" />
|
|
676
|
+
{k.keyEnvVar}
|
|
677
|
+
{k.isBackup ? ' (backup)' : ' (active)'}
|
|
678
|
+
{' · '}
|
|
679
|
+
{k.requests} req
|
|
680
|
+
</span>
|
|
681
|
+
))}
|
|
682
|
+
</div>
|
|
683
|
+
</Card>
|
|
684
|
+
)}
|
|
685
|
+
|
|
686
|
+
{/* Recent activity */}
|
|
687
|
+
{recent.length > 0 && (
|
|
688
|
+
<Card>
|
|
689
|
+
<CardTitle>Recent activity</CardTitle>
|
|
690
|
+
<div className="usage-recent-list">
|
|
691
|
+
{recent.map((r, i) => (
|
|
692
|
+
<div key={`${r.requestId}-${i}`} className={cn('usage-recent-item', r.error && 'is-err')}>
|
|
693
|
+
<span className="usage-recent-time">
|
|
694
|
+
{new Date(r.ts).toLocaleTimeString()}
|
|
695
|
+
</span>
|
|
696
|
+
<span className="usage-recent-model">
|
|
697
|
+
<code>{r.modelId}</code>
|
|
698
|
+
</span>
|
|
699
|
+
<span className="usage-recent-tokens">
|
|
700
|
+
{r.totalTokens.toLocaleString()} tok
|
|
701
|
+
</span>
|
|
702
|
+
<span className="usage-recent-latency">
|
|
703
|
+
{r.latencyMs}ms
|
|
704
|
+
</span>
|
|
705
|
+
<span className="usage-recent-endpoint">{r.endpoint}</span>
|
|
706
|
+
</div>
|
|
707
|
+
))}
|
|
708
|
+
</div>
|
|
709
|
+
</Card>
|
|
710
|
+
)}
|
|
711
|
+
</>
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// ─── Kpi card ──────────────────────────────────────────────────────────
|
|
716
|
+
|
|
717
|
+
function KpiCard({ label, value, sub, tone }: { label: string; value: string; sub?: string; tone?: 'warn' | 'err' | 'ok' }) {
|
|
718
|
+
return (
|
|
719
|
+
<div className="usage-kpi-card">
|
|
720
|
+
<div className="usage-kpi-label">{label}</div>
|
|
721
|
+
<div className={cn('usage-kpi-value', tone && `is-${tone}`)}>{value}</div>
|
|
722
|
+
{sub && <div className="usage-kpi-sub">{sub}</div>}
|
|
424
723
|
</div>
|
|
425
724
|
);
|
|
426
725
|
}
|
|
427
726
|
|
|
428
|
-
// ─── Sub-components
|
|
727
|
+
// ─── Sub-components (quota view) ───────────────────────────────────────
|
|
429
728
|
|
|
430
729
|
function Stat({ label, value, hint }: { label: string; value: string; hint?: string }) {
|
|
431
730
|
return (
|
|
@@ -446,85 +745,46 @@ function ModelQuotaCard({ model }: { model: RemainsModel }) {
|
|
|
446
745
|
<Card id={`minimax-model-${model.model_name}`} className="minimax-model-card">
|
|
447
746
|
<div className="minimax-model-head">
|
|
448
747
|
<div className="minimax-model-name">{model.model_name}</div>
|
|
449
|
-
<div
|
|
450
|
-
className={cn(
|
|
451
|
-
'minimax-model-status',
|
|
452
|
-
fivePct < 25 || weekPct < 25 ? 'is-warn' : 'is-ok'
|
|
453
|
-
)}
|
|
454
|
-
>
|
|
748
|
+
<div className={cn('minimax-model-status', fivePct < 25 || weekPct < 25 ? 'is-warn' : 'is-ok')}>
|
|
455
749
|
{model.current_interval_status === 1 ? 'active' : 'idle'} ·{' '}
|
|
456
750
|
{model.current_weekly_status === 1 ? 'week active' : 'week idle'}
|
|
457
751
|
</div>
|
|
458
752
|
</div>
|
|
459
|
-
|
|
460
753
|
<div className="minimax-quota-rows">
|
|
461
754
|
<QuotaBar
|
|
462
|
-
icon={<Activity size={12} />}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
used={model.current_interval_usage_count ?? 0}
|
|
467
|
-
total={model.current_interval_total_count ?? 0}
|
|
468
|
-
resetIn={model.intervalResetInHuman}
|
|
469
|
-
resetISO={model.endTimeISO}
|
|
755
|
+
icon={<Activity size={12} />} label="5-hour rolling"
|
|
756
|
+
remainingPct={fivePct} consumedPct={fiveConsumed}
|
|
757
|
+
used={model.current_interval_usage_count ?? 0} total={model.current_interval_total_count ?? 0}
|
|
758
|
+
resetIn={model.intervalResetInHuman} resetISO={model.endTimeISO}
|
|
470
759
|
/>
|
|
471
760
|
<QuotaBar
|
|
472
|
-
icon={<Calendar size={12} />}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
used={model.current_weekly_usage_count ?? 0}
|
|
477
|
-
total={model.current_weekly_total_count ?? 0}
|
|
478
|
-
resetIn={model.weeklyResetInHuman}
|
|
479
|
-
resetISO={model.weeklyEndTimeISO}
|
|
761
|
+
icon={<Calendar size={12} />} label="Weekly"
|
|
762
|
+
remainingPct={weekPct} consumedPct={weekConsumed}
|
|
763
|
+
used={model.current_weekly_usage_count ?? 0} total={model.current_weekly_total_count ?? 0}
|
|
764
|
+
resetIn={model.weeklyResetInHuman} resetISO={model.weeklyEndTimeISO}
|
|
480
765
|
/>
|
|
481
766
|
</div>
|
|
482
767
|
</Card>
|
|
483
768
|
);
|
|
484
769
|
}
|
|
485
770
|
|
|
486
|
-
function QuotaBar({
|
|
487
|
-
icon
|
|
488
|
-
|
|
489
|
-
remainingPct,
|
|
490
|
-
consumedPct,
|
|
491
|
-
used,
|
|
492
|
-
total,
|
|
493
|
-
resetIn,
|
|
494
|
-
resetISO,
|
|
495
|
-
}: {
|
|
496
|
-
icon: React.ReactNode;
|
|
497
|
-
label: string;
|
|
498
|
-
remainingPct: number;
|
|
499
|
-
consumedPct: number;
|
|
500
|
-
used: number;
|
|
501
|
-
total: number;
|
|
502
|
-
resetIn?: string;
|
|
503
|
-
resetISO?: string;
|
|
771
|
+
function QuotaBar({ icon, label, remainingPct, consumedPct, used, total, resetIn, resetISO }: {
|
|
772
|
+
icon: React.ReactNode; label: string; remainingPct: number; consumedPct: number;
|
|
773
|
+
used: number; total: number; resetIn?: string; resetISO?: string;
|
|
504
774
|
}) {
|
|
505
775
|
const tone = remainingPct >= 75 ? 'good' : remainingPct >= 25 ? 'warn' : 'low';
|
|
506
776
|
return (
|
|
507
777
|
<div className={`minimax-quota-row is-${tone}`}>
|
|
508
778
|
<div className="minimax-quota-head">
|
|
509
|
-
<span className="minimax-quota-label">
|
|
510
|
-
{icon} {label}
|
|
511
|
-
</span>
|
|
779
|
+
<span className="minimax-quota-label">{icon} {label}</span>
|
|
512
780
|
<span className="minimax-quota-remaining">{remainingPct}% remaining</span>
|
|
513
781
|
</div>
|
|
514
782
|
<div className="minimax-bar">
|
|
515
|
-
<div
|
|
516
|
-
className="minimax-bar-fill"
|
|
517
|
-
style={{ width: `${consumedPct}%` }}
|
|
518
|
-
aria-label={`${consumedPct}% consumed`}
|
|
519
|
-
/>
|
|
783
|
+
<div className="minimax-bar-fill" style={{ width: `${consumedPct}%` }} aria-label={`${consumedPct}% consumed`} />
|
|
520
784
|
</div>
|
|
521
785
|
<div className="minimax-quota-meta">
|
|
522
|
-
<span>
|
|
523
|
-
|
|
524
|
-
</span>
|
|
525
|
-
<span title={resetISO}>
|
|
526
|
-
{resetIn ? `resets in ${resetIn}` : '—'}
|
|
527
|
-
</span>
|
|
786
|
+
<span><strong>{used}</strong> / {total || '—'} requests</span>
|
|
787
|
+
<span title={resetISO}>{resetIn ? `resets in ${resetIn}` : '—'}</span>
|
|
528
788
|
</div>
|
|
529
789
|
</div>
|
|
530
790
|
);
|
|
@@ -541,3 +801,123 @@ function relativeTime(ts: number): string {
|
|
|
541
801
|
if (ms < 3_600_000) return `${Math.floor(ms / 60_000)}m ago`;
|
|
542
802
|
return `${Math.floor(ms / 3_600_000)}h ago`;
|
|
543
803
|
}
|
|
804
|
+
|
|
805
|
+
// ─── Onboarding wizard ─────────────────────────────────────────────────
|
|
806
|
+
|
|
807
|
+
type OnboardingProps = {
|
|
808
|
+
step: number; setStep: (n: number) => void;
|
|
809
|
+
keyDraft: string; setKeyDraft: (s: string) => void;
|
|
810
|
+
showKey: boolean; setShowKey: React.Dispatch<React.SetStateAction<boolean>>;
|
|
811
|
+
verifying: boolean; verifyResult: TestResult | null;
|
|
812
|
+
onVerify: () => void; onSkip: () => void; onManualKeySave: () => void;
|
|
813
|
+
savingKey: boolean; status: Status;
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
function OnboardingWizard({ step, setStep, keyDraft, setKeyDraft, showKey, setShowKey, verifying, verifyResult, onVerify, onSkip, onManualKeySave, savingKey, status }: OnboardingProps) {
|
|
817
|
+
return (
|
|
818
|
+
<div className="view-container view-minimax-onboarding">
|
|
819
|
+
<header className="view-header">
|
|
820
|
+
<div className="view-header-titles">
|
|
821
|
+
<h1 className="view-title">
|
|
822
|
+
<Sparkles size={20} style={{ verticalAlign: 'text-bottom', marginRight: 6 }} />
|
|
823
|
+
Set up MiniMax Token Plan tracking
|
|
824
|
+
</h1>
|
|
825
|
+
<p className="view-subtitle">We'll read your Subscription Key and show your remaining quota.</p>
|
|
826
|
+
</div>
|
|
827
|
+
<div className="view-header-actions">
|
|
828
|
+
<Button variant="ghost" size="sm" onClick={onSkip}><X size={14} /> Skip for now</Button>
|
|
829
|
+
</div>
|
|
830
|
+
</header>
|
|
831
|
+
|
|
832
|
+
<div className="minimax-wizard-stepper">
|
|
833
|
+
{(['Welcome', 'Get a key', 'Paste & test', 'Done']).map((label, i) => (
|
|
834
|
+
<div key={label} className={cn('minimax-wizard-step', i === step && 'is-current', i < step && 'is-done', i > step && 'is-todo')}>
|
|
835
|
+
<div className="minimax-wizard-step-bullet">{i < step ? <CircleCheck size={14} /> : i + 1}</div>
|
|
836
|
+
<div className="minimax-wizard-step-label">{label}</div>
|
|
837
|
+
</div>
|
|
838
|
+
))}
|
|
839
|
+
</div>
|
|
840
|
+
|
|
841
|
+
<Card id="minimax-wizard-card">
|
|
842
|
+
{step === 0 && (
|
|
843
|
+
<div className="minimax-wizard-body">
|
|
844
|
+
<h3 className="minimax-wizard-title">Welcome</h3>
|
|
845
|
+
<p className="minimax-wizard-prose">
|
|
846
|
+
BizarHarness shows you how much of your MiniMax Token Plan quota you have left —
|
|
847
|
+
both the <strong>5-hour rolling</strong> and <strong>weekly</strong> windows.
|
|
848
|
+
</p>
|
|
849
|
+
<ul className="minimax-wizard-list">
|
|
850
|
+
<li>Stored in <code>~/.local/share/opencode/auth.json</code>.</li>
|
|
851
|
+
<li>Read fresh on every dashboard load.</li>
|
|
852
|
+
<li>Never logged in full.</li>
|
|
853
|
+
</ul>
|
|
854
|
+
<div className="minimax-wizard-actions">
|
|
855
|
+
<Button onClick={() => setStep(1)} variant="primary" size="md">Get started <span style={{ marginLeft: 6 }}>→</span></Button>
|
|
856
|
+
</div>
|
|
857
|
+
</div>
|
|
858
|
+
)}
|
|
859
|
+
|
|
860
|
+
{step === 1 && (
|
|
861
|
+
<div className="minimax-wizard-body">
|
|
862
|
+
<h3 className="minimax-wizard-title">Get your Subscription Key</h3>
|
|
863
|
+
<p className="minimax-wizard-prose">Go to the MiniMax console and copy your Subscription Key.</p>
|
|
864
|
+
<ol className="minimax-wizard-list">
|
|
865
|
+
<li>Open <a href="https://platform.minimax.io/user-center/payment/token-plan" target="_blank" rel="noreferrer" className="minimax-wizard-link"><ExternalLink size={12} /> platform.minimax.io</a></li>
|
|
866
|
+
<li>Click <strong>Copy Subscription Key</strong>.</li>
|
|
867
|
+
<li>Come back here and paste it.</li>
|
|
868
|
+
</ol>
|
|
869
|
+
<div className="minimax-wizard-actions">
|
|
870
|
+
<Button variant="secondary" size="md" onClick={() => setStep(0)}>← Back</Button>
|
|
871
|
+
<Button variant="primary" size="md" onClick={() => setStep(2)}>I have my key <span style={{ marginLeft: 6 }}>→</span></Button>
|
|
872
|
+
</div>
|
|
873
|
+
</div>
|
|
874
|
+
)}
|
|
875
|
+
|
|
876
|
+
{step === 2 && (
|
|
877
|
+
<div className="minimax-wizard-body">
|
|
878
|
+
<h3 className="minimax-wizard-title">Paste & test</h3>
|
|
879
|
+
<p className="minimax-wizard-prose">Paste your key below. We'll test it against the real API before saving.</p>
|
|
880
|
+
<div className="minimax-key-row">
|
|
881
|
+
<div className="minimax-key-input-wrap">
|
|
882
|
+
<KeyRound size={12} className="minimax-key-icon" />
|
|
883
|
+
<input type={showKey ? 'text' : 'password'} value={keyDraft} onChange={e => setKeyDraft(e.target.value)}
|
|
884
|
+
placeholder="sk-cp-..." spellCheck={false} autoComplete="off" className="minimax-key-input" autoFocus />
|
|
885
|
+
<button type="button" onClick={() => setShowKey(v => !v)} className="minimax-key-toggle" aria-label={showKey ? 'Hide key' : 'Show key'}>
|
|
886
|
+
{showKey ? <EyeOff size={13} /> : <Eye size={13} />}
|
|
887
|
+
</button>
|
|
888
|
+
</div>
|
|
889
|
+
</div>
|
|
890
|
+
{verifyResult && !verifyResult.ok && (
|
|
891
|
+
<div className="minimax-wizard-error"><AlertTriangle size={14} /><span><strong>Verification failed:</strong> {verifyResult.message ?? verifyResult.error}</span></div>
|
|
892
|
+
)}
|
|
893
|
+
<div className="minimax-wizard-actions">
|
|
894
|
+
<Button variant="secondary" size="md" onClick={() => setStep(1)}>← Back</Button>
|
|
895
|
+
<Button variant="primary" size="md" onClick={onVerify} disabled={verifying || !keyDraft.trim()}>
|
|
896
|
+
{verifying ? <Loader2 size={14} className="spin" /> : <ShieldCheck size={14} />}
|
|
897
|
+
{verifying ? 'Testing…' : 'Test & save key'}
|
|
898
|
+
</Button>
|
|
899
|
+
</div>
|
|
900
|
+
<p className="minimax-wizard-prose minimax-wizard-prose--muted">
|
|
901
|
+
Don't want to test first? <a href="#" onClick={e => { e.preventDefault(); onManualKeySave(); }} className="minimax-wizard-link">Save without testing</a>
|
|
902
|
+
</p>
|
|
903
|
+
</div>
|
|
904
|
+
)}
|
|
905
|
+
|
|
906
|
+
{step === 3 && (
|
|
907
|
+
<div className="minimax-wizard-body">
|
|
908
|
+
<h3 className="minimax-wizard-title"><CircleCheck size={18} style={{ verticalAlign: 'text-bottom', marginRight: 6 }} />All set</h3>
|
|
909
|
+
<p className="minimax-wizard-prose">The key works and is saved. Reloading so you can see your live quota.</p>
|
|
910
|
+
<div className="minimax-wizard-actions">
|
|
911
|
+
<Button variant="primary" size="md" onClick={() => window.location.reload()}>View your quota →</Button>
|
|
912
|
+
</div>
|
|
913
|
+
</div>
|
|
914
|
+
)}
|
|
915
|
+
|
|
916
|
+
<div className="minimax-wizard-footer">
|
|
917
|
+
<ShieldCheck size={11} />
|
|
918
|
+
<span>Key written to <code>~/.local/share/opencode/auth.json</code> with mode 0600.</span>
|
|
919
|
+
</div>
|
|
920
|
+
</Card>
|
|
921
|
+
</div>
|
|
922
|
+
);
|
|
923
|
+
}
|