Files
learn-ai/frontend/src/components/agent/ToolCallDisplay.vue
T

68 lines
2.2 KiB
Vue
Raw Normal View History

2026-02-06 15:57:21 +08:00
<template>
<div class="mt-2 space-y-2">
<div
v-for="(call, index) in toolCalls"
:key="index"
class="rounded-lg border bg-muted/30 p-3 text-xs shadow-sm transition-all hover:bg-muted/50"
>
<div class="flex items-center justify-between mb-2">
<div class="flex items-center gap-2 font-semibold text-foreground/80">
<Terminal class="h-3.5 w-3.5 text-blue-500" />
<span>{{ getToolName(call.name) }}</span>
</div>
<div v-if="call.result" class="flex items-center gap-1 text-green-600 dark:text-green-400">
<CheckCircle2 class="h-3 w-3" />
<span>已完成</span>
</div>
<div v-else class="flex items-center gap-1 text-amber-500 animate-pulse">
<Loader2 class="h-3 w-3 animate-spin" />
<span>执行中...</span>
</div>
</div>
<div class="space-y-2">
<div class="space-y-1">
<p class="text-[10px] uppercase tracking-wider text-muted-foreground font-bold">参数 (Arguments)</p>
<pre class="overflow-x-auto rounded bg-background/50 p-2 font-mono leading-relaxed">{{ formatJson(call.arguments) }}</pre>
</div>
<div v-if="call.result" class="space-y-1">
<p class="text-[10px] uppercase tracking-wider text-muted-foreground font-bold">结果 (Result)</p>
<pre class="overflow-x-auto rounded bg-background/50 p-2 font-mono leading-relaxed max-h-32">{{ formatJson(call.result) }}</pre>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { Terminal, CheckCircle2, Loader2 } from 'lucide-vue-next'
interface Props {
toolCalls: Array<{
name: string;
arguments: any;
result?: any;
}>;
}
defineProps<Props>()
const toolNameMap: Record<string, string> = {
searchArticles: '搜索资讯库',
analyzeReport: '深度分析报告',
webSearch: '互联网实时搜索',
}
function getToolName(name: string): string {
return toolNameMap[name] || name
}
function formatJson(obj: any): string {
try {
return typeof obj === 'string' ? JSON.stringify(JSON.parse(obj), null, 2) : JSON.stringify(obj, null, 2)
} catch {
return String(obj)
}
}
</script>