Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 47 additions & 16 deletions apps/web/src/components/chat/TimelineWorkEntryRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "@t3tools/client-runtime/work-log/item-detail";
import { claudeSkillInvocation } from "@t3tools/shared/toolActivity";
import { msg, T, useGT, useMessages, Var } from "gt-react";
import { memo, use, useState, type KeyboardEvent } from "react";
import { memo, use, useLayoutEffect, useRef, useState, type KeyboardEvent } from "react";
import {
workEntryDisplayIndicatesToolFailure,
workEntrySignalsSevereFailure,
Expand All @@ -42,6 +42,7 @@ import * as DateTime from "effect/DateTime";
import { ChevronRightIcon, CircleAlertIcon, XIcon, RotateCcwIcon } from "lucide-react";
import { Button, InlineButton } from "../ui/button";
import { useAssetUrls } from "../../assets/assetUrls";
import { observeResize } from "../../lib/observeResize";
import { useThreadShell } from "../../state/entities";
import {
threadReadTargetId,
Expand Down Expand Up @@ -300,6 +301,20 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
const [expanded, setExpanded] = useState(
() => groupView?.state.expandedEntries.has(workEntry.id) ?? false,
);
const noticeMessage =
workEntry.structuredPayload?.type === "system_notice"
? workEntry.structuredPayload.message
: null;
const labelRef = useRef<HTMLSpanElement>(null);
const [noticeCutOff, setNoticeCutOff] = useState(false);
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- only layout knows whether a notice fits its row
useLayoutEffect(() => {
const label = labelRef.current;
if (!label || noticeMessage === null) return;
const measure = () => setNoticeCutOff(label.scrollWidth > label.clientWidth);
measure();
return observeResize(label, measure);
}, [noticeMessage]);
const onInitialOutputReady = () => {
if (groupView) groupView.onContentReady?.(workEntry.id);
else props.onContentReady?.();
Expand Down Expand Up @@ -417,6 +432,18 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
: null;
const viewedImagePath = workEntryViewedImagePath(workEntry);
const payload = workEntry.structuredPayload;
const mcpSignIn =
payload?.type === "system_notice" &&
payload.mcpSignIn !== undefined &&
payload.providerThreadId !== null ? (
<McpSignInAction
environmentId={ctx.activeThreadEnvironmentId}
threadId={payload.threadId}
providerThreadId={payload.providerThreadId}
server={payload.mcpSignIn.server}
noticeAt={DateTime.toEpochMillis(payload.updatedAt)}
/>
) : null;
const skill =
payload?.type === "dynamic_tool"
? claudeSkillInvocation(payload.toolName, payload.input)
Expand Down Expand Up @@ -467,8 +494,10 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
plainOutput !== undefined &&
workEntry.projectedItem !== undefined &&
turnItemNeedsDetailFetch(workEntry.projectedItem.item);
// A notice's details repeat its row, so it expands only to show text the row cuts off.
const canExpandProjectedItem =
plainOutput !== undefined
(noticeMessage === null || noticeCutOff) &&
(plainOutput !== undefined
? Boolean(plainOutput || viewedImage || workEntry.questionAnswer || plainOutputFetches)
: workEntry.projectedItem === undefined
? canExpand
Expand All @@ -478,7 +507,7 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
viewedImage ||
workEntry.questionAnswer ||
turnItemHasDetail(workEntry.projectedItem.item),
);
));
const iconWrapperClass = cn(
"flex size-4 items-center justify-center",
showWarningIndicator
Expand Down Expand Up @@ -545,7 +574,12 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
<div className="min-w-0 flex-1 overflow-hidden">
<p className="flex min-w-0 w-full items-baseline gap-1.5 text-sm leading-relaxed">
<span
className={cn(answerPreview ? "min-w-0" : "min-w-0 flex-1", "truncate", headingClass)}
ref={labelRef}
className={cn(
answerPreview || mcpSignIn ? "min-w-0" : "min-w-0 flex-1",
"truncate",
headingClass,
)}
>
{isReasoning && !expanded ? (
<ChatMarkdown
Expand Down Expand Up @@ -586,11 +620,20 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
{answerPreview}
</span>
) : null}
{mcpSignIn}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
</p>
</div>
}
trailing={
<>
{/* First, so revealing it takes label space instead of moving the controls. Notices
skip it, so hovering never changes what fits or moves Sign in. */}
{noticeMessage === null ? (
<TimelineRowTimestamp
createdAt={workEntry.createdAt}
timestampFormat={timestampFormat}
/>
) : null}
{createdThread ? (
<button
type="button"
Expand All @@ -609,17 +652,6 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
<T>Open chat</T>
</button>
) : null}
{payload?.type === "system_notice" &&
payload.mcpSignIn !== undefined &&
payload.providerThreadId !== null ? (
<McpSignInAction
environmentId={ctx.activeThreadEnvironmentId}
threadId={payload.threadId}
providerThreadId={payload.providerThreadId}
server={payload.mcpSignIn.server}
noticeAt={DateTime.toEpochMillis(payload.updatedAt)}
/>
) : null}
{notifiedSubagentThreadId ? (
<InlineButton
aria-label={gt("Open subagent thread")}
Expand Down Expand Up @@ -647,7 +679,6 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
/>
</span>
) : null}
<TimelineRowTimestamp createdAt={workEntry.createdAt} timestampFormat={timestampFormat} />
</>
}
>
Expand Down
Loading