10.7k

Tool

PreviousNext

Displays a tool call the agent makes, from input to output.

Which package managers are installed?
command not found: pnpm

Node 24 and npm 11 are installed. pnpm is not.

<script setup lang="ts">
import { TerminalIcon } from '@lucide/vue'
import { promiseTimeout, tryOnScopeDispose } from '@vueuse/core'
import { computed, reactive, ref } from 'vue'
import { Bubble, BubbleContent } from '@/components/ui/bubble'
import { Button } from '@/components/ui/button'
import { CodeBlock, CodeBlockContent } from '@/components/ui/code-block'
import { Message, MessageContent } from '@/components/ui/message'
import {
  Trace,
  TraceCollapsible,
  TraceCollapsibleContent,
  TraceCollapsibleTrigger,
  TraceIcon,
  TraceLine,
  TraceTitle,
} from '@/components/ui/trace'

interface ToolPart {
  type: 'tool-runCommand'
  toolCallId: string
  state: 'input-available' | 'output-available' | 'output-error'
  input: { command: string }
  output?: { stdout: string }
  errorText?: string
}

interface TextPart {
  type: 'text'
  text: string
}

interface ChatMessage {
  id: string
  role: 'user' | 'assistant'
  parts: (ToolPart | TextPart)[]
}

const QUESTION = 'Which package managers are installed?'
const ANSWER = 'Node 24 and npm 11 are installed. pnpm is not.'

// The commands the agent runs, in order, with their result.
const SCRIPT: ({ command: string, stdout: string } | { command: string, error: string })[] = [
  { command: 'node --version', stdout: 'v24.18.0' },
  { command: 'npm --version', stdout: '11.6.2' },
  { command: 'pnpm --version', error: 'command not found: pnpm' },
]

function finish(part: ToolPart, step: (typeof SCRIPT)[number]) {
  if ('error' in step) {
    part.state = 'output-error'
    part.errorText = step.error
  }
  else {
    part.state = 'output-available'
    part.output = { stdout: step.stdout }
  }
  return part
}

function transcript(): ChatMessage[] {
  return [
    { id: 'user-0', role: 'user', parts: [{ type: 'text', text: QUESTION }] },
    {
      id: 'assistant-0',
      role: 'assistant',
      parts: [
        ...SCRIPT.map((step, index) => finish({
          type: 'tool-runCommand',
          toolCallId: `call-0-${index}`,
          state: 'input-available',
          input: { command: step.command },
        }, step)),
        { type: 'text', text: ANSWER },
      ],
    },
  ]
}

const messages = ref<ChatMessage[]>(transcript())
const status = ref<'ready' | 'submitted' | 'streaming'>('ready')
const busy = computed(() => status.value !== 'ready')

// The finished transcript starts with the failed call open.
const initial = ref(true)

// Unmounting bumps `run`, so a running script stops at its next wait.
let run = 0
tryOnScopeDispose(() => run++)

async function sleep(ms: number) {
  const id = run
  await promiseTimeout(ms)
  return id === run
}

async function streamInto(target: { text: string }, text: string, delayMs: number) {
  for (const chunk of text.match(/\S+\s*/g) ?? []) {
    target.text += chunk
    if (!(await sleep(delayMs)))
      return false
  }
  return true
}

function getText(message: ChatMessage) {
  return message.parts
    .filter((part): part is TextPart => part.type === 'text')
    .map(part => part.text)
    .join('')
}

function getTools(message: ChatMessage) {
  return message.parts.filter((part): part is ToolPart => part.type === 'tool-runCommand')
}

function isStreaming(message: ChatMessage) {
  return busy.value && message === messages.value.at(-1)
}

async function replay() {
  const id = ++run
  initial.value = false
  messages.value = [{ id: `user-${id}`, role: 'user', parts: [{ type: 'text', text: QUESTION }] }]
  status.value = 'submitted'
  if (!(await sleep(300)))
    return

  const message = reactive<ChatMessage>({ id: `assistant-${id}`, role: 'assistant', parts: [] })
  messages.value.push(message)
  status.value = 'streaming'

  for (const [index, step] of SCRIPT.entries()) {
    const part = reactive<ToolPart>({
      type: 'tool-runCommand',
      toolCallId: `call-${id}-${index}`,
      state: 'input-available',
      input: { command: step.command },
    })
    message.parts.push(part)
    if (!(await sleep(900)))
      return
    finish(part, step)
  }

  const text = reactive<TextPart>({ type: 'text', text: '' })
  message.parts.push(text)
  if (!(await streamInto(text, ANSWER, 20)))
    return
  status.value = 'ready'
}
</script>

<template>
  <div class="flex min-h-72 w-full max-w-sm flex-col gap-4 py-6 text-sm">
    <template v-for="message in messages" :key="message.id">
      <Message v-if="message.role === 'user'" align="end">
        <MessageContent>
          <Bubble align="end" variant="muted">
            <BubbleContent>{{ getText(message) }}</BubbleContent>
          </Bubble>
        </MessageContent>
      </Message>
      <Message v-else>
        <MessageContent class="gap-4">
          <Trace v-if="getTools(message).length > 0">
            <template v-for="part in getTools(message)" :key="part.toolCallId">
              <TraceCollapsible
                v-if="part.state === 'output-available' || part.state === 'output-error'"
                :default-open="initial && part.state === 'output-error'"
              >
                <TraceCollapsibleTrigger>
                  <TraceLine :status="part.state === 'output-error' ? 'error' : undefined">
                    <TraceIcon>
                      <TerminalIcon />
                    </TraceIcon>
                    <TraceTitle>
                      {{ part.state === 'output-error' ? 'Failed to run' : 'Ran' }} {{ part.input.command }}
                    </TraceTitle>
                  </TraceLine>
                </TraceCollapsibleTrigger>
                <TraceCollapsibleContent>
                  <CodeBlock size="sm">
                    <CodeBlockContent wrap class="max-h-64">
                      {{ part.state === 'output-error' ? part.errorText : part.output?.stdout }}
                    </CodeBlockContent>
                  </CodeBlock>
                </TraceCollapsibleContent>
              </TraceCollapsible>
              <TraceLine v-else :status="isStreaming(message) ? 'running' : 'error'">
                <TraceIcon>
                  <TerminalIcon />
                </TraceIcon>
                <TraceTitle>
                  {{ isStreaming(message) ? 'Running' : 'Failed to run' }} {{ part.input.command }}
                </TraceTitle>
              </TraceLine>
            </template>
          </Trace>
          <p v-if="getText(message)">
            {{ getText(message) }}
          </p>
        </MessageContent>
      </Message>
    </template>
    <Button
      v-if="!busy"
      variant="outline"
      size="sm"
      class="mt-auto self-start"
      @click="replay"
    >
      Replay
    </Button>
  </div>
</template>

Tool is a tool call the agent makes, such as running a command or reading a file. The line follows the call from input to output, including errors and calls that wait for approval.

Tool is built with Trace with a TraceCollapsible for each call that has output.

Installation

Tool is built with the Trace and Code Block components.

pnpm dlx shadcn-vue@latest add trace code-block

Usage

<script setup lang="ts">
import { TerminalIcon } from '@lucide/vue'
import { CodeBlock, CodeBlockContent } from '@/components/ui/code-block'
import {
  Trace,
  TraceCollapsible,
  TraceCollapsibleContent,
  TraceCollapsibleTrigger,
  TraceIcon,
  TraceLine,
  TraceTitle,
} from '@/components/ui/trace'
</script>

<template>
  <Trace>
    <TraceCollapsible>
      <TraceCollapsibleTrigger>
        <TraceLine>
          <TraceIcon>
            <TerminalIcon />
          </TraceIcon>
          <TraceTitle>Ran git status --short</TraceTitle>
        </TraceLine>
      </TraceCollapsibleTrigger>
      <TraceCollapsibleContent>
        <CodeBlock size="sm">
          <CodeBlockContent wrap class="max-h-64">
            {{ output }}
          </CodeBlockContent>
        </CodeBlock>
      </TraceCollapsibleContent>
    </TraceCollapsible>
  </Trace>
</template>

States

Trace does not read tool parts. Map each part's state to a status and a title.

Denied rm -rf distRunning pnpm test
<script setup lang="ts">
import { TerminalIcon } from '@lucide/vue'
import { CodeBlock, CodeBlockContent } from '@/components/ui/code-block'
import {
  Trace,
  TraceCollapsible,
  TraceCollapsibleContent,
  TraceCollapsibleTrigger,
  TraceIcon,
  TraceLine,
  TraceTitle,
} from '@/components/ui/trace'

const status = ` M server/api/chat.post.ts
 M components/Chat.vue`
</script>

<template>
  <Trace class="max-w-sm">
    <TraceCollapsible>
      <TraceCollapsibleTrigger>
        <TraceLine>
          <TraceIcon>
            <TerminalIcon />
          </TraceIcon>
          <TraceTitle>Ran git status --short</TraceTitle>
        </TraceLine>
      </TraceCollapsibleTrigger>
      <TraceCollapsibleContent>
        <CodeBlock size="sm">
          <CodeBlockContent wrap class="max-h-64">
            {{ status }}
          </CodeBlockContent>
        </CodeBlock>
      </TraceCollapsibleContent>
    </TraceCollapsible>
    <TraceCollapsible>
      <TraceCollapsibleTrigger>
        <TraceLine status="error">
          <TraceIcon>
            <TerminalIcon />
          </TraceIcon>
          <TraceTitle>Failed to run pnpm dev</TraceTitle>
        </TraceLine>
      </TraceCollapsibleTrigger>
      <TraceCollapsibleContent>
        <CodeBlock size="sm">
          <CodeBlockContent wrap class="max-h-64">
            Command timed out after 120 seconds.
          </CodeBlockContent>
        </CodeBlock>
      </TraceCollapsibleContent>
    </TraceCollapsible>
    <TraceLine>
      <TraceIcon>
        <TerminalIcon />
      </TraceIcon>
      <TraceTitle>Denied rm -rf dist</TraceTitle>
    </TraceLine>
    <TraceLine status="running">
      <TraceIcon>
        <TerminalIcon />
      </TraceIcon>
      <TraceTitle>Running pnpm test</TraceTitle>
    </TraceLine>
  </Trace>
</template>
Tool part statestatusTitle
input-streaming, input-available"running" while the chat streamsRunning …
input-streaming, input-available after the chat stops"error"Failed to run …
approval-requested-Not a line. An Item outside Trace with Approve and Deny buttons.
approval-responded"running" if approved, none if notRunning … if approved, Denied … if not
output-availablenoneRan …
output-error"error"Failed to run …
output-deniednoneDenied …

A tool is a plain TraceLine while it runs, and a TraceCollapsible once its output arrives.

components/ToolLine.vue
<script setup lang="ts">
import { TerminalIcon } from '@lucide/vue'
import { computed } from 'vue'
import { CodeBlock, CodeBlockContent } from '@/components/ui/code-block'
import {
  TraceCollapsible,
  TraceCollapsibleContent,
  TraceCollapsibleTrigger,
  TraceIcon,
  TraceLine,
  TraceTitle,
} from '@/components/ui/trace'

const props = defineProps<{
  part: ToolPart
  streaming: boolean
}>()

const command = computed(() => props.part.input?.command)
const denied = computed(
  () =>
    props.part.state === 'output-denied'
    || (props.part.state === 'approval-responded' && !props.part.approval.approved),
)
const failed = computed(() => props.part.state === 'output-error')
</script>

<template>
  <TraceLine v-if="denied">
    <TraceIcon>
      <TerminalIcon />
    </TraceIcon>
    <TraceTitle>Denied {{ command }}</TraceTitle>
  </TraceLine>
  <TraceCollapsible
    v-else-if="part.state === 'output-available' || part.state === 'output-error'"
  >
    <TraceCollapsibleTrigger>
      <TraceLine :status="failed ? 'error' : undefined">
        <TraceIcon>
          <TerminalIcon />
        </TraceIcon>
        <TraceTitle>{{ failed ? 'Failed to run' : 'Ran' }} {{ command }}</TraceTitle>
      </TraceLine>
    </TraceCollapsibleTrigger>
    <TraceCollapsibleContent>
      <CodeBlock size="sm">
        <CodeBlockContent wrap class="max-h-64">
          {{ part.state === 'output-error' ? part.errorText : part.output.stdout }}
        </CodeBlockContent>
      </CodeBlock>
    </TraceCollapsibleContent>
  </TraceCollapsible>
  <TraceLine v-else :status="streaming ? 'running' : 'error'">
    <TraceIcon>
      <TerminalIcon />
    </TraceIcon>
    <TraceTitle>{{ streaming ? 'Running' : 'Failed to run' }} {{ command }}</TraceTitle>
  </TraceLine>
</template>
<template>
  <Trace>
    <ToolLine
      v-for="part in message.parts.filter(part => part.type === 'tool-runCommand')"
      :key="part.toolCallId"
      :part="part"
      :streaming="streaming"
    />
  </Trace>
</template>

A tool that runs on the client stays input-available after the chat stops until you call addToolOutput. Treat it as waiting, not failed.

Output in a Sheet

For long output, wrap the TraceLine in a SheetTrigger and show the output in the sheet.

<script setup lang="ts">
import { ChevronRightIcon, FileTextIcon } from '@lucide/vue'
import { promiseTimeout, tryOnScopeDispose } from '@vueuse/core'
import { computed, reactive, ref } from 'vue'
import { Bubble, BubbleContent } from '@/components/ui/bubble'
import { Button } from '@/components/ui/button'
import { CodeBlock, CodeBlockContent } from '@/components/ui/code-block'
import { Message, MessageContent } from '@/components/ui/message'
import {
  Sheet,
  SheetContent,
  SheetDescription,
  SheetHeader,
  SheetTitle,
  SheetTrigger,
} from '@/components/ui/sheet'
import {
  Trace,
  TraceIcon,
  TraceLine,
  TraceTitle,
} from '@/components/ui/trace'

interface ToolPart {
  type: 'tool-readFile'
  toolCallId: string
  state: 'input-available' | 'output-available'
  input: { path: string }
  output?: { path: string, content: string }
}

interface TextPart {
  type: 'text'
  text: string
}

interface ChatMessage {
  id: string
  role: 'user' | 'assistant'
  parts: (ToolPart | TextPart)[]
}

const PACKAGE_JSON = `{
  "name": "acme-chat",
  "private": true,
  "dependencies": {
    "@ai-sdk/vue": "^4.0.0",
    "ai": "^7.0.0",
    "nuxt": "^4.2.0"
  }
}`

const QUESTION = 'Which AI SDK version does this app use?'
const ANSWER = 'It uses ai 7 with @ai-sdk/vue 4.'

const messages = ref<ChatMessage[]>([])
const status = ref<'ready' | 'submitted' | 'streaming'>('ready')
const busy = computed(() => status.value !== 'ready')

// Unmounting bumps `run`, so a running script stops at its next wait.
let run = 0
tryOnScopeDispose(() => run++)

async function sleep(ms: number) {
  const id = run
  await promiseTimeout(ms)
  return id === run
}

async function streamInto(target: { text: string }, text: string, delayMs: number) {
  for (const chunk of text.match(/\S+\s*/g) ?? []) {
    target.text += chunk
    if (!(await sleep(delayMs)))
      return false
  }
  return true
}

function getText(message: ChatMessage) {
  return message.parts
    .filter((part): part is TextPart => part.type === 'text')
    .map(part => part.text)
    .join('')
}

function isStreaming(message: ChatMessage) {
  return busy.value && message === messages.value.at(-1)
}

async function send() {
  messages.value = [{ id: 'user', role: 'user', parts: [{ type: 'text', text: QUESTION }] }]
  status.value = 'submitted'
  if (!(await sleep(300)))
    return

  const message = reactive<ChatMessage>({ id: 'assistant', role: 'assistant', parts: [] })
  messages.value.push(message)
  status.value = 'streaming'

  const part = reactive<ToolPart>({
    type: 'tool-readFile',
    toolCallId: 'call-readFile',
    state: 'input-available',
    input: { path: 'package.json' },
  })
  message.parts.push(part)
  if (!(await sleep(900)))
    return
  part.output = { path: 'package.json', content: PACKAGE_JSON }
  part.state = 'output-available'

  const text = reactive<TextPart>({ type: 'text', text: '' })
  message.parts.push(text)
  if (!(await streamInto(text, ANSWER, 20)))
    return
  status.value = 'ready'
}

function reset() {
  messages.value = []
}
</script>

<template>
  <div class="flex min-h-72 w-full max-w-sm flex-col gap-4 py-6 text-sm">
    <template v-for="message in messages" :key="message.id">
      <Message v-if="message.role === 'user'" align="end">
        <MessageContent>
          <Bubble align="end" variant="muted">
            <BubbleContent>{{ getText(message) }}</BubbleContent>
          </Bubble>
        </MessageContent>
      </Message>
      <Message v-else>
        <MessageContent class="gap-4">
          <template v-for="(part, index) in message.parts" :key="index">
            <p v-if="part.type === 'text'">
              {{ part.text }}
            </p>
            <Trace v-else-if="part.state !== 'output-available'">
              <TraceLine :status="isStreaming(message) ? 'running' : 'error'">
                <TraceIcon>
                  <FileTextIcon />
                </TraceIcon>
                <TraceTitle>
                  {{ isStreaming(message) ? 'Reading' : 'Failed to read' }} {{ part.input.path }}
                </TraceTitle>
              </TraceLine>
            </Trace>
            <Trace v-else-if="part.output">
              <Sheet>
                <SheetTrigger>
                  <TraceLine>
                    <TraceIcon>
                      <FileTextIcon />
                    </TraceIcon>
                    <TraceTitle>Read {{ part.output.path }}</TraceTitle>
                    <TraceIcon>
                      <ChevronRightIcon />
                    </TraceIcon>
                  </TraceLine>
                </SheetTrigger>
                <SheetContent>
                  <SheetHeader>
                    <SheetTitle class="font-mono">
                      {{ part.output.path }}
                    </SheetTitle>
                    <SheetDescription>
                      {{ part.output.content.split('\n').length }} lines
                    </SheetDescription>
                  </SheetHeader>
                  <CodeBlock class="mx-6 mb-6 w-auto">
                    <CodeBlockContent line-numbers>
                      {{ part.output.content }}
                    </CodeBlockContent>
                  </CodeBlock>
                </SheetContent>
              </Sheet>
            </Trace>
          </template>
        </MessageContent>
      </Message>
    </template>
    <Button
      v-if="!busy"
      variant="outline"
      size="sm"
      class="mt-auto self-start"
      @click="messages.length === 0 ? send() : reset()"
    >
      {{ messages.length === 0 ? 'Send message' : 'Reset' }}
    </Button>
  </div>
</template>

See Trace.

Approval

A pending approval is a question for the person, not a step the agent took, so it sits outside Trace as an Item. Once the person answers, the tool goes back to being a line. See Confirmation.

<script setup lang="ts">
import { CircleCheckIcon, LoaderCircleIcon, TerminalIcon } from '@lucide/vue'
import { promiseTimeout, tryOnScopeDispose } from '@vueuse/core'
import { computed, reactive, ref } from 'vue'
import { Bubble, BubbleContent } from '@/components/ui/bubble'
import { Button } from '@/components/ui/button'
import {
  Item,
  ItemActions,
  ItemContent,
  ItemDescription,
  ItemMedia,
  ItemTitle,
} from '@/components/ui/item'
import { Message, MessageContent } from '@/components/ui/message'
import {
  Trace,
  TraceCollapsible,
  TraceCollapsibleContent,
  TraceCollapsibleTrigger,
  TraceIcon,
  TraceLine,
  TraceTitle,
} from '@/components/ui/trace'

interface ToolPart {
  type: 'tool-runCommand'
  toolCallId: string
  state: 'approval-requested' | 'approval-responded' | 'output-available' | 'output-denied'
  input: { command: string }
  approval: { id: string, approved?: boolean }
}

interface ReasoningPart {
  type: 'reasoning'
  text: string
  state: 'streaming' | 'done'
}

interface TextPart {
  type: 'text'
  text: string
}

interface ChatMessage {
  id: string
  role: 'user' | 'assistant'
  parts: (ToolPart | ReasoningPart | TextPart)[]
}

const QUESTION = 'Clean up the build folder.'
const REASONING = 'The build output lives in dist. Deleting it cannot be undone, so I should ask before I run the command.'

const messages = ref<ChatMessage[]>([])
const status = ref<'ready' | 'submitted' | 'streaming'>('ready')
const busy = computed(() => status.value !== 'ready')

// The open state of each reasoning line, once the person opens or closes it.
const openState = ref<Record<string, boolean | undefined>>({})

// Unmounting bumps `run`, so a running script stops at its next wait.
let run = 0
tryOnScopeDispose(() => run++)

async function sleep(ms: number) {
  const id = run
  await promiseTimeout(ms)
  return id === run
}

async function streamInto(target: { text: string }, text: string, delayMs: number) {
  for (const chunk of text.match(/\S+\s*/g) ?? []) {
    target.text += chunk
    if (!(await sleep(delayMs)))
      return false
  }
  return true
}

function getText(message: ChatMessage) {
  return message.parts
    .filter((part): part is TextPart => part.type === 'text')
    .map(part => part.text)
    .join('')
}

function isDenied(part: ToolPart) {
  return part.state === 'output-denied'
    || (part.state === 'approval-responded' && !part.approval.approved)
}

async function send() {
  messages.value = [{ id: 'user', role: 'user', parts: [{ type: 'text', text: QUESTION }] }]
  openState.value = {}
  status.value = 'submitted'
  if (!(await sleep(600)))
    return

  const message = reactive<ChatMessage>({ id: 'assistant', role: 'assistant', parts: [] })
  messages.value.push(message)
  status.value = 'streaming'

  const reasoning = reactive<ReasoningPart>({ type: 'reasoning', text: '', state: 'streaming' })
  message.parts.push(reasoning)
  if (!(await streamInto(reasoning, REASONING, 20)))
    return
  reasoning.state = 'done'
  if (!(await sleep(400)))
    return

  message.parts.push({
    type: 'tool-runCommand',
    toolCallId: 'call-runCommand',
    state: 'approval-requested',
    input: { command: 'rm -rf dist' },
    approval: { id: 'approval-runCommand' },
  })
  status.value = 'ready'
}

// Answers the approval, then continues the chat, like
// `sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses`.
async function respond(part: ToolPart, approved: boolean) {
  const message = messages.value.at(-1)!
  part.state = 'approval-responded'
  part.approval.approved = approved
  status.value = 'submitted'
  if (!(await sleep(600)))
    return

  status.value = 'streaming'
  part.state = approved ? 'output-available' : 'output-denied'

  const reply = approved ? 'Removed the dist folder.' : 'Okay, I left the dist folder in place.'
  const text = reactive<TextPart>({ type: 'text', text: '' })
  message.parts.push(text)
  if (!(await streamInto(text, reply, 20)))
    return
  status.value = 'ready'
}

function reset() {
  messages.value = []
}
</script>

<template>
  <div class="flex min-h-72 w-full max-w-sm flex-col gap-4 py-6 text-sm">
    <template v-for="message in messages" :key="message.id">
      <Message v-if="message.role === 'user'" align="end">
        <MessageContent>
          <Bubble align="end" variant="muted">
            <BubbleContent>{{ getText(message) }}</BubbleContent>
          </Bubble>
        </MessageContent>
      </Message>
      <Message v-else>
        <MessageContent class="gap-4">
          <template v-for="(part, index) in message.parts" :key="index">
            <p v-if="part.type === 'text'">
              {{ part.text }}
            </p>
            <Trace v-else-if="part.type === 'reasoning'">
              <TraceCollapsible
                :open="openState[`${message.id}-${index}`] ?? part.state === 'streaming'"
                @update:open="openState[`${message.id}-${index}`] = $event"
              >
                <TraceCollapsibleTrigger>
                  <TraceLine :status="part.state === 'streaming' ? 'running' : undefined">
                    <TraceIcon>
                      <LoaderCircleIcon v-if="part.state === 'streaming'" class="animate-spin" />
                      <CircleCheckIcon v-else />
                    </TraceIcon>
                    <TraceTitle>{{ part.state === 'streaming' ? 'Thinking' : 'Thought' }}</TraceTitle>
                  </TraceLine>
                </TraceCollapsibleTrigger>
                <TraceCollapsibleContent class="whitespace-pre-wrap">
                  {{ part.text }}
                </TraceCollapsibleContent>
              </TraceCollapsible>
            </Trace>
            <!-- A pending approval is a prompt, not activity, so it sits outside Trace. -->
            <Item v-else-if="part.state === 'approval-requested'" variant="outline" size="sm">
              <ItemMedia variant="icon">
                <TerminalIcon />
              </ItemMedia>
              <ItemContent>
                <ItemTitle>Run {{ part.input.command }}?</ItemTitle>
                <ItemDescription>
                  The command runs in this project.
                </ItemDescription>
              </ItemContent>
              <ItemActions>
                <Button size="sm" variant="outline" @click="respond(part, false)">
                  Deny
                </Button>
                <Button size="sm" @click="respond(part, true)">
                  Approve
                </Button>
              </ItemActions>
            </Item>
            <Trace v-else>
              <TraceLine
                :status="!isDenied(part) && part.state !== 'output-available' ? 'running' : undefined"
              >
                <TraceIcon>
                  <TerminalIcon />
                </TraceIcon>
                <TraceTitle>
                  {{ isDenied(part) ? 'Denied' : part.state === 'output-available' ? 'Ran' : 'Running' }}
                  {{ part.input.command }}
                </TraceTitle>
              </TraceLine>
            </Trace>
          </template>
        </MessageContent>
      </Message>
    </template>
    <Button
      v-if="!busy"
      variant="outline"
      size="sm"
      class="mt-auto self-start"
      @click="messages.length === 0 ? send() : reset()"
    >
      {{ messages.length === 0 ? 'Send message' : 'Reset' }}
    </Button>
  </div>
</template>
<template>
  <Item v-if="part.state === 'approval-requested'" variant="outline" size="sm">
    <ItemMedia variant="icon">
      <TerminalIcon />
    </ItemMedia>
    <ItemContent>
      <ItemTitle>Run {{ part.input.command }}?</ItemTitle>
    </ItemContent>
    <ItemActions>
      <Button
        size="sm"
        variant="outline"
        @click="chat.addToolApprovalResponse({ id: part.approval.id, approved: false })"
      >
        Deny
      </Button>
      <Button
        size="sm"
        @click="chat.addToolApprovalResponse({ id: part.approval.id, approved: true })"
      >
        Approve
      </Button>
    </ItemActions>
  </Item>
</template>

Pass sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses to the Chat so the chat continues once every approval has an answer.

Migrating from AI Elements Vue

If you added Tool from AI Elements Vue, your project has a components/ai-elements/tool/ folder. Paste this prompt into your coding agent to rebuild it on Trace and Code Block. Every export keeps its name and props, so the code that uses it keeps working.

Migrate components/ai-elements/tool/ from AI Elements Vue to the shadcn-vue Trace and Code Block components.

Keep every export, with the same name, props and emits, so the code that imports it keeps working. Only change how each part renders.

1. Install the components: npx shadcn-vue@latest add trace code-block
2. Read https://www.shadcn-vue.com/docs/ai-elements/tool and build Tool the same way.
3. Rebuild each part:
   - Import CodeBlock and CodeBlockContent from @/components/ui/code-block, not from ../code-block.
   - Tool.vue renders a Trace with a TraceCollapsible.
   - ToolHeader.vue renders a TraceCollapsibleTrigger with a TraceLine, a TraceIcon and a TraceTitle, instead of a status Badge. Map state to the status and title: "running" and "Running …" while the input streams or is available, no status and "Ran …" for output-available, "error" and "Failed to run …" for output-error, and "Denied …" for output-denied.
   - ToolContent.vue renders a TraceCollapsibleContent.
   - ToolInput.vue and ToolOutput.vue render a CodeBlock with size="sm" and a CodeBlockContent. ToolOutput shows errorText when the tool failed.
   - Keep getStatusBadge and the ToolPart type exported, even if nothing renders the badge.
4. Remove the imports the files no longer use.
5. Run vue-tsc and fix any errors.

API Reference

See Trace.