Skip to content
Draft
Show file tree
Hide file tree
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
181 changes: 148 additions & 33 deletions app/src/components/channels/chat-transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ import {
publishThreadWork,
threadWorkOf,
} from "@/components/tasks/thread-work";
import { foldTurnWork } from "@/components/tasks/turn-work";
import { foldTurnWork, type TurnWork } from "@/components/tasks/turn-work";
import {
isTaskThread,
TurnLine,
useWaitingToolCalls,
WorkedFor,
} from "@/components/tasks/worked-for";
Expand Down Expand Up @@ -202,14 +203,20 @@ import {
} from "./telemetry-assistant-message";
import {
ActivityAppMarks,
AppMark,
appOfCall,
attachmentReadName,
dropRepeatedAppCards,
FoldGrid,
groupToolSteps,
LiveConnectorStep,
LineShowsApp,
onlyApp,
rowApps,
ServerStepIcon,
ToolActivity,
type ToolGroup,
type TranscriptItem,
useAppName,
useDrawnTool,
useReportsDesktopActivity,
} from "./tool-activity";
Expand Down Expand Up @@ -1949,7 +1956,6 @@ const ToolCallBody = memo(function ToolCallBody({
result,
latest,
spokeAfter,
liveConnector,
}: {
toolCallId: string;
name: string;
Expand All @@ -1959,7 +1965,6 @@ const ToolCallBody = memo(function ToolCallBody({
latest: boolean;
/** The Bot said something after this call in its turn. See `ToolPlace`. */
spokeAfter: boolean;
liveConnector?: boolean;
}) {
const renderToolCall = useRenderToolCall();
const toolCall = useMemo(
Expand Down Expand Up @@ -2029,7 +2034,6 @@ const ToolCallBody = memo(function ToolCallBody({
) : (
<ServerToolLine
args={args}
liveConnector={liveConnector}
name={name}
place={{ toolCallId, latest }}
result={result}
Expand Down Expand Up @@ -2083,8 +2087,9 @@ type ToolRowProps = {
latest: boolean;
/** The Bot said something after this row in its turn. See `ToolPlace`. */
spokeAfter: boolean;
conversation?: boolean;
expanded?: boolean;
/** A run of calls drawn as plain lines (a `tools` group), which folds, even a run of one. */
folds?: boolean;
/**
* A lone step drawn as the folded line of work rather than as its own line: a send that delivered
* nothing and that its reply made good (`mendedSends`).
Expand All @@ -2106,8 +2111,8 @@ export function sameToolRow(a: ToolRowProps, b: ToolRowProps): boolean {
a.inFlight === b.inFlight &&
a.latest === b.latest &&
a.spokeAfter === b.spokeAfter &&
a.conversation === b.conversation &&
a.expanded === b.expanded &&
a.folds === b.folds &&
a.workAlone === b.workAlone &&
a.steps.length === b.steps.length &&
a.steps.every((step, index) => {
Expand All @@ -2130,11 +2135,14 @@ const ToolRow = memo(function ToolRow({
inFlight,
latest,
spokeAfter,
conversation,
expanded,
folds,
workAlone,
}: ToolRowProps) {
const [only] = steps;
// Inside a conversation turn's line, whose rows keep one grid (`FoldGrid`).
const inTurnLine = useContext(FoldGrid) !== undefined;
const isDrawn = useDrawnTool();
useReportsDesktopActivity(steps, active);
return (
<TurnInFlightContext.Provider value={inFlight}>
Expand All @@ -2143,13 +2151,22 @@ const ToolRow = memo(function ToolRow({
only &&
!workAlone &&
!isBrowserStep(only) &&
// Drawn open among a "Worked for" line's rows, a lone app call is a step as theirs are, not
// a muted line of its own beside them (`ToolActivity`). Inside a conversation turn's line,
// so is every lone call the app doesn't draw a card for: "Looked for a tool" drew its
// wrench where the steps drew chevrons. A command, an edit, keeps its own card.
!(
expanded &&
folds &&
((inTurnLine && !isDrawn(only.toolCall.function.name)) ||
appOfCall(only.toolCall.function.name))
) &&
// A subtask is drawn as work even alone, so a second call joining it does not change its shape.
only.toolCall.function.name !== SUBAGENT_TOOL ? (
<ArgumentsArrivingContext.Provider value={active}>
<ToolCallBody
args={only.toolCall.function.arguments}
latest={latest}
liveConnector={conversation && inFlight}
name={only.toolCall.function.name}
result={only.result}
spokeAfter={spokeAfter}
Expand All @@ -2159,7 +2176,6 @@ const ToolRow = memo(function ToolRow({
) : (
<ToolActivity
active={active}
conversation={conversation}
expanded={expanded}
group={{ kind: "tools", id, steps }}
/>
Expand All @@ -2182,15 +2198,13 @@ export function ServerToolLine({
args,
result,
place,
liveConnector,
}: {
name: string;
/** What the call was given, as the model wrote it. Read only for what a step acted on. */
args?: string;
result?: string;
/** Where this call sits in the conversation, for an app card that may carry the task on. */
place?: CardPlace;
liveConnector?: boolean;
}) {
const running = result === undefined;
// Cut off with its outcome unknown: named as it is while under way, since nobody knows it was done.
Expand All @@ -2200,10 +2214,16 @@ export function ServerToolLine({
const appId =
!role && name.startsWith("mcp__") ? name.split("__")[1] : undefined;
const folders = useContext(FolderNamesContext);
const appName = useAppName();
// On the one app the folded line above it shows (`LineShowsApp`), it doesn't draw its logo again.
const lineShows = useContext(LineShowsApp);
// The file a file step read or saved, as a computer's own file steps name it; a step on a folder
// on the person's computer names the folder too ("todo.txt in share").
// on the person's computer names the folder too ("todo.txt in share"). An app's step doesn't say
// its app's name: its logo does, and names it on hover (`AppMark`).
const detail =
(appId && named.detail === appId ? connectorName(appId) : named.detail) ??
(appId && (named.detail === appId || named.detail === connectorName(appId))
? undefined
: named.detail) ??
folderStepSubject(name, args, folders) ??
ownToolSubject(name, args) ??
// The attached file a read was of, by the name its answer carries.
Expand Down Expand Up @@ -2262,12 +2282,6 @@ export function ServerToolLine({
? readAnotherAccountPrompt(answer)
: null;
if (another) return <AnotherAccountCard prompt={another} />;
if (running && liveConnector && appId)
return (
<div className="my-1.5">
<LiveConnectorStep appId={appId} label={label} />
</div>
);
/*
* THAT TOOL'S OTHER ANSWERS ARE FOR THE MODEL. An app nobody can name comes back as plain text
* telling the Bot to say so plainly and not to browse to it — an instruction, which read by the
Expand Down Expand Up @@ -2334,7 +2348,15 @@ export function ServerToolLine({
{...(failed && ownToolFailedLabel(name)
? { failedLabel: ownToolFailedLabel(name) ?? undefined }
: {})}
icon={<ServerStepIcon name={name} />}
{...(appId && appId === lineShows
? {}
: {
icon: appId ? (
<AppMark appId={appId} name={appName(appId)} />
) : (
<ServerStepIcon name={name} />
),
})}
label={label}
refused={refused}
failed={failed}
Expand Down Expand Up @@ -2671,6 +2693,21 @@ function TranscriptRenderersWatch({
);
}

/**
* How far a row of app steps is drawn up under one drawn like it, so the two sit as two steps of one
* list do, 8px apart: a "Worked for" line's rows are 12px apart, and an open list of steps keeps 4px
* above and below it, a call on a line of its own 6px.
*/
const JOINED = { list: "-mt-3", line: "-mt-4" } as const;

/**
* Whether a row with an app's steps is drawn as an open list of them or as one call's line: in a
* "Worked for" line, a run of them is a list, a lone one in a run included (`ToolRow`).
*/
function stepsShape(item: TranscriptItem): "list" | "line" {
return item.kind === "tools" ? "list" : "line";
}

export function ChatTranscript({
threadId,
busy = false,
Expand Down Expand Up @@ -2724,7 +2761,13 @@ export function ChatTranscript({
const waiting = useWaitingToolCalls(queryClient);
const folds = taskThread
? foldTurnWork(items, busy, waiting)
: foldTurnWork(items, busy || Boolean(stopped), waiting, "conversation");
: foldTurnWork(
items,
busy || Boolean(stopped),
waiting,
"conversation",
isDrawn.known,
);
// What the task read and made, for its Details pane beside the thread (`thread-work.ts`).
useEffect(() => {
if (taskThread && threadId)
Expand Down Expand Up @@ -2854,6 +2897,12 @@ export function ChatTranscript({
* says it is still working then, so the live line comes back under them until the Bot carries on.
*/
const reconnectingNow = busy && reconnecting;
/*
* A conversation turn's line says "Thinking" (or "Reconnecting…") itself while nothing has been
* said after its last step, in its own place under the person's message: not a second time below.
*/
const lastLine = [...folds.under.values()].at(-1);
const lineSaysIt = lastLine?.running === true && !lastLine.answered;

const viewportRef = useRef<HTMLDivElement | null>(null);
const newestUserMessageId =
Expand Down Expand Up @@ -3187,8 +3236,8 @@ export function ChatTranscript({
>
<ToolRow
active={busy && index === items.length - 1}
conversation={!taskThread}
expanded={expanded}
folds={item.kind === "tools"}
id={item.id}
inFlight={busy && index >= turnStart}
latest={index >= latestIndex}
Expand Down Expand Up @@ -3234,6 +3283,54 @@ export function ChatTranscript({
* inside that row.
*/
const rowGuard = readOnly ? READ_ONLY_ROW : LIVE_ROW;
/* The rows a turn's work holds, drawn inside its line as they would be on their own. */
const foldedRows = (work: TurnWork) => (
<LineShowsApp.Provider value={onlyApp(work.rows.map((row) => row.item))}>
{work.rows.map((row, at) => {
// App steps the Bot's words had split into rows of their own sit as one list: its
// words are drawn outside this line, and the gap they left says nothing in here. Only
// rows drawn alike: a call on a line of its own is a muted line, a list's steps aren't.
const above = work.rows[at - 1];
const shape = stepsShape(row.item);
// Only in a task's "Worked for" line: a conversation turn's line keeps one gap throughout.
const joins =
taskThread &&
above !== undefined &&
stepsShape(above.item) === shape &&
rowApps(above.item).last !== undefined &&
rowApps(row.item).first !== undefined;
const drawn = rowContent(row.item, row.index, !taskThread);
// What the Bot said on the way is muted in here: it is not the answer.
const muted = row.item.kind === "text";
return (
<Fragment key={row.item.id}>
{joins ? (
<div className={JOINED[shape]}>{drawn}</div>
) : muted && !taskThread ? (
<div className="text-muted-foreground [&_*]:text-inherit">
{drawn}
</div>
) : (
drawn
)}
</Fragment>
);
})}
</LineShowsApp.Provider>
);
/* A conversation turn's one line, drawn under the person's message from the moment they send. */
const turnLine = (work: TurnWork, opening: string) => (
<MessageScrollerItem
key={work.id}
messageId={work.id}
{...openingProps(opening)}
{...rowGuard}
>
<TurnLine busy={busy} reconnecting={reconnectingNow} work={work}>
{foldedRows(work)}
</TurnLine>
</MessageScrollerItem>
);
const renderRow = (item: TranscriptItem, index: number) => {
const work = taskWork.folds.at.get(item.id);
if (work)
Expand All @@ -3249,15 +3346,24 @@ export function ChatTranscript({
threadId={taskThread ? threadId : undefined}
work={work}
>
{work.rows.map((row) => (
<Fragment key={row.item.id}>
{rowContent(row.item, row.index, !taskThread)}
</Fragment>
))}
{foldedRows(work)}
</WorkedFor>
</MessageScrollerItem>
);
if (taskWork.folds.inside.has(item.id)) return null;
/*
* The person's message, and under it their turn's line: one fragment for every row, so the
* line arriving with the send (or a moment after it) never redraws the message above it.
*/
const line = taskWork.folds.under.get(item.id);
return (
<Fragment key={item.id}>
{ownRow(item, index)}
{line ? turnLine(line, line.rows[0]?.item.id ?? item.id) : null}
</Fragment>
);
};
const ownRow = (item: TranscriptItem, index: number) => {
// A refused turn's notice, under the last row of the person's message it answered.
const refusal = refusedUnder.get(item.id);
/*
Expand Down Expand Up @@ -3315,10 +3421,18 @@ export function ChatTranscript({
);
};

const hasConnector = visible.some(
(item) =>
item.kind === "tool" && item.toolCall.function.name.startsWith("mcp__"),
);
/*
* The apps' names and logos, looked up once an app's step is in the conversation, and from the
* moment a turn starts: its line names the app it is using ("Using Google Calendar…") the instant
* the step starts. Looked up only then, the line read "Using Googlecalendar…" beside a letter for
* a beat, and then changed to the name and logo.
*/
const hasConnector =
busy ||
visible.some(
(item) =>
item.kind === "tool" && item.toolCall.function.name.startsWith("mcp__"),
);
return (
<ArrivalsLive hasConnector={hasConnector}>
{hasActivities ? (
Expand Down Expand Up @@ -3436,7 +3550,8 @@ export function ChatTranscript({
reason={stopped}
/>
)
) : waitingOnTheModel || reconnectingNow ? (
) : (waitingOnTheModel || reconnectingNow) &&
!lineSaysIt ? (
<Thinking reconnecting={reconnectingNow} />
) : null}
{working}
Expand Down
12 changes: 9 additions & 3 deletions app/src/components/channels/subtask-step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
StepOutput,
StepRow,
stepDetails,
stepOpens,
} from "./tool-activity";

type ToolItem = Extract<VisibleChatItem, { kind: "tool" }>;
Expand Down Expand Up @@ -134,9 +135,14 @@ export function SubtaskStep({
{handedBack ? <HandedBack {...handedBack} /> : null}
{step.output ? <StepOutput output={step.output} /> : null}
{steps.length ? (
<ol className="space-y-2">
{foldRereads(steps).map((inner) => (
<StepRow active={running} key={inner.id} step={inner} />
<ol className="space-y-2 text-sm">
{foldRereads(steps).map((inner, _, rows) => (
<StepRow
active={running}
chevronRoom={rows.some(stepOpens)}
key={inner.id}
step={inner}
/>
))}
</ol>
) : null}
Expand Down
Loading
Loading