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