|
| 1 | +<!-- StatusBadge.vue --> |
| 2 | +<script setup lang="ts"> |
| 3 | +import type { ToolUIPart } from 'ai' |
| 4 | +import type { Component } from 'vue' |
| 5 | +import { Badge } from '@repo/shadcn-vue/components/ui/badge' |
| 6 | +import { |
| 7 | + CheckCircleIcon, |
| 8 | + CircleIcon, |
| 9 | + ClockIcon, |
| 10 | + XCircleIcon, |
| 11 | +} from 'lucide-vue-next' |
| 12 | +import { computed } from 'vue' |
| 13 | +
|
| 14 | +const props = defineProps<{ |
| 15 | + state: ToolUIPart['state'] |
| 16 | +}>() |
| 17 | +
|
| 18 | +const label = computed(() => { |
| 19 | + const labels: Record<ToolUIPart['state'], string> = { |
| 20 | + 'input-streaming': 'Pending', |
| 21 | + 'input-available': 'Running', |
| 22 | + 'approval-requested': 'Awaiting Approval', |
| 23 | + 'approval-responded': 'Responded', |
| 24 | + 'output-available': 'Completed', |
| 25 | + 'output-error': 'Error', |
| 26 | + 'output-denied': 'Denied', |
| 27 | + } |
| 28 | + return labels[props.state] |
| 29 | +}) |
| 30 | +
|
| 31 | +const icon = computed<Component>(() => { |
| 32 | + const icons: Record<ToolUIPart['state'], Component> = { |
| 33 | + 'input-streaming': CircleIcon, |
| 34 | + 'input-available': ClockIcon, |
| 35 | + 'approval-requested': ClockIcon, |
| 36 | + 'approval-responded': CheckCircleIcon, |
| 37 | + 'output-available': CheckCircleIcon, |
| 38 | + 'output-error': XCircleIcon, |
| 39 | + 'output-denied': XCircleIcon, |
| 40 | + } |
| 41 | + return icons[props.state] |
| 42 | +}) |
| 43 | +
|
| 44 | +const iconClass = computed(() => { |
| 45 | + const classes: Record<string, boolean> = { |
| 46 | + 'size-4': true, |
| 47 | + 'animate-pulse': props.state === 'input-available', |
| 48 | + 'text-yellow-600': props.state === 'approval-requested', |
| 49 | + 'text-blue-600': props.state === 'approval-responded', |
| 50 | + 'text-green-600': props.state === 'output-available', |
| 51 | + 'text-red-600': props.state === 'output-error', |
| 52 | + 'text-orange-600': props.state === 'output-denied', |
| 53 | + } |
| 54 | + return classes |
| 55 | +}) |
| 56 | +</script> |
| 57 | + |
| 58 | +<template> |
| 59 | + <Badge class="gap-1.5 rounded-full text-xs" variant="secondary"> |
| 60 | + <component :is="icon" :class="iconClass" /> |
| 61 | + <span>{{ label }}</span> |
| 62 | + </Badge> |
| 63 | +</template> |
0 commit comments