85 lines
3.1 KiB
Vue
85 lines
3.1 KiB
Vue
<script setup lang="ts">
|
|
import { computed } from "vue";
|
|
|
|
import { Bubble, BubbleContent } from "@/components/ui/bubble";
|
|
import { Trace } from "@/components/ui/trace";
|
|
import { CodeBlockCopyButton } from "@/components/ui/code-block";
|
|
import { Message, MessageContent, MessageFooter } from "@/components/ui/message";
|
|
import ChatAttachment from "./ChatAttachment.vue";
|
|
import ChatMarkdown from "./ChatMarkdown.vue";
|
|
import ChatToolCall from "./ChatToolCall.vue";
|
|
import ChatToolGroup from "./ChatToolGroup.vue";
|
|
import type { ChatMedia, ChatToolCall as ToolCall } from "./state";
|
|
|
|
/**
|
|
* One message, from either side of the conversation. There is no speaker
|
|
* label: which side of the panel it sits on, and its fill, are what say who is
|
|
* talking. A trailing action arrives through the slot, so the retry the
|
|
* transcript offers belongs to the bubble rather than beside it. A finished
|
|
* reply carries a copy action beneath it.
|
|
*/
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
text: string;
|
|
tools?: ToolCall[];
|
|
/** Attachments the message carried, which have no bytes left to render. */
|
|
media?: ChatMedia[];
|
|
assistant?: boolean;
|
|
/** The turn is still arriving: a tool call with no outcome is running. */
|
|
streaming?: boolean;
|
|
}>(),
|
|
{ tools: () => [], media: () => [], assistant: false, streaming: false },
|
|
);
|
|
|
|
// Consecutive calls fold into one counted line. A navigation chip is an
|
|
// action for the operator, so it always stands alone and ends the run.
|
|
const runs = computed(() => {
|
|
const out: ToolCall[][] = [];
|
|
let open = false;
|
|
for (const tool of props.tools) {
|
|
if (tool.path) {
|
|
out.push([tool]);
|
|
open = false;
|
|
} else if (open) out[out.length - 1].push(tool);
|
|
else {
|
|
out.push([tool]);
|
|
open = true;
|
|
}
|
|
}
|
|
return out;
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<Message :align="assistant ? 'start' : 'end'">
|
|
<MessageContent>
|
|
<Bubble :variant="assistant ? 'muted' : 'tinted'" class="max-w-[min(78ch,92%)]">
|
|
<BubbleContent class="[overflow-wrap:anywhere]">
|
|
<Trace v-if="assistant && tools.length" class="mb-2">
|
|
<template v-for="(run, i) in runs" :key="i">
|
|
<ChatToolGroup v-if="run.length > 1" :tools="run" :streaming="streaming" />
|
|
<ChatToolCall v-else :tool="run[0]" :streaming="streaming" />
|
|
</template>
|
|
</Trace>
|
|
<div v-if="media.length" class="mb-2 flex flex-wrap gap-1.5">
|
|
<ChatAttachment
|
|
v-for="(attachment, i) in media"
|
|
:key="i"
|
|
:attachment="attachment"
|
|
/>
|
|
</div>
|
|
<ChatMarkdown v-if="assistant" :text="text" />
|
|
<div v-else class="whitespace-pre-wrap">{{ text }}</div>
|
|
<slot />
|
|
</BubbleContent>
|
|
</Bubble>
|
|
<MessageFooter
|
|
v-if="assistant && !streaming && text"
|
|
class="px-0 transition-opacity focus-within:opacity-100 [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover/message:opacity-100"
|
|
>
|
|
<CodeBlockCopyButton :value="text" />
|
|
</MessageFooter>
|
|
</MessageContent>
|
|
</Message>
|
|
</template>
|