This commit is contained in:
2026-03-23 11:13:30 -03:00
parent 8186bb5fe6
commit 71fd0510de
34 changed files with 1373 additions and 104 deletions

View File

@@ -1,12 +1,13 @@
<script setup lang="ts">
import { ref } from 'vue'
import { SSEDataSource } from 'mpr-ui-framework'
import { SSEDataSource, Panel, LayoutGrid } from 'mpr-ui-framework'
import 'mpr-ui-framework/src/tokens.css'
import type { LogEvent, StatsUpdate } from './types/sse-contract'
const jobId = ref(new URLSearchParams(window.location.search).get('job') || 'test-job')
const logs = ref<LogEvent[]>([])
const stats = ref<StatsUpdate | null>(null)
const status = ref('idle')
const status = ref<'idle' | 'live' | 'processing' | 'error'>('idle')
const source = new SSEDataSource({
id: 'detect-stream',
@@ -23,8 +24,13 @@ source.on<StatsUpdate>('stats_update', (e) => {
stats.value = e
})
// Expose status reactively
const checkStatus = () => { status.value = source.status.value }
const statusMap: Record<string, 'idle' | 'live' | 'processing' | 'error'> = {
idle: 'idle',
connecting: 'processing',
live: 'live',
error: 'error',
}
const checkStatus = () => { status.value = statusMap[source.status.value] ?? 'idle' }
setInterval(checkStatus, 500)
source.connect()
@@ -34,145 +40,118 @@ source.connect()
<div class="app">
<header>
<h1>Detection Pipeline</h1>
<span class="status" :class="status">{{ status }}</span>
<span class="status-badge" :class="status">{{ status }}</span>
<span class="job-id">job: {{ jobId }}</span>
</header>
<section class="stats" v-if="stats">
<div class="stat">
<span class="label">Frames</span>
<span class="value">{{ stats.frames_extracted }}</span>
</div>
<div class="stat">
<span class="label">After filter</span>
<span class="value">{{ stats.frames_after_scene_filter }}</span>
</div>
<div class="stat">
<span class="label">Regions</span>
<span class="value">{{ stats.regions_detected }}</span>
</div>
<div class="stat">
<span class="label">OCR resolved</span>
<span class="value">{{ stats.regions_resolved_by_ocr }}</span>
</div>
<div class="stat">
<span class="label">Cloud calls</span>
<span class="value">{{ stats.cloud_llm_calls }}</span>
</div>
<div class="stat">
<span class="label">Cost</span>
<span class="value">${{ stats.estimated_cloud_cost_usd.toFixed(4) }}</span>
</div>
</section>
<section class="logs">
<h2>Log</h2>
<div class="log-scroll">
<div v-for="(log, i) in logs" :key="i" class="log-line" :class="log.level.toLowerCase()">
<span class="ts">{{ log.ts }}</span>
<span class="level">{{ log.level }}</span>
<span class="stage">{{ log.stage }}</span>
<span class="msg">{{ log.msg }}</span>
<LayoutGrid :columns="2" :rows="1" gap="var(--space-2)">
<Panel title="Stats" :status="status">
<div class="stats" v-if="stats">
<div class="stat" v-for="s in [
{ label: 'Frames', value: stats.frames_extracted },
{ label: 'After filter', value: stats.frames_after_scene_filter },
{ label: 'Regions', value: stats.regions_detected },
{ label: 'OCR resolved', value: stats.regions_resolved_by_ocr },
{ label: 'Cloud calls', value: stats.cloud_llm_calls },
{ label: 'Cost', value: `$${stats.estimated_cloud_cost_usd.toFixed(4)}` },
]" :key="s.label">
<span class="label">{{ s.label }}</span>
<span class="value">{{ s.value }}</span>
</div>
</div>
<div v-if="logs.length === 0" class="empty">Waiting for events...</div>
</div>
</section>
<div v-else class="empty">Waiting for stats...</div>
</Panel>
<Panel title="Log" :status="status">
<div class="log-scroll">
<div v-for="(log, i) in logs" :key="i" class="log-line" :class="log.level.toLowerCase()">
<span class="ts">{{ log.ts }}</span>
<span class="level">{{ log.level }}</span>
<span class="stage">{{ log.stage }}</span>
<span class="msg">{{ log.msg }}</span>
</div>
<div v-if="logs.length === 0" class="empty">Waiting for events...</div>
</div>
</Panel>
</LayoutGrid>
</div>
</template>
<style>
:root {
--bg: #0d0d0f;
--surface: #16161a;
--border: #2e2e38;
--text: #e8e8f0;
--dim: #555568;
--green: #3ecf8e;
--blue: #4f9cf9;
--amber: #f5a623;
--red: #f06565;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: var(--bg);
color: var(--text);
font-family: 'JetBrains Mono', 'Fira Code', monospace;
font-size: 13px;
background: var(--surface-0);
color: var(--text-primary);
font-family: var(--font-mono);
font-size: var(--font-size-base);
}
.app {
max-width: 1200px;
margin: 0 auto;
padding: 16px;
height: 100vh;
display: flex;
flex-direction: column;
padding: var(--space-4);
gap: var(--space-2);
}
header {
display: flex;
align-items: center;
gap: 16px;
padding: 12px 0;
border-bottom: 1px solid var(--border);
margin-bottom: 16px;
gap: var(--space-4);
padding: var(--space-3) 0;
border-bottom: var(--panel-border);
flex-shrink: 0;
}
header h1 { font-size: 15px; font-weight: 600; }
header h1 { font-size: var(--font-size-lg); font-weight: 600; }
.status {
padding: 2px 8px;
.status-badge {
padding: 2px var(--space-2);
border-radius: 4px;
font-size: 11px;
font-size: var(--font-size-sm);
text-transform: uppercase;
}
.status.idle { background: var(--dim); }
.status.connecting { background: var(--blue); color: #000; }
.status.live { background: var(--green); color: #000; }
.status.error { background: var(--red); color: #000; }
.status-badge.idle { background: var(--status-idle); }
.status-badge.processing { background: var(--status-processing); color: #000; }
.status-badge.live { background: var(--status-live); color: #000; }
.status-badge.error { background: var(--status-error); color: #000; }
.job-id { color: var(--dim); font-size: 11px; margin-left: auto; }
.job-id { color: var(--text-dim); font-size: var(--font-size-sm); margin-left: auto; }
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 8px;
margin-bottom: 16px;
grid-template-columns: repeat(3, 1fr);
gap: var(--space-2);
}
.stat {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 6px;
padding: 12px;
background: var(--surface-2);
border-radius: var(--panel-radius);
padding: var(--space-3);
}
.stat .label { display: block; color: var(--dim); font-size: 11px; margin-bottom: 4px; }
.stat .label { display: block; color: var(--text-dim); font-size: var(--font-size-sm); margin-bottom: var(--space-1); }
.stat .value { font-size: 20px; font-weight: 600; }
.logs h2 { font-size: 13px; margin-bottom: 8px; color: var(--dim); }
.log-scroll {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 6px;
padding: 8px;
max-height: 500px;
overflow-y: auto;
}
.log-line {
display: flex;
gap: 8px;
gap: var(--space-2);
padding: 2px 0;
font-size: 12px;
line-height: 1.5;
}
.log-line .ts { color: var(--dim); min-width: 80px; }
.log-line .ts { color: var(--text-dim); min-width: 80px; }
.log-line .level { min-width: 56px; font-weight: 600; }
.log-line .stage { color: var(--blue); min-width: 120px; }
.log-line.info .level { color: var(--green); }
.log-line.warning .level { color: var(--amber); }
.log-line.error .level { color: var(--red); }
.log-line.debug .level { color: var(--dim); }
.log-line .stage { color: var(--status-processing); min-width: 120px; }
.log-line.info .level { color: var(--status-live); }
.log-line.warning .level { color: var(--status-escalating); }
.log-line.error .level { color: var(--status-error); }
.log-line.debug .level { color: var(--text-dim); }
.empty { color: var(--dim); padding: 20px; text-align: center; }
.empty { color: var(--text-dim); padding: var(--space-6); text-align: center; }
</style>

View File

@@ -0,0 +1,32 @@
<script setup lang="ts">
const props = withDefaults(defineProps<{
columns?: number
rows?: number
gap?: string
}>(), {
columns: 2,
rows: 2,
gap: 'var(--space-2)',
})
</script>
<template>
<div
class="layout-grid"
:style="{
gridTemplateColumns: `repeat(${props.columns}, 1fr)`,
gridTemplateRows: `repeat(${props.rows}, 1fr)`,
gap: props.gap,
}"
>
<slot />
</div>
</template>
<style scoped>
.layout-grid {
display: grid;
width: 100%;
height: 100%;
}
</style>

View File

@@ -0,0 +1,79 @@
<script setup lang="ts">
defineProps<{
title: string
status?: 'idle' | 'live' | 'processing' | 'error'
}>()
</script>
<template>
<div class="panel">
<div class="panel-header">
<span class="panel-title">{{ title }}</span>
<span class="panel-status" :class="status ?? 'idle'" />
</div>
<div class="panel-body">
<slot />
</div>
<div class="panel-overlay">
<slot name="overlay" />
</div>
</div>
</template>
<style scoped>
.panel {
position: relative;
background: var(--surface-1);
border: var(--panel-border);
border-radius: var(--panel-radius);
overflow: hidden;
display: flex;
flex-direction: column;
}
.panel-header {
display: flex;
align-items: center;
gap: var(--space-2);
height: var(--panel-header-height);
padding: 0 var(--space-3);
background: var(--surface-2);
border-bottom: var(--panel-border);
flex-shrink: 0;
}
.panel-title {
font-family: var(--font-ui);
font-size: var(--font-size-sm);
font-weight: 600;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.04em;
}
.panel-status {
width: 8px;
height: 8px;
border-radius: 50%;
margin-left: auto;
}
.panel-status.idle { background: var(--status-idle); }
.panel-status.live { background: var(--status-live); }
.panel-status.processing { background: var(--status-processing); }
.panel-status.error { background: var(--status-error); }
.panel-body {
flex: 1;
overflow: auto;
padding: var(--space-2);
}
.panel-overlay {
position: absolute;
inset: var(--panel-header-height) 0 0 0;
pointer-events: none;
}
.panel-overlay > :deep(*) {
pointer-events: auto;
}
</style>

View File

@@ -3,3 +3,7 @@ export { DataSource, type DataSourceStatus } from './datasources/DataSource'
export { SSEDataSource } from './datasources/SSEDataSource'
export { StaticDataSource } from './datasources/StaticDataSource'
export { useDataSource } from './composables/useDataSource'
// Components
export { default as Panel } from './components/Panel.vue'
export { default as LayoutGrid } from './components/LayoutGrid.vue'

View File

@@ -0,0 +1,45 @@
/* Framework design tokens — retheme by replacing this file */
:root {
/* spacing scale (4px base) */
--space-1: 4px;
--space-2: 8px;
--space-3: 12px;
--space-4: 16px;
--space-6: 24px;
--space-8: 32px;
/* color — dark theme (observability UIs are always dark) */
--surface-0: #0d0d0f;
--surface-1: #16161a;
--surface-2: #1e1e24;
--surface-3: #26262f;
--border: #2e2e38;
--text-primary: #e8e8f0;
--text-secondary: #8888a0;
--text-dim: #555568;
/* status colors */
--status-idle: #555568;
--status-live: #3ecf8e;
--status-processing: #4f9cf9;
--status-escalating: #f5a623;
--status-error: #f06565;
/* confidence color scale (low → high) */
--conf-low: #f06565;
--conf-mid: #f5a623;
--conf-high: #3ecf8e;
/* typography */
--font-mono: 'JetBrains Mono', 'Fira Code', monospace;
--font-ui: 'Inter', system-ui, sans-serif;
--font-size-sm: 11px;
--font-size-base: 13px;
--font-size-lg: 15px;
/* panel chrome */
--panel-radius: 6px;
--panel-border: 1px solid var(--border);
--panel-header-height: 36px;
}