82 lines
3.3 KiB
Vue
82 lines
3.3 KiB
Vue
<script setup lang="ts">
|
|
import { collectCitationSources } from '~/utils/citations';
|
|
import type { SearchSource } from '~/utils/tool-rendering';
|
|
import Error from './Error.vue';
|
|
import Reasoning from './Reasoning.vue';
|
|
import Tool from './Tool/index.vue';
|
|
import type { MessageEntity } from '~/composables/useChat';
|
|
|
|
const props = defineProps<{
|
|
message: MessageEntity
|
|
}>();
|
|
|
|
const EMPTY_SOURCES: ReadonlyMap<string, SearchSource> = new Map();
|
|
|
|
// Citation markers are rare; avoid JSON-parsing every tool output when none exist.
|
|
const sources = computed(() => {
|
|
const parts = props.message.parts ?? [];
|
|
const hasCitations = parts.some(part => part.type === 'text' && part.content?.includes('[[cite:') === true);
|
|
return hasCitations ? collectCitationSources(parts) : EMPTY_SOURCES;
|
|
});
|
|
const triggerRef = ref<HTMLElement | null>(null);
|
|
|
|
const { open, close, isOpen } = useTokenDropdown();
|
|
|
|
const toggleTokenDropdown = () => {
|
|
if (isOpen.value) {
|
|
close();
|
|
return;
|
|
}
|
|
|
|
open(props.message.generation!, triggerRef.value!);
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex flex-col w-full gap-2">
|
|
<template v-for="part in message.parts" :key="part.id">
|
|
<template v-if="part.content?.trim() !== '' || part.toolCall">
|
|
<Reasoning v-if="part.type === 'reasoning'" :part="part"></Reasoning>
|
|
<MarkdownRenderer v-else-if="part.type === 'text'" :finished="part.finished" :id="part.id"
|
|
:content="part.content!" :sources="sources" :citations="true"></MarkdownRenderer>
|
|
<Tool v-else-if="part.type === 'tool-call'" :tool-call="part.toolCall!" :part="part"></Tool>
|
|
<div v-else>
|
|
Unhandled part type: {{ part.type }} {{ part }}
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
<span class="flex items-center gap-1"
|
|
v-if="message.generation?.status === 'pending' && (message.parts || []).length === 0">
|
|
<span class="i-svg-spinners-pulse-2 text-4"></span>
|
|
<span class="text-sm text-[var(--text-secondary)]">
|
|
Preparing Generation...
|
|
</span>
|
|
</span>
|
|
|
|
<div v-else-if="message.generation?.status === 'failed'">
|
|
<Error :error="message.generation.error" />
|
|
</div>
|
|
|
|
<div class="flex flex-row justify-between text-[var(--text-tertiary)] text-xs"
|
|
v-if="message.generation && message.generation.status !== 'pending'">
|
|
<div class="flex items-center gap-1">
|
|
<ModelIcon :size="12" :model-id="message.generation.modelId" />
|
|
{{ message.generation.modelId }}
|
|
</div>
|
|
|
|
<button ref="triggerRef" @click="toggleTokenDropdown"
|
|
class="flex gap-2 @hover:bg-[var(--color-hover)] px-1 rounded transition-colors duration-150 ease-[cubic-bezier(0.5,_1,_0.89,_1)]">
|
|
<span class="flex gap-1 items-center" v-if="message.generation.tokens?.output">
|
|
<span class="i-tabler-coins"></span>
|
|
{{ message.generation?.tokens?.output }}
|
|
</span>
|
|
|
|
<span v-if="message.generation.tokens?.tps">
|
|
{{ message.generation.tokens.tps.toFixed(1) }} tps
|
|
</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</template>
|