fix(ui): anchor each question in the chat transcript and keep the live reply as the row its message takes
This commit is contained in:
1 parent
0a914d66df
commit
b2ddfafcf8
3 files changed
+84
-74
No files matched your search
@@ -35,10 +35,11 @@ import {
|
||||
*/
|
||||
const emit = defineEmits<{ prompt: [text: string] }>();
|
||||
|
||||
function parts(message: ChatMessage) {
|
||||
function parts(message: ChatMessage, index: number) {
|
||||
const from = message.from ?? message.From ?? "";
|
||||
// Anything this browser's composer did not send is Archie's answer.
|
||||
return {
|
||||
id: message.message_id || message.MessageID || `m${index}`,
|
||||
text: message.text ?? message.Text ?? "",
|
||||
tools: message.tool_calls || message.ToolCalls || [],
|
||||
// Attachments have no bytes left to render -- the record kept their
|
||||
@@ -51,10 +52,30 @@ function parts(message: ChatMessage) {
|
||||
}
|
||||
|
||||
const bubbles = computed(() => messages.value.map(parts));
|
||||
|
||||
// The live turn is the row the finished message will take, under the same id:
|
||||
// the scroller sees one row grow and settle, not one leave and another arrive.
|
||||
const rows = computed(() => {
|
||||
const turn = streamingTurn.value;
|
||||
if (!turn) return bubbles.value.map((bubble) => ({ ...bubble, live: false }));
|
||||
return [
|
||||
...bubbles.value.map((bubble) => ({ ...bubble, live: false })),
|
||||
{
|
||||
id: `m${bubbles.value.length}`,
|
||||
text: turn.text || "…",
|
||||
tools: turn.tools,
|
||||
media: [],
|
||||
assistant: true,
|
||||
update: undefined,
|
||||
choose: undefined,
|
||||
live: true,
|
||||
},
|
||||
];
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<MessageScrollerProvider auto-scroll default-scroll-position="end">
|
||||
<MessageScrollerProvider auto-scroll default-scroll-position="last-anchor">
|
||||
<MessageScroller class="min-h-0 flex-1">
|
||||
<MessageScrollerViewport>
|
||||
<MessageScrollerContent class="gap-4 p-4">
|
||||
@@ -71,43 +92,32 @@ const bubbles = computed(() => messages.value.map(parts));
|
||||
|
||||
<template v-else>
|
||||
<MessageScrollerItem
|
||||
v-for="(bubble, i) in bubbles"
|
||||
:key="i"
|
||||
:message-id="`m${i}`"
|
||||
v-for="row in rows"
|
||||
:key="row.id"
|
||||
:message-id="row.id"
|
||||
:scroll-anchor="!row.assistant"
|
||||
>
|
||||
<ChatBubble
|
||||
:text="bubble.text"
|
||||
:tools="bubble.tools"
|
||||
:media="bubble.media"
|
||||
:assistant="bubble.assistant"
|
||||
:text="row.text"
|
||||
:tools="row.tools"
|
||||
:media="row.media"
|
||||
:assistant="row.assistant"
|
||||
:streaming="row.live"
|
||||
>
|
||||
<ChatUpdateCard v-if="bubble.update" :update="bubble.update" />
|
||||
<ChatChooseCard v-if="bubble.choose" :choose="bubble.choose" />
|
||||
</ChatBubble>
|
||||
</MessageScrollerItem>
|
||||
|
||||
<!-- The live turn is a bubble like any other, so what arrives is
|
||||
rendered by the same rules as what was already there. It is the
|
||||
scroll anchor while it streams. -->
|
||||
<MessageScrollerItem
|
||||
v-if="streamingTurn"
|
||||
message-id="streaming"
|
||||
scroll-anchor
|
||||
>
|
||||
<ChatBubble
|
||||
:text="streamingTurn.text || '…'"
|
||||
:tools="streamingTurn.tools"
|
||||
assistant
|
||||
streaming
|
||||
>
|
||||
<Button
|
||||
v-if="streamingTurn.isError && streamingTurn.turn"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="mt-2"
|
||||
@click="sendMessage({ turn: streamingTurn.turn })"
|
||||
>Retry</Button>
|
||||
<ChatAskCard v-if="streamingTurn.ask" :ask="streamingTurn.ask" />
|
||||
<template v-if="row.live && streamingTurn">
|
||||
<Button
|
||||
v-if="streamingTurn.isError && streamingTurn.turn"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="mt-2"
|
||||
@click="sendMessage({ turn: streamingTurn.turn })"
|
||||
>Retry</Button>
|
||||
<ChatAskCard v-if="streamingTurn.ask" :ask="streamingTurn.ask" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<ChatUpdateCard v-if="row.update" :update="row.update" />
|
||||
<ChatChooseCard v-if="row.choose" :choose="row.choose" />
|
||||
</template>
|
||||
</ChatBubble>
|
||||
</MessageScrollerItem>
|
||||
</template>
|
||||
|
||||
Reference in new issue
Block a user