Skip to content
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 9 additions & 14 deletions packages/app/src/app/components/session/message-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ function latestStepPart(partsGroups: Part[][]): Part | undefined {
const parts = partsGroups[groupIndex] ?? [];
for (let partIndex = parts.length - 1; partIndex >= 0; partIndex -= 1) {
const part = parts[partIndex];
if (
part.type === "tool" ||
part.type === "reasoning" ||
part.type === "step-start" ||
part.type === "step-finish"
) {
if (part.type === "tool" || part.type === "reasoning") {
return part;
}
}
Expand Down Expand Up @@ -187,7 +182,7 @@ export default function MessageList(props: MessageListProps) {
}

if (part.type === "step-start" || part.type === "step-finish") {
return props.developerMode;
return false;
}

if (part.type === "text" || part.type === "tool" || part.type === "agent" || part.type === "file") {
Expand Down Expand Up @@ -225,22 +220,22 @@ export default function MessageList(props: MessageListProps) {
const groupId = String((message.info as any).id ?? "message");
const groups = groupMessageParts(renderableParts, groupId);
const isUser = (message.info as any).role === "user";
const isStepsOnly = groups.length === 1 && groups[0].kind === "steps";
const isStepsOnly = groups.length > 0 && groups.every((group) => group.kind === "steps");
const stepGroups = isStepsOnly ? (groups as { kind: "steps"; id: string; parts: Part[] }[]) : [];
stepGroupCount += groups.reduce((count, group) => (group.kind === "steps" ? count + 1 : count), 0);

if (isStepsOnly) {
const stepGroup = groups[0] as { kind: "steps"; id: string; parts: Part[] };
const lastBlock = blocks[blocks.length - 1];
if (lastBlock && lastBlock.kind === "steps-cluster" && lastBlock.isUser === isUser) {
lastBlock.partsGroups.push(stepGroup.parts);
lastBlock.stepIds.push(stepGroup.id);
lastBlock.partsGroups.push(...stepGroups.map((group) => group.parts));
lastBlock.stepIds.push(...stepGroups.map((group) => group.id));
lastBlock.messageIds.push(messageId);
} else {
blocks.push({
kind: "steps-cluster",
id: stepGroup.id,
stepIds: [stepGroup.id],
partsGroups: [stepGroup.parts],
id: stepGroups[0].id,
stepIds: stepGroups.map((group) => group.id),
partsGroups: stepGroups.map((group) => group.parts),
messageIds: [messageId],
isUser,
});
Expand Down
25 changes: 21 additions & 4 deletions packages/app/src/app/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,47 +494,64 @@ export function lastUserModelFromMessages(list: MessageWithParts[]): ModelRef |
}

export function isStepPart(part: Part) {
return part.type === "reasoning" || part.type === "tool" || part.type === "step-start" || part.type === "step-finish";
return part.type === "reasoning" || part.type === "tool";
}

export function groupMessageParts(parts: Part[], messageId: string): MessageGroup[] {
const groups: MessageGroup[] = [];
const steps: Part[] = [];
let textBuffer = "";
let stepGroupIndex = 0;

const flushText = () => {
if (!textBuffer) return;
groups.push({ kind: "text", part: { type: "text", text: textBuffer } as Part });
textBuffer = "";
};

const flushSteps = () => {
if (!steps.length) return;
groups.push({ kind: "steps", id: `steps-${messageId}-${stepGroupIndex}`, parts: steps.splice(0, steps.length) });
stepGroupIndex += 1;
};

parts.forEach((part) => {
if (part.type === "text") {
flushSteps();
textBuffer += (part as { text?: string }).text ?? "";
return;
}

if (part.type === "agent") {
flushSteps();
const name = (part as { name?: string }).name ?? "";
textBuffer += name ? `@${name}` : "@agent";
return;
}

if (part.type === "file") {
flushSteps();
flushText();
groups.push({ kind: "text", part });
return;
}

if (part.type === "step-start" || part.type === "step-finish") {
return;
}

flushText();

if (part.type === "reasoning" && steps.length > 0) {
flushSteps();
}

steps.push(part);
});

flushText();

if (steps.length) {
groups.push({ kind: "steps", id: `steps-${messageId}`, parts: steps });
}
flushSteps();

return groups;
}
Expand Down
Loading