Spaces:
Runtime error
Runtime error
Commit ·
a218835
1
Parent(s): 6b2e74b
feat(#39): replace console.log/error/warn with structured client logger
Browse filesAdd src/lib/client-logger.ts and replace all 55+ console calls across 19 client files with scoped createClientLogger instances. Production suppresses debug+info. Fix variable shadowing in log-viewer-panel.tsx.
Addresses #39
- src/components/ErrorBoundary.tsx +4 -1
- src/components/chat/chat-panel.tsx +6 -3
- src/components/chat/conversation-list.tsx +4 -1
- src/components/dashboard/sidebar.tsx +4 -1
- src/components/panels/agent-cost-panel.tsx +4 -1
- src/components/panels/agent-detail-tabs.tsx +6 -3
- src/components/panels/agent-spawn-panel.tsx +5 -2
- src/components/panels/agent-squad-panel-phase3.tsx +11 -8
- src/components/panels/agent-squad-panel.tsx +6 -3
- src/components/panels/cron-management-panel.tsx +9 -6
- src/components/panels/log-viewer-panel.tsx +24 -21
- src/components/panels/memory-browser-panel.tsx +9 -6
- src/components/panels/session-details-panel.tsx +4 -1
- src/components/panels/standup-panel.tsx +4 -1
- src/components/panels/task-board-panel.tsx +5 -2
- src/components/panels/token-dashboard-panel.tsx +6 -3
- src/lib/client-logger.ts +68 -0
- src/lib/device-identity.ts +5 -1
- src/lib/use-server-events.ts +5 -2
- src/lib/websocket.ts +20 -17
src/components/ErrorBoundary.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { Component, type ErrorInfo, type ReactNode } from 'react'
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
interface Props {
|
| 6 |
children: ReactNode
|
|
@@ -23,7 +26,7 @@ export class ErrorBoundary extends Component<Props, State> {
|
|
| 23 |
}
|
| 24 |
|
| 25 |
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
| 26 |
-
|
| 27 |
}
|
| 28 |
|
| 29 |
render() {
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { Component, type ErrorInfo, type ReactNode } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
+
|
| 6 |
+
const log = createClientLogger('ErrorBoundary')
|
| 7 |
|
| 8 |
interface Props {
|
| 9 |
children: ReactNode
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
| 29 |
+
log.error('Panel error:', error, errorInfo)
|
| 30 |
}
|
| 31 |
|
| 32 |
render() {
|
src/components/chat/chat-panel.tsx
CHANGED
|
@@ -3,10 +3,13 @@
|
|
| 3 |
import { useEffect, useCallback, useState, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
| 6 |
import { ConversationList } from './conversation-list'
|
| 7 |
import { MessageList } from './message-list'
|
| 8 |
import { ChatInput } from './chat-input'
|
| 9 |
|
|
|
|
|
|
|
| 10 |
export function ChatPanel() {
|
| 11 |
const {
|
| 12 |
chatPanelOpen,
|
|
@@ -52,7 +55,7 @@ export function ChatPanel() {
|
|
| 52 |
const data = await res.json()
|
| 53 |
if (data.agents) setAgents(data.agents)
|
| 54 |
} catch (err) {
|
| 55 |
-
|
| 56 |
}
|
| 57 |
}
|
| 58 |
if (chatPanelOpen) loadAgents()
|
|
@@ -67,7 +70,7 @@ export function ChatPanel() {
|
|
| 67 |
const data = await res.json()
|
| 68 |
if (data.messages) setChatMessages(data.messages)
|
| 69 |
} catch (err) {
|
| 70 |
-
|
| 71 |
}
|
| 72 |
}, [activeConversation, setChatMessages])
|
| 73 |
|
|
@@ -145,7 +148,7 @@ export function ChatPanel() {
|
|
| 145 |
updatePendingMessage(tempId, { pendingStatus: 'failed' })
|
| 146 |
}
|
| 147 |
} catch (err) {
|
| 148 |
-
|
| 149 |
updatePendingMessage(tempId, { pendingStatus: 'failed' })
|
| 150 |
}
|
| 151 |
}
|
|
|
|
| 3 |
import { useEffect, useCallback, useState, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
import { ConversationList } from './conversation-list'
|
| 8 |
import { MessageList } from './message-list'
|
| 9 |
import { ChatInput } from './chat-input'
|
| 10 |
|
| 11 |
+
const log = createClientLogger('ChatPanel')
|
| 12 |
+
|
| 13 |
export function ChatPanel() {
|
| 14 |
const {
|
| 15 |
chatPanelOpen,
|
|
|
|
| 55 |
const data = await res.json()
|
| 56 |
if (data.agents) setAgents(data.agents)
|
| 57 |
} catch (err) {
|
| 58 |
+
log.error('Failed to load agents:', err)
|
| 59 |
}
|
| 60 |
}
|
| 61 |
if (chatPanelOpen) loadAgents()
|
|
|
|
| 70 |
const data = await res.json()
|
| 71 |
if (data.messages) setChatMessages(data.messages)
|
| 72 |
} catch (err) {
|
| 73 |
+
log.error('Failed to load messages:', err)
|
| 74 |
}
|
| 75 |
}, [activeConversation, setChatMessages])
|
| 76 |
|
|
|
|
| 148 |
updatePendingMessage(tempId, { pendingStatus: 'failed' })
|
| 149 |
}
|
| 150 |
} catch (err) {
|
| 151 |
+
log.error('Failed to send message:', err)
|
| 152 |
updatePendingMessage(tempId, { pendingStatus: 'failed' })
|
| 153 |
}
|
| 154 |
}
|
src/components/chat/conversation-list.tsx
CHANGED
|
@@ -3,6 +3,9 @@
|
|
| 3 |
import { useState, useCallback } from 'react'
|
| 4 |
import { useMissionControl, Conversation, Agent } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
function timeAgo(timestamp: number): string {
|
| 8 |
const diff = Math.floor(Date.now() / 1000) - timestamp
|
|
@@ -64,7 +67,7 @@ export function ConversationList({ onNewConversation }: ConversationListProps) {
|
|
| 64 |
)
|
| 65 |
}
|
| 66 |
} catch (err) {
|
| 67 |
-
|
| 68 |
}
|
| 69 |
}, [setConversations])
|
| 70 |
|
|
|
|
| 3 |
import { useState, useCallback } from 'react'
|
| 4 |
import { useMissionControl, Conversation, Agent } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
+
|
| 8 |
+
const log = createClientLogger('ConversationList')
|
| 9 |
|
| 10 |
function timeAgo(timestamp: number): string {
|
| 11 |
const diff = Math.floor(Date.now() / 1000) - timestamp
|
|
|
|
| 67 |
)
|
| 68 |
}
|
| 69 |
} catch (err) {
|
| 70 |
+
log.error('Failed to load conversations:', err)
|
| 71 |
}
|
| 72 |
}, [setConversations])
|
| 73 |
|
src/components/dashboard/sidebar.tsx
CHANGED
|
@@ -3,6 +3,9 @@
|
|
| 3 |
import { useEffect, useState } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useNavigateToPanel } from '@/lib/navigation'
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
interface MenuItem {
|
| 8 |
id: string
|
|
@@ -36,7 +39,7 @@ export function Sidebar() {
|
|
| 36 |
fetch('/api/status?action=overview')
|
| 37 |
.then(res => res.json())
|
| 38 |
.then(data => setSystemStats(data))
|
| 39 |
-
.catch(err =>
|
| 40 |
}, [])
|
| 41 |
|
| 42 |
const activeSessions = sessions.filter(s => s.active).length
|
|
|
|
| 3 |
import { useEffect, useState } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useNavigateToPanel } from '@/lib/navigation'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
+
|
| 8 |
+
const log = createClientLogger('Sidebar')
|
| 9 |
|
| 10 |
interface MenuItem {
|
| 11 |
id: string
|
|
|
|
| 39 |
fetch('/api/status?action=overview')
|
| 40 |
.then(res => res.json())
|
| 41 |
.then(data => setSystemStats(data))
|
| 42 |
+
.catch(err => log.error('Failed to fetch system status:', err))
|
| 43 |
}, [])
|
| 44 |
|
| 45 |
const activeSessions = sessions.filter(s => s.active).length
|
src/components/panels/agent-cost-panel.tsx
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
|
|
|
| 4 |
import {
|
| 5 |
PieChart, Pie, Cell, LineChart, Line, XAxis, YAxis, CartesianGrid,
|
| 6 |
Tooltip, Legend, ResponsiveContainer,
|
| 7 |
} from 'recharts'
|
| 8 |
|
|
|
|
|
|
|
| 9 |
interface AgentCostData {
|
| 10 |
stats: { totalTokens: number; totalCost: number; requestCount: number; avgTokensPerRequest: number; avgCostPerRequest: number }
|
| 11 |
models: Record<string, { totalTokens: number; totalCost: number; requestCount: number }>
|
|
@@ -34,7 +37,7 @@ export function AgentCostPanel() {
|
|
| 34 |
const json = await res.json()
|
| 35 |
setData(json)
|
| 36 |
} catch (err) {
|
| 37 |
-
|
| 38 |
} finally {
|
| 39 |
setIsLoading(false)
|
| 40 |
}
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
import {
|
| 6 |
PieChart, Pie, Cell, LineChart, Line, XAxis, YAxis, CartesianGrid,
|
| 7 |
Tooltip, Legend, ResponsiveContainer,
|
| 8 |
} from 'recharts'
|
| 9 |
|
| 10 |
+
const log = createClientLogger('AgentCostPanel')
|
| 11 |
+
|
| 12 |
interface AgentCostData {
|
| 13 |
stats: { totalTokens: number; totalCost: number; requestCount: number; avgTokensPerRequest: number; avgCostPerRequest: number }
|
| 14 |
models: Record<string, { totalTokens: number; totalCost: number; requestCount: number }>
|
|
|
|
| 37 |
const json = await res.json()
|
| 38 |
setData(json)
|
| 39 |
} catch (err) {
|
| 40 |
+
log.error('Failed to load agent costs:', err)
|
| 41 |
} finally {
|
| 42 |
setIsLoading(false)
|
| 43 |
}
|
src/components/panels/agent-detail-tabs.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
interface Agent {
|
| 6 |
id: number
|
|
@@ -373,7 +376,7 @@ export function SoulTab({
|
|
| 373 |
setSelectedTemplate(templateName)
|
| 374 |
}
|
| 375 |
} catch (error) {
|
| 376 |
-
|
| 377 |
}
|
| 378 |
}
|
| 379 |
|
|
@@ -620,7 +623,7 @@ export function TasksTab({ agent }: { agent: Agent }) {
|
|
| 620 |
setTasks(data.tasks || [])
|
| 621 |
}
|
| 622 |
} catch (error) {
|
| 623 |
-
|
| 624 |
} finally {
|
| 625 |
setLoading(false)
|
| 626 |
}
|
|
@@ -713,7 +716,7 @@ export function ActivityTab({ agent }: { agent: Agent }) {
|
|
| 713 |
setActivities(data.activities || [])
|
| 714 |
}
|
| 715 |
} catch (error) {
|
| 716 |
-
|
| 717 |
} finally {
|
| 718 |
setLoading(false)
|
| 719 |
}
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
+
|
| 6 |
+
const log = createClientLogger('AgentDetailTabs')
|
| 7 |
|
| 8 |
interface Agent {
|
| 9 |
id: number
|
|
|
|
| 376 |
setSelectedTemplate(templateName)
|
| 377 |
}
|
| 378 |
} catch (error) {
|
| 379 |
+
log.error('Failed to load template:', error)
|
| 380 |
}
|
| 381 |
}
|
| 382 |
|
|
|
|
| 623 |
setTasks(data.tasks || [])
|
| 624 |
}
|
| 625 |
} catch (error) {
|
| 626 |
+
log.error('Failed to fetch tasks:', error)
|
| 627 |
} finally {
|
| 628 |
setLoading(false)
|
| 629 |
}
|
|
|
|
| 716 |
setActivities(data.activities || [])
|
| 717 |
}
|
| 718 |
} catch (error) {
|
| 719 |
+
log.error('Failed to fetch activities:', error)
|
| 720 |
} finally {
|
| 721 |
setLoading(false)
|
| 722 |
}
|
src/components/panels/agent-spawn-panel.tsx
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
interface SpawnFormData {
|
| 7 |
task: string
|
|
@@ -33,7 +36,7 @@ export function AgentSpawnPanel() {
|
|
| 33 |
fetch('/api/spawn')
|
| 34 |
.then(res => res.json())
|
| 35 |
.then(data => setSpawnHistory(data.history || []))
|
| 36 |
-
.catch(err =>
|
| 37 |
}, [])
|
| 38 |
|
| 39 |
const handleSpawn = async () => {
|
|
@@ -95,7 +98,7 @@ export function AgentSpawnPanel() {
|
|
| 95 |
})
|
| 96 |
}
|
| 97 |
} catch (error) {
|
| 98 |
-
|
| 99 |
updateSpawnRequest(spawnId, {
|
| 100 |
status: 'failed',
|
| 101 |
error: error instanceof Error ? error.message : 'Network error'
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
+
|
| 7 |
+
const log = createClientLogger('AgentSpawnPanel')
|
| 8 |
|
| 9 |
interface SpawnFormData {
|
| 10 |
task: string
|
|
|
|
| 36 |
fetch('/api/spawn')
|
| 37 |
.then(res => res.json())
|
| 38 |
.then(data => setSpawnHistory(data.history || []))
|
| 39 |
+
.catch(err => log.error('Failed to load spawn history:', err))
|
| 40 |
}, [])
|
| 41 |
|
| 42 |
const handleSpawn = async () => {
|
|
|
|
| 98 |
})
|
| 99 |
}
|
| 100 |
} catch (error) {
|
| 101 |
+
log.error('Spawn error:', error)
|
| 102 |
updateSpawnRequest(spawnId, {
|
| 103 |
status: 'failed',
|
| 104 |
error: error instanceof Error ? error.message : 'Network error'
|
src/components/panels/agent-squad-panel-phase3.tsx
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
| 5 |
import { AgentAvatar } from '@/components/ui/agent-avatar'
|
| 6 |
import {
|
| 7 |
OverviewTab,
|
|
@@ -13,6 +14,8 @@ import {
|
|
| 13 |
CreateAgentModal
|
| 14 |
} from './agent-detail-tabs'
|
| 15 |
|
|
|
|
|
|
|
| 16 |
interface Agent {
|
| 17 |
id: number
|
| 18 |
name: string
|
|
@@ -148,7 +151,7 @@ export function AgentSquadPanelPhase3() {
|
|
| 148 |
: agent
|
| 149 |
))
|
| 150 |
} catch (error) {
|
| 151 |
-
|
| 152 |
setError('Failed to update agent status')
|
| 153 |
}
|
| 154 |
}
|
|
@@ -171,7 +174,7 @@ export function AgentSquadPanelPhase3() {
|
|
| 171 |
|
| 172 |
await updateAgentStatus(agentName, 'idle', 'Manually woken via session')
|
| 173 |
} catch (error) {
|
| 174 |
-
|
| 175 |
setError('Failed to wake agent')
|
| 176 |
}
|
| 177 |
}
|
|
@@ -503,7 +506,7 @@ function AgentDetailModalPhase3({
|
|
| 503 |
setSoulTemplates(data.templates || [])
|
| 504 |
}
|
| 505 |
} catch (error) {
|
| 506 |
-
|
| 507 |
}
|
| 508 |
}
|
| 509 |
|
|
@@ -522,7 +525,7 @@ function AgentDetailModalPhase3({
|
|
| 522 |
setHeartbeatData(data)
|
| 523 |
}
|
| 524 |
} catch (error) {
|
| 525 |
-
|
| 526 |
} finally {
|
| 527 |
setLoadingHeartbeat(false)
|
| 528 |
}
|
|
@@ -544,7 +547,7 @@ function AgentDetailModalPhase3({
|
|
| 544 |
setEditing(false)
|
| 545 |
onUpdate()
|
| 546 |
} catch (error) {
|
| 547 |
-
|
| 548 |
}
|
| 549 |
}
|
| 550 |
|
|
@@ -564,7 +567,7 @@ function AgentDetailModalPhase3({
|
|
| 564 |
setFormData(prev => ({ ...prev, soul_content: content }))
|
| 565 |
onUpdate()
|
| 566 |
} catch (error) {
|
| 567 |
-
|
| 568 |
}
|
| 569 |
}
|
| 570 |
|
|
@@ -585,7 +588,7 @@ function AgentDetailModalPhase3({
|
|
| 585 |
setFormData(prev => ({ ...prev, working_memory: data.working_memory }))
|
| 586 |
onUpdate()
|
| 587 |
} catch (error) {
|
| 588 |
-
|
| 589 |
}
|
| 590 |
}
|
| 591 |
|
|
@@ -746,7 +749,7 @@ function QuickSpawnModal({
|
|
| 746 |
alert(result.error || 'Failed to spawn agent')
|
| 747 |
}
|
| 748 |
} catch (error) {
|
| 749 |
-
|
| 750 |
alert('Network error occurred')
|
| 751 |
} finally {
|
| 752 |
setIsSpawning(false)
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
import { AgentAvatar } from '@/components/ui/agent-avatar'
|
| 7 |
import {
|
| 8 |
OverviewTab,
|
|
|
|
| 14 |
CreateAgentModal
|
| 15 |
} from './agent-detail-tabs'
|
| 16 |
|
| 17 |
+
const log = createClientLogger('AgentSquadPhase3')
|
| 18 |
+
|
| 19 |
interface Agent {
|
| 20 |
id: number
|
| 21 |
name: string
|
|
|
|
| 151 |
: agent
|
| 152 |
))
|
| 153 |
} catch (error) {
|
| 154 |
+
log.error('Failed to update agent status:', error)
|
| 155 |
setError('Failed to update agent status')
|
| 156 |
}
|
| 157 |
}
|
|
|
|
| 174 |
|
| 175 |
await updateAgentStatus(agentName, 'idle', 'Manually woken via session')
|
| 176 |
} catch (error) {
|
| 177 |
+
log.error('Failed to wake agent:', error)
|
| 178 |
setError('Failed to wake agent')
|
| 179 |
}
|
| 180 |
}
|
|
|
|
| 506 |
setSoulTemplates(data.templates || [])
|
| 507 |
}
|
| 508 |
} catch (error) {
|
| 509 |
+
log.error('Failed to load SOUL templates:', error)
|
| 510 |
}
|
| 511 |
}
|
| 512 |
|
|
|
|
| 525 |
setHeartbeatData(data)
|
| 526 |
}
|
| 527 |
} catch (error) {
|
| 528 |
+
log.error('Failed to perform heartbeat:', error)
|
| 529 |
} finally {
|
| 530 |
setLoadingHeartbeat(false)
|
| 531 |
}
|
|
|
|
| 547 |
setEditing(false)
|
| 548 |
onUpdate()
|
| 549 |
} catch (error) {
|
| 550 |
+
log.error('Failed to update agent:', error)
|
| 551 |
}
|
| 552 |
}
|
| 553 |
|
|
|
|
| 567 |
setFormData(prev => ({ ...prev, soul_content: content }))
|
| 568 |
onUpdate()
|
| 569 |
} catch (error) {
|
| 570 |
+
log.error('Failed to update SOUL:', error)
|
| 571 |
}
|
| 572 |
}
|
| 573 |
|
|
|
|
| 588 |
setFormData(prev => ({ ...prev, working_memory: data.working_memory }))
|
| 589 |
onUpdate()
|
| 590 |
} catch (error) {
|
| 591 |
+
log.error('Failed to update memory:', error)
|
| 592 |
}
|
| 593 |
}
|
| 594 |
|
|
|
|
| 749 |
alert(result.error || 'Failed to spawn agent')
|
| 750 |
}
|
| 751 |
} catch (error) {
|
| 752 |
+
log.error('Spawn failed:', error)
|
| 753 |
alert('Network error occurred')
|
| 754 |
} finally {
|
| 755 |
setIsSpawning(false)
|
src/components/panels/agent-squad-panel.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
interface Agent {
|
| 6 |
id: number
|
|
@@ -103,7 +106,7 @@ export function AgentSquadPanel() {
|
|
| 103 |
: agent
|
| 104 |
))
|
| 105 |
} catch (error) {
|
| 106 |
-
|
| 107 |
setError('Failed to update agent status')
|
| 108 |
}
|
| 109 |
}
|
|
@@ -355,7 +358,7 @@ function AgentDetailModal({
|
|
| 355 |
setEditing(false)
|
| 356 |
onUpdate()
|
| 357 |
} catch (error) {
|
| 358 |
-
|
| 359 |
}
|
| 360 |
}
|
| 361 |
|
|
@@ -540,7 +543,7 @@ function CreateAgentModal({
|
|
| 540 |
onCreated()
|
| 541 |
onClose()
|
| 542 |
} catch (error) {
|
| 543 |
-
|
| 544 |
}
|
| 545 |
}
|
| 546 |
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
+
|
| 6 |
+
const log = createClientLogger('AgentSquadPanel')
|
| 7 |
|
| 8 |
interface Agent {
|
| 9 |
id: number
|
|
|
|
| 106 |
: agent
|
| 107 |
))
|
| 108 |
} catch (error) {
|
| 109 |
+
log.error('Failed to update agent status:', error)
|
| 110 |
setError('Failed to update agent status')
|
| 111 |
}
|
| 112 |
}
|
|
|
|
| 358 |
setEditing(false)
|
| 359 |
onUpdate()
|
| 360 |
} catch (error) {
|
| 361 |
+
log.error('Failed to update agent:', error)
|
| 362 |
}
|
| 363 |
}
|
| 364 |
|
|
|
|
| 543 |
onCreated()
|
| 544 |
onClose()
|
| 545 |
} catch (error) {
|
| 546 |
+
log.error('Error creating agent:', error)
|
| 547 |
}
|
| 548 |
}
|
| 549 |
|
src/components/panels/cron-management-panel.tsx
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl, CronJob } from '@/store'
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
interface NewJobForm {
|
| 7 |
name: string
|
|
@@ -90,7 +93,7 @@ export function CronManagementPanel() {
|
|
| 90 |
const data = await response.json()
|
| 91 |
setCronJobs(data.jobs || [])
|
| 92 |
} catch (error) {
|
| 93 |
-
|
| 94 |
} finally {
|
| 95 |
setIsLoading(false)
|
| 96 |
}
|
|
@@ -124,7 +127,7 @@ export function CronManagementPanel() {
|
|
| 124 |
const data = await response.json()
|
| 125 |
setJobLogs(data.logs || [])
|
| 126 |
} catch (error) {
|
| 127 |
-
|
| 128 |
setJobLogs([])
|
| 129 |
}
|
| 130 |
}
|
|
@@ -148,7 +151,7 @@ export function CronManagementPanel() {
|
|
| 148 |
alert(`Failed to toggle job: ${error.error}`)
|
| 149 |
}
|
| 150 |
} catch (error) {
|
| 151 |
-
|
| 152 |
alert('Network error occurred')
|
| 153 |
}
|
| 154 |
}
|
|
@@ -173,7 +176,7 @@ export function CronManagementPanel() {
|
|
| 173 |
alert(`Job failed:\n${result.error}\n${result.stderr}`)
|
| 174 |
}
|
| 175 |
} catch (error) {
|
| 176 |
-
|
| 177 |
alert('Network error occurred')
|
| 178 |
}
|
| 179 |
}
|
|
@@ -212,7 +215,7 @@ export function CronManagementPanel() {
|
|
| 212 |
alert(`Failed to add job: ${error.error}`)
|
| 213 |
}
|
| 214 |
} catch (error) {
|
| 215 |
-
|
| 216 |
alert('Network error occurred')
|
| 217 |
}
|
| 218 |
}
|
|
@@ -242,7 +245,7 @@ export function CronManagementPanel() {
|
|
| 242 |
alert(`Failed to remove job: ${error.error}`)
|
| 243 |
}
|
| 244 |
} catch (error) {
|
| 245 |
-
|
| 246 |
alert('Network error occurred')
|
| 247 |
}
|
| 248 |
}
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl, CronJob } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
+
|
| 7 |
+
const log = createClientLogger('CronManagement')
|
| 8 |
|
| 9 |
interface NewJobForm {
|
| 10 |
name: string
|
|
|
|
| 93 |
const data = await response.json()
|
| 94 |
setCronJobs(data.jobs || [])
|
| 95 |
} catch (error) {
|
| 96 |
+
log.error('Failed to load cron jobs:', error)
|
| 97 |
} finally {
|
| 98 |
setIsLoading(false)
|
| 99 |
}
|
|
|
|
| 127 |
const data = await response.json()
|
| 128 |
setJobLogs(data.logs || [])
|
| 129 |
} catch (error) {
|
| 130 |
+
log.error('Failed to load job logs:', error)
|
| 131 |
setJobLogs([])
|
| 132 |
}
|
| 133 |
}
|
|
|
|
| 151 |
alert(`Failed to toggle job: ${error.error}`)
|
| 152 |
}
|
| 153 |
} catch (error) {
|
| 154 |
+
log.error('Failed to toggle job:', error)
|
| 155 |
alert('Network error occurred')
|
| 156 |
}
|
| 157 |
}
|
|
|
|
| 176 |
alert(`Job failed:\n${result.error}\n${result.stderr}`)
|
| 177 |
}
|
| 178 |
} catch (error) {
|
| 179 |
+
log.error('Failed to trigger job:', error)
|
| 180 |
alert('Network error occurred')
|
| 181 |
}
|
| 182 |
}
|
|
|
|
| 215 |
alert(`Failed to add job: ${error.error}`)
|
| 216 |
}
|
| 217 |
} catch (error) {
|
| 218 |
+
log.error('Failed to add job:', error)
|
| 219 |
alert('Network error occurred')
|
| 220 |
}
|
| 221 |
}
|
|
|
|
| 245 |
alert(`Failed to remove job: ${error.error}`)
|
| 246 |
}
|
| 247 |
} catch (error) {
|
| 248 |
+
log.error('Failed to remove job:', error)
|
| 249 |
alert('Network error occurred')
|
| 250 |
}
|
| 251 |
}
|
src/components/panels/log-viewer-panel.tsx
CHANGED
|
@@ -3,6 +3,9 @@
|
|
| 3 |
import { useState, useEffect, useRef, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
interface LogFilters {
|
| 8 |
level?: string
|
|
@@ -36,7 +39,7 @@ export function LogViewerPanel() {
|
|
| 36 |
}, [logFilters])
|
| 37 |
|
| 38 |
const loadLogs = useCallback(async (tail = false) => {
|
| 39 |
-
|
| 40 |
setIsLoading(!tail) // Only show loading for initial load, not for tailing
|
| 41 |
|
| 42 |
try {
|
|
@@ -53,37 +56,37 @@ export function LogViewerPanel() {
|
|
| 53 |
...(tail && currentLogs.length > 0 && { since: currentLogs[0]?.timestamp.toString() })
|
| 54 |
})
|
| 55 |
|
| 56 |
-
|
| 57 |
const response = await fetch(`/api/logs?${params}`)
|
| 58 |
const data = await response.json()
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
if (data.logs && data.logs.length > 0) {
|
| 63 |
if (tail) {
|
| 64 |
// Add new logs for tail mode - prepend to existing logs
|
| 65 |
let newLogsAdded = 0
|
| 66 |
const existingIds = new Set((currentLogs || []).map((l: any) => l?.id).filter(Boolean))
|
| 67 |
-
data.logs.reverse().forEach((
|
| 68 |
-
if (existingIds.has(
|
| 69 |
-
addLog(
|
| 70 |
newLogsAdded++
|
| 71 |
})
|
| 72 |
-
|
| 73 |
} else {
|
| 74 |
// Replace logs for initial load or refresh
|
| 75 |
-
|
| 76 |
clearLogs() // Clear existing logs
|
| 77 |
-
data.logs.reverse().forEach((
|
| 78 |
-
addLog(
|
| 79 |
})
|
| 80 |
-
|
| 81 |
}
|
| 82 |
} else {
|
| 83 |
-
|
| 84 |
}
|
| 85 |
} catch (error) {
|
| 86 |
-
|
| 87 |
} finally {
|
| 88 |
setIsLoading(false)
|
| 89 |
}
|
|
@@ -95,13 +98,13 @@ export function LogViewerPanel() {
|
|
| 95 |
const data = await response.json()
|
| 96 |
setAvailableSources(data.sources || [])
|
| 97 |
} catch (error) {
|
| 98 |
-
|
| 99 |
}
|
| 100 |
}, [])
|
| 101 |
|
| 102 |
// Load initial logs and sources
|
| 103 |
useEffect(() => {
|
| 104 |
-
|
| 105 |
loadLogs()
|
| 106 |
loadSources()
|
| 107 |
}, [loadLogs, loadSources])
|
|
@@ -154,16 +157,16 @@ export function LogViewerPanel() {
|
|
| 154 |
}
|
| 155 |
}
|
| 156 |
|
| 157 |
-
const filteredLogs = logs.filter(
|
| 158 |
-
if (logFilters.level &&
|
| 159 |
-
if (logFilters.source &&
|
| 160 |
-
if (logFilters.search && !
|
| 161 |
-
if (logFilters.session && (!
|
| 162 |
return true
|
| 163 |
})
|
| 164 |
|
| 165 |
// Debug logging
|
| 166 |
-
|
| 167 |
|
| 168 |
return (
|
| 169 |
<div className="flex flex-col h-full p-6 space-y-4">
|
|
|
|
| 3 |
import { useState, useEffect, useRef, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
+
|
| 8 |
+
const log = createClientLogger('LogViewer')
|
| 9 |
|
| 10 |
interface LogFilters {
|
| 11 |
level?: string
|
|
|
|
| 39 |
}, [logFilters])
|
| 40 |
|
| 41 |
const loadLogs = useCallback(async (tail = false) => {
|
| 42 |
+
log.debug(`Loading logs (tail=${tail})`)
|
| 43 |
setIsLoading(!tail) // Only show loading for initial load, not for tailing
|
| 44 |
|
| 45 |
try {
|
|
|
|
| 56 |
...(tail && currentLogs.length > 0 && { since: currentLogs[0]?.timestamp.toString() })
|
| 57 |
})
|
| 58 |
|
| 59 |
+
log.debug(`Fetching /api/logs?${params}`)
|
| 60 |
const response = await fetch(`/api/logs?${params}`)
|
| 61 |
const data = await response.json()
|
| 62 |
|
| 63 |
+
log.debug(`Received ${data.logs?.length || 0} logs from API`)
|
| 64 |
|
| 65 |
if (data.logs && data.logs.length > 0) {
|
| 66 |
if (tail) {
|
| 67 |
// Add new logs for tail mode - prepend to existing logs
|
| 68 |
let newLogsAdded = 0
|
| 69 |
const existingIds = new Set((currentLogs || []).map((l: any) => l?.id).filter(Boolean))
|
| 70 |
+
data.logs.reverse().forEach((entry: any) => {
|
| 71 |
+
if (existingIds.has(entry?.id)) return
|
| 72 |
+
addLog(entry)
|
| 73 |
newLogsAdded++
|
| 74 |
})
|
| 75 |
+
log.debug(`Added ${newLogsAdded} new logs (tail mode)`)
|
| 76 |
} else {
|
| 77 |
// Replace logs for initial load or refresh
|
| 78 |
+
log.debug(`Clearing existing logs and loading ${data.logs.length} logs`)
|
| 79 |
clearLogs() // Clear existing logs
|
| 80 |
+
data.logs.reverse().forEach((entry: any) => {
|
| 81 |
+
addLog(entry)
|
| 82 |
})
|
| 83 |
+
log.debug(`Successfully added ${data.logs.length} logs to store`)
|
| 84 |
}
|
| 85 |
} else {
|
| 86 |
+
log.debug('No logs received from API')
|
| 87 |
}
|
| 88 |
} catch (error) {
|
| 89 |
+
log.error('Failed to load logs:', error)
|
| 90 |
} finally {
|
| 91 |
setIsLoading(false)
|
| 92 |
}
|
|
|
|
| 98 |
const data = await response.json()
|
| 99 |
setAvailableSources(data.sources || [])
|
| 100 |
} catch (error) {
|
| 101 |
+
log.error('Failed to load log sources:', error)
|
| 102 |
}
|
| 103 |
}, [])
|
| 104 |
|
| 105 |
// Load initial logs and sources
|
| 106 |
useEffect(() => {
|
| 107 |
+
log.debug('Initial load started')
|
| 108 |
loadLogs()
|
| 109 |
loadSources()
|
| 110 |
}, [loadLogs, loadSources])
|
|
|
|
| 157 |
}
|
| 158 |
}
|
| 159 |
|
| 160 |
+
const filteredLogs = logs.filter(entry => {
|
| 161 |
+
if (logFilters.level && entry.level !== logFilters.level) return false
|
| 162 |
+
if (logFilters.source && entry.source !== logFilters.source) return false
|
| 163 |
+
if (logFilters.search && !entry.message.toLowerCase().includes(logFilters.search.toLowerCase())) return false
|
| 164 |
+
if (logFilters.session && (!entry.session || !entry.session.includes(logFilters.session))) return false
|
| 165 |
return true
|
| 166 |
})
|
| 167 |
|
| 168 |
// Debug logging
|
| 169 |
+
log.debug(`Store has ${logs.length} logs, filtered to ${filteredLogs.length}`)
|
| 170 |
|
| 171 |
return (
|
| 172 |
<div className="flex flex-col h-full p-6 space-y-4">
|
src/components/panels/memory-browser-panel.tsx
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
|
| 3 |
import React, { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
interface MemoryFile {
|
| 7 |
path: string
|
|
@@ -46,7 +49,7 @@ export function MemoryBrowserPanel() {
|
|
| 46 |
// Auto-expand some common directories
|
| 47 |
setExpandedFolders(new Set(['daily', 'knowledge']))
|
| 48 |
} catch (error) {
|
| 49 |
-
|
| 50 |
} finally {
|
| 51 |
setIsLoading(false)
|
| 52 |
}
|
|
@@ -83,7 +86,7 @@ export function MemoryBrowserPanel() {
|
|
| 83 |
alert(data.error || 'Failed to load file content')
|
| 84 |
}
|
| 85 |
} catch (error) {
|
| 86 |
-
|
| 87 |
alert('Network error occurred')
|
| 88 |
} finally {
|
| 89 |
setIsLoading(false)
|
|
@@ -99,7 +102,7 @@ export function MemoryBrowserPanel() {
|
|
| 99 |
const data = await response.json()
|
| 100 |
setSearchResults(data.results || [])
|
| 101 |
} catch (error) {
|
| 102 |
-
|
| 103 |
setSearchResults([])
|
| 104 |
} finally {
|
| 105 |
setIsSearching(false)
|
|
@@ -165,7 +168,7 @@ export function MemoryBrowserPanel() {
|
|
| 165 |
alert(data.error || 'Failed to save file')
|
| 166 |
}
|
| 167 |
} catch (error) {
|
| 168 |
-
|
| 169 |
alert('Network error occurred')
|
| 170 |
} finally {
|
| 171 |
setIsSaving(false)
|
|
@@ -192,7 +195,7 @@ export function MemoryBrowserPanel() {
|
|
| 192 |
alert(data.error || 'Failed to create file')
|
| 193 |
}
|
| 194 |
} catch (error) {
|
| 195 |
-
|
| 196 |
alert('Network error occurred')
|
| 197 |
}
|
| 198 |
}
|
|
@@ -220,7 +223,7 @@ export function MemoryBrowserPanel() {
|
|
| 220 |
alert(data.error || 'Failed to delete file')
|
| 221 |
}
|
| 222 |
} catch (error) {
|
| 223 |
-
|
| 224 |
alert('Network error occurred')
|
| 225 |
}
|
| 226 |
}
|
|
|
|
| 2 |
|
| 3 |
import React, { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
+
|
| 7 |
+
const log = createClientLogger('MemoryBrowser')
|
| 8 |
|
| 9 |
interface MemoryFile {
|
| 10 |
path: string
|
|
|
|
| 49 |
// Auto-expand some common directories
|
| 50 |
setExpandedFolders(new Set(['daily', 'knowledge']))
|
| 51 |
} catch (error) {
|
| 52 |
+
log.error('Failed to load file tree:', error)
|
| 53 |
} finally {
|
| 54 |
setIsLoading(false)
|
| 55 |
}
|
|
|
|
| 86 |
alert(data.error || 'Failed to load file content')
|
| 87 |
}
|
| 88 |
} catch (error) {
|
| 89 |
+
log.error('Failed to load file content:', error)
|
| 90 |
alert('Network error occurred')
|
| 91 |
} finally {
|
| 92 |
setIsLoading(false)
|
|
|
|
| 102 |
const data = await response.json()
|
| 103 |
setSearchResults(data.results || [])
|
| 104 |
} catch (error) {
|
| 105 |
+
log.error('Search failed:', error)
|
| 106 |
setSearchResults([])
|
| 107 |
} finally {
|
| 108 |
setIsSearching(false)
|
|
|
|
| 168 |
alert(data.error || 'Failed to save file')
|
| 169 |
}
|
| 170 |
} catch (error) {
|
| 171 |
+
log.error('Failed to save file:', error)
|
| 172 |
alert('Network error occurred')
|
| 173 |
} finally {
|
| 174 |
setIsSaving(false)
|
|
|
|
| 195 |
alert(data.error || 'Failed to create file')
|
| 196 |
}
|
| 197 |
} catch (error) {
|
| 198 |
+
log.error('Failed to create file:', error)
|
| 199 |
alert('Network error occurred')
|
| 200 |
}
|
| 201 |
}
|
|
|
|
| 223 |
alert(data.error || 'Failed to delete file')
|
| 224 |
}
|
| 225 |
} catch (error) {
|
| 226 |
+
log.error('Failed to delete file:', error)
|
| 227 |
alert('Network error occurred')
|
| 228 |
}
|
| 229 |
}
|
src/components/panels/session-details-panel.tsx
CHANGED
|
@@ -3,6 +3,9 @@
|
|
| 3 |
import { useState, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
export function SessionDetailsPanel() {
|
| 8 |
const {
|
|
@@ -20,7 +23,7 @@ export function SessionDetailsPanel() {
|
|
| 20 |
const data = await response.json()
|
| 21 |
setSessions(data.sessions || data)
|
| 22 |
} catch (error) {
|
| 23 |
-
|
| 24 |
}
|
| 25 |
}, [setSessions])
|
| 26 |
|
|
|
|
| 3 |
import { useState, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
+
|
| 8 |
+
const log = createClientLogger('SessionDetails')
|
| 9 |
|
| 10 |
export function SessionDetailsPanel() {
|
| 11 |
const {
|
|
|
|
| 23 |
const data = await response.json()
|
| 24 |
setSessions(data.sessions || data)
|
| 25 |
} catch (error) {
|
| 26 |
+
log.error('Failed to load sessions:', error)
|
| 27 |
}
|
| 28 |
}, [setSessions])
|
| 29 |
|
src/components/panels/standup-panel.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
interface StandupReport {
|
| 6 |
date: string
|
|
@@ -133,7 +136,7 @@ export function StandupPanel() {
|
|
| 133 |
const data = await response.json()
|
| 134 |
setStandupHistory(data.history || [])
|
| 135 |
} catch (err) {
|
| 136 |
-
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
+
|
| 6 |
+
const log = createClientLogger('StandupPanel')
|
| 7 |
|
| 8 |
interface StandupReport {
|
| 9 |
date: string
|
|
|
|
| 136 |
const data = await response.json()
|
| 137 |
setStandupHistory(data.history || [])
|
| 138 |
} catch (err) {
|
| 139 |
+
log.error('Failed to fetch standup history:', err)
|
| 140 |
}
|
| 141 |
}
|
| 142 |
|
src/components/panels/task-board-panel.tsx
CHANGED
|
@@ -3,9 +3,12 @@
|
|
| 3 |
import { useState, useEffect, useCallback, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
| 6 |
import { AgentAvatar } from '@/components/ui/agent-avatar'
|
| 7 |
import { MarkdownRenderer } from '@/components/markdown-renderer'
|
| 8 |
|
|
|
|
|
|
|
| 9 |
interface Task {
|
| 10 |
id: number
|
| 11 |
title: string
|
|
@@ -869,7 +872,7 @@ function CreateTaskModal({
|
|
| 869 |
onCreated()
|
| 870 |
onClose()
|
| 871 |
} catch (error) {
|
| 872 |
-
|
| 873 |
}
|
| 874 |
}
|
| 875 |
|
|
@@ -1011,7 +1014,7 @@ function EditTaskModal({
|
|
| 1011 |
|
| 1012 |
onUpdated()
|
| 1013 |
} catch (error) {
|
| 1014 |
-
|
| 1015 |
}
|
| 1016 |
}
|
| 1017 |
|
|
|
|
| 3 |
import { useState, useEffect, useCallback, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
import { AgentAvatar } from '@/components/ui/agent-avatar'
|
| 8 |
import { MarkdownRenderer } from '@/components/markdown-renderer'
|
| 9 |
|
| 10 |
+
const log = createClientLogger('TaskBoard')
|
| 11 |
+
|
| 12 |
interface Task {
|
| 13 |
id: number
|
| 14 |
title: string
|
|
|
|
| 872 |
onCreated()
|
| 873 |
onClose()
|
| 874 |
} catch (error) {
|
| 875 |
+
log.error('Error creating task:', error)
|
| 876 |
}
|
| 877 |
}
|
| 878 |
|
|
|
|
| 1014 |
|
| 1015 |
onUpdated()
|
| 1016 |
} catch (error) {
|
| 1017 |
+
log.error('Error updating task:', error)
|
| 1018 |
}
|
| 1019 |
}
|
| 1020 |
|
src/components/panels/token-dashboard-panel.tsx
CHANGED
|
@@ -2,8 +2,11 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
|
|
|
| 5 |
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, BarChart, Bar, PieChart, Pie, Cell } from 'recharts'
|
| 6 |
|
|
|
|
|
|
|
| 7 |
interface UsageStats {
|
| 8 |
summary: {
|
| 9 |
totalTokens: number
|
|
@@ -39,7 +42,7 @@ export function TokenDashboardPanel() {
|
|
| 39 |
const data = await response.json()
|
| 40 |
setUsageStats(data)
|
| 41 |
} catch (error) {
|
| 42 |
-
|
| 43 |
} finally {
|
| 44 |
setIsLoading(false)
|
| 45 |
}
|
|
@@ -51,7 +54,7 @@ export function TokenDashboardPanel() {
|
|
| 51 |
const data = await response.json()
|
| 52 |
setTrendData(data)
|
| 53 |
} catch (error) {
|
| 54 |
-
|
| 55 |
}
|
| 56 |
}, [selectedTimeframe])
|
| 57 |
|
|
@@ -80,7 +83,7 @@ export function TokenDashboardPanel() {
|
|
| 80 |
window.URL.revokeObjectURL(url)
|
| 81 |
document.body.removeChild(a)
|
| 82 |
} catch (error) {
|
| 83 |
-
|
| 84 |
alert('Export failed: ' + error)
|
| 85 |
} finally {
|
| 86 |
setIsExporting(false)
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, BarChart, Bar, PieChart, Pie, Cell } from 'recharts'
|
| 7 |
|
| 8 |
+
const log = createClientLogger('TokenDashboard')
|
| 9 |
+
|
| 10 |
interface UsageStats {
|
| 11 |
summary: {
|
| 12 |
totalTokens: number
|
|
|
|
| 42 |
const data = await response.json()
|
| 43 |
setUsageStats(data)
|
| 44 |
} catch (error) {
|
| 45 |
+
log.error('Failed to load usage stats:', error)
|
| 46 |
} finally {
|
| 47 |
setIsLoading(false)
|
| 48 |
}
|
|
|
|
| 54 |
const data = await response.json()
|
| 55 |
setTrendData(data)
|
| 56 |
} catch (error) {
|
| 57 |
+
log.error('Failed to load trend data:', error)
|
| 58 |
}
|
| 59 |
}, [selectedTimeframe])
|
| 60 |
|
|
|
|
| 83 |
window.URL.revokeObjectURL(url)
|
| 84 |
document.body.removeChild(a)
|
| 85 |
} catch (error) {
|
| 86 |
+
log.error('Export failed:', error)
|
| 87 |
alert('Export failed: ' + error)
|
| 88 |
} finally {
|
| 89 |
setIsExporting(false)
|
src/lib/client-logger.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Lightweight structured logger for client-side ('use client') components.
|
| 3 |
+
*
|
| 4 |
+
* Mirrors pino's API surface (info/warn/error/debug) so call sites are
|
| 5 |
+
* consistent with the server-side logger in src/lib/logger.ts.
|
| 6 |
+
* In production builds, debug and info messages are suppressed.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error'
|
| 10 |
+
|
| 11 |
+
const LOG_LEVELS: Record<LogLevel, number> = {
|
| 12 |
+
debug: 10,
|
| 13 |
+
info: 20,
|
| 14 |
+
warn: 30,
|
| 15 |
+
error: 40,
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
const minLevel: number =
|
| 19 |
+
process.env.NODE_ENV === 'production' ? LOG_LEVELS.warn : LOG_LEVELS.debug
|
| 20 |
+
|
| 21 |
+
function shouldLog(level: LogLevel): boolean {
|
| 22 |
+
return LOG_LEVELS[level] >= minLevel
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
function formatArgs(
|
| 26 |
+
level: LogLevel,
|
| 27 |
+
module: string,
|
| 28 |
+
msgOrObj: unknown,
|
| 29 |
+
...rest: unknown[]
|
| 30 |
+
): unknown[] {
|
| 31 |
+
const prefix = `[${level.toUpperCase()}] ${module}:`
|
| 32 |
+
if (typeof msgOrObj === 'string') {
|
| 33 |
+
return [prefix, msgOrObj, ...rest]
|
| 34 |
+
}
|
| 35 |
+
return [prefix, msgOrObj, ...rest]
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export interface ClientLogger {
|
| 39 |
+
debug(msg: string, ...args: unknown[]): void
|
| 40 |
+
debug(obj: Record<string, unknown>, msg?: string): void
|
| 41 |
+
info(msg: string, ...args: unknown[]): void
|
| 42 |
+
info(obj: Record<string, unknown>, msg?: string): void
|
| 43 |
+
warn(msg: string, ...args: unknown[]): void
|
| 44 |
+
warn(obj: Record<string, unknown>, msg?: string): void
|
| 45 |
+
error(msg: string, ...args: unknown[]): void
|
| 46 |
+
error(obj: Record<string, unknown>, msg?: string): void
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
export function createClientLogger(module: string): ClientLogger {
|
| 50 |
+
return {
|
| 51 |
+
debug(msgOrObj: unknown, ...rest: unknown[]) {
|
| 52 |
+
if (!shouldLog('debug')) return
|
| 53 |
+
console.debug(...formatArgs('debug', module, msgOrObj, ...rest))
|
| 54 |
+
},
|
| 55 |
+
info(msgOrObj: unknown, ...rest: unknown[]) {
|
| 56 |
+
if (!shouldLog('info')) return
|
| 57 |
+
console.info(...formatArgs('info', module, msgOrObj, ...rest))
|
| 58 |
+
},
|
| 59 |
+
warn(msgOrObj: unknown, ...rest: unknown[]) {
|
| 60 |
+
if (!shouldLog('warn')) return
|
| 61 |
+
console.warn(...formatArgs('warn', module, msgOrObj, ...rest))
|
| 62 |
+
},
|
| 63 |
+
error(msgOrObj: unknown, ...rest: unknown[]) {
|
| 64 |
+
if (!shouldLog('error')) return
|
| 65 |
+
console.error(...formatArgs('error', module, msgOrObj, ...rest))
|
| 66 |
+
},
|
| 67 |
+
}
|
| 68 |
+
}
|
src/lib/device-identity.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
'use client'
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
/**
|
| 4 |
* Ed25519 device identity for OpenClaw gateway protocol v3 challenge-response.
|
| 5 |
*
|
|
@@ -101,7 +105,7 @@ export async function getOrCreateDeviceIdentity(): Promise<DeviceIdentity> {
|
|
| 101 |
}
|
| 102 |
} catch {
|
| 103 |
// Stored key corrupted — regenerate
|
| 104 |
-
|
| 105 |
}
|
| 106 |
}
|
| 107 |
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 4 |
+
|
| 5 |
+
const log = createClientLogger('DeviceIdentity')
|
| 6 |
+
|
| 7 |
/**
|
| 8 |
* Ed25519 device identity for OpenClaw gateway protocol v3 challenge-response.
|
| 9 |
*
|
|
|
|
| 105 |
}
|
| 106 |
} catch {
|
| 107 |
// Stored key corrupted — regenerate
|
| 108 |
+
log.warn('Device identity keys corrupted, regenerating...')
|
| 109 |
}
|
| 110 |
}
|
| 111 |
|
src/lib/use-server-events.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
|
| 3 |
import { useEffect, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
interface ServerEvent {
|
| 7 |
type: string
|
|
@@ -73,7 +76,7 @@ export function useServerEvents() {
|
|
| 73 |
|
| 74 |
const attempts = sseReconnectAttemptsRef.current
|
| 75 |
if (attempts >= SSE_MAX_RECONNECT_ATTEMPTS) {
|
| 76 |
-
|
| 77 |
return
|
| 78 |
}
|
| 79 |
|
|
@@ -82,7 +85,7 @@ export function useServerEvents() {
|
|
| 82 |
const delay = Math.round(base + Math.random() * base * 0.5)
|
| 83 |
sseReconnectAttemptsRef.current = attempts + 1
|
| 84 |
|
| 85 |
-
|
| 86 |
reconnectTimeoutRef.current = setTimeout(() => {
|
| 87 |
if (mounted) connect()
|
| 88 |
}, delay)
|
|
|
|
| 2 |
|
| 3 |
import { useEffect, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
+
|
| 7 |
+
const log = createClientLogger('SSE')
|
| 8 |
|
| 9 |
interface ServerEvent {
|
| 10 |
type: string
|
|
|
|
| 76 |
|
| 77 |
const attempts = sseReconnectAttemptsRef.current
|
| 78 |
if (attempts >= SSE_MAX_RECONNECT_ATTEMPTS) {
|
| 79 |
+
log.error(`Max reconnect attempts (${SSE_MAX_RECONNECT_ATTEMPTS}) reached`)
|
| 80 |
return
|
| 81 |
}
|
| 82 |
|
|
|
|
| 85 |
const delay = Math.round(base + Math.random() * base * 0.5)
|
| 86 |
sseReconnectAttemptsRef.current = attempts + 1
|
| 87 |
|
| 88 |
+
log.warn(`Reconnecting in ${delay}ms (attempt ${attempts + 1}/${SSE_MAX_RECONNECT_ATTEMPTS})`)
|
| 89 |
reconnectTimeoutRef.current = setTimeout(() => {
|
| 90 |
if (mounted) connect()
|
| 91 |
}, delay)
|
src/lib/websocket.ts
CHANGED
|
@@ -10,6 +10,9 @@ import {
|
|
| 10 |
cacheDeviceToken,
|
| 11 |
} from '@/lib/device-identity'
|
| 12 |
import { APP_VERSION } from '@/lib/version'
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
// Gateway protocol version (v3 required by OpenClaw 2026.x)
|
| 15 |
const PROTOCOL_VERSION = 3
|
|
@@ -115,7 +118,7 @@ export function useWebSocket() {
|
|
| 115 |
|
| 116 |
// Check missed pongs
|
| 117 |
if (missedPongsRef.current >= MAX_MISSED_PONGS) {
|
| 118 |
-
|
| 119 |
addLog({
|
| 120 |
id: `heartbeat-${Date.now()}`,
|
| 121 |
timestamp: Date.now(),
|
|
@@ -212,7 +215,7 @@ export function useWebSocket() {
|
|
| 212 |
nonce,
|
| 213 |
}
|
| 214 |
} catch (err) {
|
| 215 |
-
|
| 216 |
}
|
| 217 |
}
|
| 218 |
|
|
@@ -238,7 +241,7 @@ export function useWebSocket() {
|
|
| 238 |
deviceToken: cachedToken || undefined,
|
| 239 |
}
|
| 240 |
}
|
| 241 |
-
|
| 242 |
ws.send(JSON.stringify(connectRequest))
|
| 243 |
}, [])
|
| 244 |
|
|
@@ -248,7 +251,7 @@ export function useWebSocket() {
|
|
| 248 |
|
| 249 |
// Debug logging for development
|
| 250 |
if (process.env.NODE_ENV === 'development') {
|
| 251 |
-
|
| 252 |
}
|
| 253 |
|
| 254 |
switch (message.type) {
|
|
@@ -318,24 +321,24 @@ export function useWebSocket() {
|
|
| 318 |
break
|
| 319 |
|
| 320 |
default:
|
| 321 |
-
|
| 322 |
}
|
| 323 |
}, [setLastMessage, setSessions, addLog, updateSpawnRequest, setCronJobs, addTokenUsage])
|
| 324 |
|
| 325 |
// Handle gateway protocol frames
|
| 326 |
const handleGatewayFrame = useCallback((frame: GatewayFrame, ws: WebSocket) => {
|
| 327 |
-
|
| 328 |
|
| 329 |
// Handle connect challenge
|
| 330 |
if (frame.type === 'event' && frame.event === 'connect.challenge') {
|
| 331 |
-
|
| 332 |
sendConnectHandshake(ws, frame.payload?.nonce)
|
| 333 |
return
|
| 334 |
}
|
| 335 |
|
| 336 |
// Handle connect response (handshake success)
|
| 337 |
if (frame.type === 'res' && frame.ok && !handshakeCompleteRef.current) {
|
| 338 |
-
|
| 339 |
handshakeCompleteRef.current = true
|
| 340 |
reconnectAttemptsRef.current = 0
|
| 341 |
// Cache device token if returned by gateway
|
|
@@ -360,7 +363,7 @@ export function useWebSocket() {
|
|
| 360 |
|
| 361 |
// Handle connect error
|
| 362 |
if (frame.type === 'res' && !frame.ok) {
|
| 363 |
-
|
| 364 |
const rawMessage = frame.error?.message || JSON.stringify(frame.error)
|
| 365 |
const help = getGatewayErrorHelp(rawMessage)
|
| 366 |
const nonRetryable = isNonRetryableGatewayError(rawMessage)
|
|
@@ -509,14 +512,14 @@ export function useWebSocket() {
|
|
| 509 |
wsRef.current = ws
|
| 510 |
|
| 511 |
ws.onopen = () => {
|
| 512 |
-
|
| 513 |
// Don't set isConnected yet - wait for handshake
|
| 514 |
setConnection({
|
| 515 |
url: url.split('?')[0],
|
| 516 |
reconnectAttempts: 0
|
| 517 |
})
|
| 518 |
// Wait for connect.challenge from server
|
| 519 |
-
|
| 520 |
}
|
| 521 |
|
| 522 |
ws.onmessage = (event) => {
|
|
@@ -524,7 +527,7 @@ export function useWebSocket() {
|
|
| 524 |
const frame = JSON.parse(event.data) as GatewayFrame
|
| 525 |
handleGatewayFrame(frame, ws)
|
| 526 |
} catch (error) {
|
| 527 |
-
|
| 528 |
addLog({
|
| 529 |
id: `raw-${Date.now()}`,
|
| 530 |
timestamp: Date.now(),
|
|
@@ -536,7 +539,7 @@ export function useWebSocket() {
|
|
| 536 |
}
|
| 537 |
|
| 538 |
ws.onclose = (event) => {
|
| 539 |
-
|
| 540 |
setConnection({ isConnected: false })
|
| 541 |
handshakeCompleteRef.current = false
|
| 542 |
stopHeartbeat()
|
|
@@ -554,7 +557,7 @@ export function useWebSocket() {
|
|
| 554 |
if (attempts < maxReconnectAttempts) {
|
| 555 |
const base = Math.min(Math.pow(2, attempts) * 1000, 30000)
|
| 556 |
const timeout = Math.round(base + Math.random() * base * 0.5)
|
| 557 |
-
|
| 558 |
|
| 559 |
reconnectAttemptsRef.current = attempts + 1
|
| 560 |
setConnection({ reconnectAttempts: attempts + 1 })
|
|
@@ -562,7 +565,7 @@ export function useWebSocket() {
|
|
| 562 |
connectRef.current(reconnectUrl.current, authTokenRef.current)
|
| 563 |
}, timeout)
|
| 564 |
} else {
|
| 565 |
-
|
| 566 |
addLog({
|
| 567 |
id: `error-${Date.now()}`,
|
| 568 |
timestamp: Date.now(),
|
|
@@ -574,7 +577,7 @@ export function useWebSocket() {
|
|
| 574 |
}
|
| 575 |
|
| 576 |
ws.onerror = (error) => {
|
| 577 |
-
|
| 578 |
addLog({
|
| 579 |
id: `error-${Date.now()}`,
|
| 580 |
timestamp: Date.now(),
|
|
@@ -585,7 +588,7 @@ export function useWebSocket() {
|
|
| 585 |
}
|
| 586 |
|
| 587 |
} catch (error) {
|
| 588 |
-
|
| 589 |
setConnection({ isConnected: false })
|
| 590 |
}
|
| 591 |
}, [setConnection, handleGatewayFrame, addLog, stopHeartbeat])
|
|
|
|
| 10 |
cacheDeviceToken,
|
| 11 |
} from '@/lib/device-identity'
|
| 12 |
import { APP_VERSION } from '@/lib/version'
|
| 13 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 14 |
+
|
| 15 |
+
const log = createClientLogger('WebSocket')
|
| 16 |
|
| 17 |
// Gateway protocol version (v3 required by OpenClaw 2026.x)
|
| 18 |
const PROTOCOL_VERSION = 3
|
|
|
|
| 118 |
|
| 119 |
// Check missed pongs
|
| 120 |
if (missedPongsRef.current >= MAX_MISSED_PONGS) {
|
| 121 |
+
log.warn(`Missed ${MAX_MISSED_PONGS} pongs, triggering reconnect`)
|
| 122 |
addLog({
|
| 123 |
id: `heartbeat-${Date.now()}`,
|
| 124 |
timestamp: Date.now(),
|
|
|
|
| 215 |
nonce,
|
| 216 |
}
|
| 217 |
} catch (err) {
|
| 218 |
+
log.warn('Device identity unavailable, proceeding without:', err)
|
| 219 |
}
|
| 220 |
}
|
| 221 |
|
|
|
|
| 241 |
deviceToken: cachedToken || undefined,
|
| 242 |
}
|
| 243 |
}
|
| 244 |
+
log.info('Sending connect handshake')
|
| 245 |
ws.send(JSON.stringify(connectRequest))
|
| 246 |
}, [])
|
| 247 |
|
|
|
|
| 251 |
|
| 252 |
// Debug logging for development
|
| 253 |
if (process.env.NODE_ENV === 'development') {
|
| 254 |
+
log.debug(`Message received: ${message.type}`)
|
| 255 |
}
|
| 256 |
|
| 257 |
switch (message.type) {
|
|
|
|
| 321 |
break
|
| 322 |
|
| 323 |
default:
|
| 324 |
+
log.warn(`Unknown gateway message type: ${message.type}`)
|
| 325 |
}
|
| 326 |
}, [setLastMessage, setSessions, addLog, updateSpawnRequest, setCronJobs, addTokenUsage])
|
| 327 |
|
| 328 |
// Handle gateway protocol frames
|
| 329 |
const handleGatewayFrame = useCallback((frame: GatewayFrame, ws: WebSocket) => {
|
| 330 |
+
log.debug(`Gateway frame: ${frame.type}`)
|
| 331 |
|
| 332 |
// Handle connect challenge
|
| 333 |
if (frame.type === 'event' && frame.event === 'connect.challenge') {
|
| 334 |
+
log.info('Received connect challenge, sending handshake')
|
| 335 |
sendConnectHandshake(ws, frame.payload?.nonce)
|
| 336 |
return
|
| 337 |
}
|
| 338 |
|
| 339 |
// Handle connect response (handshake success)
|
| 340 |
if (frame.type === 'res' && frame.ok && !handshakeCompleteRef.current) {
|
| 341 |
+
log.info('Handshake complete')
|
| 342 |
handshakeCompleteRef.current = true
|
| 343 |
reconnectAttemptsRef.current = 0
|
| 344 |
// Cache device token if returned by gateway
|
|
|
|
| 363 |
|
| 364 |
// Handle connect error
|
| 365 |
if (frame.type === 'res' && !frame.ok) {
|
| 366 |
+
log.error(`Gateway error: ${frame.error?.message || JSON.stringify(frame.error)}`)
|
| 367 |
const rawMessage = frame.error?.message || JSON.stringify(frame.error)
|
| 368 |
const help = getGatewayErrorHelp(rawMessage)
|
| 369 |
const nonRetryable = isNonRetryableGatewayError(rawMessage)
|
|
|
|
| 512 |
wsRef.current = ws
|
| 513 |
|
| 514 |
ws.onopen = () => {
|
| 515 |
+
log.info(`Connected to ${url.split('?')[0]}`)
|
| 516 |
// Don't set isConnected yet - wait for handshake
|
| 517 |
setConnection({
|
| 518 |
url: url.split('?')[0],
|
| 519 |
reconnectAttempts: 0
|
| 520 |
})
|
| 521 |
// Wait for connect.challenge from server
|
| 522 |
+
log.debug('Waiting for connect challenge')
|
| 523 |
}
|
| 524 |
|
| 525 |
ws.onmessage = (event) => {
|
|
|
|
| 527 |
const frame = JSON.parse(event.data) as GatewayFrame
|
| 528 |
handleGatewayFrame(frame, ws)
|
| 529 |
} catch (error) {
|
| 530 |
+
log.error('Failed to parse WebSocket message:', error)
|
| 531 |
addLog({
|
| 532 |
id: `raw-${Date.now()}`,
|
| 533 |
timestamp: Date.now(),
|
|
|
|
| 539 |
}
|
| 540 |
|
| 541 |
ws.onclose = (event) => {
|
| 542 |
+
log.info(`Disconnected from Gateway: ${event.code} ${event.reason}`)
|
| 543 |
setConnection({ isConnected: false })
|
| 544 |
handshakeCompleteRef.current = false
|
| 545 |
stopHeartbeat()
|
|
|
|
| 557 |
if (attempts < maxReconnectAttempts) {
|
| 558 |
const base = Math.min(Math.pow(2, attempts) * 1000, 30000)
|
| 559 |
const timeout = Math.round(base + Math.random() * base * 0.5)
|
| 560 |
+
log.info(`Reconnecting in ${timeout}ms (attempt ${attempts + 1}/${maxReconnectAttempts})`)
|
| 561 |
|
| 562 |
reconnectAttemptsRef.current = attempts + 1
|
| 563 |
setConnection({ reconnectAttempts: attempts + 1 })
|
|
|
|
| 565 |
connectRef.current(reconnectUrl.current, authTokenRef.current)
|
| 566 |
}, timeout)
|
| 567 |
} else {
|
| 568 |
+
log.error('Max reconnection attempts reached')
|
| 569 |
addLog({
|
| 570 |
id: `error-${Date.now()}`,
|
| 571 |
timestamp: Date.now(),
|
|
|
|
| 577 |
}
|
| 578 |
|
| 579 |
ws.onerror = (error) => {
|
| 580 |
+
log.error('WebSocket error:', error)
|
| 581 |
addLog({
|
| 582 |
id: `error-${Date.now()}`,
|
| 583 |
timestamp: Date.now(),
|
|
|
|
| 588 |
}
|
| 589 |
|
| 590 |
} catch (error) {
|
| 591 |
+
log.error('Failed to connect to WebSocket:', error)
|
| 592 |
setConnection({ isConnected: false })
|
| 593 |
}
|
| 594 |
}, [setConnection, handleGatewayFrame, addLog, stopHeartbeat])
|