This commit is contained in:
2026-03-23 09:58:40 -03:00
parent 9c9c7dff09
commit 8186bb5fe6
40 changed files with 3996 additions and 17 deletions

View File

@@ -0,0 +1,178 @@
<script setup lang="ts">
import { ref } from 'vue'
import { SSEDataSource } from 'mpr-ui-framework'
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 source = new SSEDataSource({
id: 'detect-stream',
url: `/api/detect/stream/${jobId.value}`,
eventTypes: ['graph_update', 'stats_update', 'frame_update', 'detection', 'log', 'job_complete', 'waiting'],
})
source.on<LogEvent>('log', (e) => {
logs.value.push(e)
if (logs.value.length > 200) logs.value.shift()
})
source.on<StatsUpdate>('stats_update', (e) => {
stats.value = e
})
// Expose status reactively
const checkStatus = () => { status.value = source.status.value }
setInterval(checkStatus, 500)
source.connect()
</script>
<template>
<div class="app">
<header>
<h1>Detection Pipeline</h1>
<span class="status" :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>
</div>
<div v-if="logs.length === 0" class="empty">Waiting for events...</div>
</div>
</section>
</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;
}
.app {
max-width: 1200px;
margin: 0 auto;
padding: 16px;
}
header {
display: flex;
align-items: center;
gap: 16px;
padding: 12px 0;
border-bottom: 1px solid var(--border);
margin-bottom: 16px;
}
header h1 { font-size: 15px; font-weight: 600; }
.status {
padding: 2px 8px;
border-radius: 4px;
font-size: 11px;
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; }
.job-id { color: var(--dim); font-size: 11px; margin-left: auto; }
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 8px;
margin-bottom: 16px;
}
.stat {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 6px;
padding: 12px;
}
.stat .label { display: block; color: var(--dim); font-size: 11px; margin-bottom: 4px; }
.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;
padding: 2px 0;
font-size: 12px;
line-height: 1.5;
}
.log-line .ts { color: var(--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); }
.empty { color: var(--dim); padding: 20px; text-align: center; }
</style>

View File

@@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')

View File

@@ -0,0 +1,97 @@
/**
* TypeScript Types - GENERATED FILE
*
* Do not edit directly. Regenerate using modelgen.
*/
export interface GraphNode {
id: string;
status: string;
items_in: number;
items_out: number;
}
export interface GraphEdge {
source: string;
target: string;
throughput: number;
}
export interface BoundingBoxEvent {
x: number;
y: number;
w: number;
h: number;
confidence: number;
label: string;
resolved_brand: string | null;
source: string | null;
}
export interface BrandSummary {
brand: string;
total_appearances: number;
total_screen_time: number;
avg_confidence: number;
first_seen: number;
last_seen: number;
}
export interface GraphUpdate {
nodes: GraphNode[];
edges: GraphEdge[];
active_path: string[];
}
export interface StatsUpdate {
frames_extracted: number;
frames_after_scene_filter: number;
regions_detected: number;
regions_resolved_by_ocr: number;
regions_escalated_to_local_vlm: number;
regions_escalated_to_cloud_llm: number;
cloud_llm_calls: number;
processing_time_seconds: number;
estimated_cloud_cost_usd: number;
}
export interface FrameUpdate {
frame_ref: number;
timestamp: number;
jpeg_b64: string;
boxes: BoundingBoxEvent[];
}
export interface Detection {
brand: string;
timestamp: number;
duration: number;
confidence: number;
source: string;
content_type: string;
bbox: BoundingBoxEvent | null;
frame_ref: number | null;
}
export interface LogEvent {
level: string;
stage: string;
msg: string;
ts: string;
trace_id: string | null;
}
export interface DetectionReportSummary {
video_source: string;
content_type: string;
duration_seconds: number;
total_detections: number;
brands: BrandSummary[];
stats: StatsUpdate | null;
}
export interface JobComplete {
job_id: string;
report: DetectionReportSummary | null;
}