Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<!--
Copyright 2025-2026 mrveiss
SPDX-License-Identifier: Apache-2.0

RumDataTables (#18277): what the backend holds, from one /rum/export read: events by type,
sessions, and the latest events. URLs, user agents and event data are sent by browsers, so they
are shown as text only. The export lists the latest 1000 events; the totals count every one held.
-->
<template>
<div class="flex flex-col gap-4">
<BaseCard :title="t(`${NS}.types.title`)">
<BaseTable
:columns="typeColumns" :rows="typeRows" row-key="type" :aria-label="t(`${NS}.types.title`)"
:empty-title="t(`${NS}.types.empty`)" data-testid="slm-rum-types"
/>
</BaseCard>

<BaseCard :title="t(`${NS}.sessions.title`)">
<BaseTable
:columns="sessionColumns" :rows="sessionRows" row-key="id" :aria-label="t(`${NS}.sessions.title`)"
:empty-title="t(`${NS}.sessions.empty`)" data-testid="slm-rum-sessions"
/>
</BaseCard>

<BaseCard :title="t(`${NS}.events.title`)">
<p class="m-0 mb-3 text-sm text-(--aui-color-text-muted)" data-testid="slm-rum-events-note">
{{ t(`${NS}.events.shown`, { shown: data.events.length, total: data.summary.total_events }) }}
</p>
<BaseTable
:columns="eventColumns" :rows="eventRows" row-key="key" :aria-label="t(`${NS}.events.title`)"
:empty-title="t(`${NS}.events.empty`)" :page-size="EVENTS_PAGE_SIZE"
:pagination-labels="{ previous: t(`${NS}.page.previous`), next: t(`${NS}.page.next`) }"
:pagination-label="t(`${NS}.page.label`)"
:pagination-summary="(page: number, count: number) => t(`${NS}.page.summary`, { page, count })"
data-testid="slm-rum-events"
/>
</BaseCard>
</div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { BaseCard, BaseTable, type BaseTableColumn } from '@autobot/ui'
import { formatFleetDateTime } from '@/composables/useTimezone'
import type { RumExport } from '@/composables/useRumApi'

const NS = 'monitoring.rum'
const EVENTS_PAGE_SIZE = 25
const props = defineProps<{ data: RumExport }>()
const { t } = useI18n()

const typeColumns = computed<BaseTableColumn[]>(() => [
{ key: 'type', label: t(`${NS}.types.col.type`), monospace: true },
{ key: 'count', label: t(`${NS}.types.col.count`), numeric: true },
])
const typeRows = computed(() =>
Object.entries(props.data.summary.event_types)
.map(([type, count]) => ({ type, count }))
.sort((a, b) => b.count - a.count),
)

const sessionColumns = computed<BaseTableColumn[]>(() => [
{ key: 'id', label: t(`${NS}.sessions.col.id`), monospace: true },
{ key: 'initial_url', label: t(`${NS}.sessions.col.url`), wrap: true },
{ key: 'user_agent', label: t(`${NS}.sessions.col.agent`), wrap: true },
{ key: 'event_count', label: t(`${NS}.sessions.col.events`), numeric: true },
{ key: 'start', label: t(`${NS}.sessions.col.started`) },
{ key: 'last', label: t(`${NS}.sessions.col.last`) },
])
/** Most recently active first; ISO times from one server order as strings. */
const sessionRows = computed(() =>
Object.entries(props.data.sessions)
.map(([id, s]) => ({ id, initial_url: s.initial_url, user_agent: s.user_agent, event_count: s.event_count, start: formatFleetDateTime(s.start_time), last: formatFleetDateTime(s.last_activity), sort: s.last_activity }))
.sort((a, b) => b.sort.localeCompare(a.sort)),
)

const eventColumns = computed<BaseTableColumn[]>(() => [
{ key: 'at', label: t(`${NS}.events.col.at`) },
{ key: 'type', label: t(`${NS}.events.col.type`), monospace: true },
{ key: 'url', label: t(`${NS}.events.col.url`), wrap: true },
{ key: 'session', label: t(`${NS}.events.col.session`), monospace: true },
])
/** Newest first; the export lists them oldest first. */
const eventRows = computed(() =>
[...props.data.events]
.reverse()
.map((e, i) => ({ key: `${e.server_timestamp}:${i}`, at: formatFleetDateTime(e.server_timestamp), type: e.type, url: e.url, session: e.sessionId })),
)
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!--
Copyright 2025-2026 mrveiss
SPDX-License-Identifier: Apache-2.0

ValidationFindings (#18278): the alerts and the recommendations of one validation report,
each with its count by level, and each said as empty when the report has none.
-->
<template>
<div class="grid gap-4 md:grid-cols-2">
<BaseCard :title="t(`${NS}.alerts.title`, { n: alerts.length })" data-testid="slm-validation-alerts">
<p v-if="alerts.length === 0" class="m-0 text-(--aui-color-text-muted)" role="status" data-testid="slm-validation-alerts-empty">
{{ t(`${NS}.alerts.empty`) }}
</p>
<ul v-else class="m-0 flex list-none flex-col gap-3 p-0">
<li v-for="(a, i) in alerts" :key="`${a.level}:${a.title}:${i}`" class="flex flex-col gap-1" data-testid="slm-validation-alert">
<span class="flex items-center gap-2">
<BaseBadge :variant="ALERT_VARIANT[a.level] ?? 'neutral'" size="sm" tone="solid">{{ level(`alerts.level`, a.level) }}</BaseBadge>
<strong>{{ a.title }}</strong>
</span>
<span class="text-(--aui-color-text-muted)">{{ a.message }}</span>
</li>
</ul>
</BaseCard>

<BaseCard :title="t(`${NS}.recommendations.title`, { n: recommendations.length })" data-testid="slm-validation-recommendations">
<p v-if="recommendations.length === 0" class="m-0 text-(--aui-color-text-muted)" role="status" data-testid="slm-validation-recommendations-empty">
{{ t(`${NS}.recommendations.empty`) }}
</p>
<ul v-else class="m-0 flex list-none flex-col gap-3 p-0">
<li v-for="(r, i) in recommendations" :key="`${r.type}:${r.title}:${i}`" class="flex flex-col gap-1" data-testid="slm-validation-recommendation">
<span class="flex items-center gap-2">
<BaseBadge :variant="URGENCY_VARIANT[r.urgency] ?? 'neutral'" size="sm" tone="solid">{{ level(`recommendations.urgency`, r.urgency) }}</BaseBadge>
<strong>{{ r.title }}</strong>
</span>
<span class="text-(--aui-color-text-muted)">{{ r.description }}</span>
<span class="text-sm">{{ t(`${NS}.recommendations.action`, { action: r.action }) }}</span>
</li>
</ul>
</BaseCard>
</div>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { BaseBadge, BaseCard, type BadgeVariant } from '@autobot/ui'
import type { ValidationAlert, ValidationRecommendation } from '@/composables/useValidationDashboardApi'

defineProps<{ alerts: ValidationAlert[]; recommendations: ValidationRecommendation[] }>()

const NS = 'monitoring.validationDashboard'
const { t, te } = useI18n()

const ALERT_VARIANT: Record<string, BadgeVariant> = { critical: 'error', warning: 'warning', info: 'info' }
const URGENCY_VARIANT: Record<string, BadgeVariant> = { high: 'error', medium: 'warning', low: 'neutral', info: 'info' }

/** The generator's own word when this screen has no translation for it. */
function level(group: string, value: string): string {
const key = `${NS}.${group}.${value}`
return te(key) ? t(key) : value
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!--
Copyright 2025-2026 mrveiss
SPDX-License-Identifier: Apache-2.0

ValidationOverview (#18278): the headline figures and the metric groups of one validation
report (ValidationDashboard). Pure display; the report is read by the screen.
-->
<template>
<BaseCard :title="t(`${NS}.overview.title`)" data-testid="slm-validation-overview">
<dl class="m-0 grid grid-cols-[repeat(auto-fit,minmax(11rem,1fr))] gap-4">
<div v-for="stat in stats" :key="stat.key" :data-testid="`slm-validation-stat-${stat.key}`">
<dt class="text-sm text-(--aui-color-text-muted)">{{ t(`${NS}.stat.${stat.key}`) }}</dt>
<dd class="m-0 text-lg font-semibold tabular-nums">{{ stat.value }}</dd>
</div>
</dl>
<p class="m-0 mt-3 flex flex-wrap items-center gap-2 text-sm text-(--aui-color-text-muted)">
<span>{{ t(`${NS}.overview.measures`) }}</span>
<BaseBadge variant="neutral" size="sm" monospace data-testid="slm-validation-measures">{{ report.system_overview.measures }}</BaseBadge>
<span v-if="readAt">{{ t(`${NS}.overview.readAt`, { time: formatFleetDateTime(readAt) }) }}</span>
</p>
</BaseCard>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { BaseBadge, BaseCard } from '@autobot/ui'
import { formatFleetDateTime } from '@/composables/useTimezone'
import type { ValidationDashboardStatus, ValidationReport } from '@/composables/useValidationDashboardApi'

const NS = 'monitoring.validationDashboard'
const props = defineProps<{ report: ValidationReport; service: ValidationDashboardStatus | null; readAt: string }>()
const { t, te } = useI18n()

const percent = (value: number): string => t(`${NS}.percent`, { value: value.toFixed(1) })
const yesNo = (value: boolean): string => t(`${NS}.${value ? 'yes' : 'no'}`)
/** The generator's own word when this screen has no translation for it. */
const health = (value: string): string => (te(`${NS}.health.${value}`) ? t(`${NS}.health.${value}`) : value)

const stats = computed(() => {
const { system_overview: o, metrics: m, progression_status: p } = props.report
const rows: { key: string; value: string | number }[] = [
{ key: 'maturity', value: percent(o.overall_maturity) },
{ key: 'health', value: health(o.system_health) },
{ key: 'phases', value: t(`${NS}.outOf`, { done: o.completed_phases, total: o.total_phases }) },
{ key: 'capabilities', value: o.active_capabilities },
{ key: 'averageCompletion', value: percent(m.completion_statistics.average_completion) },
{ key: 'minCompletion', value: percent(m.completion_statistics.min_completion) },
{ key: 'maxCompletion', value: percent(m.completion_statistics.max_completion) },
{ key: 'above50', value: m.completion_statistics.phases_above_50 },
{ key: 'above90', value: m.completion_statistics.phases_above_90 },
{ key: 'stage', value: m.system_maturity.development_stage },
{ key: 'validationScore', value: m.quality_indicators.validation_score },
{ key: 'errorRate', value: m.quality_indicators.error_rate },
{ key: 'recentChanges', value: m.quality_indicators.recent_changes },
{ key: 'velocity', value: m.progression_metrics.progression_velocity },
{ key: 'canProgress', value: yesNo(p.can_progress) },
{ key: 'blocked', value: p.blocked_phases.length },
]
const s = props.service
if (s?.refresh_interval != null) rows.push({ key: 'refreshInterval', value: t(`${NS}.seconds`, { n: s.refresh_interval }) })
if (s?.data_retention_days != null) rows.push({ key: 'retention', value: t(`${NS}.days`, { n: s.data_retention_days }) })
return rows
})
</script>
100 changes: 100 additions & 0 deletions autobot-slm-frontend/src/composables/useRumApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2025-2026 mrveiss
// SPDX-License-Identifier: Apache-2.0
// AutoBot - AI-Powered Automation Platform
// Author: mrveiss

/**
* Real-user-monitoring (RUM) API (#18277): the main backend's `/rum` routes
* (autobot-backend/api/rum.py), read through the shared main-backend client.
*
* `GET /status` answers any signed-in user; `GET /export`, `POST /config`, `POST /disable` and
* `POST /clear` are admin-only on the backend. The envelope types are the generated contract's.
* The contract types the inner payloads as open objects (the route returns the module's in-memory
* dicts), so `RumStatus` and `RumExport` below declare the fields the screen reads, taken from
* `get_rum_status` and `export_rum_data` in rum.py and `track_session` in rum_ingest_bounds.py.
*/

import type { components as backend } from '@autobot/backend-contract'
import { createAutobotBackendClient } from '@/composables/useAutobotApi'

type BackendSchemas = backend['schemas']

/** The collection settings; `POST /config` replaces all of them, so a toggle sends the whole object. */
export type RumConfig = BackendSchemas['RumConfig']
export type RumClearResponse = BackendSchemas['RUMClearResponse']
export type RumDisableResponse = BackendSchemas['RUMDisableResponse']
export type RumConfigResponse = BackendSchemas['RUMConfigResponse']

export interface RumStatistics {
total_events: number
total_sessions: number
/** Sessions with activity in the last 30 minutes. */
active_sessions: number
events_today: number
}

/** `rum_status` of GET /status. */
export interface RumStatus {
enabled: boolean
config: RumConfig
statistics: RumStatistics
}

export interface RumSession {
start_time: string
last_activity: string
event_count: number
user_agent: string
initial_url: string
}

export interface RumEvent {
type: string
timestamp: string
sessionId: string
url: string
userAgent: string
server_timestamp: string
data: Record<string, unknown>
}

/** `data` of GET /export: all sessions, the latest 1000 events, and the totals over every event held. */
export interface RumExport {
export_timestamp: string
config: RumConfig
sessions: Record<string, RumSession>
events: RumEvent[]
summary: { total_events: number; total_sessions: number; event_types: Record<string, number> }
}

export function useRumApi() {
const client = createAutobotBackendClient()

async function getStatus(): Promise<RumStatus> {
const response = await client.get<{ status: string; rum_status: unknown }>('/rum/status', { maxRetries: 1 })
return response.rum_status as RumStatus
}

/** Admin only. */
async function exportData(): Promise<RumExport> {
const response = await client.get<{ status: string; data: unknown }>('/rum/export', { maxRetries: 1 })
return response.data as RumExport
}

/** Admin only. Turns collection on: `/config` has no partial update, so the current settings go back with `enabled: true`. */
function enable(current: RumConfig): Promise<RumConfigResponse> {
return client.post<RumConfigResponse>('/rum/config', { ...current, enabled: true })
}

/** Admin only. Turns collection off; the events already held stay until they are cleared. */
function disable(): Promise<RumDisableResponse> {
return client.post<RumDisableResponse>('/rum/disable')
}

/** Admin only. Drops every held event and session; answers how many of each. */
function clear(): Promise<RumClearResponse> {
return client.post<RumClearResponse>('/rum/clear')
}

return { getStatus, exportData, enable, disable, clear }
}
Loading