본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

ChatReasoning

원문 보기 위키 갱신

접을 수 있는(collapsible) AI 추론·사고 과정을 표시하는 컴포넌트예요. 스트리밍 중에는 자동으로 열리고, 끝나면 자동으로 닫혀요.

출처: Nuxt UI

본문

AI 추론이나 사고 내용을 표시하는 접을 수 있는 블록을 렌더링해요. 스트리밍 중에는 자동으로 열리고 끝나면 자동으로 닫혀요.

사용법

ChatReasoning 컴포넌트는 AI 추론·사고 내용을 표시하는 접을 수 있는 블록을 렌더링해요. 스트리밍 중에는 자동으로 열리고 끝나면 자동으로 닫혀요.

<script setup lang="ts">
const streaming = ref(false)
const text = ref('')

async function simulateStreaming() {
  streaming.value = true
  text.value = ''

  const content = 'The user is asking about Vue components. I should explain the Composition API pattern and how it relates to their question about reactive state management. Let me think about the best way to structure this response.\n\nFirst, I need to consider the key differences between the Options API and Composition API. The Composition API was introduced in Vue 3 to address limitations of the Options API when building large-scale applications.\n\nFor reactive state management specifically, the Composition API offers ref() for primitive values and reactive() for objects.'

  for (const char of content) {
    text.value += char
    await new Promise(resolve => setTimeout(resolve, 10))
  }

  streaming.value = false
}

onMounted(simulateStreaming)
</script>

<template>
  <UChatReasoning
    :text="text"
    :streaming="streaming"
    class="w-60"
  />
</template>

[!NOTE] See: /docs/composables/use-scroll-shadow

The body content uses the useScrollShadow composable to apply fade shadows when overflowing.

본문 콘텐츠는 useScrollShadow 컴포저블을 사용해서 넘칠 때 페이드(fade) 그림자를 적용해요.

텍스트 (Text)

text prop으로 추론 내용을 설정할 수 있어요. 텍스트는 접히는 본문 안쪽에 표시돼요.

<template>
  <UChatReasoning text="The user is asking about Vue components..." />
</template>

스트리밍 (Streaming)

streaming prop으로 활발한 추론 상태를 표시할 수 있어요. 스트리밍이 시작되면 컴포넌트가 자동으로 열리고, 끝나면 자동으로 닫혀요.

<template>
  <UChatReasoning streaming text="The user is asking about Vue components..." />
</template>

[!TIP]

Use the isPartStreaming utility from @nuxt/ui/utils/ai to determine if a part is currently being streamed.

현재 파트가 스트리밍 중인지 판별하려면 @nuxt/ui/utils/ai의 isPartStreaming 유틸리티를 쓰면 돼요.

샤이머 (Shimmer)

스트리밍 중에는 트리거 라벨이 ChatShimmer 컴포넌트를 사용해요. shimmer prop으로 그 duration과 spread를 커스터마이징할 수 있어요.

<template>
  <UChatReasoning streaming text="The user is asking about Vue components..." :shimmer="{
  duration: 2,
  spread: 2
}" />
</template>

아이콘 (Icon)

icon prop으로 트리거 옆에 Icon 컴포넌트를 표시할 수 있어요.

<template>
  <UChatReasoning icon="i-lucide-brain" text="The user is asking about Vue components..." />
</template>

셰브론 (Chevron)

chevron prop으로 셰브론 아이콘의 위치를 바꿀 수 있어요.

[!NOTE]

When chevron is set to leading with an icon, the icon swaps with the chevron on hover and when open.

chevron을 leading으로 설정하고 icon이 있으면, 호버(hover)할 때와 열릴 때 아이콘이 셰브론과 자리를 바꿔요.

<template>
  <UChatReasoning chevron="leading" icon="i-lucide-brain" text="The user is asking about Vue components..." />
</template>

셰브론 아이콘 (Chevron Icon)

chevron-icon prop으로 셰브론 Icon을 커스터마이징할 수 있어요. 기본값은 i-lucide-chevron-down이에요.

<template>
  <UChatReasoning chevron-icon="i-lucide-arrow-down" text="The user is asking about Vue components..." />
</template>

Nuxt:

[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme

You can customize this icon globally in your app.config.ts under ui.icons.chevronDown key.

app.config.ts의 ui.icons.chevronDown 키에서 이 아이콘을 전역으로 커스터마이징할 수 있어요.

Vue:

[!TIP] See: /docs/getting-started/integrations/icons/vue#theme

You can customize this icon globally in your vite.config.ts under ui.icons.chevronDown key.

vite.config.ts의 ui.icons.chevronDown 키에서 이 아이콘을 전역으로 커스터마이징할 수 있어요.

예시 (Examples)

[!TIP] See: /docs/components/chat

Check the Chat overview page for installation instructions, server setup and usage examples.

설치 방법, 서버 설정, 사용 예시는 Chat 개요 페이지에서 확인하세요.

API

Props

/**
 * Props for the ChatReasoning component
 */
interface ChatReasoningProps {
  /**
   * The reasoning text content to display.
   */
  text?: string | undefined;
  /**
   * Whether the reasoning content is currently streaming.
   * @default false
   */
  streaming?: boolean | undefined;
  /**
   * The duration in seconds that the AI spent reasoning.
   * If not provided, it will be calculated automatically based on streaming time.
   */
  duration?: number | undefined;
  /**
   * The icon displayed next to the trigger.
   */
  icon?: any;
  /**
   * The position of the chevron icon.
   * @default 'trailing'
   */
  chevron?: "trailing" | "leading" | undefined;
  /**
   * The icon displayed as the chevron.
   * @default appConfig.ui.icons.chevronDown
   */
  chevronIcon?: any;
  /**
   * The delay in milliseconds before auto-closing when streaming ends.
   * Set to `0` to disable auto-close.
   * @default 500
   */
  autoCloseDelay?: number | undefined;
  /**
   * Customize the [`ChatShimmer`](https://ui.nuxt.com/docs/components/chat-shimmer) component when streaming.
   */
  shimmer?: Partial<Omit<ChatShimmerProps, "text">> | undefined;
  ui?: { root?: SlotClass; trigger?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; chevronIcon?: SlotClass; label?: SlotClass; trailingIcon?: SlotClass; content?: SlotClass; body?: SlotClass; } | undefined;
  /**
   * When `true`, prevents the user from interacting with the collapsible.
   */
  disabled?: boolean | undefined;
  /**
   * The controlled open state of the collapsible. Can be binded with `v-model`.
   * @default undefined
   */
  open?: boolean | undefined;
  /**
   * The open state of the collapsible when it is initially rendered. <br> Use when you do not need to control its open state.
   */
  defaultOpen?: boolean | undefined;
  /**
   * When `true`, the element will be unmounted on closed state.
   * @default false
   */
  unmountOnHide?: boolean | undefined;
}

Slots

/**
 * Slots for the ChatReasoning component
 */
interface ChatReasoningSlots {
  default(): any;
}

Emits

/**
 * Emitted events for the ChatReasoning component
 */
interface ChatReasoningEmits {
  update:open: (payload: [value: boolean]) => void;
}

테마 (Theme)

export default defineAppConfig({
  ui: {
    chatReasoning: {
      slots: {
        root: '',
        trigger: [
          'group flex w-full items-center gap-1.5 text-muted text-sm disabled:cursor-default disabled:hover:text-muted hover:text-default rounded-sm outline-primary/25 focus-visible:outline-3 min-w-0',
          'transition-colors'
        ],
        leading: 'relative size-4 shrink-0',
        leadingIcon: 'size-4 shrink-0',
        chevronIcon: 'size-4 shrink-0 group-data-[state=open]:rotate-180 transition-transform duration-200 ease-out motion-reduce:transition-none',
        label: 'truncate',
        trailingIcon: 'size-4 shrink-0 group-data-[state=open]:rotate-180 transition-transform duration-200 ease-out motion-reduce:transition-none',
        content: 'data-[state=open]:animate-[collapsible-down_200ms_var(--ease-out)] data-[state=closed]:animate-[collapsible-up_200ms_var(--ease-out)] data-[state=closed]:overflow-hidden rounded-sm outline-primary/25 has-focus-visible:outline-3',
        body: 'max-h-[200px] pt-2 overflow-y-auto text-sm text-dimmed whitespace-pre-wrap focus:outline-none'
      },
      variants: {
        chevron: {
          leading: {
            leadingIcon: 'group-hover:opacity-0'
          },
          trailing: ''
        },
        alone: {
          false: {
            leadingIcon: [
              'absolute inset-0 group-data-[state=open]:opacity-0',
              'transition-opacity duration-200 ease-out'
            ],
            chevronIcon: [
              'absolute inset-0 opacity-0 group-hover:opacity-100 group-data-[state=open]:opacity-100',
              'transition-[rotate,opacity] duration-200 ease-out motion-reduce:transition-none'
            ]
          }
        }
      }
    }
  }
})

변경 이력 (Changelog)

컴포넌트와 테마의 커밋 히스토리를 참고하세요.


더 알아보기 (Learn more)