From c6aa55cb1f54c8e592359f519e7df0f8037509cc Mon Sep 17 00:00:00 2001 From: Luis Markmann <110569833+lmarkmann@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:01:47 +0100 Subject: [PATCH 1/5] feat(web): Inspector agent panel on AI Elements with live voice transcript --- .changeset/inspector-panel.md | 5 + apps/web/package.json | 4 + apps/web/src/components/app-header.tsx | 7 +- .../web/src/components/inspector/evidence.tsx | 157 +++ .../src/components/inspector/inspector.tsx | 460 +++++++ .../src/components/inspector/seal-check.tsx | 107 ++ .../src/components/inspector/tool-step.tsx | 140 ++ apps/web/src/components/omnibox.tsx | 243 ---- apps/web/src/components/packing-station.tsx | 203 +-- apps/web/src/components/ui/bubble.tsx | 123 ++ apps/web/src/components/ui/collapsible.tsx | 15 + apps/web/src/components/ui/hover-card.tsx | 43 + apps/web/src/components/ui/input-group.tsx | 144 ++ apps/web/src/components/ui/item.tsx | 188 +++ apps/web/src/components/ui/kbd.tsx | 26 + .../src/components/ui/message-scroller.tsx | 128 ++ apps/web/src/components/ui/message.tsx | 84 ++ apps/web/src/components/ui/separator.tsx | 20 + apps/web/src/components/ui/spinner.tsx | 16 + apps/web/src/components/ui/trace.tsx | 149 +++ apps/web/src/debug/state-gallery.tsx | 131 ++ apps/web/src/hooks/use-pack-session.ts | 7 + apps/web/src/hooks/use-push-to-talk.ts | 48 + apps/web/src/hooks/use-seal-check.ts | 47 + apps/web/src/hooks/use-voice.ts | 143 +- apps/web/src/index.css | 3 + apps/web/src/lib/api.ts | 8 +- apps/web/src/lib/inspector.test.ts | 32 + apps/web/src/lib/inspector.ts | 70 + apps/web/src/lib/wav.ts | 24 +- pnpm-lock.yaml | 1175 +++++++++++++++++ pnpm-workspace.yaml | 4 + 32 files changed, 3583 insertions(+), 371 deletions(-) create mode 100644 .changeset/inspector-panel.md create mode 100644 apps/web/src/components/inspector/evidence.tsx create mode 100644 apps/web/src/components/inspector/inspector.tsx create mode 100644 apps/web/src/components/inspector/seal-check.tsx create mode 100644 apps/web/src/components/inspector/tool-step.tsx delete mode 100644 apps/web/src/components/omnibox.tsx create mode 100644 apps/web/src/components/ui/bubble.tsx create mode 100644 apps/web/src/components/ui/collapsible.tsx create mode 100644 apps/web/src/components/ui/hover-card.tsx create mode 100644 apps/web/src/components/ui/input-group.tsx create mode 100644 apps/web/src/components/ui/item.tsx create mode 100644 apps/web/src/components/ui/kbd.tsx create mode 100644 apps/web/src/components/ui/message-scroller.tsx create mode 100644 apps/web/src/components/ui/message.tsx create mode 100644 apps/web/src/components/ui/separator.tsx create mode 100644 apps/web/src/components/ui/spinner.tsx create mode 100644 apps/web/src/components/ui/trace.tsx create mode 100644 apps/web/src/hooks/use-push-to-talk.ts create mode 100644 apps/web/src/hooks/use-seal-check.ts create mode 100644 apps/web/src/lib/inspector.test.ts create mode 100644 apps/web/src/lib/inspector.ts diff --git a/.changeset/inspector-panel.md b/.changeset/inspector-panel.md new file mode 100644 index 0000000..e447d6c --- /dev/null +++ b/.changeset/inspector-panel.md @@ -0,0 +1,5 @@ +--- +"web": minor +--- + +The station's Cmd-K omnibox becomes the Inspector, a docked agent panel built on AI Elements: one thread per order, live tool steps, cited moments that play in place with the detector's boxes, suggestions per bench state, hold Space to talk with a live Canary transcript, and the after-seal check with Repack or Ship as short. diff --git a/apps/web/package.json b/apps/web/package.json index ef124d0..ded6f03 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -11,12 +11,15 @@ "deploy": "vp run build && wrangler deploy" }, "dependencies": { + "@ai-sdk/react": "catalog:", "@base-ui/react": "^1.9.0", "@dicebear/collection": "catalog:", "@dicebear/core": "catalog:", "@fontsource-variable/instrument-sans": "^5.2.0", + "@shadcn/react": "catalog:", "@tailwindcss/vite": "^4", "@workos-inc/authkit-react": "catalog:", + "ai": "catalog:", "barcode-detector": "catalog:", "class-variance-authority": "^0.7.1", "cn": "^0.4.0", @@ -25,6 +28,7 @@ "react-dom": "^19.3.0", "react-error-boundary": "catalog:", "shadcn": "^4.21.5", + "streamdown": "catalog:", "tailwindcss": "^4", "tw-animate-css": "^1.4.0", "zxing-wasm": "catalog:" diff --git a/apps/web/src/components/app-header.tsx b/apps/web/src/components/app-header.tsx index 68cd712..8f7598d 100644 --- a/apps/web/src/components/app-header.tsx +++ b/apps/web/src/components/app-header.tsx @@ -2,7 +2,7 @@ import { notionists } from "@dicebear/collection"; import { createAvatar } from "@dicebear/core"; import { type User, useAuth } from "@workos-inc/authkit-react"; import { LogOutIcon } from "lucide-react"; -import { useMemo } from "react"; +import { type ReactNode, useMemo } from "react"; import { ThemeSwitch } from "@/components/theme-switch"; import { Avatar, AvatarImage } from "@/components/ui/avatar"; @@ -67,17 +67,18 @@ export function UserMenu({ user, onSignOut }: { user: Account; onSignOut: () => ); } -export function AppHeader() { +export function AppHeader({ children }: { children?: ReactNode }) { const { user, signOut } = useAuth(); return (
-
+
ProofBox Packing station
+ {children} {user && signOut()} />}
diff --git a/apps/web/src/components/inspector/evidence.tsx b/apps/web/src/components/inspector/evidence.tsx new file mode 100644 index 0000000..0f0b123 --- /dev/null +++ b/apps/web/src/components/inspector/evidence.tsx @@ -0,0 +1,157 @@ +import { ExternalLinkIcon, PlayIcon, VideoOffIcon } from "lucide-react"; +import { useEffect, useRef, useState } from "react"; + +import { labelColor, VisionOverlay } from "@/components/vision-overlay"; +import { Button } from "@/components/ui/button"; +import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/ui/hover-card"; +import { getTrack, packVideoUrl } from "@/lib/api"; +import { clipRange, type EvidenceClip } from "@/lib/inspector"; +import { cn } from "@/lib/utils"; +import { detectionsAt, type Frame, framesOf } from "@/proof/pack-model"; + +const tracks = new Map>(); + +function framesFor(packId: string) { + let frames = tracks.get(packId); + if (!frames) { + frames = getTrack(packId) + .then(framesOf) + .catch(() => { + tracks.delete(packId); + return []; + }); + tracks.set(packId, frames); + } + return frames; +} + +// a cited moment is a few seconds at most; replaying a little past it keeps the item in frame +const TAIL_S = 0.75; + +/** Plays one cited moment of a pack's clip in place, looping it, with the detector's boxes on top. */ +function EvidencePlayer({ clip }: { clip: EvidenceClip }) { + const player = useRef(null); + const [frames, setFrames] = useState([]); + const [ms, setMs] = useState(0); + const [frameSize, setFrameSize] = useState<{ width: number; height: number } | null>(null); + const [failed, setFailed] = useState(false); + const start = clip.start_s ?? 0; + + useEffect(() => { + let live = true; + void framesFor(clip.pack_id).then((loaded) => live && setFrames(loaded)); + return () => { + live = false; + }; + }, [clip.pack_id]); + + useEffect(() => { + const element = player.current; + if (!element) return; + let handle = element.requestVideoFrameCallback(function tick(_, frame) { + setMs(frame.mediaTime * 1000); + if (clip.end_s !== null && frame.mediaTime > clip.end_s + TAIL_S) element.currentTime = start; + handle = element.requestVideoFrameCallback(tick); + }); + return () => element.cancelVideoFrameCallback(handle); + }, [clip.end_s, start]); + + return ( +
+
+
+
+ {clip.text} + {clip.order_id && ( + + Proof page + + + )} +
+
+ ); +} + +/** The answer's citations as chips; choosing one plays that moment right under the answer. */ +export function EvidenceRow({ clips }: { clips: EvidenceClip[] }) { + const [playing, setPlaying] = useState(null); + const shown = playing === null ? null : clips[playing]; + return ( +
+
+ {clips.map((clip, index) => ( + + setPlaying(playing === index ? null : index)} + className="tabular-nums" + /> + } + > + + {clip.label} + {clipRange(clip) && {clipRange(clip)}} + + +

+ {clip.order_id ?? clip.pack_id.slice(0, 8)} {clipRange(clip)} +

+

{clip.text}

+

+ + Click to play this moment here +

+
+
+ ))} +
+ {shown && } +
+ ); +} diff --git a/apps/web/src/components/inspector/inspector.tsx b/apps/web/src/components/inspector/inspector.tsx new file mode 100644 index 0000000..5ec9c6f --- /dev/null +++ b/apps/web/src/components/inspector/inspector.tsx @@ -0,0 +1,460 @@ +import { Chat, useChat } from "@ai-sdk/react"; +import { DefaultChatTransport, isStaticToolUIPart } from "ai"; +import { + ArrowUpIcon, + CircleAlertIcon, + ExternalLinkIcon, + MicIcon, + SparklesIcon, + SquareIcon, + SquarePenIcon, + XIcon, +} from "lucide-react"; +import { type FormEvent, type ReactNode, useEffect, useRef, useState } from "react"; +import { Streamdown } from "streamdown"; + +import { EvidenceRow } from "@/components/inspector/evidence"; +import { type CheckChoice, SealCheckCard } from "@/components/inspector/seal-check"; +import { ToolStep } from "@/components/inspector/tool-step"; +import { Bubble, BubbleContent } from "@/components/ui/bubble"; +import { Button } from "@/components/ui/button"; +import { + InputGroup, + InputGroupAddon, + InputGroupButton, + InputGroupTextarea, +} from "@/components/ui/input-group"; +import { Kbd } from "@/components/ui/kbd"; +import { Message, MessageContent, MessageFooter } from "@/components/ui/message"; +import { + MessageScroller, + MessageScrollerButton, + MessageScrollerContent, + MessageScrollerItem, + MessageScrollerProvider, + MessageScrollerViewport, +} from "@/components/ui/message-scroller"; +import { Spinner } from "@/components/ui/spinner"; +import { Trace, TraceIcon, TraceLine, TraceTitle } from "@/components/ui/trace"; +import { usePushToTalk } from "@/hooks/use-push-to-talk"; +import type { CheckState } from "@/hooks/use-seal-check"; +import { useVoice, type VoiceState } from "@/hooks/use-voice"; +import { + type BenchPhase, + type EvidenceClip, + type InspectorMessage, + suggestionsFor, +} from "@/lib/inspector"; +import { cn } from "@/lib/utils"; + +const ANY_ORDER = "*"; + +function newChat(scope: string | null) { + return new Chat({ + id: scope ?? ANY_ORDER, + transport: new DefaultChatTransport({ api: "/api/chat", body: { order_id: scope } }), + }); +} + +function Thinking({ children = "Thinking with W&B Inference" }: { children?: ReactNode }) { + return ( + + + + + + {children} + + + ); +} + +function AgentMessage({ message, streaming }: { message: InspectorMessage; streaming: boolean }) { + const clips: EvidenceClip[] = []; + const body: ReactNode[] = []; + let waiting = streaming; + message.parts.forEach((part, index) => { + if (isStaticToolUIPart(part)) { + waiting = streaming && part.state === "output-available"; + body.push(); + } else if (part.type === "text") { + waiting = false; + body.push( + + {part.text} + , + ); + } else if (part.type === "data-evidence") clips.push(part.data); + }); + const traceUrl = message.metadata?.traceUrl; + return ( + + + {body} + {waiting && } + {clips.length > 0 && !streaming && } + {!streaming && ( + + W&B Inference + {traceUrl && ( + <> + {" "} + {"·"} + + Weave trace + + + + )} + + )} + + + ); +} + +function UserMessage({ message }: { message: InspectorMessage }) { + const text = message.parts.flatMap((part) => (part.type === "text" ? [part.text] : [])).join(""); + return ( + + + + {text} + + + + ); +} + +function EmptyThread({ scope }: { scope: string | null }) { + return ( +
+ + + +

{scope ? `Ask about ${scope}` : "Ask about any pack"}

+

+ The agent reads orders from VastDB, has Cosmos watch the pack video and searches the VAST + archive, then cites the moments it saw. +

+
+ ); +} + +function voiceHint(voice: VoiceState) { + if (voice.tag === "recording") + return ( + + + Listening, release to send + + ); + if (voice.tag === "transcribing") + return ( + + + Finishing with Canary-1B + + ); + if (voice.tag === "failed") return {voice.detail}; + return ( + + Hold Space to talk + + ); +} + +/** + * The station's agent panel: one thread per order, tool steps as they run, cited moments that + * play in place, and the after-seal check. Docked beside the station on wide screens. + */ +export function Inspector({ + open, + onOpenChange, + orderId, + phase, + check, + onRepack, +}: { + open: boolean; + onOpenChange: (open: boolean) => void; + orderId: string | null; + phase: BenchPhase; + check: CheckState; + onRepack: () => void; +}) { + const [unscopedFrom, setUnscopedFrom] = useState(null); + const scope = orderId && unscopedFrom !== orderId ? orderId : null; + const chats = useRef(new Map>()); + const key = scope ?? ANY_ORDER; + if (!chats.current.has(key)) chats.current.set(key, newChat(scope)); + const { messages, status, error, sendMessage, stop, regenerate, setMessages } = useChat({ + chat: chats.current.get(key)!, + }); + const busy = status === "submitted" || status === "streaming"; + + const [draft, setDraft] = useState(""); + const textarea = useRef(null); + const [choices, setChoices] = useState>({}); + + function ask(text: string) { + const question = text.trim(); + if (!question) return; + if (busy) return setDraft(question); + setDraft(""); + void sendMessage({ text: question }); + } + + const voice = useVoice((text) => { + onOpenChange(true); + ask(text); + }); + usePushToTalk(() => { + onOpenChange(true); + void voice.start(); + }, voice.stop); + const heard = + voice.state.tag === "recording" || voice.state.tag === "transcribing" + ? voice.state.partial + : null; + const listening = heard !== null; + + useEffect(() => { + const onKey = (event: KeyboardEvent) => { + if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") { + event.preventDefault(); + onOpenChange(!open); + } + }; + window.addEventListener("keydown", onKey); + return () => window.removeEventListener("keydown", onKey); + }, [open, onOpenChange]); + + useEffect(() => { + if (open) textarea.current?.focus(); + }, [open]); + + const flagged = check.tag === "ready" && check.check.verdict !== "complete"; + useEffect(() => { + if (flagged) onOpenChange(true); + }, [flagged, onOpenChange]); + + if (!open) return null; + + const sealedHere = phase.tag === "sealed" && scope === phase.orderId; + const checkPackId = + check.tag === "ready" ? check.check.pack_id : check.tag === "none" ? null : check.packId; + const suggestions = suggestionsFor(phase, scope !== null); + const last = messages.at(-1); + + return ( + + ); +} diff --git a/apps/web/src/components/inspector/seal-check.tsx b/apps/web/src/components/inspector/seal-check.tsx new file mode 100644 index 0000000..8dbc0e6 --- /dev/null +++ b/apps/web/src/components/inspector/seal-check.tsx @@ -0,0 +1,107 @@ +import { CircleCheckIcon, RotateCcwIcon, ScanEyeIcon, TriangleAlertIcon } from "lucide-react"; + +import { Button } from "@/components/ui/button"; +import { + Item, + ItemActions, + ItemContent, + ItemDescription, + ItemMedia, + ItemTitle, +} from "@/components/ui/item"; +import { Trace, TraceIcon, TraceLine, TraceTitle } from "@/components/ui/trace"; +import type { CheckState } from "@/hooks/use-seal-check"; +import { assertNever } from "@/lib/assert-never"; + +export type CheckChoice = "repack" | "ship"; + +/** + * The agent's own look at a box right after it is sealed. A disagreement with the order + * asks the packer to repack or ship it as it is. + */ +export function SealCheckCard({ + state, + orderId, + choice, + onChoose, +}: { + state: CheckState; + orderId: string; + choice: CheckChoice | null; + onChoose: (choice: CheckChoice) => void; +}) { + switch (state.tag) { + case "none": + return null; + case "pending": + return ( + + + + + + Cosmos is checking the sealed box against {orderId} + + + ); + case "unavailable": + return ( +

+ The after-seal check did not finish, so the detector's count stands. +

+ ); + case "ready": { + const { verdict, text } = state.check; + if (verdict === "complete") + return ( + + + + + + Cosmos agrees, everything on {orderId} went in + {text} + + + ); + const shipAs = verdict === "short" ? "Ship as short" : "Ship as is"; + return ( + + + + + + + {verdict === "short" + ? `Cosmos counted less than ${orderId} needs` + : `Cosmos saw something not on ${orderId}`} + + {text} + + {choice ? ( +

+ {choice === "repack" ? "Repacking with a new recording." : `${shipAs}, noted.`} +

+ ) : ( + + + + + )} +
+ ); + } + default: + return assertNever(state); + } +} diff --git a/apps/web/src/components/inspector/tool-step.tsx b/apps/web/src/components/inspector/tool-step.tsx new file mode 100644 index 0000000..865192b --- /dev/null +++ b/apps/web/src/components/inspector/tool-step.tsx @@ -0,0 +1,140 @@ +import type { ToolUIPart } from "ai"; +import { DatabaseIcon, ScanEyeIcon, SearchIcon } from "lucide-react"; +import type { ReactNode } from "react"; + +import { + Trace, + TraceCollapsible, + TraceCollapsibleContent, + TraceCollapsibleTrigger, + TraceDescription, + TraceIcon, + TraceLine, + TraceTitle, +} from "@/components/ui/trace"; +import { assertNever } from "@/lib/assert-never"; +import { clipRange, type InspectorTools } from "@/lib/inspector"; + +export type ToolPart = ToolUIPart; + +type Step = { icon: ReactNode; running: string; done: string; detail?: string; body?: ReactNode }; + +const shortId = (packId: string | undefined) => (packId ? packId.slice(0, 8) : ""); + +function describe(part: ToolPart): Step { + switch (part.type) { + case "tool-getOrder": { + const id = part.output?.order_id ?? part.input?.order_id ?? "the order"; + const order = part.output; + return { + icon: , + running: `Reading ${id} from VastDB`, + done: `Read ${id} from VastDB`, + detail: + order && + `${order.items.length} lines, ${order.packs.length} ${order.packs.length === 1 ? "pack" : "packs"}`, + body: order && ( +
    + {order.items.map((item) => ( +
  • + {item.qty}x {item.name} +
  • + ))} + {order.packs.map((pack) => ( +
  • + Pack {shortId(pack.pack_id)}: {pack.verdict} +
  • + ))} +
+ ), + }; + } + case "tool-watchPack": { + const pack = shortId(part.output?.pack_id ?? part.input?.pack_id); + return { + icon: , + running: `Cosmos is watching pack ${pack}`, + done: `Cosmos watched pack ${pack}`, + detail: part.output && `${part.output.seconds.toFixed(1)} s`, + body: part.output &&

{part.output.seen}

, + }; + } + case "tool-searchArchive": { + const query = part.output?.query ?? part.input?.query; + const hits = part.output?.hits; + return { + icon: , + running: query ? `Searching the VAST archive for "${query}"` : "Searching the VAST archive", + done: query ? `Searched the VAST archive for "${query}"` : "Searched the VAST archive", + detail: hits && `${hits.length} ${hits.length === 1 ? "clip" : "clips"}`, + body: hits && ( +
    + {hits.map((hit, index) => ( +
  • + + {hit.order_id ?? shortId(hit.pack_id)} {clipRange(hit)} + {" "} + {hit.text} +
  • + ))} +
+ ), + }; + } + default: + return assertNever(part); + } +} + +/** One agent tool call: present tense with a shimmer while it runs, past tense and expandable after. */ +export function ToolStep({ part }: { part: ToolPart }) { + const step = describe(part); + switch (part.state) { + case "input-streaming": + case "input-available": + case "approval-requested": + case "approval-responded": + return ( + + + {step.icon} + {step.running} + + + ); + case "output-error": + case "output-denied": + return ( + + + + + {step.icon} + {step.running} failed + + + + {"errorText" in part ? part.errorText : "The tool call was refused."} + + + + ); + case "output-available": + return ( + + + + + {step.icon} + {step.done} + {step.detail && {step.detail}} + + + {step.body} + + + ); + default: + return assertNever(part); + } +} diff --git a/apps/web/src/components/omnibox.tsx b/apps/web/src/components/omnibox.tsx deleted file mode 100644 index d0d476c..0000000 --- a/apps/web/src/components/omnibox.tsx +++ /dev/null @@ -1,243 +0,0 @@ -import { - CircleAlertIcon, - LoaderCircleIcon, - MicIcon, - PlayIcon, - SearchIcon, - SparklesIcon, - SquareIcon, - XIcon, -} from "lucide-react"; -import { type FormEvent, useEffect, useRef, useState } from "react"; - -import { Button } from "@/components/ui/button"; -import { useVoice, type VoiceState } from "@/hooks/use-voice"; -import { type Answer, ask, type Evidence } from "@/lib/api"; -import { assertNever } from "@/lib/assert-never"; -import { cn } from "@/lib/utils"; - -type AskState = - | { tag: "idle" } - | { tag: "asking"; question: string } - | { tag: "answered"; question: string; answer: Answer } - | { tag: "failed"; question: string; detail: string }; - -function clock(seconds: number) { - const whole = Math.max(0, Math.round(seconds)); - return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`; -} - -function EvidenceChip({ evidence }: { evidence: Evidence }) { - const range = - evidence.start_s === null - ? null - : `${clock(evidence.start_s)}${evidence.end_s === null ? "" : `-${clock(evidence.end_s)}`}`; - const label = [evidence.order_id ?? evidence.pack_id ?? "clip", range].filter(Boolean).join(" "); - const chip = ( - <> - - {label} - - ); - const className = - "inline-flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-xs font-medium tabular-nums"; - return evidence.order_id ? ( - - {chip} - - ) : ( - - {chip} - - ); -} - -function voiceHint(voice: VoiceState) { - switch (voice.tag) { - case "idle": - return null; - case "recording": - return "Listening. Click the mic again when you are done."; - case "transcribing": - return "Transcribing with Canary-1B."; - case "failed": - return voice.detail; - default: - return assertNever(voice); - } -} - -/** Ask anything about an order, typed or spoken; scoped to the box on the bench when there is one. */ -export function Omnibox({ orderId }: { orderId: string | null }) { - const input = useRef(null); - const pending = useRef(null); - const [question, setQuestion] = useState(""); - const [unscopedFrom, setUnscopedFrom] = useState(null); - const [result, setResult] = useState({ tag: "idle" }); - const scope = orderId && unscopedFrom !== orderId ? orderId : null; - - async function submit(text: string) { - const trimmed = text.trim(); - if (!trimmed) return; - pending.current?.abort(); - const controller = new AbortController(); - pending.current = controller; - setResult({ tag: "asking", question: trimmed }); - try { - const answer = await ask(trimmed, scope, controller.signal); - setResult({ tag: "answered", question: trimmed, answer }); - } catch (cause) { - if (controller.signal.aborted) return; - setResult({ - tag: "failed", - question: trimmed, - detail: cause instanceof Error ? cause.message : String(cause), - }); - } - } - - const voice = useVoice((text) => { - setQuestion(text); - void submit(text); - }); - - useEffect(() => { - const onKey = (event: KeyboardEvent) => { - if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") { - event.preventDefault(); - input.current?.focus(); - } - }; - window.addEventListener("keydown", onKey); - return () => window.removeEventListener("keydown", onKey); - }, []); - - useEffect(() => () => pending.current?.abort(), []); - - const hint = voiceHint(voice.state); - - return ( -
-
{ - event.preventDefault(); - void submit(question); - }} - className="flex items-center gap-2 rounded-xl bg-card p-2 pl-3 ring-1 ring-foreground/10 focus-within:ring-2 focus-within:ring-ring" - > - - {scope && ( - - {scope} - - - )} - setQuestion(event.target.value)} - onKeyDown={(event) => { - if (event.key === "Backspace" && !question && scope) setUnscopedFrom(scope); - }} - placeholder={ - scope ? `Ask about ${scope}, e.g. was anything missing?` : "Ask about any order or pack" - } - aria-label="Question" - className="min-w-0 flex-1 bg-transparent py-1.5 text-sm outline-none placeholder:text-muted-foreground" - /> - - {"\u2318"}K - - - - - {hint && ( -

- {hint} -

- )} - setResult({ tag: "idle" })} /> -
- ); -} - -function AnswerCard({ result, onDismiss }: { result: AskState; onDismiss: () => void }) { - if (result.tag === "idle") return null; - return ( -
-
-

{result.question}

- -
- {result.tag === "asking" && ( -

- - Watching the pack video with Cosmos. -

- )} - {result.tag === "failed" && ( -

- - {result.detail} -

- )} - {result.tag === "answered" && ( - <> -

- - {result.answer.answer} -

- {result.answer.evidence.length > 0 && ( -
- {result.answer.evidence.map((evidence, index) => ( - - ))} -
- )} - - )} -
- ); -} diff --git a/apps/web/src/components/packing-station.tsx b/apps/web/src/components/packing-station.tsx index 6bd2d1a..a142007 100644 --- a/apps/web/src/components/packing-station.tsx +++ b/apps/web/src/components/packing-station.tsx @@ -1,21 +1,59 @@ -import { WifiOffIcon } from "lucide-react"; +import { SparklesIcon, WifiOffIcon } from "lucide-react"; import { type RefObject, useCallback, useEffect, useRef, useState } from "react"; import { ActivityLog, usePackHistory } from "@/components/activity-log"; import { AppHeader } from "@/components/app-header"; import { CameraPanel } from "@/components/camera-panel"; import { LabelPanel, type PrintedLabel } from "@/components/label-panel"; -import { Omnibox } from "@/components/omnibox"; +import { Inspector } from "@/components/inspector/inspector"; import { PackHud, PackPanel } from "@/components/pack-panel"; import { PanelBoundary } from "@/components/panel-boundary"; import { StatusStrip } from "@/components/status-strip"; import { VisionOverlay } from "@/components/vision-overlay"; +import { Button } from "@/components/ui/button"; +import { Kbd } from "@/components/ui/kbd"; import { useCamera } from "@/hooks/use-camera"; import { useOnline } from "@/hooks/use-online"; import { usePackSession } from "@/hooks/use-pack-session"; import { type ApiHealth, type PrinterHealth, toPrinterStatus, useProbe } from "@/hooks/use-probe"; import { useQr } from "@/hooks/use-qr"; +import { useSealCheck } from "@/hooks/use-seal-check"; import { useVision } from "@/hooks/use-vision"; +import type { BenchPhase } from "@/lib/inspector"; +import type { PackState } from "@/hooks/use-pack-session"; + +function benchPhase(state: PackState): BenchPhase { + switch (state.tag) { + case "packing": + case "sealing": + case "seal-failed": + return { tag: "packing", orderId: state.order.order_id }; + case "sealed": + return { + tag: "sealed", + orderId: state.order.order_id, + items: state.order.items, + short: state.result.verdict !== "complete", + }; + default: + return { tag: "idle" }; + } +} + +function AskButton({ onClick, flagged }: { onClick: () => void; flagged: boolean }) { + return ( + + ); +} export function OfflineBanner() { return ( @@ -83,6 +121,9 @@ export function PackingStation() { const boundOrderId = "order" in session.state ? session.state.order.order_id : null; const seenOrderId = qr.sighting?.orderId ?? null; const foreignLabel = packing && seenOrderId && seenOrderId !== boundOrderId ? seenOrderId : null; + const [inspecting, setInspecting] = useState(false); + const check = useSealCheck(session.state.tag === "sealed" ? session.state.result.pack_id : null); + const flagged = check.tag === "ready" && check.check.verdict !== "complete"; useEffect(() => { if (!packing) return; @@ -96,82 +137,96 @@ export function PackingStation() { }, [packing, session]); return ( -
- - {!online && } -
-
-

Packing station

-

- Film the pack, print the label, ship every box with proof. -

-
- + + setInspecting((open) => !open)} + flagged={flagged && !inspecting} /> - -
-
- - - - + {!online && } +
+
+
+

Packing station

+

+ Film the pack, print the label, ship every box with proof. +

+
+ +
+
+ + + + + + +
+
+ + void session.seal()} + onRetrySeal={session.retrySeal} + onRetryLookup={session.retryLookup} + onReset={session.reset} /> - - -
-
- - void session.seal()} - onRetrySeal={session.retrySeal} - onRetryLookup={session.retryLookup} - onReset={session.reset} - /> - -
-
- - setLabels((all) => [label, ...all])} - /> - -
-
- - document.getElementById("order-id")?.focus()} - /> - + +
+
+ + setLabels((all) => [label, ...all])} + /> + +
+
+ + document.getElementById("order-id")?.focus()} + /> + +
-
-
+ + +
); } diff --git a/apps/web/src/components/ui/bubble.tsx b/apps/web/src/components/ui/bubble.tsx new file mode 100644 index 0000000..9818e69 --- /dev/null +++ b/apps/web/src/components/ui/bubble.tsx @@ -0,0 +1,123 @@ +import * as React from "react"; +import { mergeProps } from "@base-ui/react/merge-props"; +import { useRender } from "@base-ui/react/use-render"; +import { cva, type VariantProps } from "class-variance-authority"; +import { cn } from "cn"; + +function BubbleGroup({ className, ...props }: React.ComponentProps<"div">) { + return ( +
+ ); +} + +const bubbleVariants = cva( + "group/bubble relative flex w-fit max-w-[80%] min-w-0 flex-col gap-1 group-data-[align=end]/message:self-end data-[align=end]:self-end data-[variant=ghost]:max-w-full", + { + variants: { + variant: { + default: + "*:data-[slot=bubble-content]:bg-primary *:data-[slot=bubble-content]:text-primary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-primary/80", + secondary: + "*:data-[slot=bubble-content]:bg-secondary *:data-[slot=bubble-content]:text-secondary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)]", + muted: + "*:data-[slot=bubble-content]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--muted),var(--foreground)_5%)]", + tinted: + "*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.93_calc(c*0.4)_h)] *:data-[slot=bubble-content]:text-foreground dark:*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.3_calc(c*0.4)_h)] [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.88_calc(c*0.5)_h)] dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.35_calc(c*0.5)_h)]", + outline: + "*:data-[slot=bubble-content]:border-border *:data-[slot=bubble-content]:bg-background [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-input/30", + ghost: + "border-none *:data-[slot=bubble-content]:rounded-none *:data-[slot=bubble-content]:bg-transparent *:data-[slot=bubble-content]:p-0 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted/50", + destructive: + "*:data-[slot=bubble-content]:bg-destructive/10 *:data-[slot=bubble-content]:text-destructive dark:*:data-[slot=bubble-content]:bg-destructive/20 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/20 dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/30", + }, + }, + defaultVariants: { + variant: "default", + }, + }, +); + +function Bubble({ + variant = "default", + align = "start", + className, + ...props +}: React.ComponentProps<"div"> & + VariantProps & { + align?: "start" | "end"; + }) { + return ( +
+ ); +} + +function BubbleContent({ className, render, ...props }: useRender.ComponentProps<"div">) { + return useRender({ + defaultTagName: "div", + props: mergeProps<"div">( + { + className: cn( + "w-fit max-w-full min-w-0 overflow-hidden rounded-xl border border-transparent px-3 py-2 text-sm leading-relaxed wrap-break-word group-data-[align=end]/bubble:self-end [button]:text-left [button,a]:transition-colors [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring/50", + className, + ), + }, + props, + ), + render, + state: { + slot: "bubble-content", + }, + }); +} + +const bubbleReactionsVariants = cva( + "absolute z-10 flex w-fit shrink-0 items-center justify-center gap-1 rounded-full bg-muted px-1.5 py-0.5 text-sm ring-3 ring-card has-[button]:p-0", + { + variants: { + side: { + top: "top-0 -translate-y-3/4", + bottom: "bottom-0 translate-y-3/4", + }, + align: { + start: "left-3", + end: "right-3", + }, + }, + defaultVariants: { + side: "bottom", + align: "end", + }, + }, +); + +function BubbleReactions({ + side = "bottom", + align = "end", + className, + ...props +}: React.ComponentProps<"div"> & { + align?: "start" | "end"; + side?: "top" | "bottom"; +}) { + return ( +
+ ); +} + +export { BubbleGroup, Bubble, BubbleContent, BubbleReactions }; diff --git a/apps/web/src/components/ui/collapsible.tsx b/apps/web/src/components/ui/collapsible.tsx new file mode 100644 index 0000000..ee4277a --- /dev/null +++ b/apps/web/src/components/ui/collapsible.tsx @@ -0,0 +1,15 @@ +import { Collapsible as CollapsiblePrimitive } from "@base-ui/react/collapsible"; + +function Collapsible({ ...props }: CollapsiblePrimitive.Root.Props) { + return ; +} + +function CollapsibleTrigger({ ...props }: CollapsiblePrimitive.Trigger.Props) { + return ; +} + +function CollapsibleContent({ ...props }: CollapsiblePrimitive.Panel.Props) { + return ; +} + +export { Collapsible, CollapsibleTrigger, CollapsibleContent }; diff --git a/apps/web/src/components/ui/hover-card.tsx b/apps/web/src/components/ui/hover-card.tsx new file mode 100644 index 0000000..58e4c9e --- /dev/null +++ b/apps/web/src/components/ui/hover-card.tsx @@ -0,0 +1,43 @@ +import { PreviewCard as PreviewCardPrimitive } from "@base-ui/react/preview-card"; +import { cn } from "cn"; + +function HoverCard({ ...props }: PreviewCardPrimitive.Root.Props) { + return ; +} + +function HoverCardTrigger({ ...props }: PreviewCardPrimitive.Trigger.Props) { + return ; +} + +function HoverCardContent({ + className, + side = "bottom", + sideOffset = 4, + align = "center", + alignOffset = 4, + ...props +}: PreviewCardPrimitive.Popup.Props & + Pick) { + return ( + + + + + + ); +} + +export { HoverCard, HoverCardTrigger, HoverCardContent }; diff --git a/apps/web/src/components/ui/input-group.tsx b/apps/web/src/components/ui/input-group.tsx new file mode 100644 index 0000000..af0a326 --- /dev/null +++ b/apps/web/src/components/ui/input-group.tsx @@ -0,0 +1,144 @@ +import * as React from "react"; +import { cva, type VariantProps } from "class-variance-authority"; +import { cn } from "cn"; + +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Textarea } from "@/components/ui/textarea"; + +function InputGroup({ className, ...props }: React.ComponentProps<"div">) { + return ( +
[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-disabled:bg-input/80 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5", + className, + )} + {...props} + /> + ); +} + +const inputGroupAddonVariants = cva( + "flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4", + { + variants: { + align: { + "inline-start": "order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]", + "inline-end": "order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]", + "block-start": + "order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2", + "block-end": + "order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2", + }, + }, + defaultVariants: { + align: "inline-start", + }, + }, +); + +function InputGroupAddon({ + className, + align = "inline-start", + ...props +}: React.ComponentProps<"div"> & VariantProps) { + return ( +
{ + if ((e.target as HTMLElement).closest("button")) { + return; + } + e.currentTarget.parentElement?.querySelector("input")?.focus(); + }} + {...props} + /> + ); +} + +const inputGroupButtonVariants = cva("flex items-center gap-2 text-sm shadow-none", { + variants: { + size: { + xs: "h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5", + sm: "", + "icon-xs": "size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0", + "icon-sm": "size-8 p-0 has-[>svg]:p-0", + }, + }, + defaultVariants: { + size: "xs", + }, +}); + +function InputGroupButton({ + className, + type = "button", + variant = "ghost", + size = "xs", + ...props +}: Omit, "size" | "type"> & + VariantProps & { + type?: "button" | "submit" | "reset"; + }) { + return ( +