feat: wire dashboard v2 to backend data
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { apiFetch } from '../services/api'
|
||||
import type { AgentNodeData } from '../composables/useFlowLayout'
|
||||
import type { AgentDetailData, ThinkingItem } from '../components/dashboard/v2/types'
|
||||
import type { AgentActivityItem, AgentDetailData, ThinkingItem } from '../components/dashboard/v2/types'
|
||||
|
||||
/* ── API Response Shapes ──────────────────────────── */
|
||||
|
||||
@@ -40,6 +40,11 @@ interface ModelOption {
|
||||
provider: string
|
||||
}
|
||||
|
||||
interface AgentActivityEntry {
|
||||
time: string
|
||||
text: string
|
||||
}
|
||||
|
||||
/* ── Status Mapping ───────────────────────────────── */
|
||||
|
||||
function mapStatus(isActive: boolean, currentTask: string | null): AgentNodeData['status'] {
|
||||
@@ -148,6 +153,7 @@ export function buildAgentDetail(data: AgentNodeData, models: { id: string; alia
|
||||
lastActive: data.elapsed !== '—' ? 'Vor ' + data.elapsed : 'Nicht aktiv',
|
||||
activeTaskCount: data.task ? 1 : 0,
|
||||
thinking: buildThinkingItems(data),
|
||||
activity: [],
|
||||
availableModels: models,
|
||||
}
|
||||
}
|
||||
@@ -159,6 +165,7 @@ export const useAgentStore = defineStore('agents', {
|
||||
loading: false,
|
||||
error: null as string | null,
|
||||
selectedAgentId: null as string | null,
|
||||
activityByAgentId: {} as Record<string, AgentActivityItem[]>,
|
||||
refreshInterval: null as ReturnType<typeof setInterval> | null,
|
||||
isConnected: false,
|
||||
}),
|
||||
@@ -179,7 +186,10 @@ export const useAgentStore = defineStore('agents', {
|
||||
if (!state.selectedAgentId) return null
|
||||
const data = state.agents.find(a => a.id === state.selectedAgentId)
|
||||
if (!data) return null
|
||||
return buildAgentDetail(data, state.models)
|
||||
return {
|
||||
...buildAgentDetail(data, state.models),
|
||||
activity: state.activityByAgentId[data.id] ?? [],
|
||||
}
|
||||
},
|
||||
|
||||
/** Is the modal open? */
|
||||
@@ -249,9 +259,24 @@ export const useAgentStore = defineStore('agents', {
|
||||
}
|
||||
},
|
||||
|
||||
async fetchAgentActivity(agentId: string) {
|
||||
try {
|
||||
const res = await apiFetch(`/api/dashboard/agents/${encodeURIComponent(agentId)}/activity?limit=5`)
|
||||
if (!res.ok) return
|
||||
const data: AgentActivityEntry[] = await res.json()
|
||||
this.activityByAgentId[agentId] = data.map(entry => ({
|
||||
time: entry.time,
|
||||
text: entry.text,
|
||||
}))
|
||||
} catch (err) {
|
||||
console.warn('[AgentStore] fetchAgentActivity failed', err)
|
||||
}
|
||||
},
|
||||
|
||||
/* ── Selection ───────────────────────────────── */
|
||||
selectAgent(id: string | null) {
|
||||
this.selectedAgentId = id
|
||||
if (id) void this.fetchAgentActivity(id)
|
||||
},
|
||||
|
||||
/* ── Polling ─────────────────────────────────── */
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { apiFetch } from '../services/api'
|
||||
|
||||
interface DashboardStatusDto {
|
||||
gatewayOk: boolean
|
||||
irisStatus: string
|
||||
activeAgents: number
|
||||
pendingTasks: number
|
||||
}
|
||||
|
||||
interface FeedEntryDto {
|
||||
agent: string
|
||||
action: string
|
||||
timestamp: string
|
||||
time: string
|
||||
agentId?: string | null
|
||||
type?: string | null
|
||||
}
|
||||
|
||||
interface QueueItemDto {
|
||||
id: string
|
||||
name: string
|
||||
status: string
|
||||
priority: string
|
||||
source: string
|
||||
waitTime: string
|
||||
}
|
||||
|
||||
export const useDashboardStore = defineStore('dashboard', {
|
||||
state: () => ({
|
||||
status: null as DashboardStatusDto | null,
|
||||
operations: [] as FeedEntryDto[],
|
||||
queue: [] as QueueItemDto[],
|
||||
loading: false,
|
||||
error: null as string | null,
|
||||
refreshInterval: null as ReturnType<typeof setInterval> | null,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
isGatewayConnected: state => state.status?.gatewayOk ?? false,
|
||||
irisStatusLabel: state => state.status?.irisStatus ?? 'Offline',
|
||||
},
|
||||
|
||||
actions: {
|
||||
async fetchStatus() {
|
||||
try {
|
||||
const res = await apiFetch('/api/dashboard/status')
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
this.status = await res.json()
|
||||
} catch (err) {
|
||||
console.warn('[DashboardStore] fetchStatus failed', err)
|
||||
this.status = null
|
||||
}
|
||||
},
|
||||
|
||||
async fetchOperations() {
|
||||
try {
|
||||
const res = await apiFetch('/api/dashboard/operations?limit=20')
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
this.operations = await res.json()
|
||||
} catch (err) {
|
||||
console.warn('[DashboardStore] fetchOperations failed', err)
|
||||
this.operations = []
|
||||
}
|
||||
},
|
||||
|
||||
async fetchQueue() {
|
||||
try {
|
||||
const res = await apiFetch('/api/dashboard/queue')
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
this.queue = await res.json()
|
||||
} catch (err) {
|
||||
console.warn('[DashboardStore] fetchQueue failed', err)
|
||||
this.queue = []
|
||||
}
|
||||
},
|
||||
|
||||
async refresh() {
|
||||
this.loading = true
|
||||
try {
|
||||
await Promise.all([
|
||||
this.fetchStatus(),
|
||||
this.fetchOperations(),
|
||||
this.fetchQueue(),
|
||||
])
|
||||
this.error = null
|
||||
} catch (err) {
|
||||
console.warn('[DashboardStore] refresh failed', err)
|
||||
this.error = 'Dashboard metadata could not be loaded'
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
startPolling() {
|
||||
if (this.refreshInterval) return
|
||||
this.refresh()
|
||||
this.refreshInterval = setInterval(() => {
|
||||
this.refresh()
|
||||
}, 30000)
|
||||
},
|
||||
|
||||
stopPolling() {
|
||||
if (this.refreshInterval) {
|
||||
clearInterval(this.refreshInterval)
|
||||
this.refreshInterval = null
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -56,6 +56,8 @@ function mapTask(t: DashboardTaskDto): TaskItem {
|
||||
priority: mapPriority(t.priority),
|
||||
status: mapState(t.state),
|
||||
progress: mapProgress(t.state),
|
||||
detail: t.detail,
|
||||
source: t.source,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user