Spaces:
Sleeping
Sleeping
Download web/src/components/chat/Progress.tsx from TBM99/CoverageCheck: direct link, hf CLI and curl.
- Browser
- Download file 4.51 kB
-
https://huggingface.co/spaces/TBM99/CoverageCheck/resolve/main/web/src/components/chat/Progress.tsx
- Command line
-
hf download hf://spaces/TBM99/CoverageCheck/web/src/components/chat/Progress.tsx
-
curl -L -o Progress.tsx https://huggingface.co/spaces/TBM99/CoverageCheck/resolve/main/web/src/components/chat/Progress.tsx
4.51 kB
| import { Check, Circle, Loader2, MinusCircle } from 'lucide-react' | |
| import { useEffect, useState } from 'react' | |
| import { STEPS } from '@/lib/content' | |
| import { seconds } from '@/lib/format' | |
| import type { RunState, StepView } from '@/lib/run' | |
| import type { StepDetail } from '@/lib/types' | |
| import { cn } from '@/lib/utils' | |
| /** The run as it happens: C's graph node by node (with what each found), or A/B's steps | |
| * as one call. The running step shows a live timer from when the last event came. */ | |
| export function Progress({ run, since }: { run: RunState; since: number }) { | |
| const now = useNow(run.phase === 'running') | |
| return ( | |
| <div className="space-y-1"> | |
| {!run.live && run.steps.length > 0 && ( | |
| <p className="mb-2 text-xs text-muted-foreground"> | |
| System {run.system?.toUpperCase()} runs these steps in one call: no progress until the answer. | |
| </p> | |
| )} | |
| <ol className="space-y-1"> | |
| {run.steps.map((s) => ( | |
| <li key={s.name} className={cn('flex gap-2 rounded-md px-2 py-1.5', s.status === 'running' && 'bg-muted')}> | |
| <StatusIcon status={s.status} /> | |
| <div className="min-w-0 flex-1 break-words"> | |
| <div className="flex items-baseline justify-between gap-2 text-sm"> | |
| <span className={cn('font-medium', s.status === 'skipped' && 'text-muted-foreground line-through')}> | |
| {STEPS[s.name]?.title ?? s.name} | |
| </span> | |
| <span className="shrink-0 text-xs tabular-nums text-muted-foreground"> | |
| {s.status === 'done' ? seconds(s.ms) : s.status === 'running' ? seconds(now - since) : ''} | |
| {s.status === 'skipped' ? 'not needed' : ''} | |
| </span> | |
| </div> | |
| <p className="text-xs text-muted-foreground">{STEPS[s.name]?.what}</p> | |
| {s.status === 'done' && s.detail && <Detail step={s} detail={s.detail} />} | |
| </div> | |
| </li> | |
| ))} | |
| </ol> | |
| </div> | |
| ) | |
| } | |
| function StatusIcon({ status }: { status: StepView['status'] }) { | |
| const cls = 'mt-0.5 size-4 shrink-0' | |
| if (status === 'done') return <Check role="img" className={cn(cls, 'text-emerald-600')} aria-label="done" /> | |
| if (status === 'running') return <Loader2 role="img" className={cn(cls, 'animate-spin text-primary')} aria-label="running" /> | |
| if (status === 'skipped') return <MinusCircle role="img" className={cn(cls, 'text-muted-foreground')} aria-label="not needed" /> | |
| return <Circle role="img" className={cn(cls, 'text-muted-foreground/50')} aria-label="waiting" /> | |
| } | |
| /** What a finished step found, in a line or a short list. */ | |
| function Detail({ step, detail }: { step: StepView; detail: StepDetail }) { | |
| const line = 'mt-1 text-xs' | |
| switch (step.name) { | |
| case 'retrieve': | |
| return <p className={line}>{detail.candidates} candidate passages</p> | |
| case 'judge': | |
| case 'judge_new': | |
| return ( | |
| <ul className={cn(line, 'space-y-0.5')}> | |
| {(detail.requirements ?? []).map((r, i) => ( | |
| <li key={i} className="flex gap-1.5"> | |
| <span className={r.found ? 'text-emerald-700 dark:text-emerald-400' : 'text-amber-700 dark:text-amber-400'}> | |
| {r.found ? 'found' : 'missing'} | |
| </span> | |
| <span>{r.need}</span> | |
| </li> | |
| ))} | |
| </ul> | |
| ) | |
| case 'research': | |
| return ( | |
| <p className={line}> | |
| {(detail.queries ?? []).map((q) => `"${q}"`).join(', ')} → {detail.new_candidates} new passages | |
| </p> | |
| ) | |
| case 'select': | |
| return ( | |
| <p className={line}> | |
| {detail.kept} passages kept, {detail.expansions} cited sections added | |
| {detail.fallback ? ' (the judge kept none: the top search results are used)' : ''} | |
| </p> | |
| ) | |
| case 'verify': | |
| return ( | |
| <p className={line}> | |
| {detail.checked} citations checked | |
| {detail.retried ? `, ${detail.failed_first?.length ?? 0} failed the first time: the answer was retried` : ', all passed'} | |
| {detail.dropped ? `, ${detail.dropped} still failing and dropped` : ''} | |
| </p> | |
| ) | |
| default: | |
| return null | |
| } | |
| } | |
| /** The current time, ticking every 100 ms while `on`. */ | |
| function useNow(on: boolean): number { | |
| const [now, setNow] = useState(() => Date.now()) | |
| useEffect(() => { | |
| if (!on) return | |
| const timer = setInterval(() => setNow(Date.now()), 100) | |
| return () => clearInterval(timer) | |
| }, [on]) | |
| return now | |
| } | |