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 ─────────────────────────────────── */
|
||||
|
||||
Reference in New Issue
Block a user