Open History to see the last commit
1import { copySnapshot as copySnapshotToClipboard } from "./copySnapshot";
2import { InlineAudioPreview } from "../files/InlineAudioPreview";
3import { filePreviewKind } from "@t3tools/shared/filePreview";
4import type { MarkdownExtensions } from "~/markdown/wordsHast";
5import { T, useGT, useMessages, Var } from "gt-react";
6import { findRevealRef } from "./markdownFindContext";
7import {
8 type EnvironmentId,
9 type MessageId,
10 type ScheduledTaskId,
11 type ServerProviderSkill,
12 ThreadId,
13} from "@t3tools/contracts";
14import { scopeThreadRef } from "@t3tools/client-runtime/environment";
15import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
16import { Link } from "@tanstack/react-router";
17import { useQuietThreadShell } from "../../state/entities";
18import { useEnvironment } from "../../state/environments";
19import { useEnvironmentQuery } from "../../state/query";
20import { serverEnvironment } from "../../state/server";
21import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
22import { memo, use, useState, type ReactNode } from "react";
23import {
24 createMessageAttachmentPreviewProjector,
25 selectMessageImageResources,
26} from "../../session-logic";
27import {
28 type ChatFileAttachment,
29 isFileAttachment,
30 isImageAttachment,
31 isVideoAttachment,
32} from "../../types";
33import ChatMarkdown from "../ChatMarkdown";
34import {
35 CalendarClockIcon,
36 ChevronDownIcon,
37 DownloadIcon,
38 EyeIcon,
39 type LucideIcon,
40 MessagesSquareIcon,
41 Redo2Icon,
42 PencilIcon,
43 LinkIcon,
44} from "lucide-react";
45import { Button, InlineButton } from "../ui/button";
46import { FreshSessionRow, ModelSwitchRow } from "./V2LifecycleRow";
47import { useAssetUrlRefresh, useAssetUrls, useAssetUrlState } from "../../assets/assetUrls";
48import { AttachmentImage } from "../media/AttachmentImage";
49import { MediaVideoPlayer } from "../media/MediaVideoPlayer";
50import {
51 buildAttachmentVideoAsset,
52 buildAttachmentVideoPreview,
53 buildExpandedImagePreview,
54} from "./ExpandedImagePreview";
55import {
56 SNAP_SHOT_ATTACHMENT_FRAME_CLASS,
57 SnapShotAttachmentDetails,
58} from "./SnapShotAttachmentDetails";
59import { GuestMessageName, guestBubbleClassName } from "./guestMessageStyle";
60import { MessageCopyButton } from "./MessageCopyButton";
61import { promptLinkFor } from "../promptLinks/copyPromptLink";
62import { PierreEntryIcon } from "./PierreEntryIcon";
63import { formatBytes } from "../../lib/formatBytes";
64import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
65import {
66 asKnownContextRecord,
67 resolveUserMessageContext,
68 selectedMessageContextFragment,
69} from "~/lib/composerContextRecords";
70import {
71 collectComposerContextReferences,
72 formatComposerContextReference,
73} from "@t3tools/shared/composerContextReferences";
74import {
75 COMPOSER_CONTEXT_CLIPBOARD_MIME,
76 encodeComposerContextClipboardHtml,
77 encodeComposerContextFragment,
78} from "@t3tools/shared/composerContextClipboard";
79import { chatMarkdownClipboardPayload } from "../../markdown-clipboard";
80import type { ChatMarkdownContextReference } from "../ChatMarkdown";
81import { cn } from "~/lib/utils";
82import { markdownProseDirection } from "~/textDirection";
83import { useMediaQuery } from "~/hooks/useMediaQuery";
84import { formatChatTimestampTooltip, formatDayAwareTimestamp } from "../../timestampFormat";
85import { WorkflowOpeningBlock } from "./WorkflowOpeningBlock";
86import { useTallEnoughToFold } from "./useTallEnoughToFold";
87import { TimelineRowCtx, TimelineRowActivityCtx, type TimelineRow } from "./timelineRowContext";
88import {
89 MESSAGE_HEADING_LEVEL,
90 MessageAuthorHeading,
91 TimelineRowTimestamp,
92} from "./TimelineRowParts";
93import { UserMessageContextReferenceChip } from "./UserMessageContextChips";
94import {
95 resolvePreviewAnnotationImage,
96 userMessageFileLabel,
97} from "./TimelineUserMessageRow.logic";
98
99// Drawn inside the media so dark screenshots keep an edge on the dark background.
100const MEDIA_EDGE_CLASS_NAME =
101 "relative after:pointer-events-none after:absolute after:inset-0 after:z-10 after:rounded-[inherit] after:ring-1 after:ring-inset after:ring-black/9 dark:after:ring-white/12";
102
103const BUBBLE_CHIP_CLASS_NAME =
104 "[&_[data-slot=context-chip]]:[--context-chip-message-ink:var(--context-chip-message)]";
105
106function UserFileCard({
107 file,
108 copyMarkdown,
109}: {
110 readonly file: ChatFileAttachment;
111 readonly copyMarkdown: string | undefined;
112}) {
113 const ctx = use(TimelineRowCtx);
114 const gt = useGT();
115 const m = useMessages();
116 const pastedText = file.source?._tag === "pasted-text";
117 const label = userMessageFileLabel(file, m);
118 const extension =
119 /\.([a-z0-9]{1,8})$/i.exec(file.name)?.[1]?.toUpperCase() ??
120 gt("File", { $context: "file type badge when the name has no extension" });
121 const identity = (
122 <>
123 <span className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-background/60">
124 <PierreEntryIcon pathValue={file.name} kind="file" theme={ctx.resolvedTheme} />
125 </span>
126 <span className="min-w-0 flex-1">
127 <span className="block truncate text-sm font-medium group-hover/file:underline">
128 {label}
129 </span>
130 <span className="block text-xs text-muted-foreground tabular-nums">
131 {file.downloadable === false ? (
132 <T>Sending…</T>
133 ) : (
134 <>
135 {!pastedText && `${extension} · `}
136 {formatBytes(file.sizeBytes)}
137 </>
138 )}
139 </span>
140 </span>
141 </>
142 );
143 return (
144 <div
145 data-markdown-copy={copyMarkdown}
146 className="flex w-64 max-w-full items-center gap-1 rounded-2xl bg-message py-2 ps-2 pe-1 text-message-foreground"
147 >
148 {file.downloadable === false ? (
149 <>
150 <div className="flex min-w-0 flex-1 items-center gap-3">{identity}</div>
151 <Button
152 size="icon-xs"
153 variant="ghost-muted"
154 disabled
155 aria-label={gt("Sending attachment")}
156 >
157 <DownloadIcon />
158 </Button>
159 </>
160 ) : (
161 <>
162 <button
163 type="button"
164 aria-label={gt("Preview {label}", { label })}
165 onClick={() => ctx.onFileOpen(file)}
166 className="group/file focus-visible:ring-ring/70 flex min-w-0 flex-1 cursor-pointer items-center gap-3 rounded-xl text-left focus-visible:ring-2 focus-visible:ring-inset focus-visible:outline-none"
167 >
168 {identity}
169 </button>
170 <Tooltip>
171 <TooltipTrigger
172 render={
173 <Button
174 size="icon-xs"
175 variant="ghost-muted"
176 aria-label={gt("Download {label}", { label })}
177 onClick={() => ctx.onFileDownload(file)}
178 />
179 }
180 >
181 <DownloadIcon />
182 </TooltipTrigger>
183 <TooltipPopup side="top">
184 <T>
185 Download <Var>{label}</Var>
186 </T>
187 </TooltipPopup>
188 </Tooltip>
189 </>
190 )}
191 </div>
192 );
193}
194
195function UserVideoAttachment({
196 file,
197 standalone = false,
198 cornerClassName,
199}: {
200 readonly file: ChatFileAttachment;
201 readonly standalone?: boolean;
202 readonly cornerClassName?: string | undefined;
203}) {
204 const ctx = use(TimelineRowCtx);
205 // Row updates rebuild attachment objects, so the asset follows only the
206 // fields it reads.
207 const { downloadable, id, mimeType, name } = file;
208 const environmentId = ctx.activeThreadEnvironmentId;
209 const asset =
210 downloadable === false
211 ? null
212 : buildAttachmentVideoAsset(environmentId, { id, mimeType, name });
213 const resource = asset?.resource ?? null;
214 const assetUrl = useAssetUrlState(ctx.activeThreadEnvironmentId, resource);
215 const refreshAssetUrl = useAssetUrlRefresh(ctx.activeThreadEnvironmentId, resource);
216 const src = assetUrl._tag === "Success" ? assetUrl.url : (file.previewUrl ?? null);
217
218 if (asset === null && src === null) {
219 return (
220 <div
221 className={cn(
222 "flex aspect-[4/3] w-full items-center justify-center bg-black px-2 py-3 text-center text-2xs text-white/70",
223 standalone
224 ? cn(MEDIA_EDGE_CLASS_NAME, "rounded-2xl", cornerClassName)
225 : "rounded-lg border border-border/80",
226 )}
227 >
228 {file.name}
229 </div>
230 );
231 }
232
233 const player = (
234 <MediaVideoPlayer
235 src={src}
236 sourceFailed={
237 file.previewUrl === undefined && resource !== null && assetUrl._tag === "Failure"
238 }
239 label={file.name}
240 preload="visible"
241 onOpen={() => {
242 const preview = buildAttachmentVideoPreview(ctx.activeThreadEnvironmentId, file);
243 if (preview) ctx.onImageExpand(preview);
244 }}
245 className="block aspect-[4/3] w-full"
246 videoClassName={cn(
247 "aspect-auto size-full",
248 !standalone && "rounded-lg border border-border/80",
249 )}
250 stateClassName={cn(
251 "aspect-auto min-h-full bg-black text-white",
252 !standalone && "rounded-lg border border-border/80",
253 )}
254 onRetry={asset ? refreshAssetUrl : undefined}
255 actionsSource={asset ? { kind: "video", name: file.name, src, asset } : undefined}
256 />
257 );
258 return standalone ? (
259 <div className={cn(MEDIA_EDGE_CLASS_NAME, "overflow-hidden rounded-2xl", cornerClassName)}>
260 {player}
261 </div>
262 ) : (
263 player
264 );
265}
266
267export function UserMessageRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
268 const ctx = use(TimelineRowCtx);
269 const item = row.projectedItem?.item;
270 const modelSwitch = item?.type === "user_message" ? item.modelSwitch : undefined;
271 return (
272 <>
273 {item?.type === "user_message" && item.freshContext ? <FreshSessionRow /> : null}
274 {modelSwitch ? (
275 <ModelSwitchRow environmentId={ctx.activeThreadEnvironmentId} modelSwitch={modelSwitch} />
276 ) : null}
277 <UserMessageContent row={row} />
278 </>
279 );
280}
281
282function UserMessageContent({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
283 const ctx = use(TimelineRowCtx);
284 return ctx.workflowOpening?.messageId === row.message.id ? (
285 <WorkflowOpeningBlock
286 opening={ctx.workflowOpening}
287 environmentId={ctx.activeThreadEnvironmentId}
288 onOpenThread={(threadId, intent) =>
289 ctx.onOpenThread(ThreadId.make(threadId), undefined, intent)
290 }
291 />
292 ) : resolveUserMessagePresentation(row.message).attribution === "automation" ? (
293 <AutomationMessageRow row={row} />
294 ) : (
295 <UserTimelineRow row={row} />
296 );
297}
298
299/** Automation prompts are long, repeated runbooks; a folded bubble keeps them out of the way. */
300function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
301 const ctx = use(TimelineRowCtx);
302 const gt = useGT();
303 const [expanded, setExpanded] = useState(false);
304 const revealRef = findRevealRef(() => setExpanded(true));
305 const { text, scheduledTaskId } = resolveUserMessagePresentation(row.message);
306 const summary =
307 useScheduledTaskTitle(ctx.activeThreadEnvironmentId, scheduledTaskId) ??
308 text.trim().split(/\r?\n/, 1)[0] ??
309 "";
310
311 const revertTurnCount = row.revertTurnCount;
312 const promptLink = promptLinkFor(text);
313 // Find reads the DOM, so a folded prompt stays mounted but hidden while find is open.
314 const bodyMounted = expanded || ctx.findActive;
315
316 return (
317 <div className="group flex flex-col items-end gap-1" data-user-message-attribution="automation">
318 {row.message.inputIntent === "steer" ||
319 row.message.inputIntent === "promoted_queued_to_steer" ? (
320 <UserMessageIntentMarker
321 intent={row.message.inputIntent}
322 unread={row.projectedItem?.item.status === "pending"}
323 />
324 ) : null}
325 <div
326 className={cn(
327 "min-w-0 max-w-[80%] rounded-2xl bg-message text-message-foreground",
328 BUBBLE_CHIP_CLASS_NAME,
329 expanded && "w-full",
330 )}
331 data-user-message-bubble=""
332 >
333 <MessageAuthorHeading>{gt("Automation")}</MessageAuthorHeading>
334 <FoldedMessageHeader
335 icon={CalendarClockIcon}
336 label={gt("Automation")}
337 fitLabel
338 summary={summary}
339 expanded={expanded}
340 onToggle={() => setExpanded((value) => !value)}
341 />
342 {bodyMounted ? (
343 // `beforematch` does not bubble, so the reveal listener sits on the hidden fold itself.
344 <div
345 ref={revealRef}
346 hidden={!expanded}
347 className={cn("px-3 pb-3", !ctx.findActive && "max-h-96 overflow-auto")}
348 data-thread-find-text="true"
349 >
350 <UserMessageBody text={text} skills={ctx.skills} markdownCwd={ctx.markdownCwd} />
351 </div>
352 ) : null}
353 </div>
354 <UserMessageProjectedStatus row={row} />
355 {expanded ? (
356 <div className="flex w-full max-w-[80%] items-center justify-end pe-1 text-xs tabular-nums opacity-0 transition-opacity duration-200 pointer-coarse:opacity-100 focus-within:opacity-100 group-hover:opacity-100">
357 <div className="flex shrink-0 items-center gap-2">
358 {scheduledTaskId ? (
359 <Link
360 to="/settings/scheduled-tasks"
361 search={{ environmentId: ctx.activeThreadEnvironmentId, taskId: scheduledTaskId }}
362 className="rounded-sm text-xs text-muted-foreground hover:underline focus-visible:outline-2 focus-visible:outline-ring"
363 >
364 <T>Open automation</T>
365 </Link>
366 ) : null}
367 <TimelineRowTimestamp
368 createdAt={row.message.createdAt}
369 timestampFormat={ctx.timestampFormat}
370 alwaysVisible
371 />
372 <div className="flex items-center gap-0.5">
373 {typeof revertTurnCount === "number" && (
374 <RevertUserMessageButton turnCount={revertTurnCount} messageId={row.message.id} />
375 )}
376 <MessageCopyButton text={text} variant="ghost" />
377 {promptLink !== null && (
378 <MessageCopyButton
379 text={promptLink}
380 label={gt("Copy prompt link")}
381 icon={LinkIcon}
382 variant="ghost"
383 />
384 )}
385 </div>
386 </div>
387 </div>
388 ) : null}
389 </div>
390 );
391}
392
393export function useScheduledTaskTitle(
394 environmentId: EnvironmentId,
395 scheduledTaskId: ScheduledTaskId | undefined,
396): string | undefined {
397 const tasksQuery = useEnvironmentQuery(
398 scheduledTaskId ? serverEnvironment.scheduledTasksLive({ environmentId, input: {} }) : null,
399 );
400 return tasksQuery.data?.tasks.find((task) => task.id === scheduledTaskId)?.title;
401}
402
403export function FoldedMessageHeader(props: {
404 icon: LucideIcon;
405 label: string;
406 /** A generic label (not a thread title) never truncates, whatever its length in the UI language. */
407 fitLabel?: boolean;
408 summary: string;
409 expanded: boolean;
410 onToggle: () => void;
411}) {
412 const Icon = props.icon;
413 return (
414 <button
415 type="button"
416 aria-expanded={props.expanded}
417 data-scroll-anchor-ignore
418 onClick={props.onToggle}
419 className="flex w-full min-w-0 items-center gap-1.5 rounded-2xl px-3 py-2 text-left text-sm focus-visible:outline-2 focus-visible:outline-ring"
420 >
421 <Icon className="size-4 shrink-0 stroke-2 text-muted-foreground" />
422 <span
423 className={cn(
424 "shrink-0 text-muted-foreground",
425 props.fitLabel !== true && "max-w-1/2 truncate",
426 )}
427 >
428 {props.label}
429 </span>
430 {/* Mentioned macOS paths can be NFD; compose them like the chips in the body. */}
431 <span className="min-w-0 flex-1 truncate">{props.summary.normalize("NFC")}</span>
432 <ChevronDownIcon
433 className={cn(
434 "size-3.5 shrink-0 text-muted-foreground transition-transform",
435 props.expanded && "rotate-180",
436 )}
437 />
438 </button>
439 );
440}
441
442function UserMessageProjectedStatus({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
443 const status = row.projectedItem?.item.status;
444 if (
445 status === undefined ||
446 status === "completed" ||
447 status === "pending" ||
448 status === "waiting"
449 )
450 return null;
451 return (
452 <div className="me-1 flex items-center gap-1.5">
453 <span className="rounded-full border border-destructive/25 bg-destructive/8 px-1.5 py-0.5 text-3xs font-medium text-destructive">
454 {status}
455 </span>
456 </div>
457 );
458}
459
460function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
461 const ctx = use(TimelineRowCtx);
462 const gt = useGT();
463 const m = useMessages();
464 const { onImageExpand, onFileOpen } = ctx;
465 const coarsePointer = useMediaQuery({ pointer: "coarse" });
466 // A linked environment's agent sent it from a thread there.
467 const senderRef =
468 row.message.linkedSender ??
469 (row.message.senderThreadId === undefined
470 ? null
471 : scopeThreadRef(ctx.activeThreadEnvironmentId, row.message.senderThreadId));
472 const resources = selectMessageImageResources(row.message.attachments);
473 const previewUrls = useAssetUrls(ctx.activeThreadEnvironmentId, resources);
474 const [projectPreviews] = useState(createMessageAttachmentPreviewProjector);
475 const previewUrlsById = new Map(
476 resources.flatMap((resource, index) => {
477 const url = previewUrls[index];
478 return url ? [[resource.attachmentId, url] as const] : [];
479 }),
480 );
481 const messageWithPreviews = projectPreviews(row.message, (attachment) =>
482 previewUrlsById.get(attachment.id),
483 );
484 const userImages = (messageWithPreviews.attachments ?? []).filter(isImageAttachment);
485 const userFiles = (row.message.attachments ?? []).filter(isFileAttachment);
486 const userVideos = userFiles.filter(isVideoAttachment);
487 const userAudio = userFiles.filter(
488 (file) => file.downloadable !== false && filePreviewKind(file) === "audio",
489 );
490 const otherUserFiles = userFiles.filter(
491 (file) => !isVideoAttachment(file) && !userAudio.includes(file),
492 );
493 const unknownAttachments = (row.message.attachments ?? []).filter(
494 (attachment) => !isImageAttachment(attachment) && !isFileAttachment(attachment),
495 );
496 const userMessage = resolveUserMessagePresentation(row.message);
497 // Messages from other agents fold to one line so the user's own messages stay easy to find.
498 const folded = userMessage.attribution === "agent";
499 const [expanded, setExpanded] = useState(false);
500 const revealFoldRef = findRevealRef(() => setExpanded(true));
501 const senderShell = useQuietThreadShell(folded ? senderRef : null);
502 const senderTitle = senderShell?.title.trim() || row.message.linkedSender?.title.trim();
503 const senderLabel =
504 senderTitle || gt("Agent", { $context: "sender of a message from another agent" });
505 // Only an environment this client is connected to can open the sender's thread there.
506 const linkedSenderEnvironment = useEnvironment(row.message.linkedSender?.environmentId ?? null);
507 const canOpenSender =
508 senderRef !== null &&
509 (row.message.linkedSender === undefined || linkedSenderEnvironment !== null);
510 const resolvedContext = resolveUserMessageContext({ ...row.message, text: userMessage.text });
511 const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
512 const revertTurnCount = row.revertTurnCount;
513 const attachmentReferences = collectComposerContextReferences(resolvedContext.text).flatMap(
514 (occurrence) => {
515 const record = asKnownContextRecord(resolvedContext.recordsById.get(occurrence.contextId));
516 return record?.kind === "file" || record?.kind === "image"
517 ? [
518 {
519 attachmentId: record.attachmentId,
520 contextId: occurrence.contextId,
521 source: occurrence.source,
522 },
523 ]
524 : [];
525 },
526 );
527 const chippedAttachmentIds = new Set(
528 attachmentReferences.map((reference) => reference.attachmentId),
529 );
530 const regularImages = userImages.filter((image) => !image.name.startsWith("preview-annotation-"));
531 const unchippedFiles = otherUserFiles.filter((file) => !chippedAttachmentIds.has(file.id));
532 // Images or videos sent without words show as media, not as a bubble around them.
533 const mediaOnly =
534 !folded &&
535 userMessage.attribution !== "guest" &&
536 resolvedContext.text.trim() === "" &&
537 userAudio.length === 0 &&
538 unchippedFiles.length === 0 &&
539 unknownAttachments.length === 0 &&
540 regularImages.length + userVideos.length > 0;
541 // Media sent with words sits above the bubble as its own shape, like a chat app.
542 const mediaAboveText =
543 !folded &&
544 userMessage.attribution !== "guest" &&
545 !mediaOnly &&
546 regularImages.length + userVideos.length > 0;
547 const standaloneMedia = mediaOnly || mediaAboveText;
548 // A lone image keeps its own shape; a 4:3 crop hides most of a wide screenshot.
549 const loneImage = standaloneMedia && userVideos.length === 0 && regularImages.length === 1;
550 // Several images share one rounded shape, split by hairlines.
551 const collage =
552 standaloneMedia &&
553 userVideos.length === 0 &&
554 regularImages.length > 1 &&
555 regularImages.every((image) => image.source?.kind !== "snap-shot");
556 // Corners that touch the bubble or a neighbouring message tighten, like the bubble's.
557 const mediaCornerClassName = cn(
558 row.groupedWithPrevious && "rounded-tr-md",
559 (mediaAboveText || row.groupedWithNext) && "rounded-br-md",
560 );
561 // Files sent without words show as cards, not as a bubble around a name chip.
562 const fileCardsOnly =
563 !folded &&
564 userMessage.attribution !== "guest" &&
565 otherUserFiles.length > 0 &&
566 regularImages.length + userVideos.length + userAudio.length + unknownAttachments.length === 0 &&
567 replaceComposerContextReferences(resolvedContext.text, (reference) =>
568 attachmentReferences.some(
569 (attached) =>
570 attached.contextId === reference.contextId &&
571 otherUserFiles.some((file) => file.id === attached.attachmentId),
572 )
573 ? ""
574 : reference.label,
575 ).trim() === "";
576 const audioOnly =
577 !folded &&
578 userMessage.attribution !== "guest" &&
579 userAudio.length > 0 &&
580 regularImages.length + userVideos.length + otherUserFiles.length + unknownAttachments.length ===
581 0 &&
582 replaceComposerContextReferences(resolvedContext.text, (reference) =>
583 attachmentReferences.some(
584 (attached) =>
585 attached.contextId === reference.contextId &&
586 userAudio.some((file) => file.id === attached.attachmentId),
587 )
588 ? ""
589 : reference.label,
590 ).trim() === "";
591 const annotationRecordIds = resolvedContext.records
592 .filter((record) => record.kind === "preview-annotation")
593 .map((record) => record.contextId);
594 const plainText = replaceComposerContextReferences(
595 resolvedContext.text,
596 (reference) => reference.label,
597 );
598 const promptLink = promptLinkFor(plainText);
599 const foldSummary =
600 plainText
601 .split(/\r?\n/)
602 .find((line) => line.trim().length > 0)
603 ?.trim() ?? "";
604 const mediaCopyRecords = mediaOnly
605 ? resolvedContext.records.flatMap((record) => {
606 const known = asKnownContextRecord(record);
607 return (known?.kind === "image" || known?.kind === "file") &&
608 (regularImages.some((image) => image.id === known.attachmentId) ||
609 userVideos.some((file) => file.id === known.attachmentId))
610 ? [known]
611 : [];
612 })
613 : [];
614 const copyRecords = mediaOnly ? mediaCopyRecords : resolvedContext.records;
615 const contextClipboardFragment =
616 copyRecords.length === 0
617 ? null
618 : encodeComposerContextFragment({
619 version: 1,
620 source: {
621 environmentId: ctx.activeThreadEnvironmentId,
622 ...(ctx.threadRef ? { threadId: ctx.threadRef.threadId } : {}),
623 messageId: row.message.id,
624 },
625 records: copyRecords,
626 });
627 const copyText =
628 resolvedContext.text || mediaCopyRecords.map(formatComposerContextReference).join("\n");
629 const copySnapshot = async (id: string) => {
630 const image = userImages.find((candidate) => candidate.id === id);
631 const record = resolvedContext.records
632 .map(asKnownContextRecord)
633 .find((candidate) => candidate?.kind === "image" && candidate.attachmentId === id);
634 if (!image?.previewUrl || record?.kind !== "image")
635 throw new Error(gt("Snapshot is no longer available."));
636 const fragment = encodeComposerContextFragment({
637 version: 1,
638 source: { environmentId: ctx.activeThreadEnvironmentId, messageId: row.message.id },
639 records: [{ ...record, ...(image.source ? { source: image.source } : {}) }],
640 });
641 if (!fragment) throw new Error(gt("The snapshot is too large to copy."));
642 await copySnapshotToClipboard(
643 image.previewUrl,
644 formatComposerContextReference(record),
645 fragment,
646 );
647 };
648 const onBodyCopyCapture = (event: React.ClipboardEvent<HTMLDivElement>) => {
649 if (resolvedContext.records.length === 0 || !event.clipboardData) return;
650 const selection = window.getSelection();
651 if (!selection || selection.isCollapsed) return;
652 const copiedMarkdown: string[] = [];
653 for (let index = 0; index < selection.rangeCount; index += 1) {
654 const container = document.createElement("div");
655 container.appendChild(selection.getRangeAt(index).cloneContents());
656 // Diagram source is copied text, not authority to export context records.
657 for (const element of container.querySelectorAll(
658 "[data-markdown-copy]:not([data-markdown-mermaid])",
659 )) {
660 copiedMarkdown.push(element.getAttribute("data-markdown-copy") ?? "");
661 }
662 }
663 const fragment = selectedMessageContextFragment({
664 markdown: copiedMarkdown.join("\n"),
665 records: resolvedContext.records,
666 environmentId: ctx.activeThreadEnvironmentId,
667 ...(ctx.threadRef ? { threadId: ctx.threadRef.threadId } : {}),
668 messageId: row.message.id,
669 });
670 if (!fragment) return;
671 // Claim the copy: without preventDefault the browser default overwrites the
672 // custom MIME type. The default content must then be written back explicitly.
673 const payload = chatMarkdownClipboardPayload(selection);
674 event.preventDefault();
675 event.clipboardData.setData("text/plain", payload?.text ?? selection.toString());
676 if (payload) {
677 event.clipboardData.setData(
678 "text/html",
679 encodeComposerContextClipboardHtml(payload.text, fragment, payload.html),
680 );
681 }
682 event.clipboardData.setData(COMPOSER_CONTEXT_CLIPBOARD_MIME, fragment);
683 };
684 const renderContextReference = (reference: ChatMarkdownContextReference) => {
685 const record = asKnownContextRecord(resolvedContext.recordsById.get(reference.contextId));
686 if (record?.kind === "file" && userAudio.some((file) => file.id === record.attachmentId))
687 return null;
688 const annotationImage =
689 record?.kind === "preview-annotation"
690 ? resolvePreviewAnnotationImage({
691 record,
692 recordsById: resolvedContext.recordsById,
693 userImages,
694 previewImages,
695 annotationRecordIds,
696 })
697 : null;
698 const attachment =
699 record?.kind === "image"
700 ? (userImages.find((image) => image.id === record.attachmentId) ?? null)
701 : record?.kind === "file"
702 ? (userFiles.find((file) => file.id === record.attachmentId) ?? null)
703 : null;
704 return (
705 <span data-thread-find-ignore>
706 <UserMessageContextReferenceChip
707 reference={reference}
708 record={record}
709 annotationImage={annotationImage}
710 attachment={attachment}
711 onExpandImage={(image) => {
712 const preview = buildExpandedImagePreview(userImages, image.id, copySnapshot);
713 if (preview) onImageExpand(preview);
714 }}
715 onOpenFile={onFileOpen}
716 onExpandVideo={(file) => {
717 const preview = buildAttachmentVideoPreview(ctx.activeThreadEnvironmentId, file);
718 if (preview) onImageExpand(preview);
719 }}
720 />
721 </span>
722 );
723 };
724
725 const mediaBlock =
726 regularImages.length > 0 || userVideos.length > 0 ? (
727 <div
728 className={cn(
729 "grid",
730 !standaloneMedia
731 ? "mb-2 max-w-[210px] grid-cols-2 gap-2"
732 : loneImage
733 ? "max-w-full"
734 : collage
735 ? cn(
736 MEDIA_EDGE_CLASS_NAME,
737 "w-80 max-w-full gap-px overflow-hidden rounded-2xl bg-black/9 dark:bg-white/12",
738 mediaCornerClassName,
739 regularImages.length === 2
740 ? "auto-rows-[12rem] grid-cols-2"
741 : regularImages.length === 3
742 ? "auto-rows-[calc(6rem-0.5px)] grid-cols-[3fr_2fr]"
743 : "auto-rows-[6rem] grid-cols-2",
744 )
745 : regularImages.length + userVideos.length === 1
746 ? "w-80 max-w-full"
747 : "w-80 max-w-full grid-cols-2 gap-2",
748 )}
749 >
750 {regularImages.map((image, index) => (
751 <div
752 key={image.id}
753 className={cn(
754 "bg-background/70",
755 image.source?.kind === "snap-shot" && image.previewUrl
756 ? cn(
757 "col-span-2",
758 standaloneMedia
759 ? cn(
760 MEDIA_EDGE_CLASS_NAME,
761 "min-h-16 justify-self-end overflow-hidden rounded-2xl",
762 loneImage && mediaCornerClassName,
763 )
764 : SNAP_SHOT_ATTACHMENT_FRAME_CLASS,
765 )
766 : loneImage
767 ? cn(MEDIA_EDGE_CLASS_NAME, "overflow-hidden rounded-2xl", mediaCornerClassName)
768 : collage
769 ? cn(
770 "overflow-hidden bg-background",
771 regularImages.length === 3 && index === 0 && "row-span-2",
772 regularImages.length > 3 &&
773 regularImages.length % 2 === 1 &&
774 index === regularImages.length - 1 &&
775 "col-span-2",
776 )
777 : standaloneMedia
778 ? cn(MEDIA_EDGE_CLASS_NAME, "aspect-[4/3] overflow-hidden rounded-2xl")
779 : "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
780 )}
781 >
782 {image.previewUrl ? (
783 <button
784 type="button"
785 className="block h-full w-full cursor-zoom-in"
786 aria-label={gt("Preview {label}", { label: image.name })}
787 onClick={() => {
788 const preview = buildExpandedImagePreview(regularImages, image.id, copySnapshot);
789 if (!preview) return;
790 ctx.onImageExpand(preview);
791 }}
792 >
793 {/* Isolate the thumbnail raster from nearby activity repaints in Chromium. */}
794 <AttachmentImage
795 name={image.name}
796 mimeType={image.mimeType}
797 src={image.previewUrl}
798 alt={image.name}
799 decoding="async"
800 loading="lazy"
801 className={cn(
802 "block transform-gpu",
803 standaloneMedia && image.source?.kind === "snap-shot"
804 ? "h-auto max-h-48 w-auto min-w-24 max-w-full object-contain"
805 : loneImage
806 ? "h-48 w-auto min-w-24 max-w-full object-contain"
807 : "size-full object-cover",
808 )}
809 />
810 </button>
811 ) : (
812 <div
813 className={cn(
814 "flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70",
815 loneImage && "h-48 w-64 max-w-full",
816 collage && "h-full",
817 )}
818 >
819 {image.name}
820 </div>
821 )}
822 {image.previewUrl && image.source?.kind === "snap-shot" ? (
823 <SnapShotAttachmentDetails
824 source={image.source}
825 onCopySnapshot={() => copySnapshot(image.id)}
826 />
827 ) : null}
828 </div>
829 ))}
830 {userVideos.map((file) => (
831 <UserVideoAttachment
832 key={file.id}
833 file={file}
834 standalone={standaloneMedia}
835 cornerClassName={
836 regularImages.length + userVideos.length === 1 ? mediaCornerClassName : undefined
837 }
838 />
839 ))}
840 </div>
841 ) : null;
842
843 // Touch shows actions all the time, and narrow lanes have no room beside the
844 // bubble, so both keep the actions on their own line.
845 const floatActions = row.groupedWithNext === true && !coarsePointer;
846 const messageActions = (
847 <div
848 className={cn(
849 "flex items-center justify-end gap-x-2 gap-y-0.5",
850 floatActions ? "flex-wrap" : "shrink-0",
851 )}
852 >
853 {folded && senderRef && canOpenSender ? (
854 <InlineButton
855 onClick={() => ctx.onOpenThread(senderRef.threadId, senderRef.environmentId)}
856 tone="muted"
857 >
858 <T>Open thread</T>
859 </InlineButton>
860 ) : null}
861 <Tooltip>
862 <TooltipTrigger render={<p className="text-muted-foreground text-xs tabular-nums" />}>
863 {formatDayAwareTimestamp(
864 row.message.createdAt,
865 ctx.timestampFormat,
866 undefined,
867 undefined,
868 m,
869 )}
870 </TooltipTrigger>
871 <TooltipPopup>
872 {formatChatTimestampTooltip(row.message.createdAt, ctx.timestampFormat, m)}
873 </TooltipPopup>
874 </Tooltip>
875 <div className={cn("flex items-center gap-0.5", floatActions && "flex-wrap justify-end")}>
876 {typeof revertTurnCount === "number" && (
877 <RevertUserMessageButton turnCount={revertTurnCount} messageId={row.message.id} />
878 )}
879 {copyText && (
880 <MessageCopyButton
881 text={contextClipboardFragment ? copyText : plainText}
882 {...(contextClipboardFragment
883 ? {
884 extraFlavors: {
885 [COMPOSER_CONTEXT_CLIPBOARD_MIME]: contextClipboardFragment,
886 },
887 }
888 : {})}
889 variant="ghost"
890 />
891 )}
892 {promptLink !== null && (
893 <MessageCopyButton
894 text={promptLink}
895 label={gt("Copy prompt link")}
896 icon={LinkIcon}
897 variant="ghost"
898 />
899 )}
900 </div>
901 </div>
902 );
903 return (
904 <div
905 className="group @container flex flex-col items-end gap-1"
906 data-user-message-attribution={folded ? "agent" : undefined}
907 >
908 {userMessage.attribution === "t3code" ? (
909 <p
910 className="me-1 text-2xs text-muted-foreground/70"
911 data-user-message-attribution="t3code"
912 >
913 <T>Sent by T3 Code</T>
914 </p>
915 ) : null}
916 {/* The row's heading already names the guest for screen readers. */}
917 {userMessage.guestName !== undefined ? (
918 <div aria-hidden>
919 <GuestMessageName name={userMessage.guestName} />
920 </div>
921 ) : null}
922 {(row.message.inputIntent === "steer" ||
923 row.message.inputIntent === "promoted_queued_to_steer") &&
924 !row.continuesSteer ? (
925 <UserMessageIntentMarker
926 intent={row.message.inputIntent}
927 unread={row.projectedItem?.item.status === "pending"}
928 />
929 ) : null}
930 {mediaAboveText ? (
931 <div className="flex max-w-[80%] justify-end">
932 {/* The heading leads the media so screen readers reach it before the images. */}
933 <MessageAuthorHeading>
934 {gt("You", { $context: "author of the user's own message" })}
935 </MessageAuthorHeading>
936 {mediaBlock}
937 </div>
938 ) : null}
939 <div
940 className={cn(
941 "relative min-w-0 max-w-[80%] rounded-2xl text-message-foreground",
942 (mediaAboveText || row.groupedWithPrevious) && "rounded-tr-md",
943 row.groupedWithNext && "rounded-br-md",
944 BUBBLE_CHIP_CLASS_NAME,
945 userMessage.attribution === "guest"
946 ? guestBubbleClassName(false)
947 : !mediaOnly && !fileCardsOnly && !audioOnly && "bg-message",
948 !folded && !mediaOnly && !fileCardsOnly && !audioOnly && "p-3",
949 folded && expanded && "w-full",
950 )}
951 data-user-message-bubble=""
952 >
953 {/* Outside the fold so a collapsed message still has a heading to navigate to. */}
954 {mediaAboveText ? null : (
955 <MessageAuthorHeading>
956 {folded
957 ? senderLabel
958 : userMessage.guestName === undefined
959 ? gt("You", { $context: "author of the user's own message" })
960 : gt("{name} (guest)", { name: userMessage.guestName })}
961 </MessageAuthorHeading>
962 )}
963 {folded ? (
964 <FoldedMessageHeader
965 icon={MessagesSquareIcon}
966 label={senderLabel}
967 fitLabel={!senderTitle}
968 summary={foldSummary}
969 expanded={expanded}
970 onToggle={() => setExpanded((value) => !value)}
971 />
972 ) : null}
973 {/* Find reads the DOM, so a folded message stays mounted but hidden while find is open. */}
974 {!folded || expanded || ctx.findActive ? (
975 <div
976 ref={folded ? revealFoldRef : undefined}
977 hidden={folded && !expanded}
978 dir={markdownProseDirection(resolvedContext.text)}
979 className={cn(
980 folded && "px-3 pb-3",
981 folded && !ctx.findActive && "max-h-96 overflow-auto",
982 )}
983 >
984 {!mediaAboveText && mediaBlock}
985 {userAudio.length > 0 ? (
986 <div className={cn("flex max-w-full flex-col gap-1", !audioOnly && "mb-2")}>
987 {userAudio.map((file) => (
988 <InlineAudioPreview
989 key={file.id}
990 name={file.name}
991 variant={audioOnly ? "bubble" : "chip"}
992 environmentId={ctx.activeThreadEnvironmentId}
993 resource={{
994 _tag: "attachment",
995 attachmentId: file.id,
996 fileName: file.name,
997 mimeType: file.mimeType,
998 disposition: "inline",
999 }}
1000 onOpen={() => ctx.onFileOpen(file)}
1001 />
1002 ))}
1003 </div>
1004 ) : null}
1005 {fileCardsOnly ? (
1006 <div className="flex flex-col items-end gap-1" onCopyCapture={onBodyCopyCapture}>
1007 {otherUserFiles.map((file) => (
1008 <UserFileCard
1009 key={file.id}
1010 file={file}
1011 copyMarkdown={
1012 attachmentReferences.find((reference) => reference.attachmentId === file.id)
1013 ?.source
1014 }
1015 />
1016 ))}
1017 </div>
1018 ) : null}
1019 {!fileCardsOnly && (unchippedFiles.length > 0 || unknownAttachments.length > 0) ? (
1020 <div className="mb-2 flex flex-col gap-1">
1021 {unchippedFiles.map((file) => {
1022 const pastedText = file.source?._tag === "pasted-text";
1023 const label = userMessageFileLabel(file, m);
1024 const fileIdentity = (
1025 <>
1026 <PierreEntryIcon
1027 pathValue={file.name}
1028 kind="file"
1029 theme={ctx.resolvedTheme}
1030 />
1031 <span className="min-w-0 flex-1">
1032 <span className="block truncate">{label}</span>
1033 {file.downloadable === false || pastedText ? (
1034 <span className="block text-xs text-muted-foreground tabular-nums">
1035 {file.downloadable === false ? (
1036 <T>Sending…</T>
1037 ) : (
1038 formatBytes(file.sizeBytes)
1039 )}
1040 </span>
1041 ) : null}
1042 </span>
1043 </>
1044 );
1045 if (file.downloadable !== false) {
1046 return (
1047 <div key={file.id} className="flex min-w-0 items-center gap-1">
1048 <button
1049 type="button"
1050 aria-label={gt("Preview {label}", { label })}
1051 onClick={() => ctx.onFileOpen(file)}
1052 className="focus-visible:ring-ring/70 flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md py-1 text-left text-sm hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:outline-none"
1053 >
1054 {fileIdentity}
1055 <EyeIcon className="size-4 shrink-0" />
1056 </button>
1057 <Tooltip>
1058 <TooltipTrigger
1059 render={
1060 <Button
1061 size="icon-xs"
1062 variant="ghost-muted"
1063 aria-label={gt("Download {label}", { label })}
1064 onClick={() => ctx.onFileDownload(file)}
1065 />
1066 }
1067 >
1068 <DownloadIcon />
1069 </TooltipTrigger>
1070 <TooltipPopup side="top">
1071 <T>
1072 Download <Var>{label}</Var>
1073 </T>
1074 </TooltipPopup>
1075 </Tooltip>
1076 </div>
1077 );
1078 }
1079
1080 return (
1081 <div key={file.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
1082 {fileIdentity}
1083 </div>
1084 );
1085 })}
1086 {unknownAttachments.map((attachment) => (
1087 <div key={attachment.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
1088 <PierreEntryIcon
1089 pathValue={attachment.name}
1090 kind="file"
1091 theme={ctx.resolvedTheme}
1092 />
1093 <span className="min-w-0 flex-1 truncate">{attachment.name}</span>
1094 </div>
1095 ))}
1096 </div>
1097 ) : null}
1098 {fileCardsOnly || audioOnly ? null : (
1099 <div onCopyCapture={onBodyCopyCapture}>
1100 <CollapsibleUserMessageBody
1101 text={resolvedContext.text}
1102 renderContextReference={renderContextReference}
1103 skills={ctx.skills}
1104 markdownCwd={ctx.markdownCwd}
1105 collapsible={!folded}
1106 />
1107 </div>
1108 )}
1109 </div>
1110 ) : null}
1111 {floatActions ? (
1112 <div
1113 className={cn(
1114 "absolute end-full top-1/2 me-2 hidden w-max max-w-[calc(20cqw-0.5rem)] -translate-y-1/2 @min-[37rem]:flex",
1115 ACTIONS_REVEAL_CLASS_NAME,
1116 )}
1117 >
1118 {messageActions}
1119 </div>
1120 ) : null}
1121 </div>
1122 <UserMessageProjectedStatus row={row} />
1123 {!folded || expanded ? (
1124 <div
1125 className={cn(
1126 "flex w-full max-w-[80%] justify-end pe-1",
1127 floatActions && "@min-[37rem]:hidden",
1128 ACTIONS_REVEAL_CLASS_NAME,
1129 )}
1130 >
1131 {messageActions}
1132 </div>
1133 ) : null}
1134 </div>
1135 );
1136}
1137
1138const ACTIONS_REVEAL_CLASS_NAME =
1139 "items-center text-xs tabular-nums opacity-0 transition-opacity duration-200 pointer-coarse:opacity-100 focus-within:opacity-100 group-hover:opacity-100";
1140
1141function UserMessageIntentMarker({
1142 intent,
1143 unread,
1144}: {
1145 readonly intent: "steer" | "promoted_queued_to_steer";
1146 readonly unread: boolean;
1147}) {
1148 const gt = useGT();
1149 return (
1150 <Tooltip>
1151 <TooltipTrigger
1152 render={
1153 <div
1154 className="me-1 flex items-center justify-end gap-1 text-xs leading-none text-muted-foreground"
1155 data-user-message-intent={intent}
1156 />
1157 }
1158 >
1159 <Redo2Icon aria-hidden="true" className="size-3" />
1160 {unread
1161 ? gt("Steer · waiting to be read")
1162 : gt("Steer", { $context: "noun, a message that steers the running turn" })}
1163 </TooltipTrigger>
1164 <TooltipPopup side="top">
1165 {unread
1166 ? gt(
1167 "Waiting for the agent to read this. It reads steers between steps, after a running command finishes.",
1168 )
1169 : intent === "promoted_queued_to_steer"
1170 ? gt("Originally queued, then promoted to steer the active turn")
1171 : gt("Steered the active turn")}
1172 </TooltipPopup>
1173 </Tooltip>
1174 );
1175}
1176
1177function RevertUserMessageButton({
1178 turnCount,
1179 messageId,
1180}: {
1181 turnCount: number;
1182 messageId: MessageId;
1183}) {
1184 const ctx = use(TimelineRowCtx);
1185 const activity = use(TimelineRowActivityCtx);
1186 const gt = useGT();
1187
1188 return (
1189 <Tooltip>
1190 <TooltipTrigger
1191 render={
1192 <Button
1193 type="button"
1194 size="xs"
1195 variant="ghost"
1196 disabled={activity.isRevertingCheckpoint || activity.isWorking}
1197 onClick={() => ctx.onRevertToTurnCount(turnCount, messageId)}
1198 aria-label={gt("Edit from here")}
1199 />
1200 }
1201 >
1202 <PencilIcon className="size-3" />
1203 </TooltipTrigger>
1204 <TooltipPopup side="top">
1205 <T>Edit from here</T>
1206 </TooltipPopup>
1207 </Tooltip>
1208 );
1209}
1210
1211const COLLAPSED_USER_MESSAGE_FADE_HEIGHT_REM = 1.75;
1212
1213const COLLAPSED_USER_MESSAGE_FADE_MASK = `linear-gradient(to bottom, black calc(100% - ${COLLAPSED_USER_MESSAGE_FADE_HEIGHT_REM}rem), transparent)`;
1214
1215const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(props: {
1216 text: string;
1217 renderContextReference: (reference: ChatMarkdownContextReference) => ReactNode;
1218 skills: ReadonlyArray<ServerProviderSkill>;
1219 markdownCwd: string | undefined;
1220 collapsible?: boolean;
1221}) {
1222 const [expanded, setExpanded] = useState(false);
1223 const revealForFind = () => setExpanded(true);
1224 const revealRef = findRevealRef(revealForFind);
1225 const hasVisibleBody = props.text.trim().length > 0;
1226 const { ref: contentRef, tallEnough: canCollapse } = useTallEnoughToFold(
1227 props.collapsible !== false && hasVisibleBody,
1228 );
1229 const isCollapsed = canCollapse && !expanded;
1230 const showCollapseControl = canCollapse;
1231
1232 return (
1233 <div>
1234 {hasVisibleBody ? (
1235 <div
1236 ref={revealRef}
1237 className={cn("relative", isCollapsed && "max-h-44 overflow-hidden")}
1238 data-user-message-body="true"
1239 data-thread-find-text="true"
1240 data-thread-find-fold={isCollapsed ? "" : undefined}
1241 data-user-message-collapsed={isCollapsed ? "true" : "false"}
1242 data-user-message-collapsible={canCollapse ? "true" : "false"}
1243 data-user-message-fade={isCollapsed ? "true" : "false"}
1244 style={
1245 isCollapsed
1246 ? {
1247 WebkitMaskImage: COLLAPSED_USER_MESSAGE_FADE_MASK,
1248 maskImage: COLLAPSED_USER_MESSAGE_FADE_MASK,
1249 }
1250 : undefined
1251 }
1252 >
1253 <div ref={contentRef}>
1254 <UserMessageBody
1255 text={props.text}
1256 renderContextReference={props.renderContextReference}
1257 skills={props.skills}
1258 markdownCwd={props.markdownCwd}
1259 />
1260 </div>
1261 </div>
1262 ) : null}
1263 {showCollapseControl ? (
1264 <div className="mt-1.5 flex items-center justify-end gap-2" data-user-message-footer="true">
1265 {showCollapseControl ? (
1266 <Button
1267 type="button"
1268 size="xs"
1269 variant="ghost-muted"
1270 aria-expanded={expanded}
1271 data-scroll-anchor-ignore
1272 onClick={() => setExpanded((value) => !value)}
1273 className="-ml-1"
1274 >
1275 {expanded ? <T>Show less</T> : <T>Show full message</T>}
1276 </Button>
1277 ) : null}
1278 </div>
1279 ) : null}
1280 </div>
1281 );
1282});
1283
1284const USER_MESSAGE_MARKDOWN: MarkdownExtensions = { userMessage: true, leadingWhitespace: true };
1285
1286const UserMessageBody = memo(function UserMessageBody(props: {
1287 text: string;
1288 renderContextReference?: (reference: ChatMarkdownContextReference) => ReactNode;
1289 skills: ReadonlyArray<ServerProviderSkill>;
1290 markdownCwd: string | undefined;
1291}) {
1292 const ctx = use(TimelineRowCtx);
1293 if (props.text.length === 0) {
1294 return null;
1295 }
1296 return (
1297 <ChatMarkdown
1298 text={props.text}
1299 cwd={props.markdownCwd}
1300 threadRef={ctx.threadRef ?? undefined}
1301 skills={props.skills}
1302 className="text-message-foreground user-message-markdown"
1303 lineBreaks
1304 parseRawHtml={false}
1305 extensions={USER_MESSAGE_MARKDOWN}
1306 renderContextReference={props.renderContextReference}
1307 headingLevelOffset={MESSAGE_HEADING_LEVEL}
1308 />
1309 );
1310});