Open History to see the last commit
1import { RefreshCwIcon } from "lucide-react";
2import type { ReactNode } from "react";
3
4import { threadSyncLabel, type ThreadSyncPhase } from "../../threadSync";
5import { cn } from "~/lib/utils";
6
7/** A line of thread state for the end of the timeline. */
8export interface ThreadNowItem {
9 readonly id: string;
10 readonly icon: ReactNode;
11 readonly title: ReactNode;
12 readonly description?: ReactNode;
13 readonly actions?: ReactNode;
14}
15
16/** Matches ThreadStatusLine, so every line at the end of the timeline reads as one family. */
17const lineClassName = cn(
18 "mx-auto flex w-full min-w-0 max-w-(--chat-content-max-width) items-center gap-1.5 px-1 pb-2 text-xs text-muted-foreground [&_svg]:size-3.5 [&_svg]:shrink-0",
19 // Inline actions keep their text size but get a finger-sized hit area on touch.
20 "pointer-coarse:[&_[data-slot=inline-button]]:relative pointer-coarse:[&_[data-slot=inline-button]]:after:absolute pointer-coarse:[&_[data-slot=inline-button]]:after:-inset-x-1.5 pointer-coarse:[&_[data-slot=inline-button]]:after:-inset-y-3.5",
21 "transition-opacity duration-150 ease-out starting:opacity-0 motion-reduce:transition-none",
22);
23
24/** One line of thread state at the end of the timeline: icon, title, detail, then actions. */
25function ThreadNowLine({
26 item,
27 announce = false,
28}: {
29 readonly item: ThreadNowItem;
30 /** Announces the line when it appears; only for something that needs the user. */
31 readonly announce?: boolean;
32}) {
33 return (
34 <div
35 role={announce ? "alert" : undefined}
36 className={cn(lineClassName, "items-baseline")}
37 data-thread-now-line="true"
38 >
39 <span aria-hidden className="flex size-3.5 shrink-0 self-center items-center justify-center">
40 {item.icon}
41 </span>
42 <span className="min-w-0 truncate">
43 {item.title}
44 {item.description ? (
45 <>
46 {" "}
47 <span className="ms-0.5 text-muted-foreground/60 light:text-muted-foreground/80">
48 {item.description}
49 </span>
50 </>
51 ) : null}
52 </span>
53 {item.actions ? (
54 <span className="ms-1.5 flex shrink-0 items-baseline gap-2.5">{item.actions}</span>
55 ) : null}
56 </div>
57 );
58}
59
60function ThreadSyncLine({ phase }: { readonly phase: ThreadSyncPhase }) {
61 return (
62 <div className={lineClassName} role="status" data-composer-sync-status={phase}>
63 <RefreshCwIcon aria-hidden />
64 <span className="truncate">{threadSyncLabel(phase)}</span>
65 </div>
66 );
67}
68
69/**
70 * What the thread is doing now, at the end of the timeline: what needs you, background work,
71 * the sync status while messages load, then the goal.
72 */
73export function ThreadNow({
74 attention,
75 work,
76 syncPhase,
77 goal,
78}: {
79 /** Something that needs you elsewhere, such as a subagent's question. */
80 readonly attention: ThreadNowItem | null;
81 readonly work: ThreadNowItem | null;
82 readonly syncPhase: ThreadSyncPhase | null;
83 readonly goal: ThreadNowItem | null;
84}): ReactNode {
85 return (
86 <>
87 {attention ? <ThreadNowLine item={attention} announce /> : null}
88 {work ? <ThreadNowLine item={work} /> : null}
89 {syncPhase ? <ThreadSyncLine phase={syncPhase} /> : null}
90 {goal ? <ThreadNowLine item={goal} /> : null}
91 </>
92 );
93}