Add a complete web management panel for ZeroClaw, served directly from the binary via rust-embed. The dashboard provides real-time monitoring, agent chat, configuration editing, and system diagnostics — all accessible at http://localhost:5555/ after pairing. Backend (Rust): - Add 15+ REST API endpoints under /api/* with bearer token auth - Add WebSocket agent chat at /ws/chat with query param auth - Add SSE event stream at /api/events via BroadcastObserver - Add rust-embed static file serving at /_app/* with SPA fallback - Extend AppState with tools_registry, cost_tracker, event_tx - Extract doctor::diagnose() for structured diagnostic results - Add Serialize derives to IntegrationStatus, CliCategory, DiscoveredCli Frontend (React + Vite + Tailwind CSS): - 10 dashboard pages: Dashboard, AgentChat, Tools, Cron, Integrations, Memory, Config, Cost, Logs, Doctor - WebSocket client with auto-reconnect for agent chat - SSE client (fetch-based, supports auth headers) for live events - Full EN/TR internationalization (~190 translation keys) - Dark theme with responsive layouts - Auth flow via 6-digit pairing code, token stored in localStorage Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43 lines
805 B
TypeScript
43 lines
805 B
TypeScript
const TOKEN_KEY = 'zeroclaw_token';
|
|
|
|
/**
|
|
* Retrieve the stored authentication token.
|
|
*/
|
|
export function getToken(): string | null {
|
|
try {
|
|
return localStorage.getItem(TOKEN_KEY);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Store an authentication token.
|
|
*/
|
|
export function setToken(token: string): void {
|
|
try {
|
|
localStorage.setItem(TOKEN_KEY, token);
|
|
} catch {
|
|
// localStorage may be unavailable (e.g. in some private browsing modes)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the stored authentication token.
|
|
*/
|
|
export function clearToken(): void {
|
|
try {
|
|
localStorage.removeItem(TOKEN_KEY);
|
|
} catch {
|
|
// Ignore
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns true if a token is currently stored.
|
|
*/
|
|
export function isAuthenticated(): boolean {
|
|
const token = getToken();
|
|
return token !== null && token.length > 0;
|
|
}
|