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
21 changes: 10 additions & 11 deletions apps/app/src/conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ export function Conversation(
) {
const transcript = useTranscript(channel.id, id);
const chat = transcript.info?.chats.find((value) => value.id === id);
const events = useMemo(() => toEvents(transcript.items, channel.id, transcript.busy), [
transcript.items,
channel.id,
transcript.busy,
]);
const model = chat?.model || channel.model;
const events = useMemo(
() =>
toEvents(transcript.items, channel.id, transcript.busy, {
text: transcript.draft,
model: model?.modelId,
}),
[transcript.items, channel.id, transcript.busy, transcript.draft, model],
);
const results = useMemo(
() =>
transcript.items.reduce(
Expand Down Expand Up @@ -69,18 +73,13 @@ export function Conversation(
{transcript.error && <Button onClick={transcript.retry}>Try again</Button>}
</div>
)}
{transcript.draft && (
<div className="utils:max-width pointer-events-none absolute inset-x-0 bottom-0 px-6 pb-2 text-sm whitespace-pre-wrap text-muted-foreground">
{transcript.draft}
</div>
)}
</div>
<div className="utils:max-width relative z-20 shrink-0 px-3 pb-3">
<Composer
channel={channel}
chat={id}
user={user}
current={chat?.model || channel.model}
current={model}
busy={transcript.busy}
ready={transcript.live && channel.state !== "archived"}
draft={draft}
Expand Down
26 changes: 23 additions & 3 deletions apps/app/src/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ function tool(tool: Tool, busy: boolean): Event.Message.Content.Tool {
};
}

/** Channel transcript items in the shape the original timeline renders. */
export function toEvents(items: Item[], topic: string, busy: boolean): Event[] {
return items.map((item) => {
/**
* Channel transcript items in the shape the original timeline renders. The streamed draft joins
* the timeline as the newest agent message so it is laid out and scrolled like the rest.
*/
export function toEvents(
items: Item[],
topic: string,
busy: boolean,
draft: { text: string; model?: string },
): Event[] {
const events = items.map((item) => {
const base = {
id: `${topic}::${item.key}`,
uid: item.key,
Expand Down Expand Up @@ -73,4 +81,16 @@ export function toEvents(items: Item[], topic: string, busy: boolean): Event[] {
content,
} as Event;
});
if (!draft.text) return events;
events.push({
id: `${topic}::draft`,
uid: "draft",
type: "message",
topic,
created_at: Math.floor(Date.now() / 1000),
sender: { kind: "agent", value: AGENT, display: draft.model || "Agent" },
content: [text(draft.text)],
streaming: true,
} as Event);
return events;
}