TelemetryPanel.vue 6.62 KB
<template>
  <div class="panel">
    <div class="head">
      <div class="title">Telemetry & Analytics</div>
      <el-tag v-if="active" type="info" effect="light" class="tag">{{ active.result.verdict.toLowerCase() }}</el-tag>
      <el-tag v-else type="info" effect="light" class="tag">inactive</el-tag>
    </div>

    <div v-if="!active" class="empty">
      Click an AI card in the center column to inspect telemetry and candidates.
    </div>

    <div v-else class="body">
      <div class="section">
        <div class="section-title">Latency</div>
        <div class="metric">
          <div class="metric-top">
            <div class="metric-label">Embedding</div>
            <div class="metric-value">{{ Math.round(active.result.timing_ms.emb) }}ms</div>
          </div>
          <div class="bar-track">
            <div class="bar emb" :style="{ width: latencyPct('emb') + '%' }" />
          </div>
        </div>

        <div class="metric">
          <div class="metric-top">
            <div class="metric-label">Tree</div>
            <div class="metric-value">{{ Math.round(active.result.timing_ms.tree) }}ms</div>
          </div>
          <div class="bar-track">
            <div class="bar tree" :style="{ width: latencyPct('tree') + '%' }" />
          </div>
        </div>

        <div class="metric total">
          <div class="metric-top">
            <div class="metric-label">Total</div>
            <div class="metric-value">{{ Math.round(active.result.timing_ms.total) }}ms</div>
          </div>
        </div>
      </div>

      <div class="section">
        <div class="section-title">Candidates</div>

        <div class="cand-head">
          <span>intent</span>
          <span class="muted">final</span>
          <span class="muted">emb</span>
          <span class="muted">tree</span>
        </div>

        <div
          v-for="(c, idx) in visibleCandidates"
          :key="c.name"
          class="cand-row"
          :class="{ top: idx === 0 }"
          :style="rowStyle(c.final_score, idx)"
        >
          <div class="cand-name mono">{{ c.name }}</div>
          <div class="cand-num">{{ c.final_score.toFixed(3) }}</div>
          <div class="cand-num muted">{{ c.emb_score.toFixed(3) }}</div>
          <div class="cand-num muted">{{ c.tree_score.toFixed(3) }}</div>
        </div>

        <div v-if="hiddenCandidateCount > 0" class="more">
          +{{ hiddenCandidateCount }} more
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import type { ChatMessage } from "../../types";

const props = defineProps<{ activeAssistantId: string; messages: ChatMessage[] }>();

const active = computed(() => props.messages.find((m) => m.role === "assistant" && m.id === props.activeAssistantId) as any);
const visibleCandidates = computed(() => (active.value?.result?.candidates ?? []).slice(0, 10));
const hiddenCandidateCount = computed(() => Math.max(0, (active.value?.result?.candidates?.length ?? 0) - visibleCandidates.value.length));

function latencyPct(k: "emb" | "tree"): number {
  if (!active.value) return 0;
  const total = Math.max(1, active.value.result.timing_ms.total);
  const v = k === "emb" ? active.value.result.timing_ms.emb : active.value.result.timing_ms.tree;
  return Math.max(0, Math.min(100, Math.round((v / total) * 100)));
}

function rowStyle(score: number, idx: number): Record<string, string> {
  const s = Math.max(0, Math.min(1, score));
  const heat = 0.08 + s * 0.22;
  const zebra = idx % 2 === 0 ? 0.02 : 0.05;
  const bg = `rgba(128, 163, 143, ${heat})`;
  const base = `rgba(15, 23, 42, ${zebra})`;
  return {
    background: `linear-gradient(0deg, ${bg}, ${bg}), ${base}`,
  };
}
</script>

<style scoped>
.panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(14px);
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}
.head {
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(250, 250, 250, 0.7);
}
.title {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: rgba(15, 23, 42, 0.92);
}
.tag {
  border-radius: 999px;
}
.empty {
  margin: 14px;
  padding: 18px;
  border-radius: 14px;
  border: 1px dashed rgba(15, 23, 42, 0.10);
  background: rgba(250, 250, 250, 0.55);
  color: rgba(15, 23, 42, 0.58);
}
.body {
  flex: 1;
  overflow: hidden;
  padding: 14px;
}
.section + .section {
  margin-top: 18px;
}
.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(15, 23, 42, 0.62);
  margin-bottom: 10px;
}
.metric {
  padding: 10px 10px 9px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.55);
}
.metric + .metric {
  margin-top: 10px;
}
.metric-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.metric-label {
  font-size: 13px;
  color: rgba(15, 23, 42, 0.70);
}
.metric-value {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.01em;
  color: rgba(15, 23, 42, 0.92);
  font-variant-numeric: tabular-nums;
}
.bar-track {
  height: 7px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
  overflow: hidden;
}
.bar {
  height: 100%;
  border-radius: 999px;
}
.bar.emb {
  background: rgba(30, 58, 138, 0.78);
}
.bar.tree {
  background: rgba(128, 163, 143, 0.90);
}
.total {
  background: rgba(250, 250, 250, 0.45);
}
.cand-head {
  display: grid;
  grid-template-columns: 1fr 72px 72px 72px;
  gap: 8px;
  font-size: 12px;
  color: rgba(15, 23, 42, 0.55);
  padding: 0 8px 6px;
}
.cand-row {
  display: grid;
  grid-template-columns: 1fr 72px 72px 72px;
  gap: 8px;
  align-items: center;
  padding: 10px 8px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  margin-top: 8px;
}
.cand-row.top {
  border-color: rgba(128, 163, 143, 0.26);
  box-shadow: 0 16px 40px rgba(128, 163, 143, 0.08);
}
.cand-name {
  overflow: hidden;
  text-overflow: ellipsis;
}
.cand-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: rgba(15, 23, 42, 0.86);
}
.muted {
  color: rgba(15, 23, 42, 0.55);
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.more {
  margin-top: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(250, 250, 250, 0.55);
  color: rgba(15, 23, 42, 0.62);
  font-size: 12px;
  width: fit-content;
}
</style>