import {
CalendarClockIcon,
Clock3Icon,
HourglassIcon,
Loader2Icon,
TriangleAlertIcon,
ZapIcon,
} from "lucide-react";
import { Children, isValidElement, useId, type ReactNode } from "react";
import { CreatorMonogram } from "../creator-monogram";
import { type CreatorRef, creatorAnnouncement, creatorInitials } from "../../lib/creator-initials";
import { formatWaitingSince } from "../../lib/format";
import { t } from "../../lib/console-text";
import { cn } from "../../lib/utils";
import type { RailAggregateStatus } from "../../lib/sessions-group";
import {
sessionAutomationWaitLabel,
type SessionAutomationWait,
} from "../../../session-list-model";
export function ActiveWorkMark({ className }: { className?: string | undefined }) {
const maskId = `active-work-${useId().replaceAll(":", "")}`;
return (
);
}
/** The one descendant-aware status marker shared by rows and section headers. */
function RailAggregateDot({ summary }: { summary: RailAggregateStatus }) {
if (summary.kind === "neutral") return null;
if (summary.kind === "active") {
return (
);
}
if (summary.kind === "queued") {
return ;
}
if (summary.kind === "waiting") {
// Parked until input or its wake-up time: nothing is executing, so no spinner.
return ;
}
if (summary.kind === "active_work") {
return ;
}
if (summary.kind === "send_failed") {
return (
);
}
const tone =
summary.kind === "needs_attention"
? "bg-status-waiting"
: summary.kind === "failed"
? "bg-status-failed"
: "bg-session-update";
return (
);
}
/**
* The row's announced name.
*
* `aria-label` replaces name-from-content, so this string is the whole of what
* a screen reader hears for the row: the creator chip is `aria-hidden`, and
* even the sr-only state line inside the link is inert for it. Every fact a
* sighted user reads off the row belongs here, and in exactly one place.
*/
export function sessionRowAccessibleName({
title,
stateLabel,
pinned,
statusLabel,
spawnedLabel,
creator,
}: {
title: string;
stateLabel: string;
pinned: boolean;
statusLabel: string;
spawnedLabel?: string | null | undefined;
creator?: CreatorRef | null | undefined;
}): string {
const spokenCreator = creatorAnnouncement(creator ?? null);
return `Open ${title}. ${stateLabel}${pinned ? ". Pinned" : ""}. ${statusLabel}${
spawnedLabel ? `. ${spawnedLabel}` : ""
}${spokenCreator ? `. Created by ${spokenCreator}` : ""}`;
}
/**
* The quiet mark for a chat an automation will post into: a clock while it
* waits for its schedule, a bolt while it waits for an event. `label` says
* what exactly ("Waiting for deploy.finished from Deploys"); without it the
* plain wait is named.
*/
export function AutomationWaitIcon({
wait,
label: detail,
className,
}: {
wait: SessionAutomationWait;
label?: string | undefined;
className?: string | undefined;
}) {
const Icon = wait === "event" ? ZapIcon : CalendarClockIcon;
const label = detail || sessionAutomationWaitLabel(t, wait);
return (
);
}
export function RailTrailingMetadata({
summary,
automationWait = null,
automationWaitLabel,
relativeTime,
jumpKey,
creator,
quickActionSlots = 0,
}: {
summary: RailAggregateStatus;
/** What an automation posting into this chat is waiting for; null for none. */
automationWait?: SessionAutomationWait | null | undefined;
/** That wait in words, for the mark's tooltip and accessible name. */
automationWaitLabel?: string | undefined;
relativeTime?: string | undefined;
/** The key that opens this row ("⌘3"), shown in place of the time while ⌘ is held. */
jumpKey?: string | undefined;
/** Rightmost items replaced in place by the row's desktop quick actions. */
quickActionSlots?: number | undefined;
/**
* Session creator for a top-level row, else null; callers decide which rows
* are roots. A chip is its own reason to render this block: a mobile root row
* can have no status marker and no time and still name who started it.
*/
creator?: CreatorRef | null | undefined;
}) {
const hasStatusMarker = summary.kind !== "neutral";
const hasRelativeTime = Boolean(relativeTime);
const hasMonogram = creator ? creatorInitials(creator) !== null : false;
// How long the longest-waiting session behind a "needs you" marker has been
// blocked on a human. A collapsed parent with a child parked for ten hours
// must say so, not hide it behind a dot.
const waitingFor =
summary.kind === "needs_attention" && summary.attentionSince
? formatWaitingSince(summary.attentionSince)
: "";
if (
!automationWait &&
!hasStatusMarker &&
!hasRelativeTime &&
!jumpKey &&
!hasMonogram &&
!quickActionSlots
)
return null;
const items = Children.toArray([
automationWait ? (
) : null,
hasMonogram && creator ? (
) : null,
waitingFor ? (
{waitingFor}
) : null,
hasStatusMarker ? (
) : null,
jumpKey ? (
{jumpKey}
) : hasRelativeTime ? (
{relativeTime}
) : null,
]).filter(isValidElement);
if (!quickActionSlots) {
return (
{items}
);
}
// Empty rows still reserve their action footprint. Visibility (never display
// or padding) swaps the last items, keeping every other box stationary.
while (items.length < quickActionSlots) items.unshift();
return (
{items.map((item, index) => (
= items.length - quickActionSlots &&
"pointer-fine:group-hover:invisible pointer-fine:group-focus-within:invisible",
)}
>
{item}
))}
);
}
export function SessionRowContent({
title,
stateLabel,
depthLabel,
descendantLabel,
mobile,
summary,
automationWait = null,
automationWaitLabel,
relativeTime,
jumpKey,
creator,
quickActionSlots = 0,
leading,
parentTitle,
}: {
/** Before the title: a bot's avatar. */
leading?: ReactNode | undefined;
title: string;
/** For a pinned sub-agent chat, the chat it belongs to, said quietly after the title. */
parentTitle?: string | null | undefined;
stateLabel: string;
depthLabel?: string | null | undefined;
descendantLabel?: string | null | undefined;
mobile: boolean;
summary: RailAggregateStatus;
/** What an automation posting into this chat is waiting for; null for none. */
automationWait?: SessionAutomationWait | null | undefined;
/** See RailTrailingMetadata. */
automationWaitLabel?: string | undefined;
relativeTime?: string | undefined;
/** See RailTrailingMetadata. */
jumpKey?: string | undefined;
quickActionSlots?: number | undefined;
/** Session creator for a top-level row, else null. See RailTrailingMetadata. */
creator?: CreatorRef | null | undefined;
}) {
return (
<>
{/* Inert for the row's accessible name, which its `aria-label` owns -
including the creator. Kept as-is so this change regresses nothing. */}
{stateLabel}.
{leading}
{parentTitle ? (
// The title keeps its room; the parent's name gives way first. The
// line as a whole fades at the column's edge, as a title does.
{title}
in {parentTitle}
) : (
{title}
)}
{mobile ? (
{[stateLabel, depthLabel, descendantLabel, relativeTime].filter(Boolean).join(" · ")}
) : null}
>
);
}