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 {
65 asKnownContextRecord,
66 resolveUserMessageContext,
67 selectedMessageContextFragment,
68} from "~/lib/composerContextRecords";
69import {
70 collectComposerContextReferences,
71 formatComposerContextReference,
72} from "@t3tools/shared/composerContextReferences";
73import {
74 COMPOSER_CONTEXT_CLIPBOARD_MIME,
75 encodeComposerContextClipboardHtml,
76 encodeComposerContextFragment,
77} from "@t3tools/shared/composerContextClipboard";
78import { chatMarkdownClipboardPayload } from "../../markdown-clipboard";
79import type { ChatMarkdownContextReference } from "../ChatMarkdown";
80import { cn } from "~/lib/utils";
81import { markdownProseDirection } from "~/textDirection";
82import { useMediaQuery } from "~/hooks/useMediaQuery";
83import { formatChatTimestampTooltip, formatDayAwareTimestamp } from "../../timestampFormat";
84import { WorkflowOpeningBlock } from "./WorkflowOpeningBlock";
85import { useTallEnoughToFold } from "./useTallEnoughToFold";
86import { TimelineRowCtx, TimelineRowActivityCtx, type TimelineRow } from "./timelineRowContext";
87import {
88 MESSAGE_HEADING_LEVEL,
89 MessageAuthorHeading,
90 TimelineRowTimestamp,
91} from "./TimelineRowParts";
92import { UserMessageContextReferenceChip } from "./UserMessageContextChips";
93import {
94 resolvePreviewAnnotationImage,
95 userMessageFileLabel,
96} from "./TimelineUserMessageRow.logic";
97import { SharedTooltipTrigger } from "../ui/shared-tooltip";
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 <SharedTooltipTrigger
171 render={
172 <Button
173 size="icon-xs"
174 variant="ghost-muted"
175 aria-label={gt("Download {label}", { label })}
176 onClick={() => ctx.onFileDownload(file)}
177 />
178 }
179 label={
180 <>
181 <T>
182 Download <Var>{label}</Var>
183 </T>
184 </>
185 }
186 >
187 <DownloadIcon />
188 </SharedTooltipTrigger>
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 <SharedTooltipTrigger
862 render={<p className="text-muted-foreground text-xs tabular-nums" />}
863 label={formatChatTimestampTooltip(row.message.createdAt, ctx.timestampFormat, m)}
864 >
865 {formatDayAwareTimestamp(
866 row.message.createdAt,
867 ctx.timestampFormat,
868 undefined,
869 undefined,
870 m,
871 )}
872 </SharedTooltipTrigger>
873 <div className={cn("flex items-center gap-0.5", floatActions && "flex-wrap justify-end")}>
874 {typeof revertTurnCount === "number" && (
875 <RevertUserMessageButton turnCount={revertTurnCount} messageId={row.message.id} />
876 )}
877 {copyText && (
878 <MessageCopyButton
879 text={contextClipboardFragment ? copyText : plainText}
880 {...(contextClipboardFragment
881 ? {
882 extraFlavors: {
883 [COMPOSER_CONTEXT_CLIPBOARD_MIME]: contextClipboardFragment,
884 },
885 }
886 : {})}
887 variant="ghost"
888 />
889 )}
890 {promptLink !== null && (
891 <MessageCopyButton
892 text={promptLink}
893 label={gt("Copy prompt link")}
894 icon={LinkIcon}
895 variant="ghost"
896 />
897 )}
898 </div>
899 </div>
900 );
901 return (
902 <div
903 className="group @container flex flex-col items-end gap-1"
904 data-user-message-attribution={folded ? "agent" : undefined}
905 >
906 {userMessage.attribution === "t3code" ? (
907 <p
908 className="me-1 text-2xs text-muted-foreground/70"
909 data-user-message-attribution="t3code"
910 >
911 <T>Sent by T3 Code</T>
912 </p>
913 ) : null}
914 {/* The row's heading already names the guest for screen readers. */}
915 {userMessage.guestName !== undefined ? (
916 <div aria-hidden>
917 <GuestMessageName name={userMessage.guestName} />
918 </div>
919 ) : null}
920 {(row.message.inputIntent === "steer" ||
921 row.message.inputIntent === "promoted_queued_to_steer") &&
922 !row.continuesSteer ? (
923 <UserMessageIntentMarker
924 intent={row.message.inputIntent}
925 unread={row.projectedItem?.item.status === "pending"}
926 />
927 ) : null}
928 {mediaAboveText ? (
929 <div className="flex max-w-[80%] justify-end">
930 {/* The heading leads the media so screen readers reach it before the images. */}
931 <MessageAuthorHeading>
932 {gt("You", { $context: "author of the user's own message" })}
933 </MessageAuthorHeading>
934 {mediaBlock}
935 </div>
936 ) : null}
937 <div
938 className={cn(
939 "relative min-w-0 max-w-[80%] rounded-2xl text-message-foreground",
940 (mediaAboveText || row.groupedWithPrevious) && "rounded-tr-md",
941 row.groupedWithNext && "rounded-br-md",
942 BUBBLE_CHIP_CLASS_NAME,
943 userMessage.attribution === "guest"
944 ? guestBubbleClassName(false)
945 : !mediaOnly && !fileCardsOnly && !audioOnly && "bg-message",
946 !folded && !mediaOnly && !fileCardsOnly && !audioOnly && "p-3",
947 folded && expanded && "w-full",
948 )}
949 data-user-message-bubble=""
950 >
951 {/* Outside the fold so a collapsed message still has a heading to navigate to. */}
952 {mediaAboveText ? null : (
953 <MessageAuthorHeading>
954 {folded
955 ? senderLabel
956 : userMessage.guestName === undefined
957 ? gt("You", { $context: "author of the user's own message" })
958 : gt("{name} (guest)", { name: userMessage.guestName })}
959 </MessageAuthorHeading>
960 )}
961 {folded ? (
962 <FoldedMessageHeader
963 icon={MessagesSquareIcon}
964 label={senderLabel}
965 fitLabel={!senderTitle}
966 summary={foldSummary}
967 expanded={expanded}
968 onToggle={() => setExpanded((value) => !value)}
969 />
970 ) : null}
971 {/* Find reads the DOM, so a folded message stays mounted but hidden while find is open. */}
972 {!folded || expanded || ctx.findActive ? (
973 <div
974 ref={folded ? revealFoldRef : undefined}
975 hidden={folded && !expanded}
976 dir={markdownProseDirection(resolvedContext.text)}
977 className={cn(
978 folded && "px-3 pb-3",
979 folded && !ctx.findActive && "max-h-96 overflow-auto",
980 )}
981 >
982 {!mediaAboveText && mediaBlock}
983 {userAudio.length > 0 ? (
984 <div className={cn("flex max-w-full flex-col gap-1", !audioOnly && "mb-2")}>
985 {userAudio.map((file) => (
986 <InlineAudioPreview
987 key={file.id}
988 name={file.name}
989 variant={audioOnly ? "bubble" : "chip"}
990 environmentId={ctx.activeThreadEnvironmentId}
991 resource={{
992 _tag: "attachment",
993 attachmentId: file.id,
994 fileName: file.name,
995 mimeType: file.mimeType,
996 disposition: "inline",
997 }}
998 onOpen={() => ctx.onFileOpen(file)}
999 />
1000 ))}
1001 </div>
1002 ) : null}
1003 {fileCardsOnly ? (
1004 <div className="flex flex-col items-end gap-1" onCopyCapture={onBodyCopyCapture}>
1005 {otherUserFiles.map((file) => (
1006 <UserFileCard
1007 key={file.id}
1008 file={file}
1009 copyMarkdown={
1010 attachmentReferences.find((reference) => reference.attachmentId === file.id)
1011 ?.source
1012 }
1013 />
1014 ))}
1015 </div>
1016 ) : null}
1017 {!fileCardsOnly && (unchippedFiles.length > 0 || unknownAttachments.length > 0) ? (
1018 <div className="mb-2 flex flex-col gap-1">
1019 {unchippedFiles.map((file) => {
1020 const pastedText = file.source?._tag === "pasted-text";
1021 const label = userMessageFileLabel(file, m);
1022 const fileIdentity = (
1023 <>
1024 <PierreEntryIcon
1025 pathValue={file.name}
1026 kind="file"
1027 theme={ctx.resolvedTheme}
1028 />
1029 <span className="min-w-0 flex-1">
1030 <span className="block truncate">{label}</span>
1031 {file.downloadable === false || pastedText ? (
1032 <span className="block text-xs text-muted-foreground tabular-nums">
1033 {file.downloadable === false ? (
1034 <T>Sending…</T>
1035 ) : (
1036 formatBytes(file.sizeBytes)
1037 )}
1038 </span>
1039 ) : null}
1040 </span>
1041 </>
1042 );
1043 if (file.downloadable !== false) {
1044 return (
1045 <div key={file.id} className="flex min-w-0 items-center gap-1">
1046 <button
1047 type="button"
1048 aria-label={gt("Preview {label}", { label })}
1049 onClick={() => ctx.onFileOpen(file)}
1050 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"
1051 >
1052 {fileIdentity}
1053 <EyeIcon className="size-4 shrink-0" />
1054 </button>
1055 <SharedTooltipTrigger
1056 render={
1057 <Button
1058 size="icon-xs"
1059 variant="ghost-muted"
1060 aria-label={gt("Download {label}", { label })}
1061 onClick={() => ctx.onFileDownload(file)}
1062 />
1063 }
1064 label={
1065 <>
1066 <T>
1067 Download <Var>{label}</Var>
1068 </T>
1069 </>
1070 }
1071 >
1072 <DownloadIcon />
1073 </SharedTooltipTrigger>
1074 </div>
1075 );
1076 }
1077
1078 return (
1079 <div key={file.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
1080 {fileIdentity}
1081 </div>
1082 );
1083 })}
1084 {unknownAttachments.map((attachment) => (
1085 <div key={attachment.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
1086 <PierreEntryIcon
1087 pathValue={attachment.name}
1088 kind="file"
1089 theme={ctx.resolvedTheme}
1090 />
1091 <span className="min-w-0 flex-1 truncate">{attachment.name}</span>
1092 </div>
1093 ))}
1094 </div>
1095 ) : null}
1096 {fileCardsOnly || audioOnly ? null : (
1097 <div onCopyCapture={onBodyCopyCapture}>
1098 <CollapsibleUserMessageBody
1099 text={resolvedContext.text}
1100 renderContextReference={renderContextReference}
1101 skills={ctx.skills}
1102 markdownCwd={ctx.markdownCwd}
1103 collapsible={!folded}
1104 />
1105 </div>
1106 )}
1107 </div>
1108 ) : null}
1109 {floatActions ? (
1110 <div
1111 className={cn(
1112 "absolute end-full top-1/2 me-2 hidden w-max max-w-[calc(20cqw-0.5rem)] -translate-y-1/2 @min-[37rem]:flex",
1113 ACTIONS_REVEAL_CLASS_NAME,
1114 )}
1115 >
1116 {messageActions}
1117 </div>
1118 ) : null}
1119 </div>
1120 <UserMessageProjectedStatus row={row} />
1121 {!folded || expanded ? (
1122 <div
1123 className={cn(
1124 "flex w-full max-w-[80%] justify-end pe-1",
1125 floatActions && "@min-[37rem]:hidden",
1126 ACTIONS_REVEAL_CLASS_NAME,
1127 )}
1128 >
1129 {messageActions}
1130 </div>
1131 ) : null}
1132 </div>
1133 );
1134}
1135
1136const ACTIONS_REVEAL_CLASS_NAME =
1137 "items-center text-xs tabular-nums opacity-0 transition-opacity duration-200 pointer-coarse:opacity-100 focus-within:opacity-100 group-hover:opacity-100";
1138
1139function UserMessageIntentMarker({
1140 intent,
1141 unread,
1142}: {
1143 readonly intent: "steer" | "promoted_queued_to_steer";
1144 readonly unread: boolean;
1145}) {
1146 const gt = useGT();
1147 return (
1148 <SharedTooltipTrigger
1149 render={
1150 <div
1151 className="me-1 flex items-center justify-end gap-1 text-xs leading-none text-muted-foreground"
1152 data-user-message-intent={intent}
1153 />
1154 }
1155 label={
1156 unread
1157 ? gt(
1158 "Waiting for the agent to read this. It reads steers between steps, after a running command finishes.",
1159 )
1160 : intent === "promoted_queued_to_steer"
1161 ? gt("Originally queued, then promoted to steer the active turn")
1162 : gt("Steered the active turn")
1163 }
1164 >
1165 <Redo2Icon aria-hidden="true" className="size-3" />
1166 {unread
1167 ? gt("Steer · waiting to be read")
1168 : gt("Steer", { $context: "noun, a message that steers the running turn" })}
1169 </SharedTooltipTrigger>
1170 );
1171}
1172
1173function RevertUserMessageButton({
1174 turnCount,
1175 messageId,
1176}: {
1177 turnCount: number;
1178 messageId: MessageId;
1179}) {
1180 const ctx = use(TimelineRowCtx);
1181 const activity = use(TimelineRowActivityCtx);
1182 const gt = useGT();
1183
1184 return (
1185 <SharedTooltipTrigger
1186 render={
1187 <Button
1188 type="button"
1189 size="xs"
1190 variant="ghost"
1191 disabled={activity.isRevertingCheckpoint || activity.isWorking}
1192 onClick={() => ctx.onRevertToTurnCount(turnCount, messageId)}
1193 aria-label={gt("Edit from here")}
1194 />
1195 }
1196 label={
1197 <>
1198 <T>Edit from here</T>
1199 </>
1200 }
1201 >
1202 <PencilIcon className="size-3" />
1203 </SharedTooltipTrigger>
1204 );
1205}
1206
1207const COLLAPSED_USER_MESSAGE_FADE_HEIGHT_REM = 1.75;
1208
1209const COLLAPSED_USER_MESSAGE_FADE_MASK = `linear-gradient(to bottom, black calc(100% - ${COLLAPSED_USER_MESSAGE_FADE_HEIGHT_REM}rem), transparent)`;
1210
1211const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(props: {
1212 text: string;
1213 renderContextReference: (reference: ChatMarkdownContextReference) => ReactNode;
1214 skills: ReadonlyArray<ServerProviderSkill>;
1215 markdownCwd: string | undefined;
1216 collapsible?: boolean;
1217}) {
1218 const [expanded, setExpanded] = useState(false);
1219 const revealForFind = () => setExpanded(true);
1220 const revealRef = findRevealRef(revealForFind);
1221 const hasVisibleBody = props.text.trim().length > 0;
1222 const { ref: contentRef, tallEnough: canCollapse } = useTallEnoughToFold(
1223 props.collapsible !== false && hasVisibleBody,
1224 );
1225 const isCollapsed = canCollapse && !expanded;
1226 const showCollapseControl = canCollapse;
1227
1228 return (
1229 <div>
1230 {hasVisibleBody ? (
1231 <div
1232 ref={revealRef}
1233 className={cn("relative", isCollapsed && "max-h-44 overflow-hidden")}
1234 data-user-message-body="true"
1235 data-thread-find-text="true"
1236 data-thread-find-fold={isCollapsed ? "" : undefined}
1237 data-user-message-collapsed={isCollapsed ? "true" : "false"}
1238 data-user-message-collapsible={canCollapse ? "true" : "false"}
1239 data-user-message-fade={isCollapsed ? "true" : "false"}
1240 style={
1241 isCollapsed
1242 ? {
1243 WebkitMaskImage: COLLAPSED_USER_MESSAGE_FADE_MASK,
1244 maskImage: COLLAPSED_USER_MESSAGE_FADE_MASK,
1245 }
1246 : undefined
1247 }
1248 >
1249 <div ref={contentRef}>
1250 <UserMessageBody
1251 text={props.text}
1252 renderContextReference={props.renderContextReference}
1253 skills={props.skills}
1254 markdownCwd={props.markdownCwd}
1255 />
1256 </div>
1257 </div>
1258 ) : null}
1259 {showCollapseControl ? (
1260 <div className="mt-1.5 flex items-center justify-end gap-2" data-user-message-footer="true">
1261 {showCollapseControl ? (
1262 <Button
1263 type="button"
1264 size="xs"
1265 variant="ghost-muted"
1266 aria-expanded={expanded}
1267 data-scroll-anchor-ignore
1268 onClick={() => setExpanded((value) => !value)}
1269 className="-ml-1"
1270 >
1271 {expanded ? <T>Show less</T> : <T>Show full message</T>}
1272 </Button>
1273 ) : null}
1274 </div>
1275 ) : null}
1276 </div>
1277 );
1278});
1279
1280const USER_MESSAGE_MARKDOWN: MarkdownExtensions = { userMessage: true, leadingWhitespace: true };
1281
1282const UserMessageBody = memo(function UserMessageBody(props: {
1283 text: string;
1284 renderContextReference?: (reference: ChatMarkdownContextReference) => ReactNode;
1285 skills: ReadonlyArray<ServerProviderSkill>;
1286 markdownCwd: string | undefined;
1287}) {
1288 const ctx = use(TimelineRowCtx);
1289 if (props.text.length === 0) {
1290 return null;
1291 }
1292 return (
1293 <ChatMarkdown
1294 text={props.text}
1295 cwd={props.markdownCwd}
1296 threadRef={ctx.threadRef ?? undefined}
1297 skills={props.skills}
1298 className="text-message-foreground user-message-markdown"
1299 lineBreaks
1300 parseRawHtml={false}
1301 extensions={USER_MESSAGE_MARKDOWN}
1302 renderContextReference={props.renderContextReference}
1303 headingLevelOffset={MESSAGE_HEADING_LEVEL}
1304 />
1305 );
1306});