Open source file-system and knowledge based agent template. Build AI agents that stay up to date with your knowledge base
improve loader
Hugo Richarda20211836b39
diff --git a/apps/chat/app/components/ChatLoading.vue b/apps/chat/app/components/ChatLoading.vueindex c003dff..8d03051 100644--- a/apps/chat/app/components/ChatLoading.vue+++ b/apps/chat/app/components/ChatLoading.vue@@ -1,6 +1,17 @@<script setup lang="ts">+import { motion } from 'motion-v'++interface ToolCall {+ toolCallId: string+ toolName: string+ args: Record<string, unknown>+ state?: string+}+const props = defineProps<{text?: string+ toolCalls?: ToolCall[]+ isLoading?: boolean}>()const messages = [@@ -13,8 +24,15 @@ const messages = ['Almost there',]+const finishedMessage = 'Search complete'+const currentIndex = ref(0)-const targetText = computed(() => props.text || messages[currentIndex.value])+const targetText = computed(() => {+ if (!props.isLoading) {+ return finishedMessage+ }+ return props.text || messages[currentIndex.value]+})const displayedText = ref(targetText.value)const chars = 'abcdefghijklmnopqrstuvwxyz'@@ -34,9 +52,11 @@ function scrambleText(from: string, to: string) {if (i < charProgress - 2) {result += to[i] || ''- } else if (i < charProgress) {+ }+ else if (i < charProgress) {result += chars[Math.floor(Math.random() * chars.length)]- } else {+ }+ else {result += from[i] || ''}}@@ -45,7 +65,8 @@ function scrambleText(from: string, to: string) {if (frame < totalFrames) {requestAnimationFrame(animate)- } else {+ }+ else {displayedText.value = to}}@@ -53,59 +74,37 @@ function scrambleText(from: string, to: string) {requestAnimationFrame(animate)}-// Matrix animation-const gridSize = 3-const totalDots = gridSize * gridSize-const activeDots = ref<Set<number>>(new Set())-const animationIndex = ref(0)--// Different patterns for the matrix-const patterns = [- // Spin clockwise- [[0], [1], [2], [5], [8], [7], [6], [3]],- // Diagonal wave- [[0], [1, 3], [2, 4, 6], [5, 7], [8]],- // Center pulse- [[4], [1, 3, 5, 7], [0, 2, 6, 8], [1, 3, 5, 7], [4]],- // Corners then center- [[0, 2, 6, 8], [1, 3, 5, 7], [4]],- // Row by row- [[0, 1, 2], [3, 4, 5], [6, 7, 8]],- // Snake- [[0], [1], [2], [5], [4], [3], [6], [7], [8]],-]--let patternIndex = 0-let stepIndex = 0-let matrixInterval: ReturnType<typeof setInterval> | null = nulllet textInterval: ReturnType<typeof setInterval> | null = null-function nextStep() {- const pattern = patterns[patternIndex]- if (!pattern) return+watch(targetText, (newText, oldText) => {+ if (newText !== oldText && newText && oldText) {+ scrambleText(oldText, newText)+ }+})- activeDots.value = new Set(pattern[stepIndex])- stepIndex+++// Stop text rotation when loading finishes+watch(() => props.isLoading, (isLoading) => {+ if (!isLoading && textInterval) {+ clearInterval(textInterval)+ textInterval = null+ }+})- if (stepIndex >= pattern.length) {- stepIndex = 0- patternIndex = (patternIndex + 1) % patterns.length+function getToolLabel(toolName: string, args: Record<string, unknown>) {+ if (toolName === 'search_and_read') {+ return `Searching "${args?.query || '...'}"`}-}-watch(targetText, (newText, oldText) => {- if (newText !== oldText) {- scrambleText(oldText, newText)+ if (toolName === 'read') {+ return `Reading ${args?.path || '...'}`}-})-onMounted(() => {- // Matrix animation - faster- matrixInterval = setInterval(nextStep, 150)- nextStep()+ return toolName+}- // Text rotation- if (!props.text) {+onMounted(() => {+ // Text rotation only when loading+ if (!props.text && props.isLoading) {textInterval = setInterval(() => {currentIndex.value = (currentIndex.value + 1) % messages.length}, 3500)@@ -113,44 +112,51 @@ onMounted(() => {})onUnmounted(() => {- if (matrixInterval) clearInterval(matrixInterval)if (textInterval) clearInterval(textInterval)})</script><template>- <div class="flex items-center gap-3 text-sm text-muted">- <div class="matrix">- <span- v-for="i in totalDots"- :key="i"- class="matrix-dot"- :class="{ active: activeDots.has(i - 1) }"- />+ <div class="flex flex-col gap-2">+ <!-- Main loader with matrix and text -->+ <div class="flex items-center text-xs text-muted overflow-hidden">+ <motion.div+ v-if="isLoading"+ :initial="{ opacity: 1, width: 'auto' }"+ :exit="{ opacity: 0, width: 0 }"+ :transition="{ duration: 0.2 }"+ class="shrink-0 mr-2"+ >+ <ChatMatrix />+ </motion.div>+ <motion.span+ :animate="{ x: 0 }"+ :transition="{ duration: 0.2 }"+ class="font-mono tracking-tight"+ >+ {{ displayedText }}+ </motion.span>+ </div>++ <!-- Tool calls displayed below -->+ <div+ v-if="toolCalls?.length"+ class="flex flex-col gap-1"+ :class="isLoading ? 'pl-[22px]' : 'pl-0'"+ >+ <motion.div+ v-for="tool in toolCalls"+ :key="`${tool.toolCallId}-${JSON.stringify(tool.args)}`"+ :initial="{ opacity: 0, x: -4 }"+ :animate="{ opacity: 1, x: 0 }"+ :transition="{ duration: 0.15 }"+ class="flex items-center gap-1.5"+ >+ <span class="size-1 rounded-full bg-current opacity-40" />+ <span class="text-[11px] text-dimmed truncate max-w-[200px]">+ {{ getToolLabel(tool.toolName, tool.args) }}+ </span>+ </motion.div></div>- <span class="font-mono tracking-tight">{{ displayedText }}</span></div></template>--<style scoped>-.matrix {- display: grid;- grid-template-columns: repeat(3, 1fr);- gap: 3px;- width: 18px;- height: 18px;-}--.matrix-dot {- width: 4px;- height: 4px;- background-color: currentColor;- opacity: 0.2;- transition: opacity 0.1s ease, transform 0.1s ease;-}--.matrix-dot.active {- opacity: 1;- transform: scale(1.1);-}-</style>diff --git a/apps/chat/app/components/ChatMatrix.vue b/apps/chat/app/components/ChatMatrix.vuenew file mode 100644index 0000000..3d25609--- /dev/null+++ b/apps/chat/app/components/ChatMatrix.vue@@ -0,0 +1,92 @@+<script setup lang="ts">+interface Props {+ size?: number+ dotSize?: number+ gap?: number+}++const props = withDefaults(defineProps<Props>(), {+ size: 4,+ dotSize: 2,+ gap: 2,+})++const totalDots = computed(() => props.size * props.size)+const activeDots = ref<Set<number>>(new Set())++// Patterns for 4x4 grid (indices 0-15)+// Grid layout:+// 0 1 2 3+// 4 5 6 7+// 8 9 10 11+// 12 13 14 15+const patterns = [+ // Spiral inward+ [[0], [1], [2], [3], [7], [11], [15], [14], [13], [12], [8], [4], [5], [6], [10], [9]],+ // Wave horizontal+ [[0, 4, 8, 12], [1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15]],+ // Diamond pulse+ [[5, 6, 9, 10], [1, 4, 7, 8, 11, 14], [0, 3, 12, 15], [1, 4, 7, 8, 11, 14], [5, 6, 9, 10]],+ // Loading bar+ [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]],+ // Corners rotate+ [[0], [3], [15], [12]],+ // Cross pulse+ [[5, 6, 9, 10], [1, 2, 4, 7, 8, 11, 13, 14], [0, 3, 12, 15]],+ // Snake+ [[0], [1], [2], [3], [7], [6], [5], [4], [8], [9], [10], [11], [15], [14], [13], [12]],+ // Diagonal wave+ [[0], [1, 4], [2, 5, 8], [3, 6, 9, 12], [7, 10, 13], [11, 14], [15]],+]++let patternIndex = 0+let stepIndex = 0+let interval: ReturnType<typeof setInterval> | null = null++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 gridStyle = computed(() => ({+ display: 'grid',+ gridTemplateColumns: `repeat(${props.size}, 1fr)`,+ gap: `${props.gap}px`,+ width: `${props.size * props.dotSize + (props.size - 1) * props.gap}px`,+ height: `${props.size * props.dotSize + (props.size - 1) * props.gap}px`,+}))++const dotStyle = computed(() => ({+ width: `${props.dotSize}px`,+ height: `${props.dotSize}px`,+}))++onMounted(() => {+ interval = setInterval(nextStep, 120)+ nextStep()+})++onUnmounted(() => {+ if (interval) clearInterval(interval)+})+</script>++<template>+ <div :style="gridStyle">+ <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="dotStyle"+ />+ </div>+</template>diff --git a/apps/chat/app/components/ChatToolCall.vue b/apps/chat/app/components/ChatToolCall.vuenew file mode 100644index 0000000..3946cd3--- /dev/null+++ b/apps/chat/app/components/ChatToolCall.vue@@ -0,0 +1,63 @@+<script setup lang="ts">+import { motion } from 'motion-v'++const props = defineProps<{+ text: string+ isLoading?: boolean+ compact?: boolean+}>()++const dynamicSpread = computed(() => props.text.length * 2)+</script>++<template>+ <motion.div+ :initial="{ opacity: 0, y: 4 }"+ :animate="{ opacity: 1, y: 0 }"+ :transition="{ duration: 0.2 }"+ class="flex items-center rounded-lg bg-elevated/50 border border-default text-muted"+ :class="[+ compact ? 'gap-1.5 px-2 py-1 text-[10px]' : 'gap-2 px-2.5 py-1.5 text-xs',+ ]"+ >+ <UIcon+ :name="isLoading ? 'i-lucide-loader-circle' : 'i-lucide-file-text'"+ :class="[isLoading && 'animate-spin']"+ class="shrink-0 text-muted"+ :style="{ width: compact ? '12px' : '16px', height: compact ? '12px' : '16px' }"+ />+ <span+ class="truncate"+ :class="[+ isLoading && 'shimmer-text',+ ]"+ :style="isLoading ? {+ '--spread': `${dynamicSpread}px`,+ 'backgroundImage': 'var(--bg), linear-gradient(var(--color-neutral-600), var(--color-neutral-600))',+ } : undefined"+ >+ {{ text }}+ </span>+ </motion.div>+</template>++<style scoped>+.shimmer-text {+ --bg: linear-gradient(90deg, #0000 calc(50% - var(--spread)), var(--color-neutral-100), #0000 calc(50% + var(--spread)));+ background-size: 250% 100%, auto;+ background-clip: text;+ -webkit-background-clip: text;+ color: transparent;+ background-repeat: no-repeat, padding-box;+ animation: shimmer 2s linear infinite;+}++@keyframes shimmer {+ from {+ background-position: 100% center;+ }+ to {+ background-position: 0% center;+ }+}+</style>diff --git a/apps/chat/app/pages/chat/[id].vue b/apps/chat/app/pages/chat/[id].vueindex 0f3971b..4c39f53 100644--- a/apps/chat/app/pages/chat/[id].vue+++ b/apps/chat/app/pages/chat/[id].vue@@ -96,6 +96,34 @@ function copy(e: MouseEvent, message: UIMessage) {}, 2000)}+const lastMessage = computed(() => chat.messages.at(-1))+const showThinking = computed(() => {+ if (chat.status !== 'streaming') return false+ const msg = lastMessage.value+ if (msg?.role !== 'assistant') return false+ const parts = msg.parts as Array<{ type: string }> | undefined+ return !parts?.some(p => p.type === 'text')+})++interface ToolCallInfo {+ toolCallId: string+ toolName: string+ args: Record<string, unknown>+ state: string+}++function getMessageToolCalls(message: UIMessage): ToolCallInfo[] {+ if (!message?.parts) return []+ return (message.parts as Array<{ type: string, toolCallId?: string, toolName?: string, input?: Record<string, unknown>, state?: string }>)+ .filter(p => p.type === 'dynamic-tool')+ .map(p => ({+ toolCallId: p.toolCallId || '',+ toolName: p.toolName || '',+ args: p.input || {},+ state: p.state || ''+ }))+}+onMounted(() => {if (data.value?.messages.length === 1) {chat.regenerate()@@ -121,14 +149,21 @@ onMounted(() => {class="lg:pt-(--ui-header-height) pb-4 sm:pb-6"><template #indicator>- <ChatLoading />+ <ChatLoading :is-loading="true" /></template><template #content="{ message }"><ChatLoadingv-if="message.role === 'assistant' && chat.status === 'streaming' && !message.parts.some(p => p.type === 'text' && p.text)"+ :tool-calls="getMessageToolCalls(message)"+ :is-loading="true"+ />+ <ChatLoading+ v-else-if="message.role === 'assistant' && getMessageToolCalls(message).length > 0"+ :tool-calls="getMessageToolCalls(message)"+ :is-loading="false"/>- <template v-for="(part, index) in message.parts.filter(p => p.type !== 'data-sources')" :key="`${message.id}-${part.type}-${index}${'state' in part ? `-${part.state}` : ''}`">+ <template v-for="(part, index) in message.parts.filter(p => p.type !== 'data-sources' && p.type !== 'dynamic-tool')" :key="`${message.id}-${part.type}-${index}${'state' in part ? `-${part.state}` : ''}`"><Reasoningv-if="part.type === 'reasoning'":text="part.text"diff --git a/apps/chat/package.json b/apps/chat/package.jsonindex f3cf4f9..18263cd 100644--- a/apps/chat/package.json+++ b/apps/chat/package.json@@ -36,6 +36,7 @@"drizzle-orm": "^0.45.1","evlog": "^1.0.1","giget": "^3.1.1",+ "motion-v": "^1.10.2","nuxt": "^4.3.0","nuxt-auth-utils": "^0.5.28","pathe": "^2.0.3",diff --git a/apps/chat/server/api/chats/[id].post.ts b/apps/chat/server/api/chats/[id].post.tsindex 2a56400..8489188 100644--- a/apps/chat/server/api/chats/[id].post.ts+++ b/apps/chat/server/api/chats/[id].post.ts@@ -143,7 +143,6 @@ export default defineEventHandler(async (event) => {// Reset timer for next stepstepStartTime = Date.now()},-onFinish: (result) => {const totalDurationMs = stepDurations.reduce((a, b) => a + b, 0)requestLog.set({diff --git a/bun.lock b/bun.lockindex 920bff6..a2f1f47 100644--- a/bun.lock+++ b/bun.lock@@ -30,6 +30,7 @@"drizzle-orm": "^0.45.1","evlog": "^1.0.1","giget": "^3.1.1",+ "motion-v": "^1.10.2","nuxt": "^4.3.0","nuxt-auth-utils": "^0.5.28","pathe": "^2.0.3",