The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { RefreshCwIcon } from "lucide-react"; |
| 2 | import type { ReactNode } from "react"; |
| 3 | |
| 4 | import { threadSyncLabel, type ThreadSyncPhase } from "../../threadSync"; |
| 5 | import { cn } from "~/lib/utils"; |
| 6 | import { useMessages } from "gt-react"; |
| 7 | |
| 8 | /** A line of thread state for the end of the timeline. */ |
| 9 | export 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. */ |
| 18 | const 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. */ |
| 26 | function 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 | function ThreadSyncLine({ phase }: { readonly phase: ThreadSyncPhase }) { |
| 62 | const m = useMessages(); |
| 63 | return ( |
| 64 | <div className={lineClassName} role="status" data-composer-sync-status={phase}> |
| 65 | <RefreshCwIcon aria-hidden /> |
| 66 | <span className="truncate">{threadSyncLabel(phase, m)}</span> |
| 67 | </div> |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * What the thread is doing now, at the end of the timeline: what needs you, background work, |
| 73 | * the sync status while messages load, then the goal. |
| 74 | */ |
| 75 | export function ThreadNow({ |
| 76 | attention, |
| 77 | work, |
| 78 | syncPhase, |
| 79 | goal, |
| 80 | }: { |
| 81 | /** Something that needs you elsewhere, such as a subagent's question. */ |
| 82 | readonly attention: ThreadNowItem | null; |
| 83 | readonly work: ThreadNowItem | null; |
| 84 | readonly syncPhase: ThreadSyncPhase | null; |
| 85 | readonly goal: ThreadNowItem | null; |
| 86 | }): ReactNode { |
| 87 | return ( |
| 88 | <> |
| 89 | {attention ? <ThreadNowLine item={attention} announce /> : null} |
| 90 | {work ? <ThreadNowLine item={work} /> : null} |
| 91 | {syncPhase ? <ThreadSyncLine phase={syncPhase} /> : null} |
| 92 | {goal ? <ThreadNowLine item={goal} /> : null} |
| 93 | </> |
| 94 | ); |
| 95 | } |