Skip to content
15 changes: 15 additions & 0 deletions app/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
92 changes: 76 additions & 16 deletions layers/nuxi/app/components/agent/AgentChatMessages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,6 +36,24 @@ const display = computed(() =>
resolveChatDisplayState(props.chat.messages, props.chat.status)
)

const revealingMessages = reactive(new Set<string>())
const liveMessages = reactive(new Set<string>())
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.
Expand All @@ -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
Expand All @@ -68,53 +89,89 @@ 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

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
}
}

defineShortcuts({
home: { usingInput: true, handler: () => scrollMessages('top') },
end: { usingInput: true, handler: () => scrollMessages('bottom') }
home: { handler: () => scrollMessages('top') },
end: { handler: () => scrollMessages('bottom') }
})
</script>

<template>
<UTheme :ui="AGENT_CHAT_THEME">
<UChatMessages
v-if="display.displayMessages.length"
v-if="showConversation"
ref="messagesRoot"
v-bind="$attrs"
should-auto-scroll
:messages="display.displayMessages"
:status="display.displayStatus"
:status="chat.status === 'ready' && revealingMessages.size ? 'streaming' : display.displayStatus"
:compact="compact"
:spacing-offset="spacingOffset"
:class="compact ? 'gap-2 px-0' : 'flex-1 pt-4 pb-4 sm:pb-6'"
:user="{ ui: compact ? AGENT_USER_MESSAGE_UI_COMPACT : AGENT_USER_MESSAGE_UI }"
:assistant="{ ui: { body: 'flex-1', actions: 'has-data-[state=open]:opacity-100' } }"
:ui="compact ? undefined : { root: '[&>article]:last-of-type:min-h-0' }"
:assistant="{ ui: { body: 'flex-1', content: '[text-wrap:wrap]', actions: 'ps-10 has-data-[state=open]:opacity-100 focus-within:opacity-100' } }"
:ui="{ root: '[overflow-anchor:none]' }"
>
<template #indicator>
<AgentIndicator />
<AgentIndicator avatar :avatar-transition-name="avatarTransitionName" />
</template>

<template #content="{ message }">
<ChatContent :message="message" />
<Transition
enter-from-class="opacity-0"
enter-active-class="transition-opacity duration-200"
>
<AgentIndicator v-if="message.id === betweenStepsMessageId" class="mt-2" />
</Transition>
<div v-if="message.role === 'assistant'" class="flex items-start gap-3">
<span
class="sticky top-4 grid size-7 shrink-0 self-start place-items-center"
:style="display.displayStatus !== 'submitted' && message.id === chat.messages.at(-1)?.id ? { viewTransitionName: avatarTransitionName } : undefined"
aria-hidden="true"
>
<AgentNuxiIcon
:mood="isAssistantPending(message) ? 'thinking' : 'happy'"
:interactive="false"
class="h-6 w-7 text-default"
:class="!isAssistantPending(message) && '[&_.nuxi-body]:animate-none'"
/>
</span>
<div class="flex min-w-0 flex-1 flex-col gap-3">
<ChatContent
:message="message"
:animate="liveMessages.has(message.id)"
:preparing="message.id === betweenStepsMessageId && !revealingMessages.has(message.id)"
:streaming="(chat.status === 'submitted' || chat.status === 'streaming') && message.id === chat.messages.at(-1)?.id"
@pending="onMessagePending(message.id, $event)"
/>
</div>
</div>
<ChatContent v-else :message="message" />
</template>

<template v-if="showActions" #actions="{ message }">
Expand All @@ -138,9 +195,12 @@ defineShortcuts({
</template>
</UChatMessages>

<div v-else-if="showFaqEmpty" class="flex flex-col">
<div v-else-if="showFaqEmpty" v-bind="$attrs" class="flex flex-col">
<div class="relative h-48 overflow-hidden rounded-lg mx-1">
<LazyAgentShader />
<span class="absolute bottom-4 left-1/2 grid size-12 -translate-x-1/2 place-items-center" :style="{ viewTransitionName: avatarTransitionName }" aria-hidden="true">
<AgentNuxiIcon class="size-full text-default" />
</span>
</div>

<div class="flex flex-col gap-6 mt-6">
Expand Down
17 changes: 2 additions & 15 deletions layers/nuxi/app/components/agent/AgentChatSwitcher.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
const { isOpen, nuxiMood } = useNuxtAgent()
const { isOpen } = useNuxtAgent()
const { chatList } = useChats()

const panel = inject<{
Expand Down Expand Up @@ -42,11 +42,6 @@ watch(popoverOpen, (open) => {
v-if="!hasChatHistory"
class="inline-flex items-center gap-2 min-w-0"
>
<Transition appear enter-from-class="opacity-0 scale-50 blur-xs" enter-active-class="transition-[opacity,scale,filter] duration-300 delay-100 ease-out motion-reduce:transition-none">
<span class="inline-flex">
<AgentNuxiIcon class="size-5 shrink-0" :mood="nuxiMood" />
</span>
</Transition>
<span class="truncate">Nuxi</span>
<UBadge variant="subtle" size="sm" class="shrink-0">
Beta
Expand All @@ -66,15 +61,7 @@ watch(popoverOpen, (open) => {
variant="ghost"
class="font-medium max-w-44"
:ui="{ label: 'truncate min-w-0' }"
>
<template #leading>
<Transition appear enter-from-class="opacity-0 scale-50 blur-xs" enter-active-class="transition-[opacity,scale,filter] duration-300 delay-100 ease-out motion-reduce:transition-none">
<span class="inline-flex">
<AgentNuxiIcon class="size-5 shrink-0" :mood="nuxiMood" />
</span>
</Transition>
</template>
</UButton>
/>

<template #content>
<div class="p-1.5 border-b border-default">
Expand Down
113 changes: 6 additions & 107 deletions layers/nuxi/app/components/agent/AgentIndicator.vue
Original file line number Diff line number Diff line change
@@ -1,113 +1,12 @@
<script setup lang="ts">
const size = 4
const dotSize = 2
const gap = 2
const totalDots = size * size

const patterns = [
[[0], [1], [2], [3], [7], [11], [15], [14], [13], [12], [8], [4], [5], [6], [10], [9]],
[[0, 4, 8, 12], [1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15]],
[[5, 6, 9, 10], [1, 4, 7, 8, 11, 14], [0, 3, 12, 15], [1, 4, 7, 8, 11, 14], [5, 6, 9, 10]],
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]],
[[0], [3], [15], [12]],
[[5, 6, 9, 10], [1, 2, 4, 7, 8, 11, 13, 14], [0, 3, 12, 15]],
[[0], [1], [2], [3], [7], [6], [5], [4], [8], [9], [10], [11], [15], [14], [13], [12]],
[[0], [1, 4], [2, 5, 8], [3, 6, 9, 12], [7, 10, 13], [11, 14], [15]]
]

const activeDots = ref<Set<number>>(new Set())
let patternIndex = 0
let stepIndex = 0

function nextStep() {
const pattern = patterns[patternIndex]
if (!pattern) return

activeDots.value = new Set(pattern[stepIndex])
stepIndex++

if (stepIndex >= pattern.length) {
stepIndex = 0
patternIndex = (patternIndex + 1) % patterns.length
}
}

const statusMessages = ['Thinking...', 'Searching...', 'Reading...', 'Analyzing...']
const currentIndex = ref(0)
const displayedText = ref(statusMessages[0]!)
const chars = 'abcdefghijklmnopqrstuvwxyz'

function scramble(from: string, to: string) {
const maxLength = Math.max(from.length, to.length)
let frame = 0
const totalFrames = 15

const step = () => {
frame++
let result = ''
const progress = (frame / totalFrames) * maxLength

for (let i = 0; i < maxLength; i++) {
if (i < progress - 2) {
result += to[i] || ''
} else if (i < progress) {
result += chars[Math.floor(Math.random() * chars.length)]
} else {
result += from[i] || ''
}
}

displayedText.value = result

if (frame < totalFrames) {
requestAnimationFrame(step)
} else {
displayedText.value = to
}
}

requestAnimationFrame(step)
}

let matrixInterval: ReturnType<typeof setInterval> | undefined
let textInterval: ReturnType<typeof setInterval> | undefined

onMounted(() => {
nextStep()
matrixInterval = setInterval(nextStep, 120)
textInterval = setInterval(() => {
const prev = displayedText.value
currentIndex.value = (currentIndex.value + 1) % statusMessages.length
scramble(prev, statusMessages[currentIndex.value]!)
}, 3500)
})

onUnmounted(() => {
clearInterval(matrixInterval)
clearInterval(textInterval)
})
withDefaults(defineProps<{ text?: string, avatar?: boolean, avatarTransitionName?: string }>(), { text: 'Thinking', avatar: false })
</script>

<template>
<div class="flex items-center text-sm text-muted overflow-hidden">
<div
class="shrink-0 mr-2 grid"
:style="{
gridTemplateColumns: `repeat(${size}, 1fr)`,
gap: `${gap}px`,
width: `${size * dotSize + (size - 1) * gap}px`,
height: `${size * dotSize + (size - 1) * gap}px`
}"
>
<span
v-for="i in totalDots"
:key="i"
class="rounded-[0.5px] bg-current transition-opacity duration-100"
:class="activeDots.has(i - 1) ? 'opacity-100' : 'opacity-20'"
:style="{ width: `${dotSize}px`, height: `${dotSize}px` }"
/>
</div>

<UChatShimmer :text="displayedText" />
<div class="flex min-h-7 items-center gap-3 text-sm text-muted" role="status">
<span v-if="avatar" class="grid size-7 shrink-0 place-items-center" :style="avatarTransitionName ? { viewTransitionName: avatarTransitionName } : undefined" aria-hidden="true">
<AgentNuxiIcon mood="thinking" :interactive="false" class="h-6 w-7 text-default" />
</span>
<UChatShimmer :text="text" />
</div>
</template>
25 changes: 16 additions & 9 deletions layers/nuxi/app/components/agent/AgentPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const {
isAgentDockedBreakpoint,
currentPage,
pageContextDismissed,
pendingPrompt,
nuxiMood
pendingPrompt
} = useNuxtAgent()
const { chatList } = useChats()
const { loggedIn } = useUserSession()
Expand All @@ -18,10 +17,23 @@ const active = shallowRef<ActiveChat>({ id: crypto.randomUUID(), messages: [] })
const chatId = computed(() => active.value.id)
const initialMessages = computed(() => active.value.messages)
let loadToken = 0
const reducedMotion = usePreferredReducedMotion()

function startNewChat() {
loadToken++
active.value = { id: crypto.randomUUID(), messages: [] }
const token = ++loadToken
const reset = async () => {
if (token !== loadToken) return
active.value = { id: crypto.randomUUID(), messages: [] }
Comment thread
HugoRCD marked this conversation as resolved.
Resolved
await nextTick()
}

// The keyed chat is replaced on reset, so capture its avatar before unmounting it.
if (import.meta.client && isOpen.value && !pendingPrompt.value && reducedMotion.value !== 'reduce' && document.startViewTransition) {
const transition = document.startViewTransition(reset)
void transition.ready.catch(() => {})
} else {
void reset()
}
}

async function setActiveChat(id: string) {
Expand Down Expand Up @@ -103,11 +115,6 @@ defineShortcuts(computed(() => ({
<template #title>
<AgentChatSwitcher v-if="loggedIn" class="min-w-0" />
<span v-else class="inline-flex items-center gap-2 min-w-0">
<Transition appear enter-from-class="opacity-0 scale-50 blur-xs" enter-active-class="transition-[opacity,scale,filter] duration-300 delay-100 ease-out motion-reduce:transition-none">
<span class="inline-flex">
<AgentNuxiIcon class="size-5 shrink-0" :mood="nuxiMood" />
</span>
</Transition>
<span class="truncate">Nuxi</span>
<UBadge variant="subtle" size="sm" class="shrink-0">
Beta
Expand Down
Loading
Loading