phase 2
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user