Open History to see the last commit
1import { CircleAlertIcon, RefreshCwIcon } from "lucide-react";
2import type { ReactNode } from "react";
3
4import { threadSyncLabel, type ThreadSyncPhase } from "../../threadSync";
5import { cn } from "~/lib/utils";
6import { useMessages } from "gt-react";
7
8/** A line of thread state for the end of the timeline. */
9export interface ThreadNowItem {
10 readonly id: string;
11 readonly icon: ReactNode;
12 readonly title: ReactNode;
13 readonly description?: ReactNode;
14 readonly actions?: ReactNode;
15}
16
17/** Matches ThreadStatusLine, so every line at the end of the timeline reads as one family. */
18const lineClassName = cn(
19 "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",
20 // Inline actions keep their text size but get a finger-sized hit area on touch.
21 "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",
22 "transition-opacity duration-150 ease-out starting:opacity-0 motion-reduce:transition-none",
23);
24
25/** One line of thread state at the end of the timeline: icon, title, detail, then actions. */
26function ThreadNowLine({
27 item,
28 announce = false,
29}: {
30 readonly item: ThreadNowItem;
31 /** Announces the line when it appears; only for something that needs the user. */
32 readonly announce?: boolean;
33}) {
34 return (
35 <div
36 role={announce ? "alert" : undefined}
37 className={cn(lineClassName, "items-baseline")}
38 data-thread-now-line="true"
39 >
40 <span aria-hidden className="flex size-3.5 shrink-0 self-center items-center justify-center">
41 {item.icon}
42 </span>
43 <span className="min-w-0 truncate">
44 {item.title}
45 {item.description ? (
46 <>
47 {" "}
48 <span className="ms-0.5 text-muted-foreground/60 light:text-muted-foreground/80">
49 {item.description}
50 </span>
51 </>
52 ) : null}
53 </span>
54 {item.actions ? (
55 <span className="ms-1.5 flex shrink-0 items-baseline gap-2.5">{item.actions}</span>
56 ) : null}
57 </div>
58 );
59}
60
61/**
62 * The sync status, last at the end of the timeline. It comes and goes within a second or two, so
63 * it takes no height: it sits in the gap above the composer instead of moving the whole chat by a
64 * line each time it shows and hides.
65 */
66export function ThreadSyncStatus({ phase }: { readonly phase: ThreadSyncPhase }) {
67 const m = useMessages();
68 return (
69 <div className="relative h-0">
70 <div
71 className={cn(lineClassName, "absolute inset-x-0 top-0 pb-0")}
72 role={phase === "failed" ? "alert" : "status"}
73 data-composer-sync-status={phase}
74 >
75 {phase === "failed" ? <CircleAlertIcon aria-hidden /> : <RefreshCwIcon aria-hidden />}
76 <span className="truncate">{threadSyncLabel(phase, m)}</span>
77 </div>
78 </div>
79 );
80}
81
82/**
83 * What the thread is doing now, at the end of the timeline: what needs you, background work,
84 * then the goal.
85 */
86export function ThreadNow({
87 attention,
88 work,
89 goal,
90}: {
91 /** Something that needs you elsewhere, such as a subagent's question. */
92 readonly attention: ThreadNowItem | null;
93 readonly work: ThreadNowItem | null;
94 readonly goal: ThreadNowItem | null;
95}): ReactNode {
96 return (
97 <>
98 {attention ? <ThreadNowLine item={attention} announce /> : null}
99 {work ? <ThreadNowLine item={work} /> : null}
100 {goal ? <ThreadNowLine item={goal} /> : null}
101 </>
102 );
103}