From b52573e9c30b304a1618a05bb27997ad38486f54 Mon Sep 17 00:00:00 2001 From: Hugo Richard Date: Tue, 17 Nov 2026 17:45:20 +0000 Subject: [PATCH 1/7] feat(nuxi): smooth chat streaming and compact tool activity --- app/assets/css/main.css | 15 ++ .../components/agent/AgentChatMessages.vue | 92 +++++-- .../components/agent/AgentChatSwitcher.vue | 25 +- .../app/components/agent/AgentIndicator.vue | 113 +------- .../nuxi/app/components/agent/AgentPanel.vue | 12 +- .../app/components/agent/AgentStreamText.vue | 61 +++++ .../nuxi/app/components/chat/ChatContent.vue | 252 +++--------------- .../components/chat/ChatMessageActions.vue | 119 +++++---- .../app/components/chat/ChatToolActivity.vue | 113 ++++++++ .../nuxi/app/components/chat/ChatToolCall.vue | 98 +++++++ .../app/components/chat/ChatToolDetails.vue | 110 ++++++++ layers/nuxi/app/composables/eve/adapter.ts | 8 +- layers/nuxi/app/composables/useChatTools.ts | 163 ++++++++--- layers/nuxi/app/composables/useNuxiIcon.ts | 14 +- .../nuxi/app/composables/useStreamedText.ts | 89 +++++++ .../nuxi/app/pages/dashboard/chat/index.vue | 4 +- layers/nuxi/app/utils/ai.ts | 4 +- nuxt.config.ts | 7 +- 18 files changed, 812 insertions(+), 487 deletions(-) create mode 100644 layers/nuxi/app/components/agent/AgentStreamText.vue create mode 100644 layers/nuxi/app/components/chat/ChatToolActivity.vue create mode 100644 layers/nuxi/app/components/chat/ChatToolCall.vue create mode 100644 layers/nuxi/app/components/chat/ChatToolDetails.vue create mode 100644 layers/nuxi/app/composables/useStreamedText.ts diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 43a756477..1c5d4ed2a 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -39,6 +39,21 @@ 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 0f06588ab..05567d10f 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 @@ -31,6 +33,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. @@ -56,6 +76,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 @@ -65,6 +86,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 @@ -72,7 +111,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 @@ -80,38 +119,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') } })