Agent Activity
Streaming Text
AgentActivity.vue<script setup lang="ts">
import { AgentActivity, type ActivityItem } from 'beui-vue'
import { computed, onBeforeUnmount, onMounted, shallowRef, watch, ref } from 'vue'
function useAgentVariant(selected: () => string | undefined, choices: Record<string,string>) {
const pinned = undefined as string | undefined
const fixed = Boolean(pinned)
const query = ref('')
const options = Object.keys(choices)
const variant = computed(() => {
const requested = pinned || selected() || query.value
return options.find(slug => requested === slug || requested === choices[slug]) ?? options[0]
})
function refresh() {
query.value = new URL(location.href).searchParams.get('variant') ?? ''
}
function choose(slug:string) {
if (fixed || !options.includes(slug)) return
const url = new URL(location.href)
url.searchParams.set('variant',slug)
history.replaceState(history.state,'',url)
refresh()
}
onMounted(() => {
if (fixed) return
refresh()
window.addEventListener('popstate',refresh)
})
onBeforeUnmount(() => window.removeEventListener('popstate',refresh))
return { variant, choose, options, fixed }
}
const props = defineProps<{ variant?: string }>()
const { variant, choose, options, fixed } = useAgentVariant(() => props.variant, {
'streaming-text': 'agents/agent-activity-text', 'reasoning-steps': 'agents/agent-activity-steps', 'web-search': 'agents/agent-activity-search',
'tool-calls': 'agents/agent-activity-tools', 'mixed-activity': 'agents/agent-activity-mixed', 'agent-trace': 'agents/agent-trace',
})
const REASONING = [
'Reading the request and separating the content model from its presentation.',
'The activity shell can stay consistent while each event supplies its own compact renderer.',
'Text remains freeform so partial tokens can update without recreating the surrounding timeline.',
'As each sentence wraps, the measured stream moves upward through a single transform instead of repeatedly jumping the native scroll position.',
'Older context stays available above the fold while the newest tokens remain crisp at the bottom edge.',
'Once the run finishes, the viewport switches from automatic following to ordinary user-controlled scrolling.',
'Opening the completed disclosure returns to the beginning so the reasoning can be read in order.',
'The capped viewport follows the latest sentence and preserves the full log after completion.',
].join('\n')
const CHARACTERS_PER_SECOND = 90
const STEPS = [
{ id: 'brief', label: 'Reading the product brief' },
{ id: 'patterns', label: 'Mapping the interaction patterns' },
{ id: 'states', label: 'Connecting the loading and completion states', meta: '3 states' },
{ id: 'verify', label: 'Verifying the final behavior' },
]
const SEARCH_RESULTS = [
{ id: 'google', title: 'Google for Developers', domain: 'developers.google.com' },
{ id: 'github', title: 'GitHub', domain: 'github.com' },
{ id: 'wikipedia', title: 'Wikipedia', domain: 'wikipedia.org' },
{ id: 'vercel', title: 'Vercel Docs', domain: 'vercel.com/docs' },
]
const MARKS: Record<string, string[]> = {
google: ['M21.35 12.23c0-.65-.06-1.28-.17-1.89H12v3.79h5.25a4.5 4.5 0 0 1-1.95 2.87v2.46h3.16c1.85-1.71 2.89-4.22 2.89-7.23Z', 'M12 21.75c2.64 0 4.86-.87 6.46-2.29L15.3 17c-.87.58-1.98.92-3.3.92a5.7 5.7 0 0 1-5.35-3.93H3.39v2.54A9.75 9.75 0 0 0 12 21.75Z', 'M6.65 13.99A5.85 5.85 0 0 1 6.34 12c0-.69.12-1.36.31-1.99V7.47H3.39A9.76 9.76 0 0 0 2.25 12c0 1.63.39 3.18 1.14 4.53l3.26-2.54Z', 'M12 6.08c1.44 0 2.73.49 3.75 1.47l2.78-2.78A9.34 9.34 0 0 0 12 2.25a9.75 9.75 0 0 0-8.61 5.22l3.26 2.54A5.7 5.7 0 0 1 12 6.08Z'],
github: ['M12 2a10 10 0 0 0-3.16 19.49c.5.09.68-.22.68-.48v-1.87c-2.78.6-3.37-1.18-3.37-1.18-.45-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.61.07-.61 1 .07 1.53 1.03 1.53 1.03.9 1.53 2.35 1.09 2.92.83.09-.65.35-1.09.64-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.98 1.03-2.68-.1-.25-.45-1.27.1-2.64 0 0 .84-.27 2.75 1.02A9.58 9.58 0 0 1 12 6.82c.85 0 1.71.11 2.51.34 1.91-1.29 2.75-1.02 2.75-1.02.55 1.37.2 2.39.1 2.64.64.7 1.03 1.59 1.03 2.68 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85v2.77c0 .27.18.58.69.48A10 10 0 0 0 12 2Z'],
wikipedia: ['M1.5 4h6v1.2H6l4.08 10.73 1.26-3.12L8.45 5.2H7.2V4h6v1.2h-1.47l1.66 4.57 1.82-4.57H13.8V4h4.9v1.2h-1.45l-3.19 7.92 1.08 2.81L19.48 5.2H18V4h4.5v1.2h-1.42L15.25 20h-1.2l-1.91-4.86L10.18 20H8.92L3.25 5.2H1.5V4Z'],
vercel: ['m12 3 10 18H2L12 3Z'],
}
const TOOLS: ActivityItem[] = [
{ id: 'read', type: 'tool', action: 'read', target: 'campaign-notes.md' },
{ id: 'edit', type: 'tool', action: 'edit', target: 'launch-plan.ts', additions: 42, deletions: 8 },
{ id: 'run', type: 'tool', action: 'run', target: 'bun test launch' },
]
const ACTIVE_BRIEF: ActivityItem = { id: 'brief', type: 'step', label: 'Reading the launch brief', status: 'active' }
const COMPLETE_BRIEF: ActivityItem = { ...ACTIVE_BRIEF, status: 'complete' }
const PENDING_SEARCH: ActivityItem = { id: 'search', type: 'search', query: 'independent coffee roasters in Portland', results: [] }
const COMPLETE_SEARCH: ActivityItem = {
...PENDING_SEARCH,
results: [
{ id: 'heart', title: 'Heart Coffee', domain: 'heartroasters.com' },
{ id: 'coava', title: 'Coava Coffee', domain: 'coavacoffee.com' },
{ id: 'upper-left', title: 'Upper Left Roasters', domain: 'upperleftroasters.com' },
],
moreCount: 5,
}
const MIXED_FRAMES: ActivityItem[][] = [
[ACTIVE_BRIEF],
[COMPLETE_BRIEF, PENDING_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0]],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0], TOOLS[1], TOOLS[2], { id: 'verify', type: 'step', label: 'Checking the final campaign plan', status: 'complete' }],
]
const TRACE_ITEMS: ActivityItem[] = [
{ id: 'plan', type: 'trace', kind: 'thinking', label: 'Thinking', detail: 'Mapping the interaction flow…' },
{ id: 'decision', type: 'trace', kind: 'message', label: 'Decision', detail: 'Use one compact disclosure' },
{ id: 'write', type: 'trace', kind: 'write', label: 'Draft component', detail: 'components/agents/run-log.tsx' },
{ id: 'verify', type: 'trace', kind: 'run', label: 'Validate types', detail: 'bun run typecheck' },
{ id: 'inspect', type: 'trace', kind: 'read', label: 'Inspect preview', detail: 'activity-preview.png' },
]
const LAYOUT: Record<string, { height: number, width: string }> = {
'streaming-text': { height: 330, width: '32rem' }, 'reasoning-steps': { height: 330, width: '32rem' }, 'web-search': { height: 330, width: '32rem' },
'tool-calls': { height: 330, width: '32rem' }, 'mixed-activity': { height: 330, width: '36rem' }, 'agent-trace': { height: 300, width: '36rem' },
}
const run = shallowRef(0)
const reduce = shallowRef(false)
const mounted = shallowRef(false)
const items = shallowRef<ActivityItem[]>([])
const complete = shallowRef(false)
const settings = computed(() => ({
'streaming-text': { contentType: 'text', maxHeight: 180, duration: REASONING.length / CHARACTERS_PER_SECOND },
'reasoning-steps': { contentType: 'step', maxHeight: 220, duration: 4.2 },
'web-search': { contentType: 'search', maxHeight: 220, duration: 0 },
'tool-calls': { contentType: 'tool', maxHeight: 220, duration: 0 },
'mixed-activity': { contentType: undefined, maxHeight: 220, duration: 5.1 },
'agent-trace': { contentType: 'trace', maxHeight: 190, duration: 0 },
} as const)[variant.value as 'agent-trace'] ?? { contentType: undefined, maxHeight: 220, duration: 0 })
function stepItems(visible: number, settled: boolean): ActivityItem[] {
return STEPS.slice(0, visible).map((step, index) => ({ ...step, type: 'step' as const, status: settled || index < visible - 1 ? 'complete' as const : 'active' as const }))
}
function searchItems(visible: number): ActivityItem[] {
return [{ id: 'search', type: 'search', query: 'accessible animation patterns for Vue', results: SEARCH_RESULTS.slice(0, visible), moreCount: visible === SEARCH_RESULTS.length ? 7 : undefined }]
}
function textItems(text: string): ActivityItem[] {
return text.split('\n').filter(Boolean).map((content, index) => ({ id: `reasoning-${index}`, type: 'text' as const, content }))
}
/** Final (reduced-motion) frame for each example. */
function finalItems(name: string): ActivityItem[] {
if (name === 'streaming-text') return textItems(REASONING)
if (name === 'reasoning-steps') return stepItems(STEPS.length, true)
if (name === 'web-search') return searchItems(SEARCH_RESULTS.length)
if (name === 'tool-calls') return TOOLS
if (name === 'mixed-activity') return MIXED_FRAMES[MIXED_FRAMES.length - 1]
return TRACE_ITEMS
}
onMounted(() => { reduce.value = matchMedia('(prefers-reduced-motion: reduce)').matches; mounted.value = true })
let frame = 0
watch([variant, run, mounted], (_, __, cleanup) => {
if (!mounted.value) return
const name = variant.value
const timers: ReturnType<typeof setTimeout>[] = []
const at = (ms: number, task: () => void) => timers.push(setTimeout(task, ms))
cleanup(() => { timers.forEach(clearTimeout); cancelAnimationFrame(frame) })
if (reduce.value) { items.value = finalItems(name); complete.value = true; return }
complete.value = false
if (name === 'streaming-text') {
items.value = []
const startedAt = performance.now()
const stream = (now: number) => {
const cursor = Math.min(REASONING.length, Math.floor(((now - startedAt) / 1000) * CHARACTERS_PER_SECOND))
items.value = textItems(REASONING.slice(0, cursor))
if (cursor === REASONING.length) at(500, () => { complete.value = true })
else frame = requestAnimationFrame(stream)
}
frame = requestAnimationFrame(stream)
} else if (name === 'reasoning-steps') {
items.value = stepItems(1, false)
STEPS.slice(1).forEach((_, index) => at(850 + index * 800, () => { items.value = stepItems(index + 2, false) }))
at(3300, () => { items.value = stepItems(STEPS.length, true) })
at(4200, () => { complete.value = true })
} else if (name === 'web-search') {
items.value = searchItems(0)
SEARCH_RESULTS.forEach((_, index) => at(650 + index * 650, () => { items.value = searchItems(index + 1) }))
at(3900, () => { complete.value = true })
} else if (name === 'tool-calls') {
items.value = []
TOOLS.forEach((_, index) => at(550 + index * 850, () => { items.value = TOOLS.slice(0, index + 1) }))
at(3600, () => { complete.value = true })
} else if (name === 'mixed-activity') {
items.value = MIXED_FRAMES[0]
MIXED_FRAMES.slice(1).forEach((_, index) => at(850 + index * 1050, () => { items.value = MIXED_FRAMES[index + 1] }))
at(850 + (MIXED_FRAMES.length - 2) * 1050 + 900, () => { complete.value = true })
} else {
items.value = []
TRACE_ITEMS.forEach((_, index) => at(250 + index * 650, () => { items.value = TRACE_ITEMS.slice(0, index + 1) }))
at(250 + TRACE_ITEMS.length * 650, () => { complete.value = true })
}
}, { immediate: true })
onBeforeUnmount(() => cancelAnimationFrame(frame))
</script>
<template>
<div :key="variant" style="position:relative;width:100%" :style="{ height: `${LAYOUT[variant].height}px`, maxWidth: LAYOUT[variant].width }" :data-example-variant="variant">
<AgentActivity
:key="`${variant}-${run}`" :items="items" :content-type="settings.contentType" :status="complete ? 'complete' : 'working'" :duration="settings.duration"
:default-open="reduce" :collapse-on-complete="!reduce" :max-height="settings.maxHeight" :active-label="variant === 'agent-trace' ? 'Running the agent trace…' : undefined"
>
<template #result-icon="{ result }">
<svg v-if="MARKS[result.id]" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path v-for="d in MARKS[result.id]" :key="d" :d="d" /></svg>
</template>
</AgentActivity>
<button type="button" class="be-agent-replay" @click="run++"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /><path d="M3 3v5h5" /></svg>Replay</button>
<label v-if="!fixed" class="be-agent-variant">Example <select :value="variant" @change="choose(($event.target as HTMLSelectElement).value)"><option v-for="option in options" :key="option">{{ option }}</option></select></label>
</div>
</template><script lang="ts">
export { agentActivityMessages } from './activity-types'
export type { ActivityItem, AgentActivityMessages, AgentSearchResult, AgentStepStatus, AgentTraceKind } from './activity-types'
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onBeforeUnmount, onMounted, shallowRef, useId, watch } from 'vue'
import { easeOut, layoutSpring, swapSpring } from '../core/motion'
import { useOpenState } from '../primitives/state'
import ThinkingShimmer from '../effects/ThinkingShimmer.vue'
import ActivityRow from './ActivityRow.vue'
import AgentIcon from './AgentIcon.vue'
import AgentReveal from './AgentReveal.vue'
import { agentActivityMessages, type ActivityContentType, type ActivityItem, type AgentActivityTranslate, type AgentSearchResult } from './activity-types'
import type { Labels } from './shared'
const props = withDefaults(defineProps<{
items: ActivityItem[], contentType?: ActivityContentType, status?: 'working' | 'complete', duration?: number,
open?: boolean, defaultOpen?: boolean, collapseOnComplete?: boolean, activeLabel?: string, summary?: string, maxHeight?: number, labels?: Labels, contentClassName?: string
}>(), { status: 'working', duration: 0, open: undefined, defaultOpen: false, collapseOnComplete: true, maxHeight: 208 })
const emit = defineEmits<{ 'update:open': [value: boolean], openChange: [value: boolean] }>()
defineSlots<{
/** Replaces the live status line while the run is working. */
renderWorkingStatus?(props: { label: string, duration: number }): unknown
/** Replaces the summary inside the completed disclosure trigger. */
renderCompletedStatus?(props: { summary: string, duration: number }): unknown
/** Replaces the row renderer for one item. */
item?(props: { item: ActivityItem }): unknown
'result-icon'?(props: { result: AgentSearchResult }): unknown
'trace-icon'?(props: { item: ActivityItem }): unknown
}>()
const { open: currentOpen, setOpen } = useOpenState(() => props.open, props.defaultOpen, next => { emit('update:open', next); emit('openChange', next) })
const reduce = useReducedMotion()
const baseId = useId()
const triggerId = `${baseId}-trigger`
const contentId = `${baseId}-content`
const contentRef = shallowRef<HTMLElement | { $el: HTMLElement } | null>(null)
const viewportRef = shallowRef<HTMLElement | null>(null)
const contentHeight = shallowRef(0)
const t: AgentActivityTranslate = (key, values) => (props.labels?.[key] ?? agentActivityMessages[key]).replace(/\{(\w+)\}/g, (match, name) => values?.[name] === undefined ? match : String(values[name]))
const working = computed(() => props.status === 'working')
const expanded = computed(() => working.value || currentOpen.value)
const contentType = computed<ActivityContentType>(() => {
if (!props.items.length) return props.contentType ?? 'mixed'
const first = props.items[0].type
return props.items.every(item => item.type === first) ? first : 'mixed'
})
const cappedHeight = computed(() => Math.min(contentHeight.value, Math.max(0, props.maxHeight)))
const viewportHeight = computed(() => working.value ? Math.max(0, props.maxHeight) : cappedHeight.value)
const capped = computed(() => contentHeight.value > props.maxHeight)
const streamOffset = computed(() => working.value ? Math.min(0, viewportHeight.value - contentHeight.value) : 0)
const maskImage = computed(() => !capped.value ? undefined : working.value
? 'linear-gradient(to bottom, transparent, black 12px)'
: 'linear-gradient(to bottom, transparent, black 12px, black calc(100% - 12px), transparent)')
function formatDuration(value: number) {
const seconds = Math.max(0, Math.round(value))
if (seconds < 60) return t('seconds', { seconds })
const minutes = Math.floor(seconds / 60)
const remainder = seconds % 60
return remainder === 0 ? t('minutes', { minutes }) : t('minutesSeconds', { minutes, seconds: remainder })
}
const liveLabel = computed(() => {
if (props.activeLabel) return props.activeLabel
const type = contentType.value
if (type === 'search') return t('searching')
if (type === 'tool') return t('runningTools')
if (type === 'trace') return t('workingTrace')
if (type === 'mixed') return t('workingMixed')
return t('thinking')
})
/** Summary split around the duration so it can keep tabular figures; `parts` is a plain string otherwise. */
const summaryParts = computed<{ text: string } | { before: string, duration: string, after: string }>(() => {
if (props.summary) return { text: props.summary }
const type = contentType.value
const count = props.items.length
if (type === 'step' || type === 'text') {
const [before, after = ''] = (props.labels?.thoughtFor ?? agentActivityMessages.thoughtFor).split('{duration}')
return { before, duration: formatDuration(props.duration), after }
}
if (type === 'search') return { text: t('searched') }
if (type === 'tool') return { text: t(count === 1 ? 'ranToolsOne' : 'ranToolsOther', { count }) }
if (type === 'trace') {
const messages = props.items.filter(item => item.type === 'trace' && (item.kind === 'thinking' || item.kind === 'message')).length
const tools = count - messages
return { text: t('traceSummary', { toolCalls: t(tools === 1 ? 'toolCallsOne' : 'toolCallsOther', { count: tools }), messages: t(messages === 1 ? 'messagesOne' : 'messagesOther', { count: messages }) }) }
}
return { text: t(count === 1 ? 'completedStepsOne' : 'completedStepsOther', { count }) }
})
const summaryText = computed(() => 'text' in summaryParts.value ? summaryParts.value.text : `${summaryParts.value.before}${summaryParts.value.duration}${summaryParts.value.after}`)
let observer: ResizeObserver | undefined
let measureFrame = 0
onMounted(() => {
const target = contentRef.value
const node = target && '$el' in target ? target.$el : target
if (!node) return
const measure = () => { contentHeight.value = node.offsetHeight }
measure()
if (typeof ResizeObserver === 'undefined') return
// Vue flushes the height change on a microtask, which still runs inside this
// observer round, so the resize it causes would trip a "ResizeObserver loop"
// error. React commits the same setState on a later task; match that here.
observer = new ResizeObserver(() => {
cancelAnimationFrame(measureFrame)
measureFrame = requestAnimationFrame(measure)
})
observer.observe(node)
})
onBeforeUnmount(() => {
observer?.disconnect()
cancelAnimationFrame(measureFrame)
})
watch(() => props.status, (next, previous) => {
if (previous === 'working' && next === 'complete') setOpen(!props.collapseOnComplete)
})
let frame = 0
function toggle() {
const next = !currentOpen.value
setOpen(next)
if (next) { cancelAnimationFrame(frame); frame = requestAnimationFrame(() => viewportRef.value?.scrollTo({ top: 0 })) }
}
onBeforeUnmount(() => cancelAnimationFrame(frame))
const enter = computed(() => reduce.value ? { opacity: 1 } : { opacity: 0, y: 6 })
const exit = computed(() => reduce.value ? { opacity: 0 } : { opacity: 0, y: -3 })
const itemTransition = computed(() => reduce.value ? { duration: 0 } : { opacity: { duration: 0.18, ease: easeOut }, y: layoutSpring, layout: layoutSpring })
</script>
<template>
<div class="aa" :data-state="working ? 'working' : expanded ? 'open' : 'closed'" :data-content="contentType" :aria-busy="working">
<div v-if="working" :id="triggerId" role="status" class="aa-status">
<slot name="renderWorkingStatus" :label="liveLabel" :duration="duration"><ThinkingShimmer>{{ liveLabel }}</ThinkingShimmer></slot>
</div>
<button v-else :id="triggerId" type="button" class="aa-trigger" :aria-expanded="expanded" :aria-controls="contentId" @click="toggle">
<span class="aa-summary"><slot name="renderCompletedStatus" :summary="summaryText" :duration="duration">
<template v-if="'text' in summaryParts">{{ summaryParts.text }}</template>
<template v-else>{{ summaryParts.before }}<span class="aa-tabular">{{ summaryParts.duration }}</span>{{ summaryParts.after }}</template>
</slot></span>
<motion.span aria-hidden="true" class="aa-chevron" :animate="{ rotate: expanded ? 180 : 0 }" :transition="reduce ? { duration: 0 } : swapSpring"><AgentIcon name="ChevronDown" :size="14" /></motion.span>
</button>
<AgentReveal :id="contentId" role="region" :aria-labelledby="triggerId" :open="expanded" :open-height="viewportHeight">
<div ref="viewportRef" class="aa-viewport" :data-scroll="capped && expanded && !working || undefined" :style="{ height: `${viewportHeight}px`, maskImage, WebkitMaskImage: maskImage }">
<motion.div ref="contentRef" role="list" class="aa-list" :class="contentClassName" :initial="false" :animate="{ y: streamOffset }" :transition="reduce ? { duration: 0 } : layoutSpring">
<AnimatePresence mode="popLayout">
<motion.div v-for="item in items" :key="item.id" layout="position" role="listitem" :initial="enter" :animate="{ opacity: 1, y: 0 }" :exit="exit" :transition="itemTransition">
<slot name="item" :item="item">
<ActivityRow :item="item" :t="t"><template #result-icon="scope"><slot name="result-icon" v-bind="scope" /></template><template #trace-icon="scope"><slot name="trace-icon" v-bind="scope" /></template></ActivityRow>
</slot>
</motion.div>
</AnimatePresence>
</motion.div>
</div>
</AgentReveal>
</div>
</template>
<style scoped>
.aa { width: 100%; font-size: .875rem; line-height: 1.25rem; }
.aa-status { display: flex; height: 1.75rem; min-width: 0; align-items: center; color: var(--beui-muted-foreground); }
.aa-trigger { display: flex; height: 1.75rem; min-width: 0; align-items: center; gap: .375rem; padding: 0; border: 0; border-radius: .375rem; background: none; font: inherit; font-weight: 500; text-align: left; color: var(--beui-muted-foreground); cursor: pointer; outline: none; transition: color .15s; }
.aa-trigger:hover { color: var(--beui-foreground); }
.aa-trigger:focus-visible { box-shadow: 0 0 0 2px var(--beui-background), 0 0 0 4px var(--beui-ring); }
.aa-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aa-tabular { font-variant-numeric: tabular-nums; }
.aa-chevron { display: inline-flex; flex: none; color: color-mix(in oklab, var(--beui-muted-foreground) 70%, transparent); }
.aa-trigger:hover .aa-chevron { color: var(--beui-foreground); }
.aa-viewport { box-sizing: border-box; padding-right: .25rem; overflow-y: hidden; scrollbar-width: none; }
.aa-viewport[data-scroll] { overflow-y: auto; }
.aa-viewport::-webkit-scrollbar { display: none; }
.aa-list { display: grid; gap: .125rem; padding-block: .5rem; }
</style>Reasoning Steps
AgentActivity.vue<script setup lang="ts">
import { AgentActivity, type ActivityItem } from 'beui-vue'
import { computed, onBeforeUnmount, onMounted, shallowRef, watch, ref } from 'vue'
function useAgentVariant(selected: () => string | undefined, choices: Record<string,string>) {
const pinned = undefined as string | undefined
const fixed = Boolean(pinned)
const query = ref('')
const options = Object.keys(choices)
const variant = computed(() => {
const requested = pinned || selected() || query.value
return options.find(slug => requested === slug || requested === choices[slug]) ?? options[0]
})
function refresh() {
query.value = new URL(location.href).searchParams.get('variant') ?? ''
}
function choose(slug:string) {
if (fixed || !options.includes(slug)) return
const url = new URL(location.href)
url.searchParams.set('variant',slug)
history.replaceState(history.state,'',url)
refresh()
}
onMounted(() => {
if (fixed) return
refresh()
window.addEventListener('popstate',refresh)
})
onBeforeUnmount(() => window.removeEventListener('popstate',refresh))
return { variant, choose, options, fixed }
}
const props = defineProps<{ variant?: string }>()
const { variant, choose, options, fixed } = useAgentVariant(() => props.variant, {
'streaming-text': 'agents/agent-activity-text', 'reasoning-steps': 'agents/agent-activity-steps', 'web-search': 'agents/agent-activity-search',
'tool-calls': 'agents/agent-activity-tools', 'mixed-activity': 'agents/agent-activity-mixed', 'agent-trace': 'agents/agent-trace',
})
const REASONING = [
'Reading the request and separating the content model from its presentation.',
'The activity shell can stay consistent while each event supplies its own compact renderer.',
'Text remains freeform so partial tokens can update without recreating the surrounding timeline.',
'As each sentence wraps, the measured stream moves upward through a single transform instead of repeatedly jumping the native scroll position.',
'Older context stays available above the fold while the newest tokens remain crisp at the bottom edge.',
'Once the run finishes, the viewport switches from automatic following to ordinary user-controlled scrolling.',
'Opening the completed disclosure returns to the beginning so the reasoning can be read in order.',
'The capped viewport follows the latest sentence and preserves the full log after completion.',
].join('\n')
const CHARACTERS_PER_SECOND = 90
const STEPS = [
{ id: 'brief', label: 'Reading the product brief' },
{ id: 'patterns', label: 'Mapping the interaction patterns' },
{ id: 'states', label: 'Connecting the loading and completion states', meta: '3 states' },
{ id: 'verify', label: 'Verifying the final behavior' },
]
const SEARCH_RESULTS = [
{ id: 'google', title: 'Google for Developers', domain: 'developers.google.com' },
{ id: 'github', title: 'GitHub', domain: 'github.com' },
{ id: 'wikipedia', title: 'Wikipedia', domain: 'wikipedia.org' },
{ id: 'vercel', title: 'Vercel Docs', domain: 'vercel.com/docs' },
]
const MARKS: Record<string, string[]> = {
google: ['M21.35 12.23c0-.65-.06-1.28-.17-1.89H12v3.79h5.25a4.5 4.5 0 0 1-1.95 2.87v2.46h3.16c1.85-1.71 2.89-4.22 2.89-7.23Z', 'M12 21.75c2.64 0 4.86-.87 6.46-2.29L15.3 17c-.87.58-1.98.92-3.3.92a5.7 5.7 0 0 1-5.35-3.93H3.39v2.54A9.75 9.75 0 0 0 12 21.75Z', 'M6.65 13.99A5.85 5.85 0 0 1 6.34 12c0-.69.12-1.36.31-1.99V7.47H3.39A9.76 9.76 0 0 0 2.25 12c0 1.63.39 3.18 1.14 4.53l3.26-2.54Z', 'M12 6.08c1.44 0 2.73.49 3.75 1.47l2.78-2.78A9.34 9.34 0 0 0 12 2.25a9.75 9.75 0 0 0-8.61 5.22l3.26 2.54A5.7 5.7 0 0 1 12 6.08Z'],
github: ['M12 2a10 10 0 0 0-3.16 19.49c.5.09.68-.22.68-.48v-1.87c-2.78.6-3.37-1.18-3.37-1.18-.45-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.61.07-.61 1 .07 1.53 1.03 1.53 1.03.9 1.53 2.35 1.09 2.92.83.09-.65.35-1.09.64-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.98 1.03-2.68-.1-.25-.45-1.27.1-2.64 0 0 .84-.27 2.75 1.02A9.58 9.58 0 0 1 12 6.82c.85 0 1.71.11 2.51.34 1.91-1.29 2.75-1.02 2.75-1.02.55 1.37.2 2.39.1 2.64.64.7 1.03 1.59 1.03 2.68 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85v2.77c0 .27.18.58.69.48A10 10 0 0 0 12 2Z'],
wikipedia: ['M1.5 4h6v1.2H6l4.08 10.73 1.26-3.12L8.45 5.2H7.2V4h6v1.2h-1.47l1.66 4.57 1.82-4.57H13.8V4h4.9v1.2h-1.45l-3.19 7.92 1.08 2.81L19.48 5.2H18V4h4.5v1.2h-1.42L15.25 20h-1.2l-1.91-4.86L10.18 20H8.92L3.25 5.2H1.5V4Z'],
vercel: ['m12 3 10 18H2L12 3Z'],
}
const TOOLS: ActivityItem[] = [
{ id: 'read', type: 'tool', action: 'read', target: 'campaign-notes.md' },
{ id: 'edit', type: 'tool', action: 'edit', target: 'launch-plan.ts', additions: 42, deletions: 8 },
{ id: 'run', type: 'tool', action: 'run', target: 'bun test launch' },
]
const ACTIVE_BRIEF: ActivityItem = { id: 'brief', type: 'step', label: 'Reading the launch brief', status: 'active' }
const COMPLETE_BRIEF: ActivityItem = { ...ACTIVE_BRIEF, status: 'complete' }
const PENDING_SEARCH: ActivityItem = { id: 'search', type: 'search', query: 'independent coffee roasters in Portland', results: [] }
const COMPLETE_SEARCH: ActivityItem = {
...PENDING_SEARCH,
results: [
{ id: 'heart', title: 'Heart Coffee', domain: 'heartroasters.com' },
{ id: 'coava', title: 'Coava Coffee', domain: 'coavacoffee.com' },
{ id: 'upper-left', title: 'Upper Left Roasters', domain: 'upperleftroasters.com' },
],
moreCount: 5,
}
const MIXED_FRAMES: ActivityItem[][] = [
[ACTIVE_BRIEF],
[COMPLETE_BRIEF, PENDING_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0]],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0], TOOLS[1], TOOLS[2], { id: 'verify', type: 'step', label: 'Checking the final campaign plan', status: 'complete' }],
]
const TRACE_ITEMS: ActivityItem[] = [
{ id: 'plan', type: 'trace', kind: 'thinking', label: 'Thinking', detail: 'Mapping the interaction flow…' },
{ id: 'decision', type: 'trace', kind: 'message', label: 'Decision', detail: 'Use one compact disclosure' },
{ id: 'write', type: 'trace', kind: 'write', label: 'Draft component', detail: 'components/agents/run-log.tsx' },
{ id: 'verify', type: 'trace', kind: 'run', label: 'Validate types', detail: 'bun run typecheck' },
{ id: 'inspect', type: 'trace', kind: 'read', label: 'Inspect preview', detail: 'activity-preview.png' },
]
const LAYOUT: Record<string, { height: number, width: string }> = {
'streaming-text': { height: 330, width: '32rem' }, 'reasoning-steps': { height: 330, width: '32rem' }, 'web-search': { height: 330, width: '32rem' },
'tool-calls': { height: 330, width: '32rem' }, 'mixed-activity': { height: 330, width: '36rem' }, 'agent-trace': { height: 300, width: '36rem' },
}
const run = shallowRef(0)
const reduce = shallowRef(false)
const mounted = shallowRef(false)
const items = shallowRef<ActivityItem[]>([])
const complete = shallowRef(false)
const settings = computed(() => ({
'streaming-text': { contentType: 'text', maxHeight: 180, duration: REASONING.length / CHARACTERS_PER_SECOND },
'reasoning-steps': { contentType: 'step', maxHeight: 220, duration: 4.2 },
'web-search': { contentType: 'search', maxHeight: 220, duration: 0 },
'tool-calls': { contentType: 'tool', maxHeight: 220, duration: 0 },
'mixed-activity': { contentType: undefined, maxHeight: 220, duration: 5.1 },
'agent-trace': { contentType: 'trace', maxHeight: 190, duration: 0 },
} as const)[variant.value as 'agent-trace'] ?? { contentType: undefined, maxHeight: 220, duration: 0 })
function stepItems(visible: number, settled: boolean): ActivityItem[] {
return STEPS.slice(0, visible).map((step, index) => ({ ...step, type: 'step' as const, status: settled || index < visible - 1 ? 'complete' as const : 'active' as const }))
}
function searchItems(visible: number): ActivityItem[] {
return [{ id: 'search', type: 'search', query: 'accessible animation patterns for Vue', results: SEARCH_RESULTS.slice(0, visible), moreCount: visible === SEARCH_RESULTS.length ? 7 : undefined }]
}
function textItems(text: string): ActivityItem[] {
return text.split('\n').filter(Boolean).map((content, index) => ({ id: `reasoning-${index}`, type: 'text' as const, content }))
}
/** Final (reduced-motion) frame for each example. */
function finalItems(name: string): ActivityItem[] {
if (name === 'streaming-text') return textItems(REASONING)
if (name === 'reasoning-steps') return stepItems(STEPS.length, true)
if (name === 'web-search') return searchItems(SEARCH_RESULTS.length)
if (name === 'tool-calls') return TOOLS
if (name === 'mixed-activity') return MIXED_FRAMES[MIXED_FRAMES.length - 1]
return TRACE_ITEMS
}
onMounted(() => { reduce.value = matchMedia('(prefers-reduced-motion: reduce)').matches; mounted.value = true })
let frame = 0
watch([variant, run, mounted], (_, __, cleanup) => {
if (!mounted.value) return
const name = variant.value
const timers: ReturnType<typeof setTimeout>[] = []
const at = (ms: number, task: () => void) => timers.push(setTimeout(task, ms))
cleanup(() => { timers.forEach(clearTimeout); cancelAnimationFrame(frame) })
if (reduce.value) { items.value = finalItems(name); complete.value = true; return }
complete.value = false
if (name === 'streaming-text') {
items.value = []
const startedAt = performance.now()
const stream = (now: number) => {
const cursor = Math.min(REASONING.length, Math.floor(((now - startedAt) / 1000) * CHARACTERS_PER_SECOND))
items.value = textItems(REASONING.slice(0, cursor))
if (cursor === REASONING.length) at(500, () => { complete.value = true })
else frame = requestAnimationFrame(stream)
}
frame = requestAnimationFrame(stream)
} else if (name === 'reasoning-steps') {
items.value = stepItems(1, false)
STEPS.slice(1).forEach((_, index) => at(850 + index * 800, () => { items.value = stepItems(index + 2, false) }))
at(3300, () => { items.value = stepItems(STEPS.length, true) })
at(4200, () => { complete.value = true })
} else if (name === 'web-search') {
items.value = searchItems(0)
SEARCH_RESULTS.forEach((_, index) => at(650 + index * 650, () => { items.value = searchItems(index + 1) }))
at(3900, () => { complete.value = true })
} else if (name === 'tool-calls') {
items.value = []
TOOLS.forEach((_, index) => at(550 + index * 850, () => { items.value = TOOLS.slice(0, index + 1) }))
at(3600, () => { complete.value = true })
} else if (name === 'mixed-activity') {
items.value = MIXED_FRAMES[0]
MIXED_FRAMES.slice(1).forEach((_, index) => at(850 + index * 1050, () => { items.value = MIXED_FRAMES[index + 1] }))
at(850 + (MIXED_FRAMES.length - 2) * 1050 + 900, () => { complete.value = true })
} else {
items.value = []
TRACE_ITEMS.forEach((_, index) => at(250 + index * 650, () => { items.value = TRACE_ITEMS.slice(0, index + 1) }))
at(250 + TRACE_ITEMS.length * 650, () => { complete.value = true })
}
}, { immediate: true })
onBeforeUnmount(() => cancelAnimationFrame(frame))
</script>
<template>
<div :key="variant" style="position:relative;width:100%" :style="{ height: `${LAYOUT[variant].height}px`, maxWidth: LAYOUT[variant].width }" :data-example-variant="variant">
<AgentActivity
:key="`${variant}-${run}`" :items="items" :content-type="settings.contentType" :status="complete ? 'complete' : 'working'" :duration="settings.duration"
:default-open="reduce" :collapse-on-complete="!reduce" :max-height="settings.maxHeight" :active-label="variant === 'agent-trace' ? 'Running the agent trace…' : undefined"
>
<template #result-icon="{ result }">
<svg v-if="MARKS[result.id]" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path v-for="d in MARKS[result.id]" :key="d" :d="d" /></svg>
</template>
</AgentActivity>
<button type="button" class="be-agent-replay" @click="run++"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /><path d="M3 3v5h5" /></svg>Replay</button>
<label v-if="!fixed" class="be-agent-variant">Example <select :value="variant" @change="choose(($event.target as HTMLSelectElement).value)"><option v-for="option in options" :key="option">{{ option }}</option></select></label>
</div>
</template><script lang="ts">
export { agentActivityMessages } from './activity-types'
export type { ActivityItem, AgentActivityMessages, AgentSearchResult, AgentStepStatus, AgentTraceKind } from './activity-types'
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onBeforeUnmount, onMounted, shallowRef, useId, watch } from 'vue'
import { easeOut, layoutSpring, swapSpring } from '../core/motion'
import { useOpenState } from '../primitives/state'
import ThinkingShimmer from '../effects/ThinkingShimmer.vue'
import ActivityRow from './ActivityRow.vue'
import AgentIcon from './AgentIcon.vue'
import AgentReveal from './AgentReveal.vue'
import { agentActivityMessages, type ActivityContentType, type ActivityItem, type AgentActivityTranslate, type AgentSearchResult } from './activity-types'
import type { Labels } from './shared'
const props = withDefaults(defineProps<{
items: ActivityItem[], contentType?: ActivityContentType, status?: 'working' | 'complete', duration?: number,
open?: boolean, defaultOpen?: boolean, collapseOnComplete?: boolean, activeLabel?: string, summary?: string, maxHeight?: number, labels?: Labels, contentClassName?: string
}>(), { status: 'working', duration: 0, open: undefined, defaultOpen: false, collapseOnComplete: true, maxHeight: 208 })
const emit = defineEmits<{ 'update:open': [value: boolean], openChange: [value: boolean] }>()
defineSlots<{
/** Replaces the live status line while the run is working. */
renderWorkingStatus?(props: { label: string, duration: number }): unknown
/** Replaces the summary inside the completed disclosure trigger. */
renderCompletedStatus?(props: { summary: string, duration: number }): unknown
/** Replaces the row renderer for one item. */
item?(props: { item: ActivityItem }): unknown
'result-icon'?(props: { result: AgentSearchResult }): unknown
'trace-icon'?(props: { item: ActivityItem }): unknown
}>()
const { open: currentOpen, setOpen } = useOpenState(() => props.open, props.defaultOpen, next => { emit('update:open', next); emit('openChange', next) })
const reduce = useReducedMotion()
const baseId = useId()
const triggerId = `${baseId}-trigger`
const contentId = `${baseId}-content`
const contentRef = shallowRef<HTMLElement | { $el: HTMLElement } | null>(null)
const viewportRef = shallowRef<HTMLElement | null>(null)
const contentHeight = shallowRef(0)
const t: AgentActivityTranslate = (key, values) => (props.labels?.[key] ?? agentActivityMessages[key]).replace(/\{(\w+)\}/g, (match, name) => values?.[name] === undefined ? match : String(values[name]))
const working = computed(() => props.status === 'working')
const expanded = computed(() => working.value || currentOpen.value)
const contentType = computed<ActivityContentType>(() => {
if (!props.items.length) return props.contentType ?? 'mixed'
const first = props.items[0].type
return props.items.every(item => item.type === first) ? first : 'mixed'
})
const cappedHeight = computed(() => Math.min(contentHeight.value, Math.max(0, props.maxHeight)))
const viewportHeight = computed(() => working.value ? Math.max(0, props.maxHeight) : cappedHeight.value)
const capped = computed(() => contentHeight.value > props.maxHeight)
const streamOffset = computed(() => working.value ? Math.min(0, viewportHeight.value - contentHeight.value) : 0)
const maskImage = computed(() => !capped.value ? undefined : working.value
? 'linear-gradient(to bottom, transparent, black 12px)'
: 'linear-gradient(to bottom, transparent, black 12px, black calc(100% - 12px), transparent)')
function formatDuration(value: number) {
const seconds = Math.max(0, Math.round(value))
if (seconds < 60) return t('seconds', { seconds })
const minutes = Math.floor(seconds / 60)
const remainder = seconds % 60
return remainder === 0 ? t('minutes', { minutes }) : t('minutesSeconds', { minutes, seconds: remainder })
}
const liveLabel = computed(() => {
if (props.activeLabel) return props.activeLabel
const type = contentType.value
if (type === 'search') return t('searching')
if (type === 'tool') return t('runningTools')
if (type === 'trace') return t('workingTrace')
if (type === 'mixed') return t('workingMixed')
return t('thinking')
})
/** Summary split around the duration so it can keep tabular figures; `parts` is a plain string otherwise. */
const summaryParts = computed<{ text: string } | { before: string, duration: string, after: string }>(() => {
if (props.summary) return { text: props.summary }
const type = contentType.value
const count = props.items.length
if (type === 'step' || type === 'text') {
const [before, after = ''] = (props.labels?.thoughtFor ?? agentActivityMessages.thoughtFor).split('{duration}')
return { before, duration: formatDuration(props.duration), after }
}
if (type === 'search') return { text: t('searched') }
if (type === 'tool') return { text: t(count === 1 ? 'ranToolsOne' : 'ranToolsOther', { count }) }
if (type === 'trace') {
const messages = props.items.filter(item => item.type === 'trace' && (item.kind === 'thinking' || item.kind === 'message')).length
const tools = count - messages
return { text: t('traceSummary', { toolCalls: t(tools === 1 ? 'toolCallsOne' : 'toolCallsOther', { count: tools }), messages: t(messages === 1 ? 'messagesOne' : 'messagesOther', { count: messages }) }) }
}
return { text: t(count === 1 ? 'completedStepsOne' : 'completedStepsOther', { count }) }
})
const summaryText = computed(() => 'text' in summaryParts.value ? summaryParts.value.text : `${summaryParts.value.before}${summaryParts.value.duration}${summaryParts.value.after}`)
let observer: ResizeObserver | undefined
let measureFrame = 0
onMounted(() => {
const target = contentRef.value
const node = target && '$el' in target ? target.$el : target
if (!node) return
const measure = () => { contentHeight.value = node.offsetHeight }
measure()
if (typeof ResizeObserver === 'undefined') return
// Vue flushes the height change on a microtask, which still runs inside this
// observer round, so the resize it causes would trip a "ResizeObserver loop"
// error. React commits the same setState on a later task; match that here.
observer = new ResizeObserver(() => {
cancelAnimationFrame(measureFrame)
measureFrame = requestAnimationFrame(measure)
})
observer.observe(node)
})
onBeforeUnmount(() => {
observer?.disconnect()
cancelAnimationFrame(measureFrame)
})
watch(() => props.status, (next, previous) => {
if (previous === 'working' && next === 'complete') setOpen(!props.collapseOnComplete)
})
let frame = 0
function toggle() {
const next = !currentOpen.value
setOpen(next)
if (next) { cancelAnimationFrame(frame); frame = requestAnimationFrame(() => viewportRef.value?.scrollTo({ top: 0 })) }
}
onBeforeUnmount(() => cancelAnimationFrame(frame))
const enter = computed(() => reduce.value ? { opacity: 1 } : { opacity: 0, y: 6 })
const exit = computed(() => reduce.value ? { opacity: 0 } : { opacity: 0, y: -3 })
const itemTransition = computed(() => reduce.value ? { duration: 0 } : { opacity: { duration: 0.18, ease: easeOut }, y: layoutSpring, layout: layoutSpring })
</script>
<template>
<div class="aa" :data-state="working ? 'working' : expanded ? 'open' : 'closed'" :data-content="contentType" :aria-busy="working">
<div v-if="working" :id="triggerId" role="status" class="aa-status">
<slot name="renderWorkingStatus" :label="liveLabel" :duration="duration"><ThinkingShimmer>{{ liveLabel }}</ThinkingShimmer></slot>
</div>
<button v-else :id="triggerId" type="button" class="aa-trigger" :aria-expanded="expanded" :aria-controls="contentId" @click="toggle">
<span class="aa-summary"><slot name="renderCompletedStatus" :summary="summaryText" :duration="duration">
<template v-if="'text' in summaryParts">{{ summaryParts.text }}</template>
<template v-else>{{ summaryParts.before }}<span class="aa-tabular">{{ summaryParts.duration }}</span>{{ summaryParts.after }}</template>
</slot></span>
<motion.span aria-hidden="true" class="aa-chevron" :animate="{ rotate: expanded ? 180 : 0 }" :transition="reduce ? { duration: 0 } : swapSpring"><AgentIcon name="ChevronDown" :size="14" /></motion.span>
</button>
<AgentReveal :id="contentId" role="region" :aria-labelledby="triggerId" :open="expanded" :open-height="viewportHeight">
<div ref="viewportRef" class="aa-viewport" :data-scroll="capped && expanded && !working || undefined" :style="{ height: `${viewportHeight}px`, maskImage, WebkitMaskImage: maskImage }">
<motion.div ref="contentRef" role="list" class="aa-list" :class="contentClassName" :initial="false" :animate="{ y: streamOffset }" :transition="reduce ? { duration: 0 } : layoutSpring">
<AnimatePresence mode="popLayout">
<motion.div v-for="item in items" :key="item.id" layout="position" role="listitem" :initial="enter" :animate="{ opacity: 1, y: 0 }" :exit="exit" :transition="itemTransition">
<slot name="item" :item="item">
<ActivityRow :item="item" :t="t"><template #result-icon="scope"><slot name="result-icon" v-bind="scope" /></template><template #trace-icon="scope"><slot name="trace-icon" v-bind="scope" /></template></ActivityRow>
</slot>
</motion.div>
</AnimatePresence>
</motion.div>
</div>
</AgentReveal>
</div>
</template>
<style scoped>
.aa { width: 100%; font-size: .875rem; line-height: 1.25rem; }
.aa-status { display: flex; height: 1.75rem; min-width: 0; align-items: center; color: var(--beui-muted-foreground); }
.aa-trigger { display: flex; height: 1.75rem; min-width: 0; align-items: center; gap: .375rem; padding: 0; border: 0; border-radius: .375rem; background: none; font: inherit; font-weight: 500; text-align: left; color: var(--beui-muted-foreground); cursor: pointer; outline: none; transition: color .15s; }
.aa-trigger:hover { color: var(--beui-foreground); }
.aa-trigger:focus-visible { box-shadow: 0 0 0 2px var(--beui-background), 0 0 0 4px var(--beui-ring); }
.aa-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aa-tabular { font-variant-numeric: tabular-nums; }
.aa-chevron { display: inline-flex; flex: none; color: color-mix(in oklab, var(--beui-muted-foreground) 70%, transparent); }
.aa-trigger:hover .aa-chevron { color: var(--beui-foreground); }
.aa-viewport { box-sizing: border-box; padding-right: .25rem; overflow-y: hidden; scrollbar-width: none; }
.aa-viewport[data-scroll] { overflow-y: auto; }
.aa-viewport::-webkit-scrollbar { display: none; }
.aa-list { display: grid; gap: .125rem; padding-block: .5rem; }
</style>Web Search
AgentActivity.vue<script setup lang="ts">
import { AgentActivity, type ActivityItem } from 'beui-vue'
import { computed, onBeforeUnmount, onMounted, shallowRef, watch, ref } from 'vue'
function useAgentVariant(selected: () => string | undefined, choices: Record<string,string>) {
const pinned = undefined as string | undefined
const fixed = Boolean(pinned)
const query = ref('')
const options = Object.keys(choices)
const variant = computed(() => {
const requested = pinned || selected() || query.value
return options.find(slug => requested === slug || requested === choices[slug]) ?? options[0]
})
function refresh() {
query.value = new URL(location.href).searchParams.get('variant') ?? ''
}
function choose(slug:string) {
if (fixed || !options.includes(slug)) return
const url = new URL(location.href)
url.searchParams.set('variant',slug)
history.replaceState(history.state,'',url)
refresh()
}
onMounted(() => {
if (fixed) return
refresh()
window.addEventListener('popstate',refresh)
})
onBeforeUnmount(() => window.removeEventListener('popstate',refresh))
return { variant, choose, options, fixed }
}
const props = defineProps<{ variant?: string }>()
const { variant, choose, options, fixed } = useAgentVariant(() => props.variant, {
'streaming-text': 'agents/agent-activity-text', 'reasoning-steps': 'agents/agent-activity-steps', 'web-search': 'agents/agent-activity-search',
'tool-calls': 'agents/agent-activity-tools', 'mixed-activity': 'agents/agent-activity-mixed', 'agent-trace': 'agents/agent-trace',
})
const REASONING = [
'Reading the request and separating the content model from its presentation.',
'The activity shell can stay consistent while each event supplies its own compact renderer.',
'Text remains freeform so partial tokens can update without recreating the surrounding timeline.',
'As each sentence wraps, the measured stream moves upward through a single transform instead of repeatedly jumping the native scroll position.',
'Older context stays available above the fold while the newest tokens remain crisp at the bottom edge.',
'Once the run finishes, the viewport switches from automatic following to ordinary user-controlled scrolling.',
'Opening the completed disclosure returns to the beginning so the reasoning can be read in order.',
'The capped viewport follows the latest sentence and preserves the full log after completion.',
].join('\n')
const CHARACTERS_PER_SECOND = 90
const STEPS = [
{ id: 'brief', label: 'Reading the product brief' },
{ id: 'patterns', label: 'Mapping the interaction patterns' },
{ id: 'states', label: 'Connecting the loading and completion states', meta: '3 states' },
{ id: 'verify', label: 'Verifying the final behavior' },
]
const SEARCH_RESULTS = [
{ id: 'google', title: 'Google for Developers', domain: 'developers.google.com' },
{ id: 'github', title: 'GitHub', domain: 'github.com' },
{ id: 'wikipedia', title: 'Wikipedia', domain: 'wikipedia.org' },
{ id: 'vercel', title: 'Vercel Docs', domain: 'vercel.com/docs' },
]
const MARKS: Record<string, string[]> = {
google: ['M21.35 12.23c0-.65-.06-1.28-.17-1.89H12v3.79h5.25a4.5 4.5 0 0 1-1.95 2.87v2.46h3.16c1.85-1.71 2.89-4.22 2.89-7.23Z', 'M12 21.75c2.64 0 4.86-.87 6.46-2.29L15.3 17c-.87.58-1.98.92-3.3.92a5.7 5.7 0 0 1-5.35-3.93H3.39v2.54A9.75 9.75 0 0 0 12 21.75Z', 'M6.65 13.99A5.85 5.85 0 0 1 6.34 12c0-.69.12-1.36.31-1.99V7.47H3.39A9.76 9.76 0 0 0 2.25 12c0 1.63.39 3.18 1.14 4.53l3.26-2.54Z', 'M12 6.08c1.44 0 2.73.49 3.75 1.47l2.78-2.78A9.34 9.34 0 0 0 12 2.25a9.75 9.75 0 0 0-8.61 5.22l3.26 2.54A5.7 5.7 0 0 1 12 6.08Z'],
github: ['M12 2a10 10 0 0 0-3.16 19.49c.5.09.68-.22.68-.48v-1.87c-2.78.6-3.37-1.18-3.37-1.18-.45-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.61.07-.61 1 .07 1.53 1.03 1.53 1.03.9 1.53 2.35 1.09 2.92.83.09-.65.35-1.09.64-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.98 1.03-2.68-.1-.25-.45-1.27.1-2.64 0 0 .84-.27 2.75 1.02A9.58 9.58 0 0 1 12 6.82c.85 0 1.71.11 2.51.34 1.91-1.29 2.75-1.02 2.75-1.02.55 1.37.2 2.39.1 2.64.64.7 1.03 1.59 1.03 2.68 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85v2.77c0 .27.18.58.69.48A10 10 0 0 0 12 2Z'],
wikipedia: ['M1.5 4h6v1.2H6l4.08 10.73 1.26-3.12L8.45 5.2H7.2V4h6v1.2h-1.47l1.66 4.57 1.82-4.57H13.8V4h4.9v1.2h-1.45l-3.19 7.92 1.08 2.81L19.48 5.2H18V4h4.5v1.2h-1.42L15.25 20h-1.2l-1.91-4.86L10.18 20H8.92L3.25 5.2H1.5V4Z'],
vercel: ['m12 3 10 18H2L12 3Z'],
}
const TOOLS: ActivityItem[] = [
{ id: 'read', type: 'tool', action: 'read', target: 'campaign-notes.md' },
{ id: 'edit', type: 'tool', action: 'edit', target: 'launch-plan.ts', additions: 42, deletions: 8 },
{ id: 'run', type: 'tool', action: 'run', target: 'bun test launch' },
]
const ACTIVE_BRIEF: ActivityItem = { id: 'brief', type: 'step', label: 'Reading the launch brief', status: 'active' }
const COMPLETE_BRIEF: ActivityItem = { ...ACTIVE_BRIEF, status: 'complete' }
const PENDING_SEARCH: ActivityItem = { id: 'search', type: 'search', query: 'independent coffee roasters in Portland', results: [] }
const COMPLETE_SEARCH: ActivityItem = {
...PENDING_SEARCH,
results: [
{ id: 'heart', title: 'Heart Coffee', domain: 'heartroasters.com' },
{ id: 'coava', title: 'Coava Coffee', domain: 'coavacoffee.com' },
{ id: 'upper-left', title: 'Upper Left Roasters', domain: 'upperleftroasters.com' },
],
moreCount: 5,
}
const MIXED_FRAMES: ActivityItem[][] = [
[ACTIVE_BRIEF],
[COMPLETE_BRIEF, PENDING_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0]],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0], TOOLS[1], TOOLS[2], { id: 'verify', type: 'step', label: 'Checking the final campaign plan', status: 'complete' }],
]
const TRACE_ITEMS: ActivityItem[] = [
{ id: 'plan', type: 'trace', kind: 'thinking', label: 'Thinking', detail: 'Mapping the interaction flow…' },
{ id: 'decision', type: 'trace', kind: 'message', label: 'Decision', detail: 'Use one compact disclosure' },
{ id: 'write', type: 'trace', kind: 'write', label: 'Draft component', detail: 'components/agents/run-log.tsx' },
{ id: 'verify', type: 'trace', kind: 'run', label: 'Validate types', detail: 'bun run typecheck' },
{ id: 'inspect', type: 'trace', kind: 'read', label: 'Inspect preview', detail: 'activity-preview.png' },
]
const LAYOUT: Record<string, { height: number, width: string }> = {
'streaming-text': { height: 330, width: '32rem' }, 'reasoning-steps': { height: 330, width: '32rem' }, 'web-search': { height: 330, width: '32rem' },
'tool-calls': { height: 330, width: '32rem' }, 'mixed-activity': { height: 330, width: '36rem' }, 'agent-trace': { height: 300, width: '36rem' },
}
const run = shallowRef(0)
const reduce = shallowRef(false)
const mounted = shallowRef(false)
const items = shallowRef<ActivityItem[]>([])
const complete = shallowRef(false)
const settings = computed(() => ({
'streaming-text': { contentType: 'text', maxHeight: 180, duration: REASONING.length / CHARACTERS_PER_SECOND },
'reasoning-steps': { contentType: 'step', maxHeight: 220, duration: 4.2 },
'web-search': { contentType: 'search', maxHeight: 220, duration: 0 },
'tool-calls': { contentType: 'tool', maxHeight: 220, duration: 0 },
'mixed-activity': { contentType: undefined, maxHeight: 220, duration: 5.1 },
'agent-trace': { contentType: 'trace', maxHeight: 190, duration: 0 },
} as const)[variant.value as 'agent-trace'] ?? { contentType: undefined, maxHeight: 220, duration: 0 })
function stepItems(visible: number, settled: boolean): ActivityItem[] {
return STEPS.slice(0, visible).map((step, index) => ({ ...step, type: 'step' as const, status: settled || index < visible - 1 ? 'complete' as const : 'active' as const }))
}
function searchItems(visible: number): ActivityItem[] {
return [{ id: 'search', type: 'search', query: 'accessible animation patterns for Vue', results: SEARCH_RESULTS.slice(0, visible), moreCount: visible === SEARCH_RESULTS.length ? 7 : undefined }]
}
function textItems(text: string): ActivityItem[] {
return text.split('\n').filter(Boolean).map((content, index) => ({ id: `reasoning-${index}`, type: 'text' as const, content }))
}
/** Final (reduced-motion) frame for each example. */
function finalItems(name: string): ActivityItem[] {
if (name === 'streaming-text') return textItems(REASONING)
if (name === 'reasoning-steps') return stepItems(STEPS.length, true)
if (name === 'web-search') return searchItems(SEARCH_RESULTS.length)
if (name === 'tool-calls') return TOOLS
if (name === 'mixed-activity') return MIXED_FRAMES[MIXED_FRAMES.length - 1]
return TRACE_ITEMS
}
onMounted(() => { reduce.value = matchMedia('(prefers-reduced-motion: reduce)').matches; mounted.value = true })
let frame = 0
watch([variant, run, mounted], (_, __, cleanup) => {
if (!mounted.value) return
const name = variant.value
const timers: ReturnType<typeof setTimeout>[] = []
const at = (ms: number, task: () => void) => timers.push(setTimeout(task, ms))
cleanup(() => { timers.forEach(clearTimeout); cancelAnimationFrame(frame) })
if (reduce.value) { items.value = finalItems(name); complete.value = true; return }
complete.value = false
if (name === 'streaming-text') {
items.value = []
const startedAt = performance.now()
const stream = (now: number) => {
const cursor = Math.min(REASONING.length, Math.floor(((now - startedAt) / 1000) * CHARACTERS_PER_SECOND))
items.value = textItems(REASONING.slice(0, cursor))
if (cursor === REASONING.length) at(500, () => { complete.value = true })
else frame = requestAnimationFrame(stream)
}
frame = requestAnimationFrame(stream)
} else if (name === 'reasoning-steps') {
items.value = stepItems(1, false)
STEPS.slice(1).forEach((_, index) => at(850 + index * 800, () => { items.value = stepItems(index + 2, false) }))
at(3300, () => { items.value = stepItems(STEPS.length, true) })
at(4200, () => { complete.value = true })
} else if (name === 'web-search') {
items.value = searchItems(0)
SEARCH_RESULTS.forEach((_, index) => at(650 + index * 650, () => { items.value = searchItems(index + 1) }))
at(3900, () => { complete.value = true })
} else if (name === 'tool-calls') {
items.value = []
TOOLS.forEach((_, index) => at(550 + index * 850, () => { items.value = TOOLS.slice(0, index + 1) }))
at(3600, () => { complete.value = true })
} else if (name === 'mixed-activity') {
items.value = MIXED_FRAMES[0]
MIXED_FRAMES.slice(1).forEach((_, index) => at(850 + index * 1050, () => { items.value = MIXED_FRAMES[index + 1] }))
at(850 + (MIXED_FRAMES.length - 2) * 1050 + 900, () => { complete.value = true })
} else {
items.value = []
TRACE_ITEMS.forEach((_, index) => at(250 + index * 650, () => { items.value = TRACE_ITEMS.slice(0, index + 1) }))
at(250 + TRACE_ITEMS.length * 650, () => { complete.value = true })
}
}, { immediate: true })
onBeforeUnmount(() => cancelAnimationFrame(frame))
</script>
<template>
<div :key="variant" style="position:relative;width:100%" :style="{ height: `${LAYOUT[variant].height}px`, maxWidth: LAYOUT[variant].width }" :data-example-variant="variant">
<AgentActivity
:key="`${variant}-${run}`" :items="items" :content-type="settings.contentType" :status="complete ? 'complete' : 'working'" :duration="settings.duration"
:default-open="reduce" :collapse-on-complete="!reduce" :max-height="settings.maxHeight" :active-label="variant === 'agent-trace' ? 'Running the agent trace…' : undefined"
>
<template #result-icon="{ result }">
<svg v-if="MARKS[result.id]" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path v-for="d in MARKS[result.id]" :key="d" :d="d" /></svg>
</template>
</AgentActivity>
<button type="button" class="be-agent-replay" @click="run++"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /><path d="M3 3v5h5" /></svg>Replay</button>
<label v-if="!fixed" class="be-agent-variant">Example <select :value="variant" @change="choose(($event.target as HTMLSelectElement).value)"><option v-for="option in options" :key="option">{{ option }}</option></select></label>
</div>
</template><script lang="ts">
export { agentActivityMessages } from './activity-types'
export type { ActivityItem, AgentActivityMessages, AgentSearchResult, AgentStepStatus, AgentTraceKind } from './activity-types'
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onBeforeUnmount, onMounted, shallowRef, useId, watch } from 'vue'
import { easeOut, layoutSpring, swapSpring } from '../core/motion'
import { useOpenState } from '../primitives/state'
import ThinkingShimmer from '../effects/ThinkingShimmer.vue'
import ActivityRow from './ActivityRow.vue'
import AgentIcon from './AgentIcon.vue'
import AgentReveal from './AgentReveal.vue'
import { agentActivityMessages, type ActivityContentType, type ActivityItem, type AgentActivityTranslate, type AgentSearchResult } from './activity-types'
import type { Labels } from './shared'
const props = withDefaults(defineProps<{
items: ActivityItem[], contentType?: ActivityContentType, status?: 'working' | 'complete', duration?: number,
open?: boolean, defaultOpen?: boolean, collapseOnComplete?: boolean, activeLabel?: string, summary?: string, maxHeight?: number, labels?: Labels, contentClassName?: string
}>(), { status: 'working', duration: 0, open: undefined, defaultOpen: false, collapseOnComplete: true, maxHeight: 208 })
const emit = defineEmits<{ 'update:open': [value: boolean], openChange: [value: boolean] }>()
defineSlots<{
/** Replaces the live status line while the run is working. */
renderWorkingStatus?(props: { label: string, duration: number }): unknown
/** Replaces the summary inside the completed disclosure trigger. */
renderCompletedStatus?(props: { summary: string, duration: number }): unknown
/** Replaces the row renderer for one item. */
item?(props: { item: ActivityItem }): unknown
'result-icon'?(props: { result: AgentSearchResult }): unknown
'trace-icon'?(props: { item: ActivityItem }): unknown
}>()
const { open: currentOpen, setOpen } = useOpenState(() => props.open, props.defaultOpen, next => { emit('update:open', next); emit('openChange', next) })
const reduce = useReducedMotion()
const baseId = useId()
const triggerId = `${baseId}-trigger`
const contentId = `${baseId}-content`
const contentRef = shallowRef<HTMLElement | { $el: HTMLElement } | null>(null)
const viewportRef = shallowRef<HTMLElement | null>(null)
const contentHeight = shallowRef(0)
const t: AgentActivityTranslate = (key, values) => (props.labels?.[key] ?? agentActivityMessages[key]).replace(/\{(\w+)\}/g, (match, name) => values?.[name] === undefined ? match : String(values[name]))
const working = computed(() => props.status === 'working')
const expanded = computed(() => working.value || currentOpen.value)
const contentType = computed<ActivityContentType>(() => {
if (!props.items.length) return props.contentType ?? 'mixed'
const first = props.items[0].type
return props.items.every(item => item.type === first) ? first : 'mixed'
})
const cappedHeight = computed(() => Math.min(contentHeight.value, Math.max(0, props.maxHeight)))
const viewportHeight = computed(() => working.value ? Math.max(0, props.maxHeight) : cappedHeight.value)
const capped = computed(() => contentHeight.value > props.maxHeight)
const streamOffset = computed(() => working.value ? Math.min(0, viewportHeight.value - contentHeight.value) : 0)
const maskImage = computed(() => !capped.value ? undefined : working.value
? 'linear-gradient(to bottom, transparent, black 12px)'
: 'linear-gradient(to bottom, transparent, black 12px, black calc(100% - 12px), transparent)')
function formatDuration(value: number) {
const seconds = Math.max(0, Math.round(value))
if (seconds < 60) return t('seconds', { seconds })
const minutes = Math.floor(seconds / 60)
const remainder = seconds % 60
return remainder === 0 ? t('minutes', { minutes }) : t('minutesSeconds', { minutes, seconds: remainder })
}
const liveLabel = computed(() => {
if (props.activeLabel) return props.activeLabel
const type = contentType.value
if (type === 'search') return t('searching')
if (type === 'tool') return t('runningTools')
if (type === 'trace') return t('workingTrace')
if (type === 'mixed') return t('workingMixed')
return t('thinking')
})
/** Summary split around the duration so it can keep tabular figures; `parts` is a plain string otherwise. */
const summaryParts = computed<{ text: string } | { before: string, duration: string, after: string }>(() => {
if (props.summary) return { text: props.summary }
const type = contentType.value
const count = props.items.length
if (type === 'step' || type === 'text') {
const [before, after = ''] = (props.labels?.thoughtFor ?? agentActivityMessages.thoughtFor).split('{duration}')
return { before, duration: formatDuration(props.duration), after }
}
if (type === 'search') return { text: t('searched') }
if (type === 'tool') return { text: t(count === 1 ? 'ranToolsOne' : 'ranToolsOther', { count }) }
if (type === 'trace') {
const messages = props.items.filter(item => item.type === 'trace' && (item.kind === 'thinking' || item.kind === 'message')).length
const tools = count - messages
return { text: t('traceSummary', { toolCalls: t(tools === 1 ? 'toolCallsOne' : 'toolCallsOther', { count: tools }), messages: t(messages === 1 ? 'messagesOne' : 'messagesOther', { count: messages }) }) }
}
return { text: t(count === 1 ? 'completedStepsOne' : 'completedStepsOther', { count }) }
})
const summaryText = computed(() => 'text' in summaryParts.value ? summaryParts.value.text : `${summaryParts.value.before}${summaryParts.value.duration}${summaryParts.value.after}`)
let observer: ResizeObserver | undefined
let measureFrame = 0
onMounted(() => {
const target = contentRef.value
const node = target && '$el' in target ? target.$el : target
if (!node) return
const measure = () => { contentHeight.value = node.offsetHeight }
measure()
if (typeof ResizeObserver === 'undefined') return
// Vue flushes the height change on a microtask, which still runs inside this
// observer round, so the resize it causes would trip a "ResizeObserver loop"
// error. React commits the same setState on a later task; match that here.
observer = new ResizeObserver(() => {
cancelAnimationFrame(measureFrame)
measureFrame = requestAnimationFrame(measure)
})
observer.observe(node)
})
onBeforeUnmount(() => {
observer?.disconnect()
cancelAnimationFrame(measureFrame)
})
watch(() => props.status, (next, previous) => {
if (previous === 'working' && next === 'complete') setOpen(!props.collapseOnComplete)
})
let frame = 0
function toggle() {
const next = !currentOpen.value
setOpen(next)
if (next) { cancelAnimationFrame(frame); frame = requestAnimationFrame(() => viewportRef.value?.scrollTo({ top: 0 })) }
}
onBeforeUnmount(() => cancelAnimationFrame(frame))
const enter = computed(() => reduce.value ? { opacity: 1 } : { opacity: 0, y: 6 })
const exit = computed(() => reduce.value ? { opacity: 0 } : { opacity: 0, y: -3 })
const itemTransition = computed(() => reduce.value ? { duration: 0 } : { opacity: { duration: 0.18, ease: easeOut }, y: layoutSpring, layout: layoutSpring })
</script>
<template>
<div class="aa" :data-state="working ? 'working' : expanded ? 'open' : 'closed'" :data-content="contentType" :aria-busy="working">
<div v-if="working" :id="triggerId" role="status" class="aa-status">
<slot name="renderWorkingStatus" :label="liveLabel" :duration="duration"><ThinkingShimmer>{{ liveLabel }}</ThinkingShimmer></slot>
</div>
<button v-else :id="triggerId" type="button" class="aa-trigger" :aria-expanded="expanded" :aria-controls="contentId" @click="toggle">
<span class="aa-summary"><slot name="renderCompletedStatus" :summary="summaryText" :duration="duration">
<template v-if="'text' in summaryParts">{{ summaryParts.text }}</template>
<template v-else>{{ summaryParts.before }}<span class="aa-tabular">{{ summaryParts.duration }}</span>{{ summaryParts.after }}</template>
</slot></span>
<motion.span aria-hidden="true" class="aa-chevron" :animate="{ rotate: expanded ? 180 : 0 }" :transition="reduce ? { duration: 0 } : swapSpring"><AgentIcon name="ChevronDown" :size="14" /></motion.span>
</button>
<AgentReveal :id="contentId" role="region" :aria-labelledby="triggerId" :open="expanded" :open-height="viewportHeight">
<div ref="viewportRef" class="aa-viewport" :data-scroll="capped && expanded && !working || undefined" :style="{ height: `${viewportHeight}px`, maskImage, WebkitMaskImage: maskImage }">
<motion.div ref="contentRef" role="list" class="aa-list" :class="contentClassName" :initial="false" :animate="{ y: streamOffset }" :transition="reduce ? { duration: 0 } : layoutSpring">
<AnimatePresence mode="popLayout">
<motion.div v-for="item in items" :key="item.id" layout="position" role="listitem" :initial="enter" :animate="{ opacity: 1, y: 0 }" :exit="exit" :transition="itemTransition">
<slot name="item" :item="item">
<ActivityRow :item="item" :t="t"><template #result-icon="scope"><slot name="result-icon" v-bind="scope" /></template><template #trace-icon="scope"><slot name="trace-icon" v-bind="scope" /></template></ActivityRow>
</slot>
</motion.div>
</AnimatePresence>
</motion.div>
</div>
</AgentReveal>
</div>
</template>
<style scoped>
.aa { width: 100%; font-size: .875rem; line-height: 1.25rem; }
.aa-status { display: flex; height: 1.75rem; min-width: 0; align-items: center; color: var(--beui-muted-foreground); }
.aa-trigger { display: flex; height: 1.75rem; min-width: 0; align-items: center; gap: .375rem; padding: 0; border: 0; border-radius: .375rem; background: none; font: inherit; font-weight: 500; text-align: left; color: var(--beui-muted-foreground); cursor: pointer; outline: none; transition: color .15s; }
.aa-trigger:hover { color: var(--beui-foreground); }
.aa-trigger:focus-visible { box-shadow: 0 0 0 2px var(--beui-background), 0 0 0 4px var(--beui-ring); }
.aa-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aa-tabular { font-variant-numeric: tabular-nums; }
.aa-chevron { display: inline-flex; flex: none; color: color-mix(in oklab, var(--beui-muted-foreground) 70%, transparent); }
.aa-trigger:hover .aa-chevron { color: var(--beui-foreground); }
.aa-viewport { box-sizing: border-box; padding-right: .25rem; overflow-y: hidden; scrollbar-width: none; }
.aa-viewport[data-scroll] { overflow-y: auto; }
.aa-viewport::-webkit-scrollbar { display: none; }
.aa-list { display: grid; gap: .125rem; padding-block: .5rem; }
</style>Tool Calls
AgentActivity.vue<script setup lang="ts">
import { AgentActivity, type ActivityItem } from 'beui-vue'
import { computed, onBeforeUnmount, onMounted, shallowRef, watch, ref } from 'vue'
function useAgentVariant(selected: () => string | undefined, choices: Record<string,string>) {
const pinned = undefined as string | undefined
const fixed = Boolean(pinned)
const query = ref('')
const options = Object.keys(choices)
const variant = computed(() => {
const requested = pinned || selected() || query.value
return options.find(slug => requested === slug || requested === choices[slug]) ?? options[0]
})
function refresh() {
query.value = new URL(location.href).searchParams.get('variant') ?? ''
}
function choose(slug:string) {
if (fixed || !options.includes(slug)) return
const url = new URL(location.href)
url.searchParams.set('variant',slug)
history.replaceState(history.state,'',url)
refresh()
}
onMounted(() => {
if (fixed) return
refresh()
window.addEventListener('popstate',refresh)
})
onBeforeUnmount(() => window.removeEventListener('popstate',refresh))
return { variant, choose, options, fixed }
}
const props = defineProps<{ variant?: string }>()
const { variant, choose, options, fixed } = useAgentVariant(() => props.variant, {
'streaming-text': 'agents/agent-activity-text', 'reasoning-steps': 'agents/agent-activity-steps', 'web-search': 'agents/agent-activity-search',
'tool-calls': 'agents/agent-activity-tools', 'mixed-activity': 'agents/agent-activity-mixed', 'agent-trace': 'agents/agent-trace',
})
const REASONING = [
'Reading the request and separating the content model from its presentation.',
'The activity shell can stay consistent while each event supplies its own compact renderer.',
'Text remains freeform so partial tokens can update without recreating the surrounding timeline.',
'As each sentence wraps, the measured stream moves upward through a single transform instead of repeatedly jumping the native scroll position.',
'Older context stays available above the fold while the newest tokens remain crisp at the bottom edge.',
'Once the run finishes, the viewport switches from automatic following to ordinary user-controlled scrolling.',
'Opening the completed disclosure returns to the beginning so the reasoning can be read in order.',
'The capped viewport follows the latest sentence and preserves the full log after completion.',
].join('\n')
const CHARACTERS_PER_SECOND = 90
const STEPS = [
{ id: 'brief', label: 'Reading the product brief' },
{ id: 'patterns', label: 'Mapping the interaction patterns' },
{ id: 'states', label: 'Connecting the loading and completion states', meta: '3 states' },
{ id: 'verify', label: 'Verifying the final behavior' },
]
const SEARCH_RESULTS = [
{ id: 'google', title: 'Google for Developers', domain: 'developers.google.com' },
{ id: 'github', title: 'GitHub', domain: 'github.com' },
{ id: 'wikipedia', title: 'Wikipedia', domain: 'wikipedia.org' },
{ id: 'vercel', title: 'Vercel Docs', domain: 'vercel.com/docs' },
]
const MARKS: Record<string, string[]> = {
google: ['M21.35 12.23c0-.65-.06-1.28-.17-1.89H12v3.79h5.25a4.5 4.5 0 0 1-1.95 2.87v2.46h3.16c1.85-1.71 2.89-4.22 2.89-7.23Z', 'M12 21.75c2.64 0 4.86-.87 6.46-2.29L15.3 17c-.87.58-1.98.92-3.3.92a5.7 5.7 0 0 1-5.35-3.93H3.39v2.54A9.75 9.75 0 0 0 12 21.75Z', 'M6.65 13.99A5.85 5.85 0 0 1 6.34 12c0-.69.12-1.36.31-1.99V7.47H3.39A9.76 9.76 0 0 0 2.25 12c0 1.63.39 3.18 1.14 4.53l3.26-2.54Z', 'M12 6.08c1.44 0 2.73.49 3.75 1.47l2.78-2.78A9.34 9.34 0 0 0 12 2.25a9.75 9.75 0 0 0-8.61 5.22l3.26 2.54A5.7 5.7 0 0 1 12 6.08Z'],
github: ['M12 2a10 10 0 0 0-3.16 19.49c.5.09.68-.22.68-.48v-1.87c-2.78.6-3.37-1.18-3.37-1.18-.45-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.61.07-.61 1 .07 1.53 1.03 1.53 1.03.9 1.53 2.35 1.09 2.92.83.09-.65.35-1.09.64-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.98 1.03-2.68-.1-.25-.45-1.27.1-2.64 0 0 .84-.27 2.75 1.02A9.58 9.58 0 0 1 12 6.82c.85 0 1.71.11 2.51.34 1.91-1.29 2.75-1.02 2.75-1.02.55 1.37.2 2.39.1 2.64.64.7 1.03 1.59 1.03 2.68 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85v2.77c0 .27.18.58.69.48A10 10 0 0 0 12 2Z'],
wikipedia: ['M1.5 4h6v1.2H6l4.08 10.73 1.26-3.12L8.45 5.2H7.2V4h6v1.2h-1.47l1.66 4.57 1.82-4.57H13.8V4h4.9v1.2h-1.45l-3.19 7.92 1.08 2.81L19.48 5.2H18V4h4.5v1.2h-1.42L15.25 20h-1.2l-1.91-4.86L10.18 20H8.92L3.25 5.2H1.5V4Z'],
vercel: ['m12 3 10 18H2L12 3Z'],
}
const TOOLS: ActivityItem[] = [
{ id: 'read', type: 'tool', action: 'read', target: 'campaign-notes.md' },
{ id: 'edit', type: 'tool', action: 'edit', target: 'launch-plan.ts', additions: 42, deletions: 8 },
{ id: 'run', type: 'tool', action: 'run', target: 'bun test launch' },
]
const ACTIVE_BRIEF: ActivityItem = { id: 'brief', type: 'step', label: 'Reading the launch brief', status: 'active' }
const COMPLETE_BRIEF: ActivityItem = { ...ACTIVE_BRIEF, status: 'complete' }
const PENDING_SEARCH: ActivityItem = { id: 'search', type: 'search', query: 'independent coffee roasters in Portland', results: [] }
const COMPLETE_SEARCH: ActivityItem = {
...PENDING_SEARCH,
results: [
{ id: 'heart', title: 'Heart Coffee', domain: 'heartroasters.com' },
{ id: 'coava', title: 'Coava Coffee', domain: 'coavacoffee.com' },
{ id: 'upper-left', title: 'Upper Left Roasters', domain: 'upperleftroasters.com' },
],
moreCount: 5,
}
const MIXED_FRAMES: ActivityItem[][] = [
[ACTIVE_BRIEF],
[COMPLETE_BRIEF, PENDING_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0]],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0], TOOLS[1], TOOLS[2], { id: 'verify', type: 'step', label: 'Checking the final campaign plan', status: 'complete' }],
]
const TRACE_ITEMS: ActivityItem[] = [
{ id: 'plan', type: 'trace', kind: 'thinking', label: 'Thinking', detail: 'Mapping the interaction flow…' },
{ id: 'decision', type: 'trace', kind: 'message', label: 'Decision', detail: 'Use one compact disclosure' },
{ id: 'write', type: 'trace', kind: 'write', label: 'Draft component', detail: 'components/agents/run-log.tsx' },
{ id: 'verify', type: 'trace', kind: 'run', label: 'Validate types', detail: 'bun run typecheck' },
{ id: 'inspect', type: 'trace', kind: 'read', label: 'Inspect preview', detail: 'activity-preview.png' },
]
const LAYOUT: Record<string, { height: number, width: string }> = {
'streaming-text': { height: 330, width: '32rem' }, 'reasoning-steps': { height: 330, width: '32rem' }, 'web-search': { height: 330, width: '32rem' },
'tool-calls': { height: 330, width: '32rem' }, 'mixed-activity': { height: 330, width: '36rem' }, 'agent-trace': { height: 300, width: '36rem' },
}
const run = shallowRef(0)
const reduce = shallowRef(false)
const mounted = shallowRef(false)
const items = shallowRef<ActivityItem[]>([])
const complete = shallowRef(false)
const settings = computed(() => ({
'streaming-text': { contentType: 'text', maxHeight: 180, duration: REASONING.length / CHARACTERS_PER_SECOND },
'reasoning-steps': { contentType: 'step', maxHeight: 220, duration: 4.2 },
'web-search': { contentType: 'search', maxHeight: 220, duration: 0 },
'tool-calls': { contentType: 'tool', maxHeight: 220, duration: 0 },
'mixed-activity': { contentType: undefined, maxHeight: 220, duration: 5.1 },
'agent-trace': { contentType: 'trace', maxHeight: 190, duration: 0 },
} as const)[variant.value as 'agent-trace'] ?? { contentType: undefined, maxHeight: 220, duration: 0 })
function stepItems(visible: number, settled: boolean): ActivityItem[] {
return STEPS.slice(0, visible).map((step, index) => ({ ...step, type: 'step' as const, status: settled || index < visible - 1 ? 'complete' as const : 'active' as const }))
}
function searchItems(visible: number): ActivityItem[] {
return [{ id: 'search', type: 'search', query: 'accessible animation patterns for Vue', results: SEARCH_RESULTS.slice(0, visible), moreCount: visible === SEARCH_RESULTS.length ? 7 : undefined }]
}
function textItems(text: string): ActivityItem[] {
return text.split('\n').filter(Boolean).map((content, index) => ({ id: `reasoning-${index}`, type: 'text' as const, content }))
}
/** Final (reduced-motion) frame for each example. */
function finalItems(name: string): ActivityItem[] {
if (name === 'streaming-text') return textItems(REASONING)
if (name === 'reasoning-steps') return stepItems(STEPS.length, true)
if (name === 'web-search') return searchItems(SEARCH_RESULTS.length)
if (name === 'tool-calls') return TOOLS
if (name === 'mixed-activity') return MIXED_FRAMES[MIXED_FRAMES.length - 1]
return TRACE_ITEMS
}
onMounted(() => { reduce.value = matchMedia('(prefers-reduced-motion: reduce)').matches; mounted.value = true })
let frame = 0
watch([variant, run, mounted], (_, __, cleanup) => {
if (!mounted.value) return
const name = variant.value
const timers: ReturnType<typeof setTimeout>[] = []
const at = (ms: number, task: () => void) => timers.push(setTimeout(task, ms))
cleanup(() => { timers.forEach(clearTimeout); cancelAnimationFrame(frame) })
if (reduce.value) { items.value = finalItems(name); complete.value = true; return }
complete.value = false
if (name === 'streaming-text') {
items.value = []
const startedAt = performance.now()
const stream = (now: number) => {
const cursor = Math.min(REASONING.length, Math.floor(((now - startedAt) / 1000) * CHARACTERS_PER_SECOND))
items.value = textItems(REASONING.slice(0, cursor))
if (cursor === REASONING.length) at(500, () => { complete.value = true })
else frame = requestAnimationFrame(stream)
}
frame = requestAnimationFrame(stream)
} else if (name === 'reasoning-steps') {
items.value = stepItems(1, false)
STEPS.slice(1).forEach((_, index) => at(850 + index * 800, () => { items.value = stepItems(index + 2, false) }))
at(3300, () => { items.value = stepItems(STEPS.length, true) })
at(4200, () => { complete.value = true })
} else if (name === 'web-search') {
items.value = searchItems(0)
SEARCH_RESULTS.forEach((_, index) => at(650 + index * 650, () => { items.value = searchItems(index + 1) }))
at(3900, () => { complete.value = true })
} else if (name === 'tool-calls') {
items.value = []
TOOLS.forEach((_, index) => at(550 + index * 850, () => { items.value = TOOLS.slice(0, index + 1) }))
at(3600, () => { complete.value = true })
} else if (name === 'mixed-activity') {
items.value = MIXED_FRAMES[0]
MIXED_FRAMES.slice(1).forEach((_, index) => at(850 + index * 1050, () => { items.value = MIXED_FRAMES[index + 1] }))
at(850 + (MIXED_FRAMES.length - 2) * 1050 + 900, () => { complete.value = true })
} else {
items.value = []
TRACE_ITEMS.forEach((_, index) => at(250 + index * 650, () => { items.value = TRACE_ITEMS.slice(0, index + 1) }))
at(250 + TRACE_ITEMS.length * 650, () => { complete.value = true })
}
}, { immediate: true })
onBeforeUnmount(() => cancelAnimationFrame(frame))
</script>
<template>
<div :key="variant" style="position:relative;width:100%" :style="{ height: `${LAYOUT[variant].height}px`, maxWidth: LAYOUT[variant].width }" :data-example-variant="variant">
<AgentActivity
:key="`${variant}-${run}`" :items="items" :content-type="settings.contentType" :status="complete ? 'complete' : 'working'" :duration="settings.duration"
:default-open="reduce" :collapse-on-complete="!reduce" :max-height="settings.maxHeight" :active-label="variant === 'agent-trace' ? 'Running the agent trace…' : undefined"
>
<template #result-icon="{ result }">
<svg v-if="MARKS[result.id]" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path v-for="d in MARKS[result.id]" :key="d" :d="d" /></svg>
</template>
</AgentActivity>
<button type="button" class="be-agent-replay" @click="run++"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /><path d="M3 3v5h5" /></svg>Replay</button>
<label v-if="!fixed" class="be-agent-variant">Example <select :value="variant" @change="choose(($event.target as HTMLSelectElement).value)"><option v-for="option in options" :key="option">{{ option }}</option></select></label>
</div>
</template><script lang="ts">
export { agentActivityMessages } from './activity-types'
export type { ActivityItem, AgentActivityMessages, AgentSearchResult, AgentStepStatus, AgentTraceKind } from './activity-types'
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onBeforeUnmount, onMounted, shallowRef, useId, watch } from 'vue'
import { easeOut, layoutSpring, swapSpring } from '../core/motion'
import { useOpenState } from '../primitives/state'
import ThinkingShimmer from '../effects/ThinkingShimmer.vue'
import ActivityRow from './ActivityRow.vue'
import AgentIcon from './AgentIcon.vue'
import AgentReveal from './AgentReveal.vue'
import { agentActivityMessages, type ActivityContentType, type ActivityItem, type AgentActivityTranslate, type AgentSearchResult } from './activity-types'
import type { Labels } from './shared'
const props = withDefaults(defineProps<{
items: ActivityItem[], contentType?: ActivityContentType, status?: 'working' | 'complete', duration?: number,
open?: boolean, defaultOpen?: boolean, collapseOnComplete?: boolean, activeLabel?: string, summary?: string, maxHeight?: number, labels?: Labels, contentClassName?: string
}>(), { status: 'working', duration: 0, open: undefined, defaultOpen: false, collapseOnComplete: true, maxHeight: 208 })
const emit = defineEmits<{ 'update:open': [value: boolean], openChange: [value: boolean] }>()
defineSlots<{
/** Replaces the live status line while the run is working. */
renderWorkingStatus?(props: { label: string, duration: number }): unknown
/** Replaces the summary inside the completed disclosure trigger. */
renderCompletedStatus?(props: { summary: string, duration: number }): unknown
/** Replaces the row renderer for one item. */
item?(props: { item: ActivityItem }): unknown
'result-icon'?(props: { result: AgentSearchResult }): unknown
'trace-icon'?(props: { item: ActivityItem }): unknown
}>()
const { open: currentOpen, setOpen } = useOpenState(() => props.open, props.defaultOpen, next => { emit('update:open', next); emit('openChange', next) })
const reduce = useReducedMotion()
const baseId = useId()
const triggerId = `${baseId}-trigger`
const contentId = `${baseId}-content`
const contentRef = shallowRef<HTMLElement | { $el: HTMLElement } | null>(null)
const viewportRef = shallowRef<HTMLElement | null>(null)
const contentHeight = shallowRef(0)
const t: AgentActivityTranslate = (key, values) => (props.labels?.[key] ?? agentActivityMessages[key]).replace(/\{(\w+)\}/g, (match, name) => values?.[name] === undefined ? match : String(values[name]))
const working = computed(() => props.status === 'working')
const expanded = computed(() => working.value || currentOpen.value)
const contentType = computed<ActivityContentType>(() => {
if (!props.items.length) return props.contentType ?? 'mixed'
const first = props.items[0].type
return props.items.every(item => item.type === first) ? first : 'mixed'
})
const cappedHeight = computed(() => Math.min(contentHeight.value, Math.max(0, props.maxHeight)))
const viewportHeight = computed(() => working.value ? Math.max(0, props.maxHeight) : cappedHeight.value)
const capped = computed(() => contentHeight.value > props.maxHeight)
const streamOffset = computed(() => working.value ? Math.min(0, viewportHeight.value - contentHeight.value) : 0)
const maskImage = computed(() => !capped.value ? undefined : working.value
? 'linear-gradient(to bottom, transparent, black 12px)'
: 'linear-gradient(to bottom, transparent, black 12px, black calc(100% - 12px), transparent)')
function formatDuration(value: number) {
const seconds = Math.max(0, Math.round(value))
if (seconds < 60) return t('seconds', { seconds })
const minutes = Math.floor(seconds / 60)
const remainder = seconds % 60
return remainder === 0 ? t('minutes', { minutes }) : t('minutesSeconds', { minutes, seconds: remainder })
}
const liveLabel = computed(() => {
if (props.activeLabel) return props.activeLabel
const type = contentType.value
if (type === 'search') return t('searching')
if (type === 'tool') return t('runningTools')
if (type === 'trace') return t('workingTrace')
if (type === 'mixed') return t('workingMixed')
return t('thinking')
})
/** Summary split around the duration so it can keep tabular figures; `parts` is a plain string otherwise. */
const summaryParts = computed<{ text: string } | { before: string, duration: string, after: string }>(() => {
if (props.summary) return { text: props.summary }
const type = contentType.value
const count = props.items.length
if (type === 'step' || type === 'text') {
const [before, after = ''] = (props.labels?.thoughtFor ?? agentActivityMessages.thoughtFor).split('{duration}')
return { before, duration: formatDuration(props.duration), after }
}
if (type === 'search') return { text: t('searched') }
if (type === 'tool') return { text: t(count === 1 ? 'ranToolsOne' : 'ranToolsOther', { count }) }
if (type === 'trace') {
const messages = props.items.filter(item => item.type === 'trace' && (item.kind === 'thinking' || item.kind === 'message')).length
const tools = count - messages
return { text: t('traceSummary', { toolCalls: t(tools === 1 ? 'toolCallsOne' : 'toolCallsOther', { count: tools }), messages: t(messages === 1 ? 'messagesOne' : 'messagesOther', { count: messages }) }) }
}
return { text: t(count === 1 ? 'completedStepsOne' : 'completedStepsOther', { count }) }
})
const summaryText = computed(() => 'text' in summaryParts.value ? summaryParts.value.text : `${summaryParts.value.before}${summaryParts.value.duration}${summaryParts.value.after}`)
let observer: ResizeObserver | undefined
let measureFrame = 0
onMounted(() => {
const target = contentRef.value
const node = target && '$el' in target ? target.$el : target
if (!node) return
const measure = () => { contentHeight.value = node.offsetHeight }
measure()
if (typeof ResizeObserver === 'undefined') return
// Vue flushes the height change on a microtask, which still runs inside this
// observer round, so the resize it causes would trip a "ResizeObserver loop"
// error. React commits the same setState on a later task; match that here.
observer = new ResizeObserver(() => {
cancelAnimationFrame(measureFrame)
measureFrame = requestAnimationFrame(measure)
})
observer.observe(node)
})
onBeforeUnmount(() => {
observer?.disconnect()
cancelAnimationFrame(measureFrame)
})
watch(() => props.status, (next, previous) => {
if (previous === 'working' && next === 'complete') setOpen(!props.collapseOnComplete)
})
let frame = 0
function toggle() {
const next = !currentOpen.value
setOpen(next)
if (next) { cancelAnimationFrame(frame); frame = requestAnimationFrame(() => viewportRef.value?.scrollTo({ top: 0 })) }
}
onBeforeUnmount(() => cancelAnimationFrame(frame))
const enter = computed(() => reduce.value ? { opacity: 1 } : { opacity: 0, y: 6 })
const exit = computed(() => reduce.value ? { opacity: 0 } : { opacity: 0, y: -3 })
const itemTransition = computed(() => reduce.value ? { duration: 0 } : { opacity: { duration: 0.18, ease: easeOut }, y: layoutSpring, layout: layoutSpring })
</script>
<template>
<div class="aa" :data-state="working ? 'working' : expanded ? 'open' : 'closed'" :data-content="contentType" :aria-busy="working">
<div v-if="working" :id="triggerId" role="status" class="aa-status">
<slot name="renderWorkingStatus" :label="liveLabel" :duration="duration"><ThinkingShimmer>{{ liveLabel }}</ThinkingShimmer></slot>
</div>
<button v-else :id="triggerId" type="button" class="aa-trigger" :aria-expanded="expanded" :aria-controls="contentId" @click="toggle">
<span class="aa-summary"><slot name="renderCompletedStatus" :summary="summaryText" :duration="duration">
<template v-if="'text' in summaryParts">{{ summaryParts.text }}</template>
<template v-else>{{ summaryParts.before }}<span class="aa-tabular">{{ summaryParts.duration }}</span>{{ summaryParts.after }}</template>
</slot></span>
<motion.span aria-hidden="true" class="aa-chevron" :animate="{ rotate: expanded ? 180 : 0 }" :transition="reduce ? { duration: 0 } : swapSpring"><AgentIcon name="ChevronDown" :size="14" /></motion.span>
</button>
<AgentReveal :id="contentId" role="region" :aria-labelledby="triggerId" :open="expanded" :open-height="viewportHeight">
<div ref="viewportRef" class="aa-viewport" :data-scroll="capped && expanded && !working || undefined" :style="{ height: `${viewportHeight}px`, maskImage, WebkitMaskImage: maskImage }">
<motion.div ref="contentRef" role="list" class="aa-list" :class="contentClassName" :initial="false" :animate="{ y: streamOffset }" :transition="reduce ? { duration: 0 } : layoutSpring">
<AnimatePresence mode="popLayout">
<motion.div v-for="item in items" :key="item.id" layout="position" role="listitem" :initial="enter" :animate="{ opacity: 1, y: 0 }" :exit="exit" :transition="itemTransition">
<slot name="item" :item="item">
<ActivityRow :item="item" :t="t"><template #result-icon="scope"><slot name="result-icon" v-bind="scope" /></template><template #trace-icon="scope"><slot name="trace-icon" v-bind="scope" /></template></ActivityRow>
</slot>
</motion.div>
</AnimatePresence>
</motion.div>
</div>
</AgentReveal>
</div>
</template>
<style scoped>
.aa { width: 100%; font-size: .875rem; line-height: 1.25rem; }
.aa-status { display: flex; height: 1.75rem; min-width: 0; align-items: center; color: var(--beui-muted-foreground); }
.aa-trigger { display: flex; height: 1.75rem; min-width: 0; align-items: center; gap: .375rem; padding: 0; border: 0; border-radius: .375rem; background: none; font: inherit; font-weight: 500; text-align: left; color: var(--beui-muted-foreground); cursor: pointer; outline: none; transition: color .15s; }
.aa-trigger:hover { color: var(--beui-foreground); }
.aa-trigger:focus-visible { box-shadow: 0 0 0 2px var(--beui-background), 0 0 0 4px var(--beui-ring); }
.aa-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aa-tabular { font-variant-numeric: tabular-nums; }
.aa-chevron { display: inline-flex; flex: none; color: color-mix(in oklab, var(--beui-muted-foreground) 70%, transparent); }
.aa-trigger:hover .aa-chevron { color: var(--beui-foreground); }
.aa-viewport { box-sizing: border-box; padding-right: .25rem; overflow-y: hidden; scrollbar-width: none; }
.aa-viewport[data-scroll] { overflow-y: auto; }
.aa-viewport::-webkit-scrollbar { display: none; }
.aa-list { display: grid; gap: .125rem; padding-block: .5rem; }
</style>Mixed Activity
AgentActivity.vue<script setup lang="ts">
import { AgentActivity, type ActivityItem } from 'beui-vue'
import { computed, onBeforeUnmount, onMounted, shallowRef, watch, ref } from 'vue'
function useAgentVariant(selected: () => string | undefined, choices: Record<string,string>) {
const pinned = undefined as string | undefined
const fixed = Boolean(pinned)
const query = ref('')
const options = Object.keys(choices)
const variant = computed(() => {
const requested = pinned || selected() || query.value
return options.find(slug => requested === slug || requested === choices[slug]) ?? options[0]
})
function refresh() {
query.value = new URL(location.href).searchParams.get('variant') ?? ''
}
function choose(slug:string) {
if (fixed || !options.includes(slug)) return
const url = new URL(location.href)
url.searchParams.set('variant',slug)
history.replaceState(history.state,'',url)
refresh()
}
onMounted(() => {
if (fixed) return
refresh()
window.addEventListener('popstate',refresh)
})
onBeforeUnmount(() => window.removeEventListener('popstate',refresh))
return { variant, choose, options, fixed }
}
const props = defineProps<{ variant?: string }>()
const { variant, choose, options, fixed } = useAgentVariant(() => props.variant, {
'streaming-text': 'agents/agent-activity-text', 'reasoning-steps': 'agents/agent-activity-steps', 'web-search': 'agents/agent-activity-search',
'tool-calls': 'agents/agent-activity-tools', 'mixed-activity': 'agents/agent-activity-mixed', 'agent-trace': 'agents/agent-trace',
})
const REASONING = [
'Reading the request and separating the content model from its presentation.',
'The activity shell can stay consistent while each event supplies its own compact renderer.',
'Text remains freeform so partial tokens can update without recreating the surrounding timeline.',
'As each sentence wraps, the measured stream moves upward through a single transform instead of repeatedly jumping the native scroll position.',
'Older context stays available above the fold while the newest tokens remain crisp at the bottom edge.',
'Once the run finishes, the viewport switches from automatic following to ordinary user-controlled scrolling.',
'Opening the completed disclosure returns to the beginning so the reasoning can be read in order.',
'The capped viewport follows the latest sentence and preserves the full log after completion.',
].join('\n')
const CHARACTERS_PER_SECOND = 90
const STEPS = [
{ id: 'brief', label: 'Reading the product brief' },
{ id: 'patterns', label: 'Mapping the interaction patterns' },
{ id: 'states', label: 'Connecting the loading and completion states', meta: '3 states' },
{ id: 'verify', label: 'Verifying the final behavior' },
]
const SEARCH_RESULTS = [
{ id: 'google', title: 'Google for Developers', domain: 'developers.google.com' },
{ id: 'github', title: 'GitHub', domain: 'github.com' },
{ id: 'wikipedia', title: 'Wikipedia', domain: 'wikipedia.org' },
{ id: 'vercel', title: 'Vercel Docs', domain: 'vercel.com/docs' },
]
const MARKS: Record<string, string[]> = {
google: ['M21.35 12.23c0-.65-.06-1.28-.17-1.89H12v3.79h5.25a4.5 4.5 0 0 1-1.95 2.87v2.46h3.16c1.85-1.71 2.89-4.22 2.89-7.23Z', 'M12 21.75c2.64 0 4.86-.87 6.46-2.29L15.3 17c-.87.58-1.98.92-3.3.92a5.7 5.7 0 0 1-5.35-3.93H3.39v2.54A9.75 9.75 0 0 0 12 21.75Z', 'M6.65 13.99A5.85 5.85 0 0 1 6.34 12c0-.69.12-1.36.31-1.99V7.47H3.39A9.76 9.76 0 0 0 2.25 12c0 1.63.39 3.18 1.14 4.53l3.26-2.54Z', 'M12 6.08c1.44 0 2.73.49 3.75 1.47l2.78-2.78A9.34 9.34 0 0 0 12 2.25a9.75 9.75 0 0 0-8.61 5.22l3.26 2.54A5.7 5.7 0 0 1 12 6.08Z'],
github: ['M12 2a10 10 0 0 0-3.16 19.49c.5.09.68-.22.68-.48v-1.87c-2.78.6-3.37-1.18-3.37-1.18-.45-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.61.07-.61 1 .07 1.53 1.03 1.53 1.03.9 1.53 2.35 1.09 2.92.83.09-.65.35-1.09.64-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.98 1.03-2.68-.1-.25-.45-1.27.1-2.64 0 0 .84-.27 2.75 1.02A9.58 9.58 0 0 1 12 6.82c.85 0 1.71.11 2.51.34 1.91-1.29 2.75-1.02 2.75-1.02.55 1.37.2 2.39.1 2.64.64.7 1.03 1.59 1.03 2.68 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85v2.77c0 .27.18.58.69.48A10 10 0 0 0 12 2Z'],
wikipedia: ['M1.5 4h6v1.2H6l4.08 10.73 1.26-3.12L8.45 5.2H7.2V4h6v1.2h-1.47l1.66 4.57 1.82-4.57H13.8V4h4.9v1.2h-1.45l-3.19 7.92 1.08 2.81L19.48 5.2H18V4h4.5v1.2h-1.42L15.25 20h-1.2l-1.91-4.86L10.18 20H8.92L3.25 5.2H1.5V4Z'],
vercel: ['m12 3 10 18H2L12 3Z'],
}
const TOOLS: ActivityItem[] = [
{ id: 'read', type: 'tool', action: 'read', target: 'campaign-notes.md' },
{ id: 'edit', type: 'tool', action: 'edit', target: 'launch-plan.ts', additions: 42, deletions: 8 },
{ id: 'run', type: 'tool', action: 'run', target: 'bun test launch' },
]
const ACTIVE_BRIEF: ActivityItem = { id: 'brief', type: 'step', label: 'Reading the launch brief', status: 'active' }
const COMPLETE_BRIEF: ActivityItem = { ...ACTIVE_BRIEF, status: 'complete' }
const PENDING_SEARCH: ActivityItem = { id: 'search', type: 'search', query: 'independent coffee roasters in Portland', results: [] }
const COMPLETE_SEARCH: ActivityItem = {
...PENDING_SEARCH,
results: [
{ id: 'heart', title: 'Heart Coffee', domain: 'heartroasters.com' },
{ id: 'coava', title: 'Coava Coffee', domain: 'coavacoffee.com' },
{ id: 'upper-left', title: 'Upper Left Roasters', domain: 'upperleftroasters.com' },
],
moreCount: 5,
}
const MIXED_FRAMES: ActivityItem[][] = [
[ACTIVE_BRIEF],
[COMPLETE_BRIEF, PENDING_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0]],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0], TOOLS[1], TOOLS[2], { id: 'verify', type: 'step', label: 'Checking the final campaign plan', status: 'complete' }],
]
const TRACE_ITEMS: ActivityItem[] = [
{ id: 'plan', type: 'trace', kind: 'thinking', label: 'Thinking', detail: 'Mapping the interaction flow…' },
{ id: 'decision', type: 'trace', kind: 'message', label: 'Decision', detail: 'Use one compact disclosure' },
{ id: 'write', type: 'trace', kind: 'write', label: 'Draft component', detail: 'components/agents/run-log.tsx' },
{ id: 'verify', type: 'trace', kind: 'run', label: 'Validate types', detail: 'bun run typecheck' },
{ id: 'inspect', type: 'trace', kind: 'read', label: 'Inspect preview', detail: 'activity-preview.png' },
]
const LAYOUT: Record<string, { height: number, width: string }> = {
'streaming-text': { height: 330, width: '32rem' }, 'reasoning-steps': { height: 330, width: '32rem' }, 'web-search': { height: 330, width: '32rem' },
'tool-calls': { height: 330, width: '32rem' }, 'mixed-activity': { height: 330, width: '36rem' }, 'agent-trace': { height: 300, width: '36rem' },
}
const run = shallowRef(0)
const reduce = shallowRef(false)
const mounted = shallowRef(false)
const items = shallowRef<ActivityItem[]>([])
const complete = shallowRef(false)
const settings = computed(() => ({
'streaming-text': { contentType: 'text', maxHeight: 180, duration: REASONING.length / CHARACTERS_PER_SECOND },
'reasoning-steps': { contentType: 'step', maxHeight: 220, duration: 4.2 },
'web-search': { contentType: 'search', maxHeight: 220, duration: 0 },
'tool-calls': { contentType: 'tool', maxHeight: 220, duration: 0 },
'mixed-activity': { contentType: undefined, maxHeight: 220, duration: 5.1 },
'agent-trace': { contentType: 'trace', maxHeight: 190, duration: 0 },
} as const)[variant.value as 'agent-trace'] ?? { contentType: undefined, maxHeight: 220, duration: 0 })
function stepItems(visible: number, settled: boolean): ActivityItem[] {
return STEPS.slice(0, visible).map((step, index) => ({ ...step, type: 'step' as const, status: settled || index < visible - 1 ? 'complete' as const : 'active' as const }))
}
function searchItems(visible: number): ActivityItem[] {
return [{ id: 'search', type: 'search', query: 'accessible animation patterns for Vue', results: SEARCH_RESULTS.slice(0, visible), moreCount: visible === SEARCH_RESULTS.length ? 7 : undefined }]
}
function textItems(text: string): ActivityItem[] {
return text.split('\n').filter(Boolean).map((content, index) => ({ id: `reasoning-${index}`, type: 'text' as const, content }))
}
/** Final (reduced-motion) frame for each example. */
function finalItems(name: string): ActivityItem[] {
if (name === 'streaming-text') return textItems(REASONING)
if (name === 'reasoning-steps') return stepItems(STEPS.length, true)
if (name === 'web-search') return searchItems(SEARCH_RESULTS.length)
if (name === 'tool-calls') return TOOLS
if (name === 'mixed-activity') return MIXED_FRAMES[MIXED_FRAMES.length - 1]
return TRACE_ITEMS
}
onMounted(() => { reduce.value = matchMedia('(prefers-reduced-motion: reduce)').matches; mounted.value = true })
let frame = 0
watch([variant, run, mounted], (_, __, cleanup) => {
if (!mounted.value) return
const name = variant.value
const timers: ReturnType<typeof setTimeout>[] = []
const at = (ms: number, task: () => void) => timers.push(setTimeout(task, ms))
cleanup(() => { timers.forEach(clearTimeout); cancelAnimationFrame(frame) })
if (reduce.value) { items.value = finalItems(name); complete.value = true; return }
complete.value = false
if (name === 'streaming-text') {
items.value = []
const startedAt = performance.now()
const stream = (now: number) => {
const cursor = Math.min(REASONING.length, Math.floor(((now - startedAt) / 1000) * CHARACTERS_PER_SECOND))
items.value = textItems(REASONING.slice(0, cursor))
if (cursor === REASONING.length) at(500, () => { complete.value = true })
else frame = requestAnimationFrame(stream)
}
frame = requestAnimationFrame(stream)
} else if (name === 'reasoning-steps') {
items.value = stepItems(1, false)
STEPS.slice(1).forEach((_, index) => at(850 + index * 800, () => { items.value = stepItems(index + 2, false) }))
at(3300, () => { items.value = stepItems(STEPS.length, true) })
at(4200, () => { complete.value = true })
} else if (name === 'web-search') {
items.value = searchItems(0)
SEARCH_RESULTS.forEach((_, index) => at(650 + index * 650, () => { items.value = searchItems(index + 1) }))
at(3900, () => { complete.value = true })
} else if (name === 'tool-calls') {
items.value = []
TOOLS.forEach((_, index) => at(550 + index * 850, () => { items.value = TOOLS.slice(0, index + 1) }))
at(3600, () => { complete.value = true })
} else if (name === 'mixed-activity') {
items.value = MIXED_FRAMES[0]
MIXED_FRAMES.slice(1).forEach((_, index) => at(850 + index * 1050, () => { items.value = MIXED_FRAMES[index + 1] }))
at(850 + (MIXED_FRAMES.length - 2) * 1050 + 900, () => { complete.value = true })
} else {
items.value = []
TRACE_ITEMS.forEach((_, index) => at(250 + index * 650, () => { items.value = TRACE_ITEMS.slice(0, index + 1) }))
at(250 + TRACE_ITEMS.length * 650, () => { complete.value = true })
}
}, { immediate: true })
onBeforeUnmount(() => cancelAnimationFrame(frame))
</script>
<template>
<div :key="variant" style="position:relative;width:100%" :style="{ height: `${LAYOUT[variant].height}px`, maxWidth: LAYOUT[variant].width }" :data-example-variant="variant">
<AgentActivity
:key="`${variant}-${run}`" :items="items" :content-type="settings.contentType" :status="complete ? 'complete' : 'working'" :duration="settings.duration"
:default-open="reduce" :collapse-on-complete="!reduce" :max-height="settings.maxHeight" :active-label="variant === 'agent-trace' ? 'Running the agent trace…' : undefined"
>
<template #result-icon="{ result }">
<svg v-if="MARKS[result.id]" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path v-for="d in MARKS[result.id]" :key="d" :d="d" /></svg>
</template>
</AgentActivity>
<button type="button" class="be-agent-replay" @click="run++"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /><path d="M3 3v5h5" /></svg>Replay</button>
<label v-if="!fixed" class="be-agent-variant">Example <select :value="variant" @change="choose(($event.target as HTMLSelectElement).value)"><option v-for="option in options" :key="option">{{ option }}</option></select></label>
</div>
</template><script lang="ts">
export { agentActivityMessages } from './activity-types'
export type { ActivityItem, AgentActivityMessages, AgentSearchResult, AgentStepStatus, AgentTraceKind } from './activity-types'
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onBeforeUnmount, onMounted, shallowRef, useId, watch } from 'vue'
import { easeOut, layoutSpring, swapSpring } from '../core/motion'
import { useOpenState } from '../primitives/state'
import ThinkingShimmer from '../effects/ThinkingShimmer.vue'
import ActivityRow from './ActivityRow.vue'
import AgentIcon from './AgentIcon.vue'
import AgentReveal from './AgentReveal.vue'
import { agentActivityMessages, type ActivityContentType, type ActivityItem, type AgentActivityTranslate, type AgentSearchResult } from './activity-types'
import type { Labels } from './shared'
const props = withDefaults(defineProps<{
items: ActivityItem[], contentType?: ActivityContentType, status?: 'working' | 'complete', duration?: number,
open?: boolean, defaultOpen?: boolean, collapseOnComplete?: boolean, activeLabel?: string, summary?: string, maxHeight?: number, labels?: Labels, contentClassName?: string
}>(), { status: 'working', duration: 0, open: undefined, defaultOpen: false, collapseOnComplete: true, maxHeight: 208 })
const emit = defineEmits<{ 'update:open': [value: boolean], openChange: [value: boolean] }>()
defineSlots<{
/** Replaces the live status line while the run is working. */
renderWorkingStatus?(props: { label: string, duration: number }): unknown
/** Replaces the summary inside the completed disclosure trigger. */
renderCompletedStatus?(props: { summary: string, duration: number }): unknown
/** Replaces the row renderer for one item. */
item?(props: { item: ActivityItem }): unknown
'result-icon'?(props: { result: AgentSearchResult }): unknown
'trace-icon'?(props: { item: ActivityItem }): unknown
}>()
const { open: currentOpen, setOpen } = useOpenState(() => props.open, props.defaultOpen, next => { emit('update:open', next); emit('openChange', next) })
const reduce = useReducedMotion()
const baseId = useId()
const triggerId = `${baseId}-trigger`
const contentId = `${baseId}-content`
const contentRef = shallowRef<HTMLElement | { $el: HTMLElement } | null>(null)
const viewportRef = shallowRef<HTMLElement | null>(null)
const contentHeight = shallowRef(0)
const t: AgentActivityTranslate = (key, values) => (props.labels?.[key] ?? agentActivityMessages[key]).replace(/\{(\w+)\}/g, (match, name) => values?.[name] === undefined ? match : String(values[name]))
const working = computed(() => props.status === 'working')
const expanded = computed(() => working.value || currentOpen.value)
const contentType = computed<ActivityContentType>(() => {
if (!props.items.length) return props.contentType ?? 'mixed'
const first = props.items[0].type
return props.items.every(item => item.type === first) ? first : 'mixed'
})
const cappedHeight = computed(() => Math.min(contentHeight.value, Math.max(0, props.maxHeight)))
const viewportHeight = computed(() => working.value ? Math.max(0, props.maxHeight) : cappedHeight.value)
const capped = computed(() => contentHeight.value > props.maxHeight)
const streamOffset = computed(() => working.value ? Math.min(0, viewportHeight.value - contentHeight.value) : 0)
const maskImage = computed(() => !capped.value ? undefined : working.value
? 'linear-gradient(to bottom, transparent, black 12px)'
: 'linear-gradient(to bottom, transparent, black 12px, black calc(100% - 12px), transparent)')
function formatDuration(value: number) {
const seconds = Math.max(0, Math.round(value))
if (seconds < 60) return t('seconds', { seconds })
const minutes = Math.floor(seconds / 60)
const remainder = seconds % 60
return remainder === 0 ? t('minutes', { minutes }) : t('minutesSeconds', { minutes, seconds: remainder })
}
const liveLabel = computed(() => {
if (props.activeLabel) return props.activeLabel
const type = contentType.value
if (type === 'search') return t('searching')
if (type === 'tool') return t('runningTools')
if (type === 'trace') return t('workingTrace')
if (type === 'mixed') return t('workingMixed')
return t('thinking')
})
/** Summary split around the duration so it can keep tabular figures; `parts` is a plain string otherwise. */
const summaryParts = computed<{ text: string } | { before: string, duration: string, after: string }>(() => {
if (props.summary) return { text: props.summary }
const type = contentType.value
const count = props.items.length
if (type === 'step' || type === 'text') {
const [before, after = ''] = (props.labels?.thoughtFor ?? agentActivityMessages.thoughtFor).split('{duration}')
return { before, duration: formatDuration(props.duration), after }
}
if (type === 'search') return { text: t('searched') }
if (type === 'tool') return { text: t(count === 1 ? 'ranToolsOne' : 'ranToolsOther', { count }) }
if (type === 'trace') {
const messages = props.items.filter(item => item.type === 'trace' && (item.kind === 'thinking' || item.kind === 'message')).length
const tools = count - messages
return { text: t('traceSummary', { toolCalls: t(tools === 1 ? 'toolCallsOne' : 'toolCallsOther', { count: tools }), messages: t(messages === 1 ? 'messagesOne' : 'messagesOther', { count: messages }) }) }
}
return { text: t(count === 1 ? 'completedStepsOne' : 'completedStepsOther', { count }) }
})
const summaryText = computed(() => 'text' in summaryParts.value ? summaryParts.value.text : `${summaryParts.value.before}${summaryParts.value.duration}${summaryParts.value.after}`)
let observer: ResizeObserver | undefined
let measureFrame = 0
onMounted(() => {
const target = contentRef.value
const node = target && '$el' in target ? target.$el : target
if (!node) return
const measure = () => { contentHeight.value = node.offsetHeight }
measure()
if (typeof ResizeObserver === 'undefined') return
// Vue flushes the height change on a microtask, which still runs inside this
// observer round, so the resize it causes would trip a "ResizeObserver loop"
// error. React commits the same setState on a later task; match that here.
observer = new ResizeObserver(() => {
cancelAnimationFrame(measureFrame)
measureFrame = requestAnimationFrame(measure)
})
observer.observe(node)
})
onBeforeUnmount(() => {
observer?.disconnect()
cancelAnimationFrame(measureFrame)
})
watch(() => props.status, (next, previous) => {
if (previous === 'working' && next === 'complete') setOpen(!props.collapseOnComplete)
})
let frame = 0
function toggle() {
const next = !currentOpen.value
setOpen(next)
if (next) { cancelAnimationFrame(frame); frame = requestAnimationFrame(() => viewportRef.value?.scrollTo({ top: 0 })) }
}
onBeforeUnmount(() => cancelAnimationFrame(frame))
const enter = computed(() => reduce.value ? { opacity: 1 } : { opacity: 0, y: 6 })
const exit = computed(() => reduce.value ? { opacity: 0 } : { opacity: 0, y: -3 })
const itemTransition = computed(() => reduce.value ? { duration: 0 } : { opacity: { duration: 0.18, ease: easeOut }, y: layoutSpring, layout: layoutSpring })
</script>
<template>
<div class="aa" :data-state="working ? 'working' : expanded ? 'open' : 'closed'" :data-content="contentType" :aria-busy="working">
<div v-if="working" :id="triggerId" role="status" class="aa-status">
<slot name="renderWorkingStatus" :label="liveLabel" :duration="duration"><ThinkingShimmer>{{ liveLabel }}</ThinkingShimmer></slot>
</div>
<button v-else :id="triggerId" type="button" class="aa-trigger" :aria-expanded="expanded" :aria-controls="contentId" @click="toggle">
<span class="aa-summary"><slot name="renderCompletedStatus" :summary="summaryText" :duration="duration">
<template v-if="'text' in summaryParts">{{ summaryParts.text }}</template>
<template v-else>{{ summaryParts.before }}<span class="aa-tabular">{{ summaryParts.duration }}</span>{{ summaryParts.after }}</template>
</slot></span>
<motion.span aria-hidden="true" class="aa-chevron" :animate="{ rotate: expanded ? 180 : 0 }" :transition="reduce ? { duration: 0 } : swapSpring"><AgentIcon name="ChevronDown" :size="14" /></motion.span>
</button>
<AgentReveal :id="contentId" role="region" :aria-labelledby="triggerId" :open="expanded" :open-height="viewportHeight">
<div ref="viewportRef" class="aa-viewport" :data-scroll="capped && expanded && !working || undefined" :style="{ height: `${viewportHeight}px`, maskImage, WebkitMaskImage: maskImage }">
<motion.div ref="contentRef" role="list" class="aa-list" :class="contentClassName" :initial="false" :animate="{ y: streamOffset }" :transition="reduce ? { duration: 0 } : layoutSpring">
<AnimatePresence mode="popLayout">
<motion.div v-for="item in items" :key="item.id" layout="position" role="listitem" :initial="enter" :animate="{ opacity: 1, y: 0 }" :exit="exit" :transition="itemTransition">
<slot name="item" :item="item">
<ActivityRow :item="item" :t="t"><template #result-icon="scope"><slot name="result-icon" v-bind="scope" /></template><template #trace-icon="scope"><slot name="trace-icon" v-bind="scope" /></template></ActivityRow>
</slot>
</motion.div>
</AnimatePresence>
</motion.div>
</div>
</AgentReveal>
</div>
</template>
<style scoped>
.aa { width: 100%; font-size: .875rem; line-height: 1.25rem; }
.aa-status { display: flex; height: 1.75rem; min-width: 0; align-items: center; color: var(--beui-muted-foreground); }
.aa-trigger { display: flex; height: 1.75rem; min-width: 0; align-items: center; gap: .375rem; padding: 0; border: 0; border-radius: .375rem; background: none; font: inherit; font-weight: 500; text-align: left; color: var(--beui-muted-foreground); cursor: pointer; outline: none; transition: color .15s; }
.aa-trigger:hover { color: var(--beui-foreground); }
.aa-trigger:focus-visible { box-shadow: 0 0 0 2px var(--beui-background), 0 0 0 4px var(--beui-ring); }
.aa-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aa-tabular { font-variant-numeric: tabular-nums; }
.aa-chevron { display: inline-flex; flex: none; color: color-mix(in oklab, var(--beui-muted-foreground) 70%, transparent); }
.aa-trigger:hover .aa-chevron { color: var(--beui-foreground); }
.aa-viewport { box-sizing: border-box; padding-right: .25rem; overflow-y: hidden; scrollbar-width: none; }
.aa-viewport[data-scroll] { overflow-y: auto; }
.aa-viewport::-webkit-scrollbar { display: none; }
.aa-list { display: grid; gap: .125rem; padding-block: .5rem; }
</style>Agent Trace
AgentActivity.vue<script setup lang="ts">
import { AgentActivity, type ActivityItem } from 'beui-vue'
import { computed, onBeforeUnmount, onMounted, shallowRef, watch, ref } from 'vue'
function useAgentVariant(selected: () => string | undefined, choices: Record<string,string>) {
const pinned = undefined as string | undefined
const fixed = Boolean(pinned)
const query = ref('')
const options = Object.keys(choices)
const variant = computed(() => {
const requested = pinned || selected() || query.value
return options.find(slug => requested === slug || requested === choices[slug]) ?? options[0]
})
function refresh() {
query.value = new URL(location.href).searchParams.get('variant') ?? ''
}
function choose(slug:string) {
if (fixed || !options.includes(slug)) return
const url = new URL(location.href)
url.searchParams.set('variant',slug)
history.replaceState(history.state,'',url)
refresh()
}
onMounted(() => {
if (fixed) return
refresh()
window.addEventListener('popstate',refresh)
})
onBeforeUnmount(() => window.removeEventListener('popstate',refresh))
return { variant, choose, options, fixed }
}
const props = defineProps<{ variant?: string }>()
const { variant, choose, options, fixed } = useAgentVariant(() => props.variant, {
'streaming-text': 'agents/agent-activity-text', 'reasoning-steps': 'agents/agent-activity-steps', 'web-search': 'agents/agent-activity-search',
'tool-calls': 'agents/agent-activity-tools', 'mixed-activity': 'agents/agent-activity-mixed', 'agent-trace': 'agents/agent-trace',
})
const REASONING = [
'Reading the request and separating the content model from its presentation.',
'The activity shell can stay consistent while each event supplies its own compact renderer.',
'Text remains freeform so partial tokens can update without recreating the surrounding timeline.',
'As each sentence wraps, the measured stream moves upward through a single transform instead of repeatedly jumping the native scroll position.',
'Older context stays available above the fold while the newest tokens remain crisp at the bottom edge.',
'Once the run finishes, the viewport switches from automatic following to ordinary user-controlled scrolling.',
'Opening the completed disclosure returns to the beginning so the reasoning can be read in order.',
'The capped viewport follows the latest sentence and preserves the full log after completion.',
].join('\n')
const CHARACTERS_PER_SECOND = 90
const STEPS = [
{ id: 'brief', label: 'Reading the product brief' },
{ id: 'patterns', label: 'Mapping the interaction patterns' },
{ id: 'states', label: 'Connecting the loading and completion states', meta: '3 states' },
{ id: 'verify', label: 'Verifying the final behavior' },
]
const SEARCH_RESULTS = [
{ id: 'google', title: 'Google for Developers', domain: 'developers.google.com' },
{ id: 'github', title: 'GitHub', domain: 'github.com' },
{ id: 'wikipedia', title: 'Wikipedia', domain: 'wikipedia.org' },
{ id: 'vercel', title: 'Vercel Docs', domain: 'vercel.com/docs' },
]
const MARKS: Record<string, string[]> = {
google: ['M21.35 12.23c0-.65-.06-1.28-.17-1.89H12v3.79h5.25a4.5 4.5 0 0 1-1.95 2.87v2.46h3.16c1.85-1.71 2.89-4.22 2.89-7.23Z', 'M12 21.75c2.64 0 4.86-.87 6.46-2.29L15.3 17c-.87.58-1.98.92-3.3.92a5.7 5.7 0 0 1-5.35-3.93H3.39v2.54A9.75 9.75 0 0 0 12 21.75Z', 'M6.65 13.99A5.85 5.85 0 0 1 6.34 12c0-.69.12-1.36.31-1.99V7.47H3.39A9.76 9.76 0 0 0 2.25 12c0 1.63.39 3.18 1.14 4.53l3.26-2.54Z', 'M12 6.08c1.44 0 2.73.49 3.75 1.47l2.78-2.78A9.34 9.34 0 0 0 12 2.25a9.75 9.75 0 0 0-8.61 5.22l3.26 2.54A5.7 5.7 0 0 1 12 6.08Z'],
github: ['M12 2a10 10 0 0 0-3.16 19.49c.5.09.68-.22.68-.48v-1.87c-2.78.6-3.37-1.18-3.37-1.18-.45-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.61.07-.61 1 .07 1.53 1.03 1.53 1.03.9 1.53 2.35 1.09 2.92.83.09-.65.35-1.09.64-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.98 1.03-2.68-.1-.25-.45-1.27.1-2.64 0 0 .84-.27 2.75 1.02A9.58 9.58 0 0 1 12 6.82c.85 0 1.71.11 2.51.34 1.91-1.29 2.75-1.02 2.75-1.02.55 1.37.2 2.39.1 2.64.64.7 1.03 1.59 1.03 2.68 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85v2.77c0 .27.18.58.69.48A10 10 0 0 0 12 2Z'],
wikipedia: ['M1.5 4h6v1.2H6l4.08 10.73 1.26-3.12L8.45 5.2H7.2V4h6v1.2h-1.47l1.66 4.57 1.82-4.57H13.8V4h4.9v1.2h-1.45l-3.19 7.92 1.08 2.81L19.48 5.2H18V4h4.5v1.2h-1.42L15.25 20h-1.2l-1.91-4.86L10.18 20H8.92L3.25 5.2H1.5V4Z'],
vercel: ['m12 3 10 18H2L12 3Z'],
}
const TOOLS: ActivityItem[] = [
{ id: 'read', type: 'tool', action: 'read', target: 'campaign-notes.md' },
{ id: 'edit', type: 'tool', action: 'edit', target: 'launch-plan.ts', additions: 42, deletions: 8 },
{ id: 'run', type: 'tool', action: 'run', target: 'bun test launch' },
]
const ACTIVE_BRIEF: ActivityItem = { id: 'brief', type: 'step', label: 'Reading the launch brief', status: 'active' }
const COMPLETE_BRIEF: ActivityItem = { ...ACTIVE_BRIEF, status: 'complete' }
const PENDING_SEARCH: ActivityItem = { id: 'search', type: 'search', query: 'independent coffee roasters in Portland', results: [] }
const COMPLETE_SEARCH: ActivityItem = {
...PENDING_SEARCH,
results: [
{ id: 'heart', title: 'Heart Coffee', domain: 'heartroasters.com' },
{ id: 'coava', title: 'Coava Coffee', domain: 'coavacoffee.com' },
{ id: 'upper-left', title: 'Upper Left Roasters', domain: 'upperleftroasters.com' },
],
moreCount: 5,
}
const MIXED_FRAMES: ActivityItem[][] = [
[ACTIVE_BRIEF],
[COMPLETE_BRIEF, PENDING_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0]],
[COMPLETE_BRIEF, COMPLETE_SEARCH, TOOLS[0], TOOLS[1], TOOLS[2], { id: 'verify', type: 'step', label: 'Checking the final campaign plan', status: 'complete' }],
]
const TRACE_ITEMS: ActivityItem[] = [
{ id: 'plan', type: 'trace', kind: 'thinking', label: 'Thinking', detail: 'Mapping the interaction flow…' },
{ id: 'decision', type: 'trace', kind: 'message', label: 'Decision', detail: 'Use one compact disclosure' },
{ id: 'write', type: 'trace', kind: 'write', label: 'Draft component', detail: 'components/agents/run-log.tsx' },
{ id: 'verify', type: 'trace', kind: 'run', label: 'Validate types', detail: 'bun run typecheck' },
{ id: 'inspect', type: 'trace', kind: 'read', label: 'Inspect preview', detail: 'activity-preview.png' },
]
const LAYOUT: Record<string, { height: number, width: string }> = {
'streaming-text': { height: 330, width: '32rem' }, 'reasoning-steps': { height: 330, width: '32rem' }, 'web-search': { height: 330, width: '32rem' },
'tool-calls': { height: 330, width: '32rem' }, 'mixed-activity': { height: 330, width: '36rem' }, 'agent-trace': { height: 300, width: '36rem' },
}
const run = shallowRef(0)
const reduce = shallowRef(false)
const mounted = shallowRef(false)
const items = shallowRef<ActivityItem[]>([])
const complete = shallowRef(false)
const settings = computed(() => ({
'streaming-text': { contentType: 'text', maxHeight: 180, duration: REASONING.length / CHARACTERS_PER_SECOND },
'reasoning-steps': { contentType: 'step', maxHeight: 220, duration: 4.2 },
'web-search': { contentType: 'search', maxHeight: 220, duration: 0 },
'tool-calls': { contentType: 'tool', maxHeight: 220, duration: 0 },
'mixed-activity': { contentType: undefined, maxHeight: 220, duration: 5.1 },
'agent-trace': { contentType: 'trace', maxHeight: 190, duration: 0 },
} as const)[variant.value as 'agent-trace'] ?? { contentType: undefined, maxHeight: 220, duration: 0 })
function stepItems(visible: number, settled: boolean): ActivityItem[] {
return STEPS.slice(0, visible).map((step, index) => ({ ...step, type: 'step' as const, status: settled || index < visible - 1 ? 'complete' as const : 'active' as const }))
}
function searchItems(visible: number): ActivityItem[] {
return [{ id: 'search', type: 'search', query: 'accessible animation patterns for Vue', results: SEARCH_RESULTS.slice(0, visible), moreCount: visible === SEARCH_RESULTS.length ? 7 : undefined }]
}
function textItems(text: string): ActivityItem[] {
return text.split('\n').filter(Boolean).map((content, index) => ({ id: `reasoning-${index}`, type: 'text' as const, content }))
}
/** Final (reduced-motion) frame for each example. */
function finalItems(name: string): ActivityItem[] {
if (name === 'streaming-text') return textItems(REASONING)
if (name === 'reasoning-steps') return stepItems(STEPS.length, true)
if (name === 'web-search') return searchItems(SEARCH_RESULTS.length)
if (name === 'tool-calls') return TOOLS
if (name === 'mixed-activity') return MIXED_FRAMES[MIXED_FRAMES.length - 1]
return TRACE_ITEMS
}
onMounted(() => { reduce.value = matchMedia('(prefers-reduced-motion: reduce)').matches; mounted.value = true })
let frame = 0
watch([variant, run, mounted], (_, __, cleanup) => {
if (!mounted.value) return
const name = variant.value
const timers: ReturnType<typeof setTimeout>[] = []
const at = (ms: number, task: () => void) => timers.push(setTimeout(task, ms))
cleanup(() => { timers.forEach(clearTimeout); cancelAnimationFrame(frame) })
if (reduce.value) { items.value = finalItems(name); complete.value = true; return }
complete.value = false
if (name === 'streaming-text') {
items.value = []
const startedAt = performance.now()
const stream = (now: number) => {
const cursor = Math.min(REASONING.length, Math.floor(((now - startedAt) / 1000) * CHARACTERS_PER_SECOND))
items.value = textItems(REASONING.slice(0, cursor))
if (cursor === REASONING.length) at(500, () => { complete.value = true })
else frame = requestAnimationFrame(stream)
}
frame = requestAnimationFrame(stream)
} else if (name === 'reasoning-steps') {
items.value = stepItems(1, false)
STEPS.slice(1).forEach((_, index) => at(850 + index * 800, () => { items.value = stepItems(index + 2, false) }))
at(3300, () => { items.value = stepItems(STEPS.length, true) })
at(4200, () => { complete.value = true })
} else if (name === 'web-search') {
items.value = searchItems(0)
SEARCH_RESULTS.forEach((_, index) => at(650 + index * 650, () => { items.value = searchItems(index + 1) }))
at(3900, () => { complete.value = true })
} else if (name === 'tool-calls') {
items.value = []
TOOLS.forEach((_, index) => at(550 + index * 850, () => { items.value = TOOLS.slice(0, index + 1) }))
at(3600, () => { complete.value = true })
} else if (name === 'mixed-activity') {
items.value = MIXED_FRAMES[0]
MIXED_FRAMES.slice(1).forEach((_, index) => at(850 + index * 1050, () => { items.value = MIXED_FRAMES[index + 1] }))
at(850 + (MIXED_FRAMES.length - 2) * 1050 + 900, () => { complete.value = true })
} else {
items.value = []
TRACE_ITEMS.forEach((_, index) => at(250 + index * 650, () => { items.value = TRACE_ITEMS.slice(0, index + 1) }))
at(250 + TRACE_ITEMS.length * 650, () => { complete.value = true })
}
}, { immediate: true })
onBeforeUnmount(() => cancelAnimationFrame(frame))
</script>
<template>
<div :key="variant" style="position:relative;width:100%" :style="{ height: `${LAYOUT[variant].height}px`, maxWidth: LAYOUT[variant].width }" :data-example-variant="variant">
<AgentActivity
:key="`${variant}-${run}`" :items="items" :content-type="settings.contentType" :status="complete ? 'complete' : 'working'" :duration="settings.duration"
:default-open="reduce" :collapse-on-complete="!reduce" :max-height="settings.maxHeight" :active-label="variant === 'agent-trace' ? 'Running the agent trace…' : undefined"
>
<template #result-icon="{ result }">
<svg v-if="MARKS[result.id]" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path v-for="d in MARKS[result.id]" :key="d" :d="d" /></svg>
</template>
</AgentActivity>
<button type="button" class="be-agent-replay" @click="run++"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /><path d="M3 3v5h5" /></svg>Replay</button>
<label v-if="!fixed" class="be-agent-variant">Example <select :value="variant" @change="choose(($event.target as HTMLSelectElement).value)"><option v-for="option in options" :key="option">{{ option }}</option></select></label>
</div>
</template><script lang="ts">
export { agentActivityMessages } from './activity-types'
export type { ActivityItem, AgentActivityMessages, AgentSearchResult, AgentStepStatus, AgentTraceKind } from './activity-types'
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onBeforeUnmount, onMounted, shallowRef, useId, watch } from 'vue'
import { easeOut, layoutSpring, swapSpring } from '../core/motion'
import { useOpenState } from '../primitives/state'
import ThinkingShimmer from '../effects/ThinkingShimmer.vue'
import ActivityRow from './ActivityRow.vue'
import AgentIcon from './AgentIcon.vue'
import AgentReveal from './AgentReveal.vue'
import { agentActivityMessages, type ActivityContentType, type ActivityItem, type AgentActivityTranslate, type AgentSearchResult } from './activity-types'
import type { Labels } from './shared'
const props = withDefaults(defineProps<{
items: ActivityItem[], contentType?: ActivityContentType, status?: 'working' | 'complete', duration?: number,
open?: boolean, defaultOpen?: boolean, collapseOnComplete?: boolean, activeLabel?: string, summary?: string, maxHeight?: number, labels?: Labels, contentClassName?: string
}>(), { status: 'working', duration: 0, open: undefined, defaultOpen: false, collapseOnComplete: true, maxHeight: 208 })
const emit = defineEmits<{ 'update:open': [value: boolean], openChange: [value: boolean] }>()
defineSlots<{
/** Replaces the live status line while the run is working. */
renderWorkingStatus?(props: { label: string, duration: number }): unknown
/** Replaces the summary inside the completed disclosure trigger. */
renderCompletedStatus?(props: { summary: string, duration: number }): unknown
/** Replaces the row renderer for one item. */
item?(props: { item: ActivityItem }): unknown
'result-icon'?(props: { result: AgentSearchResult }): unknown
'trace-icon'?(props: { item: ActivityItem }): unknown
}>()
const { open: currentOpen, setOpen } = useOpenState(() => props.open, props.defaultOpen, next => { emit('update:open', next); emit('openChange', next) })
const reduce = useReducedMotion()
const baseId = useId()
const triggerId = `${baseId}-trigger`
const contentId = `${baseId}-content`
const contentRef = shallowRef<HTMLElement | { $el: HTMLElement } | null>(null)
const viewportRef = shallowRef<HTMLElement | null>(null)
const contentHeight = shallowRef(0)
const t: AgentActivityTranslate = (key, values) => (props.labels?.[key] ?? agentActivityMessages[key]).replace(/\{(\w+)\}/g, (match, name) => values?.[name] === undefined ? match : String(values[name]))
const working = computed(() => props.status === 'working')
const expanded = computed(() => working.value || currentOpen.value)
const contentType = computed<ActivityContentType>(() => {
if (!props.items.length) return props.contentType ?? 'mixed'
const first = props.items[0].type
return props.items.every(item => item.type === first) ? first : 'mixed'
})
const cappedHeight = computed(() => Math.min(contentHeight.value, Math.max(0, props.maxHeight)))
const viewportHeight = computed(() => working.value ? Math.max(0, props.maxHeight) : cappedHeight.value)
const capped = computed(() => contentHeight.value > props.maxHeight)
const streamOffset = computed(() => working.value ? Math.min(0, viewportHeight.value - contentHeight.value) : 0)
const maskImage = computed(() => !capped.value ? undefined : working.value
? 'linear-gradient(to bottom, transparent, black 12px)'
: 'linear-gradient(to bottom, transparent, black 12px, black calc(100% - 12px), transparent)')
function formatDuration(value: number) {
const seconds = Math.max(0, Math.round(value))
if (seconds < 60) return t('seconds', { seconds })
const minutes = Math.floor(seconds / 60)
const remainder = seconds % 60
return remainder === 0 ? t('minutes', { minutes }) : t('minutesSeconds', { minutes, seconds: remainder })
}
const liveLabel = computed(() => {
if (props.activeLabel) return props.activeLabel
const type = contentType.value
if (type === 'search') return t('searching')
if (type === 'tool') return t('runningTools')
if (type === 'trace') return t('workingTrace')
if (type === 'mixed') return t('workingMixed')
return t('thinking')
})
/** Summary split around the duration so it can keep tabular figures; `parts` is a plain string otherwise. */
const summaryParts = computed<{ text: string } | { before: string, duration: string, after: string }>(() => {
if (props.summary) return { text: props.summary }
const type = contentType.value
const count = props.items.length
if (type === 'step' || type === 'text') {
const [before, after = ''] = (props.labels?.thoughtFor ?? agentActivityMessages.thoughtFor).split('{duration}')
return { before, duration: formatDuration(props.duration), after }
}
if (type === 'search') return { text: t('searched') }
if (type === 'tool') return { text: t(count === 1 ? 'ranToolsOne' : 'ranToolsOther', { count }) }
if (type === 'trace') {
const messages = props.items.filter(item => item.type === 'trace' && (item.kind === 'thinking' || item.kind === 'message')).length
const tools = count - messages
return { text: t('traceSummary', { toolCalls: t(tools === 1 ? 'toolCallsOne' : 'toolCallsOther', { count: tools }), messages: t(messages === 1 ? 'messagesOne' : 'messagesOther', { count: messages }) }) }
}
return { text: t(count === 1 ? 'completedStepsOne' : 'completedStepsOther', { count }) }
})
const summaryText = computed(() => 'text' in summaryParts.value ? summaryParts.value.text : `${summaryParts.value.before}${summaryParts.value.duration}${summaryParts.value.after}`)
let observer: ResizeObserver | undefined
let measureFrame = 0
onMounted(() => {
const target = contentRef.value
const node = target && '$el' in target ? target.$el : target
if (!node) return
const measure = () => { contentHeight.value = node.offsetHeight }
measure()
if (typeof ResizeObserver === 'undefined') return
// Vue flushes the height change on a microtask, which still runs inside this
// observer round, so the resize it causes would trip a "ResizeObserver loop"
// error. React commits the same setState on a later task; match that here.
observer = new ResizeObserver(() => {
cancelAnimationFrame(measureFrame)
measureFrame = requestAnimationFrame(measure)
})
observer.observe(node)
})
onBeforeUnmount(() => {
observer?.disconnect()
cancelAnimationFrame(measureFrame)
})
watch(() => props.status, (next, previous) => {
if (previous === 'working' && next === 'complete') setOpen(!props.collapseOnComplete)
})
let frame = 0
function toggle() {
const next = !currentOpen.value
setOpen(next)
if (next) { cancelAnimationFrame(frame); frame = requestAnimationFrame(() => viewportRef.value?.scrollTo({ top: 0 })) }
}
onBeforeUnmount(() => cancelAnimationFrame(frame))
const enter = computed(() => reduce.value ? { opacity: 1 } : { opacity: 0, y: 6 })
const exit = computed(() => reduce.value ? { opacity: 0 } : { opacity: 0, y: -3 })
const itemTransition = computed(() => reduce.value ? { duration: 0 } : { opacity: { duration: 0.18, ease: easeOut }, y: layoutSpring, layout: layoutSpring })
</script>
<template>
<div class="aa" :data-state="working ? 'working' : expanded ? 'open' : 'closed'" :data-content="contentType" :aria-busy="working">
<div v-if="working" :id="triggerId" role="status" class="aa-status">
<slot name="renderWorkingStatus" :label="liveLabel" :duration="duration"><ThinkingShimmer>{{ liveLabel }}</ThinkingShimmer></slot>
</div>
<button v-else :id="triggerId" type="button" class="aa-trigger" :aria-expanded="expanded" :aria-controls="contentId" @click="toggle">
<span class="aa-summary"><slot name="renderCompletedStatus" :summary="summaryText" :duration="duration">
<template v-if="'text' in summaryParts">{{ summaryParts.text }}</template>
<template v-else>{{ summaryParts.before }}<span class="aa-tabular">{{ summaryParts.duration }}</span>{{ summaryParts.after }}</template>
</slot></span>
<motion.span aria-hidden="true" class="aa-chevron" :animate="{ rotate: expanded ? 180 : 0 }" :transition="reduce ? { duration: 0 } : swapSpring"><AgentIcon name="ChevronDown" :size="14" /></motion.span>
</button>
<AgentReveal :id="contentId" role="region" :aria-labelledby="triggerId" :open="expanded" :open-height="viewportHeight">
<div ref="viewportRef" class="aa-viewport" :data-scroll="capped && expanded && !working || undefined" :style="{ height: `${viewportHeight}px`, maskImage, WebkitMaskImage: maskImage }">
<motion.div ref="contentRef" role="list" class="aa-list" :class="contentClassName" :initial="false" :animate="{ y: streamOffset }" :transition="reduce ? { duration: 0 } : layoutSpring">
<AnimatePresence mode="popLayout">
<motion.div v-for="item in items" :key="item.id" layout="position" role="listitem" :initial="enter" :animate="{ opacity: 1, y: 0 }" :exit="exit" :transition="itemTransition">
<slot name="item" :item="item">
<ActivityRow :item="item" :t="t"><template #result-icon="scope"><slot name="result-icon" v-bind="scope" /></template><template #trace-icon="scope"><slot name="trace-icon" v-bind="scope" /></template></ActivityRow>
</slot>
</motion.div>
</AnimatePresence>
</motion.div>
</div>
</AgentReveal>
</div>
</template>
<style scoped>
.aa { width: 100%; font-size: .875rem; line-height: 1.25rem; }
.aa-status { display: flex; height: 1.75rem; min-width: 0; align-items: center; color: var(--beui-muted-foreground); }
.aa-trigger { display: flex; height: 1.75rem; min-width: 0; align-items: center; gap: .375rem; padding: 0; border: 0; border-radius: .375rem; background: none; font: inherit; font-weight: 500; text-align: left; color: var(--beui-muted-foreground); cursor: pointer; outline: none; transition: color .15s; }
.aa-trigger:hover { color: var(--beui-foreground); }
.aa-trigger:focus-visible { box-shadow: 0 0 0 2px var(--beui-background), 0 0 0 4px var(--beui-ring); }
.aa-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aa-tabular { font-variant-numeric: tabular-nums; }
.aa-chevron { display: inline-flex; flex: none; color: color-mix(in oklab, var(--beui-muted-foreground) 70%, transparent); }
.aa-trigger:hover .aa-chevron { color: var(--beui-foreground); }
.aa-viewport { box-sizing: border-box; padding-right: .25rem; overflow-y: hidden; scrollbar-width: none; }
.aa-viewport[data-scroll] { overflow-y: auto; }
.aa-viewport::-webkit-scrollbar { display: none; }
.aa-list { display: grid; gap: .125rem; padding-block: .5rem; }
</style>API Reference
itemsActivityItem[]Chronological activity entries. Append or update items as events stream.
—contentType?ActivityContentTypeExpected activity kind before the first streamed item arrives.
—status?"working" | "complete"Current run phase. Active runs always stay expanded.
workingduration?numberElapsed run time, in seconds. Used by the step-only summary.
0v-model:open?booleanControlled expanded state used after the run completes.
undefineddefaultOpen?booleanInitial expanded state used after the run completes.
falsecollapseOnComplete?booleanCollapse the disclosure when status changes from working to complete.
trueactiveLabel?stringOptional label shown while the run is active.
—summary?stringOptional completed summary. Derived from the item types by default.
—#renderWorkingStatus?{ label: string, duration: number }Replaces the live status line while the run is working.
—#renderCompletedStatus?{ summary: string, duration: number }Replaces the summary inside the completed disclosure trigger.
—maxHeight?numberMaximum visible activity height before the stream begins gliding.
208labels?LabelsOverride any built-in string. Pick `One`/`Other` keys by count; `{count}`, `{duration}`, `{seconds}` and `{minutes}` fill the matching messages.
—class?string—contentClassName?string—@open-change?(value: boolean) => void—#item?{ item: ActivityItem }Replaces the row renderer for one item.
—#result-icon?{ result: AgentSearchResult }—#trace-icon?{ item: ActivityItem }—Install
Add it with your package manager, or copy the source manually.
Run it in a project set up with shadcn-vue. The source is copied to components/beui and its dependencies are added to your package.json. Read the shadcn-vue guide
$ bunx --bun shadcn-vue@latest add @beui-vue/agent-activity$ bun add beui-vueDownload the release archive to your project root, then install the local file.
$ bun add ./beui-vue-0.1.0.tgzImport the shared styles once in your application.
import AgentActivity from '@/components/beui/agents/AgentActivity.vue'
import '@/components/beui/styles.css'Composition
Render progressive work as message content so it remains attached to the turn that produced it.
Message
└── MessageContent
└── AgentActivityNote: Agent Loading States covers the interval before the first structured event. Todo List separates durable planned work from transient events. Tool Result expands one completed execution into inspectable output.
How it works
Agent activity explains how work is progressing without exposing an unfiltered internal transcript. Events should arrive chronologically, remain easy to scan, and reduce to a useful summary when the run finishes.
Related components
Tool Result
A lightweight execution disclosure for syntax-highlighted terminal output and request responses that collapses into a compact completed state.
Tool Approval
A human-in-the-loop permission card for reviewing tool details, allowing once, remembering access, or denying execution.
Agent Loading States
Three thoughtful loading states for AI interfaces: shimmering status text, live agent progress, and cycling reasoning phrases.
Updated