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

TimelineWorkEntryRow.tsx

670 lines23.6 KB

1import { TimelinePendingApprovalRow } from "./TimelinePendingApprovalRow";
2import { WorkLogDetails, WorkLogRow } from "./WorkLog";
3import {
4 getQuestionAnswerPreview,
5 getQuestionAnswerText,
6 getQuestionTextPreview,
7 hasQuestionAnswer,
8} from "@t3tools/client-runtime/work-log/user-input";
9import {
10 ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE,
11 type EnvironmentId,
12 ThreadId,
13} from "@t3tools/contracts";
14import { scopeThreadRef } from "@t3tools/client-runtime/environment";
15import { Link } from "@tanstack/react-router";
16import { notificationChildThreadId } from "@t3tools/client-runtime/state/thread-execution";
17import {
18 resolveViewedImageAsset,
19 toolGroupAction,
20 workEntryViewedImagePath,
21} from "@t3tools/client-runtime/work-log/presentation";
22import {
23 turnItemHasDetail,
24 turnItemNeedsDetailFetch,
25} from "@t3tools/client-runtime/work-log/item-detail";
26import { claudeSkillInvocation } from "@t3tools/shared/toolActivity";
27import { memo, use, useState, type KeyboardEvent } from "react";
28import {
29 workEntryDisplayIndicatesToolFailure,
30 workEntrySignalsSevereFailure,
31 workLogEntryIsToolLike,
32} from "../../session-logic";
33import ChatMarkdown from "../ChatMarkdown";
34import { ChatMarkdownAssetImage } from "./ChatMarkdownMedia";
35import { ChevronRightIcon, CircleAlertIcon, XIcon, RotateCcwIcon } from "lucide-react";
36import { Button, InlineButton } from "../ui/button";
37import { useAssetUrls } from "../../assets/assetUrls";
38import { useThreadShell } from "../../state/entities";
39import {
40 threadReadLabelPrefix,
41 threadReadTargetId,
42 threadReadTargetTitle,
43 workEntryDisplayLabel,
44 workEntryReadOutput,
45} from "./MessagesTimeline.logic";
46import { cn } from "~/lib/utils";
47import { formatUpcomingTimestamp } from "../../timestampFormat";
48import { FetchedToolOutput, V2ItemInspector } from "./V2ItemInspector";
49import { SubagentNotificationLink } from "./V2LifecycleRow";
50import {
51 TimelineRowCtx,
52 TimelineRowActivityCtx,
53 WorkGroupViewCtx,
54 type TimelineRow,
55 type TimelineWorkEntry,
56} from "./timelineRowContext";
57import { MESSAGE_HEADING_LEVEL, TimelineRowTimestamp } from "./TimelineRowParts";
58import {
59 failedToolIconClassName,
60 toolIconAcceptsTint,
61 ToolActivityIconView,
62} from "./TimelineToolActivityIcon";
63import {
64 workToneIcon,
65 workEntryRawCommand,
66 buildToolCallExpandedBody,
67 workEntryIconName,
68 THINKING_PREVIEW_PLUGINS,
69 THOUGHT_PREVIEW_PLUGINS,
70} from "./TimelineWorkEntryRow.logic";
71​
72export function useThreadReadTarget(entry: TimelineWorkEntry, environmentId: EnvironmentId) {
73 const rawThreadId = threadReadTargetId(entry);
74 const threadId = rawThreadId === null ? null : ThreadId.make(rawThreadId);
75 const shell = useThreadShell(threadId ? scopeThreadRef(environmentId, threadId) : null);
76 const title = threadReadTargetTitle(shell);
77 return threadId && title ? { threadId, title } : null;
79​
80export function threadReadLabel(label: string, target: ReturnType<typeof useThreadReadTarget>) {
81 const prefix = target && threadReadLabelPrefix(label);
82 return prefix ? { ...target, prefix, text: `${prefix} “${target.title}”` } : null;
84​
85export function ThreadReadLabel({
86 label,
87 environmentId,
88 linked,
89}: {
90 label: NonNullable<ReturnType<typeof threadReadLabel>>;
91 environmentId: EnvironmentId;
92 linked: boolean;
93}) {
94 return (
95 <span className="flex min-w-0">
96 <span className="shrink-0">{label.prefix} “</span>
97 {linked ? (
98 <Link
99 to="/$environmentId/$threadId"
100 params={{ environmentId, threadId: label.threadId }}
101 className="min-w-0 truncate rounded-sm text-foreground underline-offset-2 hover:underline focus-visible:outline-2 focus-visible:outline-ring"
102 onClick={stopRowToggle}
103 onKeyDown={stopRowToggle}
104 >
105 {label.title}
106 </Link>
107 ) : (
108 <span className="min-w-0 truncate">{label.title}</span>
109 )}
110 <span className="shrink-0">”</span>
111 </span>
112 );
114​
115const toolCallExpandedBodyClassName =
116 "max-h-64 cursor-text overflow-auto whitespace-pre-wrap break-words font-mono text-secondary-label text-(length:--font-size-code,var(--text-2xs)) leading-relaxed select-text";
117​
118const stopRowToggle = (e: { stopPropagation: () => void }) => e.stopPropagation();
119​
120export function ReasoningTraceContent({ entries }: { entries: ReadonlyArray<TimelineWorkEntry> }) {
121 const ctx = use(TimelineRowCtx);
122 const { isWorking, latestRunId } = use(TimelineRowActivityCtx);
123 const isStreaming = (entry: TimelineWorkEntry) =>
124 isWorking && entry.runId === latestRunId && entry.toolLifecycleStatus === "inProgress";
125 return (
126 <WorkLogDetails followLive={entries.some(isStreaming)}>
127 {entries.map((entry) => (
128 <ChatMarkdown
129 key={entry.id}
130 className="text-foreground"
131 text={entry.detail ?? ""}
132 cwd={ctx.markdownCwd}
133 threadRef={ctx.threadRef ?? undefined}
134 skills={ctx.skills}
135 isStreaming={isStreaming(entry)}
136 headingLevelOffset={MESSAGE_HEADING_LEVEL}
137 onUseArtifactTemplate={ctx.onUseArtifactTemplate}
138 onImageExpand={ctx.onImageExpand}
139 lineBreaks
140 />
141 ))}
142 </WorkLogDetails>
143 );
145​
146type WorkEntryRowProps = {
147 workEntry: TimelineWorkEntry;
148 workspaceRoot: string | undefined;
149 displayLabel?: string | undefined;
150 onToggleEntry?: ((collapsed: boolean) => void) | undefined;
151 onContentReady?: (() => void) | undefined;
152};
153​
154export const SimpleWorkEntryRow = memo(function SimpleWorkEntryRow(props: WorkEntryRowProps) {
155 const ctx = use(TimelineRowCtx);
156 const item = props.workEntry.projectedItem?.item;
157 const childThreadId =
158 item?.type === "notification" ? notificationChildThreadId(item.source) : undefined;
159 if (item?.type !== "notification" || childThreadId === undefined) {
160 return <WorkEntryLogRow {...props} />;
161 }
162 return (
163 <SubagentNotificationLink
164 parentRef={scopeThreadRef(ctx.activeThreadEnvironmentId, item.threadId)}
165 childThreadId={childThreadId}
166 taskIds={item.source.kind === "delegated_task" ? item.source.taskIds : undefined}
167 outcome={item.outcome}
168 createdAt={props.workEntry.createdAt}
169 timestampFormat={ctx.timestampFormat}
170 onOpenThread={ctx.onOpenThread}
171 fallback={<WorkEntryLogRow {...props} />}
172 />
173 );
174});
175​
176export function ViewedImagesTimelineRow({
177 row,
178}: {
179 row: Extract<TimelineRow, { kind: "viewed-images" }>;
180}) {
181 const { threadRef, workspaceRoot, onImageExpand } = use(TimelineRowCtx);
182 if (!threadRef) return null;
183 return (
184 <div className="flex flex-wrap items-start gap-2 px-0.5">
185 {row.paths.map((path) => {
186 const image = resolveViewedImageAsset(path, {
187 threadId: threadRef.threadId,
188 workspaceRoot,
189 });
190 return image ? (
191 <ChatMarkdownAssetImage
192 key={path}
193 environmentId={threadRef.environmentId}
194 resource={image.resource}
195 alt={image.alt}
196 srcFragment={image.srcFragment}
197 workspaceRoot={workspaceRoot}
198 maxHeightRem={10}
199 onImageExpand={onImageExpand}
200 />
201 ) : null;
202 })}
203 </div>
204 );
206​
207function WorkEntryLogRow(props: WorkEntryRowProps) {
208 const { workEntry, workspaceRoot, displayLabel } = props;
209 const ctx = use(TimelineRowCtx);
210 const { threadRef, onImageExpand, timestampFormat } = ctx;
211 const { retryableWorkspacePreparationRunIds, onRetryWorkspacePreparation } = ctx;
212 const threadTarget = useThreadReadTarget(workEntry, ctx.activeThreadEnvironmentId);
213 const createdThread =
214 workEntry.projectedItem?.item.type === "thread_created"
215 ? workEntry.projectedItem.item
216 : undefined;
217 const notifiedSubagentThreadId =
218 workEntry.projectedItem?.item.type === "notification"
219 ? notificationChildThreadId(workEntry.projectedItem.item.source)
220 : undefined;
221 const groupView = use(WorkGroupViewCtx);
222 const [expanded, setExpanded] = useState(
223 () => groupView?.state.expandedEntries.has(workEntry.id) ?? false,
224 );
225 const onInitialOutputReady = () => {
226 if (groupView) groupView.onContentReady?.(workEntry.id);
227 else props.onContentReady?.();
228 };
229 const toggleExpanded = () => {
230 const next = !expanded;
231 if (groupView) {
232 groupView.onToggleEntry(!next, workEntry.id);
233 if (next) groupView.state.expandedEntries.add(workEntry.id);
234 else groupView.state.expandedEntries.delete(workEntry.id);
235 } else {
236 props.onToggleEntry?.(!next);
237 }
238 setExpanded(next);
239 };
240 const failureItem = workEntry.projectedItem?.item;
241 const pendingApproval =
242 failureItem?.type === "approval_request"
243 ? ctx.pendingApprovals.get(failureItem.requestId)
244 : undefined;
245 if (pendingApproval) return <TimelinePendingApprovalRow approval={pendingApproval} />;
246 if (failureItem?.type === "error" && failureItem.status === "failed") {
247 const warning = failureItem.failure.class === "usage_limit";
248 const resetAt = failureItem.failure.resetAt;
249 // The reset time is the viewer's local time; naming the zone keeps it
250 // unambiguous. Both read the zone now, since the device's can change.
251 const timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
252 const resetTime = resetAt
253 ? `${formatUpcomingTimestamp(resetAt, timestampFormat, undefined, timeZone)} (${timeZone})`
254 : null;
255 const label = warning
256 ? `Usage limit reached.${resetTime ? ` Retry after ${resetTime}.` : ""}`
257 : workEntry.label;
258 const retryRunId =
259 failureItem.runId !== null &&
260 retryableWorkspacePreparationRunIds.has(failureItem.runId) &&
261 failureItem.failure.code === ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE
262 ? failureItem.runId
263 : null;
264 return (
265 <WorkLogRow
266 data-v2-item-type="error"
267 data-v2-item-visibility={workEntry.projectedItem?.visibility}
268 wrapLabel
269 icon={
270 <CircleAlertIcon
271 className={cn("size-4", warning ? "text-warning" : "text-destructive")}
272 />
273 }
274 label={
275 <span
276 className={cn("text-sm font-medium", warning ? "text-warning" : "text-destructive")}
277 >
278 {label}
279 </span>
280 }
281 trailing={
282 <TimelineRowTimestamp
283 createdAt={workEntry.createdAt}
284 timestampFormat={timestampFormat}
285 alwaysVisible
286 />
287 }
288 >
289 {!warning ? (
290 <p className="ms-7 whitespace-pre-wrap break-words py-1 text-sm leading-relaxed text-foreground/80">
291 {failureItem.failure.message}
292 </p>
293 ) : null}
294 {retryRunId !== null && onRetryWorkspacePreparation ? (
295 <div className="ms-7 pb-1">
296 <Button
297 type="button"
298 size="xs"
299 variant="outline"
300 onClick={() => onRetryWorkspacePreparation(retryRunId)}
301 >
302 <RotateCcwIcon aria-hidden />
303 Retry
304 </Button>
305 </div>
306 ) : null}
307 </WorkLogRow>
308 );
309 }
310 const iconConfig = workToneIcon(workEntry.tone);
311 const showWarningIndicator = workEntry.sourceActivityKind === "runtime.warning";
312 const showFailedIndicator =
313 !showWarningIndicator && workEntryDisplayIndicatesToolFailure(workEntry);
314 const showDestructiveRowStyle =
315 !showWarningIndicator &&
316 showFailedIndicator &&
317 (workEntrySignalsSevereFailure(workEntry) || !workLogEntryIsToolLike(workEntry));
318 const entryIconName =
319 showWarningIndicator || showDestructiveRowStyle ? "circle-alert" : workEntryIconName(workEntry);
320 const entryToolIcon =
321 showWarningIndicator || showDestructiveRowStyle
322 ? undefined
323 : (workEntry.toolIcon ?? workEntry.toolSource?.icon);
324 const isReasoning = workEntry.itemType === "reasoning";
325 const questionHeading = workEntry.questionAnswer
326 ? getQuestionTextPreview(workEntry.questionAnswer)
327 : "";
328 const previewText =
329 isReasoning && expanded
330 ? workEntry.toolLifecycleStatus === "inProgress"
331 ? "Thinking"
332 : "Thought"
333 : questionHeading || (displayLabel ?? workEntryDisplayLabel(workEntry, workspaceRoot));
334 const answerPreview =
335 workEntry.questionAnswer && hasQuestionAnswer(workEntry.questionAnswer)
336 ? getQuestionAnswerPreview(workEntry.questionAnswer)
337 : null;
338 const viewedImagePath = workEntryViewedImagePath(workEntry);
339 const payload = workEntry.structuredPayload;
340 const skill =
341 payload?.type === "dynamic_tool"
342 ? claudeSkillInvocation(payload.toolName, payload.input)
343 : undefined;
344 const plainOutput =
345 toolGroupAction(workEntry) === "read"
346 ? workEntryReadOutput(workEntry, workspaceRoot)
347 : skill
348 ? (skill.args ?? null)
349 : undefined;
350 const viewedImage =
351 viewedImagePath && threadRef
352 ? resolveViewedImageAsset(viewedImagePath, {
353 threadId: threadRef.threadId,
354 workspaceRoot,
355 })
356 : null;
357 const canExpand =
358 previewText.trim().length > 0 ||
359 (workEntry.itemType === "dynamic_tool" && workEntry.toolData !== undefined) ||
360 Boolean(
361 workEntryRawCommand(workEntry) ||
362 workEntry.command?.trim() ||
363 workEntry.detail?.trim() ||
364 workEntry.changedFiles?.length ||
365 viewedImage,
366 );
367 const expandedBody =
368 expanded && !isReasoning
369 ? plainOutput !== undefined
370 ? plainOutput
371 : buildToolCallExpandedBody(
372 workEntry,
373 workspaceRoot,
374 previewText,
375 viewedImage ? viewedImagePath : null,
376 )
377 : null;
378 const plainOutputFetches =
379 plainOutput !== undefined &&
380 workEntry.projectedItem !== undefined &&
381 turnItemNeedsDetailFetch(workEntry.projectedItem.item);
382 const canExpandProjectedItem =
383 plainOutput !== undefined
384 ? Boolean(plainOutput || viewedImage || workEntry.questionAnswer || plainOutputFetches)
385 : workEntry.projectedItem === undefined
386 ? canExpand
387 : isReasoning
388 ? Boolean(workEntry.detail?.trim())
389 : Boolean(
390 viewedImage ||
391 workEntry.questionAnswer ||
392 turnItemHasDetail(workEntry.projectedItem.item),
393 );
394 const iconWrapperClass = cn(
395 "flex size-4 items-center justify-center",
396 showWarningIndicator
397 ? "text-warning"
398 : showDestructiveRowStyle
399 ? "text-destructive"
400 : showFailedIndicator
401 ? failedToolIconClassName
402 : workEntry.tone === "tool"
403 ? "text-icon-muted"
404 : iconConfig.className,
405 );
406 const headingClass = showWarningIndicator
407 ? "font-medium text-warning"
408 : showDestructiveRowStyle
409 ? "font-medium text-destructive"
410 : workLogEntryIsToolLike(workEntry)
411 ? "text-secondary-label"
412 : "text-foreground/80";
413 const threadLabel = isReasoning ? null : threadReadLabel(previewText, threadTarget);
414 const accessiblePreview = [threadLabel?.text ?? previewText, answerPreview]
415 .filter(Boolean)
416 .join(": ");
417 const accessibleDisplayText = showFailedIndicator
418 ? `${accessiblePreview}, tool call failed`
419 : accessiblePreview;
420 const rowToggleProps = canExpandProjectedItem
421 ? {
422 role: "button" as const,
423 tabIndex: 0 as const,
424 "aria-label": accessibleDisplayText,
425 "aria-expanded": expanded,
426 onClick: toggleExpanded,
427 onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => {
428 if (e.target === e.currentTarget && (e.key === "Enter" || e.key === " ")) {
429 e.preventDefault();
430 toggleExpanded();
431 }
432 },
433 }
434 : {};
435​
436 return (
437 <WorkLogRow
438 data-work-entry-id={workEntry.id}
439 data-v2-item-type={workEntry.projectedItem?.item.type}
440 data-v2-item-visibility={workEntry.projectedItem?.visibility}
441 {...rowToggleProps}
442 icon={
443 <span
444 className={iconWrapperClass}
445 role={showFailedIndicator ? "img" : undefined}
446 aria-label={showFailedIndicator ? "Tool call failed" : undefined}
447 >
448 <ToolActivityIconView
449 icon={entryToolIcon}
450 fallbackName={entryIconName}
451 className="block size-4 shrink-0 stroke-2"
452 muted
453 />
454 </span>
455 }
456 label={
457 <div className="min-w-0 flex-1 overflow-hidden">
458 <p className="flex min-w-0 w-full items-baseline gap-1.5 text-sm leading-relaxed">
459 <span
460 className={cn(answerPreview ? "min-w-0" : "min-w-0 flex-1", "truncate", headingClass)}
461 >
462 {isReasoning && !expanded ? (
463 <ChatMarkdown
464 inline
465 text={workEntry.detail ?? previewText}
466 cwd={ctx.markdownCwd}
467 parseRawHtml={false}
468 extraRemarkPlugins={
469 workEntry.toolLifecycleStatus === "inProgress"
470 ? THINKING_PREVIEW_PLUGINS
471 : THOUGHT_PREVIEW_PLUGINS
472 }
473 />
474 ) : threadLabel ? (
475 <ThreadReadLabel
476 label={threadLabel}
477 environmentId={ctx.activeThreadEnvironmentId}
478 linked
479 />
480 ) : (
481 previewText
482 )}
483 </span>
484 {answerPreview ? (
485 <span
486 className={cn(
487 "min-w-0 truncate",
488 !expanded &&
489 workEntry.questionAnswer &&
490 hasQuestionAnswer(workEntry.questionAnswer)
491 ? "text-foreground"
492 : "text-muted-foreground",
493 )}
494 >
495 {answerPreview}
496 </span>
497 ) : null}
498 </p>
499 </div>
500 }
501 trailing={
502 <>
503 {createdThread ? (
504 <button
505 type="button"
506 className="shrink-0 rounded-sm text-sm text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
507 aria-label={`Open ${createdThread.title ?? "created thread"}`}
508 onClick={(event) => {
509 event.stopPropagation();
510 ctx.onOpenThread(createdThread.targetThreadId);
511 }}
512 onKeyDown={stopRowToggle}
513 >
514 Open chat
515 </button>
516 ) : null}
517 {notifiedSubagentThreadId ? (
518 <InlineButton
519 aria-label="Open subagent thread"
520 onClick={(event) => {
521 event.stopPropagation();
522 ctx.onOpenThread(notifiedSubagentThreadId);
523 }}
524 onKeyDown={stopRowToggle}
525 >
526 Open subagent
527 </InlineButton>
528 ) : null}
529 {showFailedIndicator &&
530 !showDestructiveRowStyle &&
531 !toolIconAcceptsTint(entryToolIcon) ? (
532 <XIcon aria-hidden className={cn("size-3 shrink-0", failedToolIconClassName)} />
533 ) : null}
534 <TimelineRowTimestamp createdAt={workEntry.createdAt} timestampFormat={timestampFormat} />
535 <span
536 className={cn(
537 "flex size-4 shrink-0 items-center justify-center",
538 !canExpandProjectedItem && "invisible",
539 )}
540 aria-hidden
541 >
542 <ChevronRightIcon
543 className={cn(
544 "size-3 shrink-0 text-icon-muted opacity-70 transition-transform duration-200",
545 expanded && "rotate-90",
546 )}
547 />
548 </span>
549 </>
550 }
551 >
552 {expanded && viewedImage && threadRef ? (
553 <WorkLogDetails kind="media">
554 <ChatMarkdownAssetImage
555 environmentId={threadRef.environmentId}
556 resource={viewedImage.resource}
557 alt={viewedImage.alt}
558 srcFragment={viewedImage.srcFragment}
559 workspaceRoot={workspaceRoot}
560 maxHeightRem={16}
561 onImageExpand={onImageExpand}
562 />
563 </WorkLogDetails>
564 ) : null}
565 {expanded && workEntry.questionAnswer ? (
566 <QuestionAnswerHistory answer={workEntry.questionAnswer} />
567 ) : null}
568 {expanded && isReasoning ? <ReasoningTraceContent entries={[workEntry]} /> : null}
569 {expanded &&
570 !isReasoning &&
571 !workEntry.questionAnswer &&
572 canExpandProjectedItem &&
573 (expandedBody ||
574 plainOutputFetches ||
575 (workEntry.projectedItem && plainOutput === undefined)) ? (
576 <WorkLogDetails kind="panel">
577 {workEntry.projectedItem && plainOutput === undefined ? (
578 <V2ItemInspector
579 onInitialOutputReady={onInitialOutputReady}
580 projectedItem={workEntry.projectedItem}
581 environmentId={ctx.activeThreadEnvironmentId}
582 cwd={ctx.markdownCwd}
583 workspaceRoot={workspaceRoot}
584 onOpenToolDiff={ctx.onOpenToolDiff}
585 onImageExpand={ctx.onImageExpand}
586 source={ctx.turnItemSource}
587 />
588 ) : (
589 <>
590 {expandedBody ? (
591 <pre className={toolCallExpandedBodyClassName}>{expandedBody}</pre>
592 ) : null}
593 {plainOutputFetches && workEntry.projectedItem ? (
594 <FetchedToolOutput
595 onInitialOutputReady={onInitialOutputReady}
596 projectedItem={workEntry.projectedItem}
597 environmentId={ctx.activeThreadEnvironmentId}
598 onImageExpand={onImageExpand}
599 source={ctx.turnItemSource}
600 />
601 ) : null}
602 </>
603 )}
604 </WorkLogDetails>
605 ) : null}
606 </WorkLogRow>
607 );
609​
610function QuestionAnswerHistory({
611 answer,
612}: {
613 answer: import("@t3tools/contracts").UserInputAttachmentAnswerPayload;
614}) {
615 const { activeThreadEnvironmentId } = use(TimelineRowCtx);
616 const attachments = Object.values(answer.attachmentsByQuestionId).flat();
617 const resources = attachments.map((attachment) => ({
618 _tag: "attachment" as const,
619 attachmentId: attachment.id,
620 }));
621 const urls = useAssetUrls(activeThreadEnvironmentId, resources);
622 return (
623 <div className="ms-7 mt-2 space-y-2" onClick={stopRowToggle}>
624 {[
625 ...new Set([
626 ...Object.keys(answer.questionTextById ?? {}),
627 ...Object.keys(answer.answers),
628 ...Object.keys(answer.attachmentsByQuestionId),
629 ]),
630 ].map((questionId) => (
631 <div key={questionId} className="space-y-1">
632 {answer.questionTextById?.[questionId] ? (
633 <p className="whitespace-pre-wrap text-sm text-muted-foreground">
634 {answer.questionTextById[questionId]}
635 </p>
636 ) : null}
637 {getQuestionAnswerText(answer.answers[questionId]) ? (
638 <p className="ms-3 whitespace-pre-wrap text-sm text-muted-foreground">
639 {getQuestionAnswerText(answer.answers[questionId])}
640 </p>
641 ) : null}
642 <div className="flex flex-wrap gap-2">
643 {(answer.attachmentsByQuestionId[questionId] ?? []).map((attachment) => {
644 const url = urls[attachments.indexOf(attachment)];
645 return (
646 <a
647 key={attachment.id}
648 href={url ?? undefined}
649 target="_blank"
650 rel="noreferrer"
651 className="text-sm underline"
652 >
653 {attachment.type === "image" && url ? (
654 <img
655 src={url}
656 alt={attachment.name}
657 className="h-20 max-w-32 rounded object-contain"
658 />
659 ) : (
660 attachment.name
661 )}
662 </a>
663 );
664 })}
665 </div>
666 </div>
667 ))}
668 </div>
669 );