@polderlabs/bizar 4.5.0 → 4.5.2
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/dist/assets/__vite-browser-external-BIHI7g3E.js +1 -0
- package/bizar-dash/dist/assets/__vite-browser-external-BIHI7g3E.js.map +1 -0
- package/bizar-dash/dist/assets/main-B4OfGAwz.js +361 -0
- package/bizar-dash/dist/assets/main-B4OfGAwz.js.map +1 -0
- package/bizar-dash/dist/assets/main-DAlLdW8I.css +1 -0
- package/bizar-dash/dist/assets/{mobile--0FBIKX3.js → mobile-BRhoDOUz.js} +1 -2
- package/bizar-dash/dist/assets/{mobile--0FBIKX3.js.map → mobile-BRhoDOUz.js.map} +1 -1
- package/bizar-dash/dist/assets/{mobile-OgRp8VIb.js → mobile-lbH6szyX.js} +2 -3
- package/bizar-dash/dist/assets/mobile-lbH6szyX.js.map +1 -0
- package/bizar-dash/dist/index.html +3 -3
- package/bizar-dash/dist/mobile.html +2 -2
- package/bizar-dash/skills/bizar/SKILL.md +20 -0
- package/bizar-dash/skills/headroom/SKILL.md +94 -0
- package/bizar-dash/skills/lightrag/SKILL.md +11 -0
- package/bizar-dash/skills/obsidian/SKILL.md +13 -0
- package/bizar-dash/src/server/api.mjs +6 -0
- package/bizar-dash/src/server/headroom.mjs +647 -0
- package/bizar-dash/src/server/memory-lightrag.mjs +281 -6
- package/bizar-dash/src/server/memory-obsidian.mjs +230 -0
- package/bizar-dash/src/server/memory-store.mjs +151 -0
- package/bizar-dash/src/server/mods-loader.mjs +13 -5
- package/bizar-dash/src/server/providers-store.mjs +73 -1
- package/bizar-dash/src/server/routes/_shared.mjs +17 -0
- package/bizar-dash/src/server/routes/chat.mjs +38 -0
- package/bizar-dash/src/server/routes/headroom.mjs +126 -0
- package/bizar-dash/src/server/routes/lightrag.mjs +6 -2
- package/bizar-dash/src/server/routes/memory.mjs +439 -4
- package/bizar-dash/src/server/schedules-runner.mjs +4 -4
- package/bizar-dash/src/server/server.mjs +55 -37
- package/bizar-dash/src/server/watcher.mjs +2 -2
- package/bizar-dash/src/web/App.tsx +42 -6
- package/bizar-dash/src/web/components/HeadroomSettings.tsx +418 -0
- package/bizar-dash/src/web/components/HeadroomStatus.tsx +158 -0
- package/bizar-dash/src/web/components/Toast.tsx +1 -1
- package/bizar-dash/src/web/components/Topbar.tsx +3 -1
- package/bizar-dash/src/web/lib/api.ts +12 -11
- package/bizar-dash/src/web/lib/types.ts +16 -0
- package/bizar-dash/src/web/main.tsx +1 -0
- package/bizar-dash/src/web/styles/chat.css +2 -0
- package/bizar-dash/src/web/styles/main.css +52 -23
- package/bizar-dash/src/web/styles/memory.css +955 -0
- package/bizar-dash/src/web/styles/tasks.css +2 -0
- package/bizar-dash/src/web/views/Memory.tsx +141 -0
- package/bizar-dash/src/web/views/MiniMaxUsage.tsx +3 -2
- package/bizar-dash/src/web/views/Overview.tsx +7 -2
- package/bizar-dash/src/web/views/Settings.tsx +32 -1
- package/bizar-dash/src/web/views/Skills.tsx +3 -2
- package/bizar-dash/src/web/views/Tasks.tsx +4 -3
- package/bizar-dash/src/web/views/memory/ConfigPanel.tsx +289 -0
- package/bizar-dash/src/web/views/memory/GitSyncPanel.tsx +220 -0
- package/bizar-dash/src/web/views/memory/LightragPanel.tsx +307 -0
- package/bizar-dash/src/web/views/memory/MemoryOverview.tsx +356 -0
- package/bizar-dash/src/web/views/memory/MemoryStatusCard.tsx +160 -0
- package/bizar-dash/src/web/views/memory/ObsidianPanel.tsx +642 -0
- package/bizar-dash/src/web/views/memory/SemanticSearchPanel.tsx +194 -0
- package/bizar-dash/tests/cli-bugfixes.test.mjs +151 -0
- package/bizar-dash/tests/frontend-bugfixes.test.mjs +151 -0
- package/bizar-dash/tests/headroom-install.test.mjs +173 -0
- package/bizar-dash/tests/headroom-settings.test.mjs +126 -0
- package/bizar-dash/tests/headroom-status.test.mjs +117 -0
- package/bizar-dash/tests/memory-lightrag-extended.test.mjs +162 -0
- package/bizar-dash/tests/memory-obsidian.test.mjs +269 -0
- package/bizar-dash/tests/memory-tab.test.mjs +322 -0
- package/bizar-dash/tests/mod-upgrade.node.test.mjs +1 -1
- package/bizar-dash/tests/server-bugfixes.test.mjs +318 -0
- package/bizar-dash/tests/submit-feedback.test.mjs +6 -6
- package/cli/artifact.mjs +11 -4
- package/cli/bin.mjs +211 -12
- package/cli/doctor.mjs +5 -3
- package/cli/memory.mjs +65 -21
- package/cli/provision.mjs +8 -2
- package/install.sh +1 -2
- package/package.json +3 -3
- package/bizar-dash/dist/assets/main-CDFKHzBg.css +0 -1
- package/bizar-dash/dist/assets/main-NYFpS2wY.js +0 -312
- package/bizar-dash/dist/assets/main-NYFpS2wY.js.map +0 -1
- package/bizar-dash/dist/assets/mobile-OgRp8VIb.js.map +0 -1
|
@@ -69,8 +69,8 @@ export function createWatcher({ paths, onChange, options = {} }) {
|
|
|
69
69
|
async stop() {
|
|
70
70
|
try {
|
|
71
71
|
await watcher.close();
|
|
72
|
-
} catch {
|
|
73
|
-
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.warn('swallowed in watcher.close:', err.message);
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
/** Force a synthetic broadcast — useful after a self-mutation. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/App.tsx — root shell. Wires data + contexts + tab routing.
|
|
2
2
|
|
|
3
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Component, Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { Topbar, TABS } from './components/Topbar';
|
|
5
5
|
import { Sidebar } from './components/Sidebar';
|
|
6
6
|
import { ModalProvider, useModal } from './components/Modal';
|
|
@@ -34,6 +34,7 @@ import { Mods } from './views/Mods';
|
|
|
34
34
|
import { ModView, type ModView as ModViewType } from './views/ModView';
|
|
35
35
|
import { Schedules } from './views/Schedules';
|
|
36
36
|
import { Skills } from './views/Skills';
|
|
37
|
+
import { Memory } from './views/Memory';
|
|
37
38
|
import { History } from './views/History';
|
|
38
39
|
import { MiniMaxUsage } from './views/MiniMaxUsage';
|
|
39
40
|
import { BackgroundAgents } from './views/BackgroundAgents';
|
|
@@ -67,6 +68,7 @@ const VIEW_MAP: Record<string, (p: ViewProps) => React.ReactNode> = {
|
|
|
67
68
|
chat: Chat,
|
|
68
69
|
agents: Agents,
|
|
69
70
|
artifacts: Artifacts,
|
|
71
|
+
memory: Memory,
|
|
70
72
|
tasks: Tasks,
|
|
71
73
|
activity: Activity,
|
|
72
74
|
background: BackgroundAgents,
|
|
@@ -392,10 +394,6 @@ function Shell() {
|
|
|
392
394
|
const m = msg;
|
|
393
395
|
const file = m.path?.split('/').pop() || m.path || '';
|
|
394
396
|
toast.info(`File changed: ${file}`, 2500);
|
|
395
|
-
api
|
|
396
|
-
.get<Snapshot>('/snapshot')
|
|
397
|
-
.then((s) => setSnapshot((cur) => ({ ...(cur ?? ({} as Snapshot)), ...s })))
|
|
398
|
-
.catch(() => undefined);
|
|
399
397
|
} else if (msg.type === 'tasks:change') {
|
|
400
398
|
const m = msg;
|
|
401
399
|
setSnapshot((cur) => {
|
|
@@ -796,7 +794,11 @@ function Shell() {
|
|
|
796
794
|
<p>Loading Bizar…</p>
|
|
797
795
|
</div>
|
|
798
796
|
)}
|
|
799
|
-
{renderedView
|
|
797
|
+
{renderedView && (
|
|
798
|
+
<Suspense fallback={<div className="loading"><Spinner size="lg" /><p>Loading…</p></div>}>
|
|
799
|
+
<ViewErrorBoundary>{renderedView}</ViewErrorBoundary>
|
|
800
|
+
</Suspense>
|
|
801
|
+
)}
|
|
800
802
|
</main>
|
|
801
803
|
</div>
|
|
802
804
|
<SearchModal
|
|
@@ -807,3 +809,37 @@ function Shell() {
|
|
|
807
809
|
</div>
|
|
808
810
|
);
|
|
809
811
|
}
|
|
812
|
+
|
|
813
|
+
// v4.5.x — Catches render-time errors in the active view so a single bad
|
|
814
|
+
// component doesn't bring down the whole dashboard (topbar, sidebar, WS).
|
|
815
|
+
// Falls back to a friendly error card with a Retry button that re-mounts
|
|
816
|
+
// the wrapped subtree by remounting the boundary via React `key` bumps.
|
|
817
|
+
class ViewErrorBoundary extends Component<
|
|
818
|
+
{ children: React.ReactNode },
|
|
819
|
+
{ err: Error | null }
|
|
820
|
+
> {
|
|
821
|
+
state: { err: Error | null } = { err: null };
|
|
822
|
+
static getDerivedStateFromError(err: Error): { err: Error | null } {
|
|
823
|
+
return { err };
|
|
824
|
+
}
|
|
825
|
+
componentDidCatch(err: Error, info: { componentStack?: string }) {
|
|
826
|
+
// eslint-disable-next-line no-console
|
|
827
|
+
console.error('[ViewErrorBoundary] caught render error:', err, info?.componentStack);
|
|
828
|
+
}
|
|
829
|
+
reset = () => this.setState({ err: null });
|
|
830
|
+
override render() {
|
|
831
|
+
if (this.state.err) {
|
|
832
|
+
return (
|
|
833
|
+
<div className="view-error-fallback" role="alert">
|
|
834
|
+
<AlertTriangle size={20} />
|
|
835
|
+
<div className="view-error-body">
|
|
836
|
+
<strong>This view crashed.</strong>
|
|
837
|
+
<pre>{this.state.err.message}</pre>
|
|
838
|
+
<Button variant="secondary" size="sm" onClick={this.reset}>Retry</Button>
|
|
839
|
+
</div>
|
|
840
|
+
</div>
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
return this.props.children;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
// src/web/components/HeadroomSettings.tsx
|
|
2
|
+
//
|
|
3
|
+
// v1.0.0 — Headroom settings card for the Settings view.
|
|
4
|
+
// Displays live status and provides controls for install, wrap, proxy, and configuration.
|
|
5
|
+
import React, { useEffect, useState, useCallback } from 'react';
|
|
6
|
+
import {
|
|
7
|
+
Activity,
|
|
8
|
+
CheckCircle,
|
|
9
|
+
XCircle,
|
|
10
|
+
Download,
|
|
11
|
+
Play,
|
|
12
|
+
Square,
|
|
13
|
+
RefreshCw,
|
|
14
|
+
ExternalLink,
|
|
15
|
+
Zap,
|
|
16
|
+
} from 'lucide-react';
|
|
17
|
+
import { Card, CardTitle, CardMeta } from '../components/Card';
|
|
18
|
+
import { Button } from '../components/Button';
|
|
19
|
+
import { useToast } from '../components/Toast';
|
|
20
|
+
import { api } from '../lib/api';
|
|
21
|
+
import { type HeadroomSettings } from '../lib/types';
|
|
22
|
+
|
|
23
|
+
type HeadroomStatus = {
|
|
24
|
+
installed: boolean;
|
|
25
|
+
version: string | null;
|
|
26
|
+
proxyRunning: boolean;
|
|
27
|
+
proxyPort: number | null;
|
|
28
|
+
proxyPid: number | null;
|
|
29
|
+
wrapped: boolean;
|
|
30
|
+
healthy: 'ok' | 'warn' | 'fail';
|
|
31
|
+
messages: string[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type HeadroomStats = {
|
|
35
|
+
tokensSaved?: number;
|
|
36
|
+
compressionRatio?: number;
|
|
37
|
+
cacheHits?: number;
|
|
38
|
+
transforms?: number;
|
|
39
|
+
error?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const BACKEND_OPTIONS = [
|
|
43
|
+
{ value: 'anthropic', label: 'Anthropic' },
|
|
44
|
+
{ value: 'anyllm', label: 'AnyLLM' },
|
|
45
|
+
{ value: 'litellm-anthropic', label: 'LiteLLM (Anthropic)' },
|
|
46
|
+
{ value: 'litellm-openai', label: 'LiteLLM (OpenAI)' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
type Props = {
|
|
50
|
+
settings: HeadroomSettings;
|
|
51
|
+
onPatch: (patch: Partial<HeadroomSettings>) => void;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export function HeadroomSettingsCard({ settings, onPatch }: Props) {
|
|
55
|
+
const toast = useToast();
|
|
56
|
+
const [status, setStatus] = useState<HeadroomStatus | null>(null);
|
|
57
|
+
const [stats, setStats] = useState<HeadroomStats | null>(null);
|
|
58
|
+
const [loadingStatus, setLoadingStatus] = useState(false);
|
|
59
|
+
const [installing, setInstalling] = useState(false);
|
|
60
|
+
const [wrapping, setWrapping] = useState(false);
|
|
61
|
+
const [unwrapping, setUnwrapping] = useState(false);
|
|
62
|
+
const [startingProxy, setStartingProxy] = useState(false);
|
|
63
|
+
const [stoppingProxy, setStoppingProxy] = useState(false);
|
|
64
|
+
|
|
65
|
+
const loadStatus = useCallback(async () => {
|
|
66
|
+
setLoadingStatus(true);
|
|
67
|
+
try {
|
|
68
|
+
const [s, st] = await Promise.all([
|
|
69
|
+
api.get<HeadroomStatus>('/headroom/status'),
|
|
70
|
+
api.get<HeadroomStats>('/headroom/stats?hours=24').catch(() => ({ error: 'no stats' })),
|
|
71
|
+
]);
|
|
72
|
+
setStatus(s);
|
|
73
|
+
if (!st.error) setStats(st);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
toast.error(`Failed to load Headroom status: ${(err as Error).message}`);
|
|
76
|
+
} finally {
|
|
77
|
+
setLoadingStatus(false);
|
|
78
|
+
}
|
|
79
|
+
}, [toast]);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
loadStatus();
|
|
83
|
+
}, [loadStatus]);
|
|
84
|
+
|
|
85
|
+
const handleInstall = async () => {
|
|
86
|
+
setInstalling(true);
|
|
87
|
+
try {
|
|
88
|
+
const r = await api.post<{ ok: boolean; installed: boolean; method: string }>('/headroom/install', { force: true });
|
|
89
|
+
if (r.installed) {
|
|
90
|
+
toast.success(`Headroom installed via ${r.method}.`);
|
|
91
|
+
await loadStatus();
|
|
92
|
+
} else {
|
|
93
|
+
toast.error('Headroom install failed. Try: pip install "headroom-ai[all]"');
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
toast.error(`Install failed: ${(err as Error).message}`);
|
|
97
|
+
} finally {
|
|
98
|
+
setInstalling(false);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const handleWrap = async () => {
|
|
103
|
+
setWrapping(true);
|
|
104
|
+
try {
|
|
105
|
+
const r = await api.post<{ ok: boolean }>('/headroom/wrap', { port: settings.port });
|
|
106
|
+
if (r.ok) {
|
|
107
|
+
toast.success('opencode wrapped with Headroom.');
|
|
108
|
+
await loadStatus();
|
|
109
|
+
} else {
|
|
110
|
+
toast.error('Wrap failed.');
|
|
111
|
+
}
|
|
112
|
+
} catch (err) {
|
|
113
|
+
toast.error(`Wrap failed: ${(err as Error).message}`);
|
|
114
|
+
} finally {
|
|
115
|
+
setWrapping(false);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const handleUnwrap = async () => {
|
|
120
|
+
setUnwrapping(true);
|
|
121
|
+
try {
|
|
122
|
+
const r = await api.post<{ ok: boolean }>('/headroom/unwrap');
|
|
123
|
+
if (r.ok) {
|
|
124
|
+
toast.success('opencode unwrapped from Headroom.');
|
|
125
|
+
await loadStatus();
|
|
126
|
+
} else {
|
|
127
|
+
toast.error('Unwrap failed.');
|
|
128
|
+
}
|
|
129
|
+
} catch (err) {
|
|
130
|
+
toast.error(`Unwrap failed: ${(err as Error).message}`);
|
|
131
|
+
} finally {
|
|
132
|
+
setUnwrapping(false);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const handleStartProxy = async () => {
|
|
137
|
+
setStartingProxy(true);
|
|
138
|
+
try {
|
|
139
|
+
const r = await api.post<{ ok: boolean }>('/headroom/proxy/start', {
|
|
140
|
+
port: settings.port,
|
|
141
|
+
host: settings.host,
|
|
142
|
+
});
|
|
143
|
+
if (r.ok) {
|
|
144
|
+
toast.success(`Headroom proxy started on ${settings.host}:${settings.port}.`);
|
|
145
|
+
await loadStatus();
|
|
146
|
+
} else {
|
|
147
|
+
toast.error('Proxy start failed.');
|
|
148
|
+
}
|
|
149
|
+
} catch (err) {
|
|
150
|
+
toast.error(`Proxy start failed: ${(err as Error).message}`);
|
|
151
|
+
} finally {
|
|
152
|
+
setStartingProxy(false);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const handleStopProxy = async () => {
|
|
157
|
+
setStoppingProxy(true);
|
|
158
|
+
try {
|
|
159
|
+
const r = await api.post<{ ok: boolean }>('/headroom/proxy/stop');
|
|
160
|
+
if (r.ok) {
|
|
161
|
+
toast.success('Headroom proxy stopped.');
|
|
162
|
+
await loadStatus();
|
|
163
|
+
} else {
|
|
164
|
+
toast.error('Proxy stop failed.');
|
|
165
|
+
}
|
|
166
|
+
} catch (err) {
|
|
167
|
+
toast.error(`Proxy stop failed: ${(err as Error).message}`);
|
|
168
|
+
} finally {
|
|
169
|
+
setStoppingProxy(false);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const handleOpenDashboard = async () => {
|
|
174
|
+
try {
|
|
175
|
+
const { spawn } = await import('node:child_process');
|
|
176
|
+
spawn('headroom', ['dashboard'], { detached: true, stdio: 'ignore' });
|
|
177
|
+
} catch {
|
|
178
|
+
toast.error('Could not open Headroom dashboard. Run `headroom dashboard` manually.');
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const { installed, version, proxyRunning, proxyPort, wrapped } = status || {};
|
|
183
|
+
const ratio = stats?.compressionRatio ?? 0;
|
|
184
|
+
const saved = stats?.tokensSaved ?? 0;
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<div id="settings-headroom" data-section="headroom">
|
|
188
|
+
<Card>
|
|
189
|
+
<CardTitle>
|
|
190
|
+
<Activity size={14} style={{ color: proxyRunning ? 'var(--success)' : 'var(--text-dim)' }} />
|
|
191
|
+
Headroom
|
|
192
|
+
{installed && version && (
|
|
193
|
+
<span style={{ fontSize: 11, color: 'var(--text-dim)', marginLeft: 6 }}>
|
|
194
|
+
v{version} {proxyRunning ? '✓' : '✗'}
|
|
195
|
+
</span>
|
|
196
|
+
)}
|
|
197
|
+
{!installed && (
|
|
198
|
+
<span style={{ fontSize: 11, color: 'var(--error)', marginLeft: 6 }}>not installed</span>
|
|
199
|
+
)}
|
|
200
|
+
</CardTitle>
|
|
201
|
+
<CardMeta>
|
|
202
|
+
Context compression for token efficiency. Compresses tool outputs, logs, and conversation
|
|
203
|
+
history by 60–95% before they reach the model.
|
|
204
|
+
</CardMeta>
|
|
205
|
+
|
|
206
|
+
{/* Live status row */}
|
|
207
|
+
<div style={{ display: 'flex', gap: 16, flexWrap: 'wrap', marginTop: 12, marginBottom: 12 }}>
|
|
208
|
+
<div className="headroom-status-item">
|
|
209
|
+
{installed ? (
|
|
210
|
+
<CheckCircle size={12} style={{ color: 'var(--success)' }} />
|
|
211
|
+
) : (
|
|
212
|
+
<XCircle size={12} style={{ color: 'var(--error)' }} />
|
|
213
|
+
)}
|
|
214
|
+
<span>{installed ? 'Installed' : 'Not installed'}</span>
|
|
215
|
+
</div>
|
|
216
|
+
<div className="headroom-status-item">
|
|
217
|
+
{proxyRunning ? (
|
|
218
|
+
<CheckCircle size={12} style={{ color: 'var(--success)' }} />
|
|
219
|
+
) : (
|
|
220
|
+
<XCircle size={12} style={{ color: 'var(--text-dim)' }} />
|
|
221
|
+
)}
|
|
222
|
+
<span>Proxy {proxyRunning ? `${proxyPort} ✓` : 'stopped'}</span>
|
|
223
|
+
</div>
|
|
224
|
+
<div className="headroom-status-item">
|
|
225
|
+
{wrapped ? (
|
|
226
|
+
<CheckCircle size={12} style={{ color: 'var(--success)' }} />
|
|
227
|
+
) : (
|
|
228
|
+
<XCircle size={12} style={{ color: 'var(--text-dim)' }} />
|
|
229
|
+
)}
|
|
230
|
+
<span>opencode {wrapped ? 'wrapped' : 'not wrapped'}</span>
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
|
|
234
|
+
{/* Stats */}
|
|
235
|
+
{(saved > 0 || ratio > 0) && (
|
|
236
|
+
<div style={{ display: 'flex', gap: 24, marginBottom: 12 }}>
|
|
237
|
+
<div>
|
|
238
|
+
<div style={{ fontSize: 20, fontWeight: 700, color: 'var(--success)' }}>
|
|
239
|
+
{ratio > 0 ? `${Math.round(ratio * 100)}%` : '—'}
|
|
240
|
+
</div>
|
|
241
|
+
<div className="muted" style={{ fontSize: 11 }}>Compression ratio</div>
|
|
242
|
+
</div>
|
|
243
|
+
<div>
|
|
244
|
+
<div style={{ fontSize: 20, fontWeight: 700, color: 'var(--accent)' }}>
|
|
245
|
+
{saved > 0 ? saved.toLocaleString() : '—'}
|
|
246
|
+
</div>
|
|
247
|
+
<div className="muted" style={{ fontSize: 11 }}>Tokens saved (24h)</div>
|
|
248
|
+
</div>
|
|
249
|
+
</div>
|
|
250
|
+
)}
|
|
251
|
+
|
|
252
|
+
{/* Action buttons */}
|
|
253
|
+
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', marginBottom: 8 }}>
|
|
254
|
+
{!installed ? (
|
|
255
|
+
<Button variant="primary" size="sm" onClick={handleInstall} disabled={installing}>
|
|
256
|
+
{installing ? <span className="btn-spinner" /> : <Download size={13} />}
|
|
257
|
+
{installing ? 'Installing…' : 'Install Headroom'}
|
|
258
|
+
</Button>
|
|
259
|
+
) : (
|
|
260
|
+
<>
|
|
261
|
+
<Button
|
|
262
|
+
variant="secondary"
|
|
263
|
+
size="sm"
|
|
264
|
+
onClick={handleWrap}
|
|
265
|
+
disabled={wrapping || wrapped}
|
|
266
|
+
title={wrapped ? 'opencode is already wrapped' : 'Wrap opencode to route through Headroom proxy'}
|
|
267
|
+
>
|
|
268
|
+
{wrapping ? <span className="btn-spinner" /> : <Zap size={13} />}
|
|
269
|
+
{wrapping ? 'Wrapping…' : wrapped ? 'Wrapped ✓' : 'Wrap opencode'}
|
|
270
|
+
</Button>
|
|
271
|
+
{wrapped && (
|
|
272
|
+
<Button variant="ghost" size="sm" onClick={handleUnwrap} disabled={unwrapping}>
|
|
273
|
+
{unwrapping ? <span className="btn-spinner" /> : <RefreshCw size={13} />}
|
|
274
|
+
{unwrapping ? 'Unwrapping…' : 'Unwrap'}
|
|
275
|
+
</Button>
|
|
276
|
+
)}
|
|
277
|
+
</>
|
|
278
|
+
)}
|
|
279
|
+
|
|
280
|
+
{installed && (
|
|
281
|
+
<>
|
|
282
|
+
{proxyRunning ? (
|
|
283
|
+
<Button variant="secondary" size="sm" onClick={handleStopProxy} disabled={stoppingProxy}>
|
|
284
|
+
{stoppingProxy ? <span className="btn-spinner" /> : <Square size={13} />}
|
|
285
|
+
{stoppingProxy ? 'Stopping…' : 'Stop proxy'}
|
|
286
|
+
</Button>
|
|
287
|
+
) : (
|
|
288
|
+
<Button variant="secondary" size="sm" onClick={handleStartProxy} disabled={startingProxy}>
|
|
289
|
+
{startingProxy ? <span className="btn-spinner" /> : <Play size={13} />}
|
|
290
|
+
{startingProxy ? 'Starting…' : 'Start proxy'}
|
|
291
|
+
</Button>
|
|
292
|
+
)}
|
|
293
|
+
<Button variant="ghost" size="sm" onClick={handleOpenDashboard}>
|
|
294
|
+
<ExternalLink size={13} />
|
|
295
|
+
Dashboard
|
|
296
|
+
</Button>
|
|
297
|
+
</>
|
|
298
|
+
)}
|
|
299
|
+
|
|
300
|
+
<Button variant="ghost" size="sm" onClick={loadStatus} disabled={loadingStatus}>
|
|
301
|
+
<RefreshCw size={13} className={loadingStatus ? 'spin' : ''} />
|
|
302
|
+
</Button>
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
{/* Settings */}
|
|
306
|
+
<div style={{ marginTop: 16 }}>
|
|
307
|
+
<label className="checkbox-row">
|
|
308
|
+
<input
|
|
309
|
+
type="checkbox"
|
|
310
|
+
checked={settings.enabled}
|
|
311
|
+
onChange={(e) => onPatch({ enabled: e.target.checked })}
|
|
312
|
+
/>
|
|
313
|
+
<span>Enable Headroom</span>
|
|
314
|
+
</label>
|
|
315
|
+
<label className="checkbox-row">
|
|
316
|
+
<input
|
|
317
|
+
type="checkbox"
|
|
318
|
+
checked={settings.autoInstall}
|
|
319
|
+
onChange={(e) => onPatch({ autoInstall: e.target.checked })}
|
|
320
|
+
/>
|
|
321
|
+
<span>Auto-install if missing on dashboard startup</span>
|
|
322
|
+
</label>
|
|
323
|
+
<label className="checkbox-row">
|
|
324
|
+
<input
|
|
325
|
+
type="checkbox"
|
|
326
|
+
checked={settings.autoStart}
|
|
327
|
+
onChange={(e) => onPatch({ autoStart: e.target.checked })}
|
|
328
|
+
/>
|
|
329
|
+
<span>Auto-start proxy on dashboard startup</span>
|
|
330
|
+
</label>
|
|
331
|
+
<label className="checkbox-row">
|
|
332
|
+
<input
|
|
333
|
+
type="checkbox"
|
|
334
|
+
checked={settings.autoWrap}
|
|
335
|
+
onChange={(e) => onPatch({ autoWrap: e.target.checked })}
|
|
336
|
+
/>
|
|
337
|
+
<span>Auto-wrap opencode on dashboard startup</span>
|
|
338
|
+
</label>
|
|
339
|
+
<label className="checkbox-row">
|
|
340
|
+
<input
|
|
341
|
+
type="checkbox"
|
|
342
|
+
checked={settings.routeAllProviders}
|
|
343
|
+
onChange={(e) => onPatch({ routeAllProviders: e.target.checked })}
|
|
344
|
+
/>
|
|
345
|
+
<span>Route all providers through Headroom proxy</span>
|
|
346
|
+
</label>
|
|
347
|
+
|
|
348
|
+
<div className="task-form-row" style={{ marginTop: 12 }}>
|
|
349
|
+
<div className="task-form-field">
|
|
350
|
+
<label className="field-label">Proxy port</label>
|
|
351
|
+
<input
|
|
352
|
+
type="number"
|
|
353
|
+
className="input"
|
|
354
|
+
value={settings.port}
|
|
355
|
+
min={1}
|
|
356
|
+
max={65535}
|
|
357
|
+
onChange={(e) => onPatch({ port: Math.max(1, Math.min(65535, parseInt(e.target.value, 10) || 8787)) })}
|
|
358
|
+
/>
|
|
359
|
+
</div>
|
|
360
|
+
<div className="task-form-field">
|
|
361
|
+
<label className="field-label">Proxy host</label>
|
|
362
|
+
<input
|
|
363
|
+
type="text"
|
|
364
|
+
className="input"
|
|
365
|
+
value={settings.host}
|
|
366
|
+
onChange={(e) => onPatch({ host: e.target.value })}
|
|
367
|
+
/>
|
|
368
|
+
</div>
|
|
369
|
+
</div>
|
|
370
|
+
|
|
371
|
+
<div className="task-form-row">
|
|
372
|
+
<div className="task-form-field">
|
|
373
|
+
<label className="field-label">Backend</label>
|
|
374
|
+
<select
|
|
375
|
+
className="select"
|
|
376
|
+
value={settings.backend}
|
|
377
|
+
onChange={(e) => onPatch({ backend: e.target.value })}
|
|
378
|
+
>
|
|
379
|
+
{BACKEND_OPTIONS.map((o) => (
|
|
380
|
+
<option key={o.value} value={o.value}>{o.label}</option>
|
|
381
|
+
))}
|
|
382
|
+
</select>
|
|
383
|
+
</div>
|
|
384
|
+
<div className="task-form-field">
|
|
385
|
+
<label className="field-label">Monthly budget (USD)</label>
|
|
386
|
+
<input
|
|
387
|
+
type="number"
|
|
388
|
+
className="input"
|
|
389
|
+
value={settings.budget}
|
|
390
|
+
min={0}
|
|
391
|
+
step={1}
|
|
392
|
+
onChange={(e) => onPatch({ budget: Math.max(0, parseFloat(e.target.value) || 0) })}
|
|
393
|
+
/>
|
|
394
|
+
<span className="field-help">0 = unlimited</span>
|
|
395
|
+
</div>
|
|
396
|
+
</div>
|
|
397
|
+
|
|
398
|
+
<label className="checkbox-row">
|
|
399
|
+
<input
|
|
400
|
+
type="checkbox"
|
|
401
|
+
checked={settings.outputShaper}
|
|
402
|
+
onChange={(e) => onPatch({ outputShaper: e.target.checked })}
|
|
403
|
+
/>
|
|
404
|
+
<span>Enable output shaper</span>
|
|
405
|
+
</label>
|
|
406
|
+
<label className="checkbox-row">
|
|
407
|
+
<input
|
|
408
|
+
type="checkbox"
|
|
409
|
+
checked={settings.telemetry}
|
|
410
|
+
onChange={(e) => onPatch({ telemetry: e.target.checked })}
|
|
411
|
+
/>
|
|
412
|
+
<span>Enable telemetry</span>
|
|
413
|
+
</label>
|
|
414
|
+
</div>
|
|
415
|
+
</Card>
|
|
416
|
+
</div>
|
|
417
|
+
);
|
|
418
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// src/web/components/HeadroomStatus.tsx
|
|
2
|
+
//
|
|
3
|
+
// v1.0.0 — Small status widget showing Headroom proxy status and live stats.
|
|
4
|
+
// Shown on the Overview tab or wherever fits in the dashboard layout.
|
|
5
|
+
import React, { useEffect, useState } from 'react';
|
|
6
|
+
import { Activity, CheckCircle, XCircle, ExternalLink } from 'lucide-react';
|
|
7
|
+
import { Card, CardTitle } from '../components/Card';
|
|
8
|
+
import { api } from '../lib/api';
|
|
9
|
+
import { cn } from '../lib/utils';
|
|
10
|
+
|
|
11
|
+
type HeadroomStatus = {
|
|
12
|
+
installed: boolean;
|
|
13
|
+
version: string | null;
|
|
14
|
+
proxyRunning: boolean;
|
|
15
|
+
proxyPort: number | null;
|
|
16
|
+
proxyPid: number | null;
|
|
17
|
+
wrapped: boolean;
|
|
18
|
+
healthy: 'ok' | 'warn' | 'fail';
|
|
19
|
+
messages: string[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type HeadroomStats = {
|
|
23
|
+
tokensSaved?: number;
|
|
24
|
+
compressionRatio?: number;
|
|
25
|
+
cacheHits?: number;
|
|
26
|
+
transforms?: number;
|
|
27
|
+
error?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function HeadroomStatus() {
|
|
31
|
+
const [status, setStatus] = useState<HeadroomStatus | null>(null);
|
|
32
|
+
const [stats, setStats] = useState<HeadroomStats | null>(null);
|
|
33
|
+
const [loading, setLoading] = useState(true);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
let cancelled = false;
|
|
37
|
+
(async () => {
|
|
38
|
+
try {
|
|
39
|
+
const [s, st] = await Promise.all([
|
|
40
|
+
api.get<HeadroomStatus>('/headroom/status'),
|
|
41
|
+
api.get<HeadroomStats>('/headroom/stats?hours=24').catch(() => ({ error: 'no stats' })),
|
|
42
|
+
]);
|
|
43
|
+
if (!cancelled) {
|
|
44
|
+
setStatus(s);
|
|
45
|
+
setStats(st.error ? null : st);
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
if (!cancelled) setStatus(null);
|
|
49
|
+
} finally {
|
|
50
|
+
if (!cancelled) setLoading(false);
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
53
|
+
return () => { cancelled = true; };
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
if (loading) {
|
|
57
|
+
return (
|
|
58
|
+
<Card>
|
|
59
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
|
60
|
+
<Activity size={14} className="spin" style={{ animation: 'spin 1s linear infinite' }} />
|
|
61
|
+
<span className="muted">Loading Headroom status…</span>
|
|
62
|
+
</div>
|
|
63
|
+
</Card>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!status) {
|
|
68
|
+
return (
|
|
69
|
+
<Card>
|
|
70
|
+
<div style={{ color: 'var(--error, #f85149)', display: 'flex', alignItems: 'center', gap: 8 }}>
|
|
71
|
+
<XCircle size={14} />
|
|
72
|
+
<span>Headroom unavailable</span>
|
|
73
|
+
</div>
|
|
74
|
+
</Card>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const { installed, version, proxyRunning, proxyPort, proxyPid, wrapped, healthy } = status;
|
|
79
|
+
const isHealthy = healthy === 'ok';
|
|
80
|
+
const ratio = stats?.compressionRatio ?? 0;
|
|
81
|
+
const saved = stats?.tokensSaved ?? 0;
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Card>
|
|
85
|
+
<CardTitle>
|
|
86
|
+
<Activity size={14} style={{ color: isHealthy ? 'var(--success, #3fb950)' : 'var(--warning, #d29922)' }} />
|
|
87
|
+
Headroom
|
|
88
|
+
{installed && version && (
|
|
89
|
+
<span style={{ fontSize: 11, color: 'var(--text-dim)', marginLeft: 4 }}>v{version}</span>
|
|
90
|
+
)}
|
|
91
|
+
</CardTitle>
|
|
92
|
+
|
|
93
|
+
{/* Status pills */}
|
|
94
|
+
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', marginTop: 8 }}>
|
|
95
|
+
{installed ? (
|
|
96
|
+
<span className="status-pill status-pill-ok">
|
|
97
|
+
<CheckCircle size={10} /> Installed
|
|
98
|
+
</span>
|
|
99
|
+
) : (
|
|
100
|
+
<span className="status-pill status-pill-error">
|
|
101
|
+
<XCircle size={10} /> Not installed
|
|
102
|
+
</span>
|
|
103
|
+
)}
|
|
104
|
+
{proxyRunning ? (
|
|
105
|
+
<span className="status-pill status-pill-ok">
|
|
106
|
+
<CheckCircle size={10} /> Proxy {proxyPort ? `@ ${proxyPort}` : ''}
|
|
107
|
+
{proxyPid ? ` (PID ${proxyPid})` : ''}
|
|
108
|
+
</span>
|
|
109
|
+
) : (
|
|
110
|
+
<span className="status-pill status-pill-warn">
|
|
111
|
+
<XCircle size={10} /> Proxy stopped
|
|
112
|
+
</span>
|
|
113
|
+
)}
|
|
114
|
+
{wrapped ? (
|
|
115
|
+
<span className="status-pill status-pill-ok">
|
|
116
|
+
<CheckCircle size={10} /> Wrapped
|
|
117
|
+
</span>
|
|
118
|
+
) : (
|
|
119
|
+
<span className="status-pill status-pill-warn">
|
|
120
|
+
<XCircle size={10} /> Not wrapped
|
|
121
|
+
</span>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
{/* Stats row */}
|
|
126
|
+
{(saved > 0 || ratio > 0) && (
|
|
127
|
+
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, marginTop: 12 }}>
|
|
128
|
+
<div className="stat-block">
|
|
129
|
+
<div className="stat-big">{ratio > 0 ? `${Math.round(ratio * 100)}%` : '—'}</div>
|
|
130
|
+
<div className="stat-label">Compression ratio</div>
|
|
131
|
+
</div>
|
|
132
|
+
<div className="stat-block">
|
|
133
|
+
<div className="stat-big">{saved > 0 ? saved.toLocaleString() : '—'}</div>
|
|
134
|
+
<div className="stat-label">Tokens saved (24h)</div>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
)}
|
|
138
|
+
|
|
139
|
+
{/* Actions */}
|
|
140
|
+
<div style={{ marginTop: 10, display: 'flex', gap: 8 }}>
|
|
141
|
+
<a
|
|
142
|
+
href="#settings-headroom"
|
|
143
|
+
style={{
|
|
144
|
+
display: 'inline-flex',
|
|
145
|
+
alignItems: 'center',
|
|
146
|
+
gap: 4,
|
|
147
|
+
fontSize: 12,
|
|
148
|
+
color: 'var(--accent, #8b5cf6)',
|
|
149
|
+
textDecoration: 'none',
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
<ExternalLink size={12} />
|
|
153
|
+
Open settings
|
|
154
|
+
</a>
|
|
155
|
+
</div>
|
|
156
|
+
</Card>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
@@ -134,7 +134,7 @@ function ToastItem({
|
|
|
134
134
|
}) {
|
|
135
135
|
const Icon = ICONS[toast.kind];
|
|
136
136
|
return (
|
|
137
|
-
<div className={`toast toast-${toast.kind}`} role="
|
|
137
|
+
<div className={`toast toast-${toast.kind}`} role="alert" aria-live="assertive" aria-atomic="true">
|
|
138
138
|
<Icon size={16} className="toast-icon" />
|
|
139
139
|
<span className="toast-message">{toast.message}</span>
|
|
140
140
|
<button
|