Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadNow.tsx

99 lines3.4 KB

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;
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 );
60​
61function ThreadSyncLine({ phase }: { readonly phase: ThreadSyncPhase }) {
62 const m = useMessages();
63 return (
64 <div
65 className={lineClassName}
66 role={phase === "failed" ? "alert" : "status"}
67 data-composer-sync-status={phase}
68 >
69 {phase === "failed" ? <CircleAlertIcon aria-hidden /> : <RefreshCwIcon aria-hidden />}
70 <span className="truncate">{threadSyncLabel(phase, m)}</span>
71 </div>
72 );
74​
75/**
76 * What the thread is doing now, at the end of the timeline: what needs you, background work,
77 * the sync status while messages load, then the goal.
78 */
79export function ThreadNow({
80 attention,
81 work,
82 syncPhase,
83 goal,
84}: {
85 /** Something that needs you elsewhere, such as a subagent's question. */
86 readonly attention: ThreadNowItem | null;
87 readonly work: ThreadNowItem | null;
88 readonly syncPhase: ThreadSyncPhase | null;
89 readonly goal: ThreadNowItem | null;
90}): ReactNode {
91 return (
92 <>
93 {attention ? <ThreadNowLine item={attention} announce /> : null}
94 {work ? <ThreadNowLine item={work} /> : null}
95 {syncPhase ? <ThreadSyncLine phase={syncPhase} /> : null}
96 {goal ? <ThreadNowLine item={goal} /> : null}
97 </>
98 );