diff --git a/app/assets/css/main.css b/app/assets/css/main.css index bab3daeba..8a2ef6130 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -52,6 +52,21 @@ body { animation: none; } +::view-transition-group(nuxi-avatar), +::view-transition-group(nuxi-panel-avatar), +::view-transition-group(chat-prompt) { + animation-duration: 420ms; + animation-timing-function: var(--ease-snappy); +} + +@media (prefers-reduced-motion: reduce) { + ::view-transition-group(nuxi-avatar), + ::view-transition-group(nuxi-panel-avatar), + ::view-transition-group(chat-prompt) { + animation-duration: 0s; + } +} + .dark { --ui-bg: var(--ui-color-neutral-950); --ui-bg-muted: var(--ui-color-neutral-900); diff --git a/layers/nuxi/app/components/agent/AgentChatMessages.vue b/layers/nuxi/app/components/agent/AgentChatMessages.vue index 31220eeca..24af9720f 100644 --- a/layers/nuxi/app/components/agent/AgentChatMessages.vue +++ b/layers/nuxi/app/components/agent/AgentChatMessages.vue @@ -3,6 +3,8 @@ import type { UIMessage } from 'ai' import type { AgentChatHandle } from '../../composables/eve/types' import { isBetweenSteps, resolveChatDisplayState } from '../../composables/eve/adapter' +defineOptions({ inheritAttrs: false }) + const props = withDefaults(defineProps<{ chat: AgentChatHandle chatId: string @@ -34,6 +36,24 @@ const display = computed(() => resolveChatDisplayState(props.chat.messages, props.chat.status) ) +const revealingMessages = reactive(new Set()) +const liveMessages = reactive(new Set()) +watch([() => props.chat.messages.at(-1)?.id, () => props.chat.status], ([id, status], [previousId, previousStatus]) => { + if (id === previousId || ![status, previousStatus].some(value => value === 'submitted' || value === 'streaming')) return + const message = props.chat.messages.at(-1) + if (message?.role !== 'assistant') return + liveMessages.add(message.id) + if (message.parts.some(part => part.type === 'text' && part.text.length > 0)) revealingMessages.add(message.id) +}) +watch(() => props.chatId, () => { + liveMessages.clear() + revealingMessages.clear() +}) +function onMessagePending(id: string, pending: boolean) { + if (pending) revealingMessages.add(id) + else revealingMessages.delete(id) +} + /** * Mounted after a short delay, so the pause between the final text and the end of the turn * does not flash an indicator under every answer. @@ -59,6 +79,7 @@ onBeforeUnmount(() => clearTimeout(betweenStepsTimer)) function isAssistantPending(message: UIMessage): boolean { if (message.role !== 'assistant') return false + if (revealingMessages.has(message.id)) return true const { status, messages } = props.chat if (status !== 'submitted' && status !== 'streaming') return false @@ -68,6 +89,24 @@ function isAssistantPending(message: UIMessage): boolean { } const messagesRoot = useTemplateRef<{ $el: HTMLElement }>('messagesRoot') +const reducedMotion = usePreferredReducedMotion() +const avatarTransitionName = computed(() => props.compact ? 'nuxi-panel-avatar' : 'nuxi-avatar') +const showConversation = ref(!!display.value.displayMessages.length) + +// Capture only the welcome-to-conversation swap; streaming stays outside the transition. +watch(() => !!display.value.displayMessages.length, (hasMessages) => { + if (!props.compact || !props.showFaqEmpty || !import.meta.client || reducedMotion.value === 'reduce' || !document.startViewTransition) { + showConversation.value = hasMessages + return + } + + const transition = document.startViewTransition(async () => { + showConversation.value = hasMessages + await nextTick() + }) + void transition.ready.catch(() => {}) + onWatcherCleanup(() => transition.skipTransition()) +}) function scrollMessages(to: 'top' | 'bottom') { if (!display.value.displayMessages.length) return @@ -75,7 +114,7 @@ function scrollMessages(to: 'top' | 'bottom') { let node = messagesRoot.value?.$el while (node && node !== document.documentElement) { if (/auto|scroll/.test(getComputedStyle(node).overflowY)) { - node.scrollTo({ top: to === 'top' ? 0 : node.scrollHeight, behavior: 'smooth' }) + node.scrollTo({ top: to === 'top' ? 0 : node.scrollHeight, behavior: reducedMotion.value === 'reduce' ? 'instant' : 'smooth' }) return } node = node.parentElement @@ -83,38 +122,56 @@ function scrollMessages(to: 'top' | 'bottom') { } defineShortcuts({ - home: { usingInput: true, handler: () => scrollMessages('top') }, - end: { usingInput: true, handler: () => scrollMessages('bottom') } + home: { handler: () => scrollMessages('top') }, + end: { handler: () => scrollMessages('bottom') } })