import { Icon } from "../lib/icons.jsx"; import { AGENT_ICON, GROUPS, TOOL_WORD, WRITE_TOOLS, fmt, kindWords, kindsOf, pctOf, plain, when } from "../lib/constants.js"; import { useData } from "../lib/data.jsx"; import { go, useTipProps, useUi } from "../lib/ui.jsx"; import { CardHead, CountUp, KindTag, StatCard, Status, Toggle } from "../components/common.jsx"; import { ImpactMap } from "../components/ImpactMap.jsx"; import { LiveTicker } from "../components/LiveRun.jsx"; import { useEventRun } from "../lib/run.jsx"; import { CallsChart, KindBars } from "../components/charts.jsx"; import { Page } from "./Page.jsx"; import { tr, trx } from "../lib/i18n.js"; export function useFilteredTraces() { const d = useData(); const { ui } = useUi(); const q = ui.q.trim().toLowerCase(); if (!q) return d.traces; return d.traces.filter((t) => `${t.event_id} ${t.text} ${t.classification}`.toLowerCase().includes(q)); } export function AgentCard({ a }) { return (
{a.title}
{tr(a.handbook_rules.includes(",") ? "Handbook rules {rules}" : "Handbook rule {rules}", { rules: a.handbook_rules })}

{a.responsibility}

{tr("Takes {what}", { what: a.takes })}
{a.tools.map((t) => {TOOL_WORD[t] || plain(t)})}
); } function TimelineItem({ t }) { const d = useData(); const o = d.outcome(t.event_id); const rows = d.byEvent[t.event_id] || []; const ic = o === "acted" ? "wrench" : o === "esc" ? "alert" : "minus"; const color = o === "acted" ? "var(--good-text)" : o === "esc" ? "var(--warn)" : "var(--muted)"; const writes = rows.filter((r) => r.ok && WRITE_TOOLS.has(r.tool)).length; const what = o === "acted" ? tr("{writes} changes made", { writes: writes }) : o === "esc" ? tr("Handed to a human") : tr("No action needed"); return (
{t.event_id} · {what}
{when(t.received_at)} · {kindWords(t)}
); } function CallsTable({ data }) { return (
{GROUPS.map((g) => )}{data.map((r) => {r.vals.map((v, i) => )})}
{tr("Event")}{g.label}{tr("Total")}
{r.id}{v}{r.total}
); } // Customer promise impact: each customer order behind a moved build, its new build date against the // date the customer was promised. Built by the server from the action log and the company records. const BANDS = [ ["on_track", "On track", "var(--good)", "Still built at least 2 days before the promised date"], ["tight", "Tight", "var(--warn)", "Built 0 to 1 day before the promised date"], ["late", "Late", "var(--bad)", "Built after the promised date"], ]; function PromiseCard({ p }) { const tipProps = useTipProps(); const { set } = useUi(); const total = p?.orders || 0; return (
{!total ?
{tr("No customer orders affected yet.")}
: <>
{fmt(p.bands.late)}
{tr("orders now late")}
{fmt(p.avg_delay_days)}{tr(" days")}
{tr("average build delay")}
{fmt(p.max_days_late)}{tr(" days")}
{tr("latest past promise")}
`${tr(l)} ${p.bands[k]}`).join(", ")}> {BANDS.map(([k, label, color, hint]) => p.bands[k] > 0 && ( ))}
{BANDS.map(([k, label, color, hint]) => (
{tr(label)}{fmt(p.bands[k])} {tr("{n} priority", { n: fmt(p.priority[k]) })}
))}
{p.late_priority ? tr("{n} of {m} late Platinum and Gold customers have a loaner", { n: fmt(p.late_priority_with_loaner), m: fmt(p.late_priority) }) : tr("No Platinum or Gold customer is late")}
{p.most_at_risk.length > 0 && <>
{tr("Most at risk")}
{p.most_at_risk.map((o) => ( ))}
} }
); } // The first thing a visitor sees: what this is, how well it works (from the saved test runs), and a // button that plays the given events through the real tower, live. Online the numbers come only from // the visitor's own test run of the demo events ("—" until they run one). function Hero({ run }) { const d = useData(); const { toast } = useUi(); const job = run.job; const reader = (sid, label) => d.suiteById(sid)?.readers.find((r) => r.label === label); const blind = reader("blind100", tr("AI model")), rules = reader("blind100", tr("Rule reader")), given = reader("given", tr("AI model")); // Online the demo has a short set of the given events: count only their test results. const demoCases = d.demoSize && given?.cases ? given.cases.filter((c) => d.demoIds.includes(c.id)) : null; const tested = demoCases ? { passed: demoCases.filter((c) => c.verdict === "PASS").length, total: demoCases.length } : given; const pct = (r) => (r && r.total ? Math.round((r.passed / r.total) * 100) : null); const now = job?.current ? String(job.current) : ""; const runDemo = async () => { const err = await run.start(); if (err) toast(err); }; return (
); } export default function Overview() { const d = useData(); const { ui, set } = useUi(); const traces = d.traces; const calls = d.log.length; const failed = d.log.filter((r) => !r.ok).length; const escal = d.log.filter((r) => r.tool === "escalate").length; const count = (o) => traces.filter((t) => d.outcome(t.event_id) === o).length; const acted = count("acted"); const incidents = traces.flatMap((t) => t.incidents || []); const filtered = useFilteredTraces(); const run = useEventRun(); // The map follows the event just handled: the newest in a run, otherwise the newest real incident. const lastRun = run.job?.events?.[run.job.events.length - 1]?.id; const lastReal = [...traces].reverse().find((t) => (t.incidents || []).some((i) => i.plant_id))?.event_id; const focusId = (lastRun && d.traceById[lastRun] ? lastRun : null) || lastReal; const open = (id) => { set({ sel: id, openEvent: id }); go("#/events"); }; const chartData = traces.map((t) => { const rows = d.byEvent[t.event_id] || []; const vals = GROUPS.map((g) => rows.filter((r) => g.tools.includes(r.tool)).length); return { id: t.event_id, vals, total: vals.reduce((a, b) => a + b, 0) }; }); const subtitle = <> {tr("Monday 8 March 2027")} {trx("{n} events, {m} acted on", { n: {fmt(traces.length)}, m: {fmt(acted)} })} {trx("{n} tool calls", { n: {fmt(calls)} })} {trx("{n} failed", { n: {fmt(failed)} })} ; return (
{d.agents.length > 0 && (
{d.agents.map((a) => )}
)}
set({ chartView: v })} />
{GROUPS.map((g) => {g.label})}
{ui.chartView === "table" ? : }
{tr("View all")}
{filtered.map((t) => ( open(t.event_id)}> ))}
{tr("Event")}{tr("Message")}{tr("Read as")}{tr("Calls")}{tr("Outcome")}
{t.event_id}
{t.source}
{t.text}
{kindsOf(t).map((k, i) => )} {fmt((d.byEvent[t.event_id] || []).length)}
{traces.map((t) => )}
); }